Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.ColumnMetaData


        }
       
        // If there is a discriminator column add that too
        if (cmd.getSuperAbstractClassMetaData() == null && cmd.getDiscriminatorMetaData() != null
                && cmd.getDiscriminatorMetaData().getColumnMetaData() != null) {
            ColumnMetaData colmd = cmd.getDiscriminatorMetaData().getColumnMetaData();
            addFieldToListIfAbsent(new ForceMemberMetaData(colmd, colmd.getName()) {
                @Override
                public Class<?> getType() {
                    return String.class;
                }
            }, storeManager);
View Full Code Here


                AbstractClassMetaData relatedClass = ammd.getType() != null
                        ? storeManager.getMetaDataManager().getMetaDataForClass(ammd.getType(),
                                storeManager.getOMFContext().getClassLoaderResolver(null)) : null;
                // Try the first column if specified
                ColumnMetaData[] colmds = ammd.getColumnMetaData();
                ColumnMetaData colmd = null;
                FieldType type = PersistenceUtils.getFieldTypeFromForceAnnotation(extensions);
                Integer scale = getIntegerFromForceAnnotation(extensions, "scale");
                Integer precision = getIntegerFromForceAnnotation(extensions, "precision");
                Integer length = getIntegerFromForceAnnotation(extensions, "length");
                Integer startValue = getIntegerFromForceAnnotation(extensions, "startValue");
                boolean enableFeeds = getBooleanFromForceAnnotation(extensions, "enableFeeds");
                boolean externalId = getBooleanFromForceAnnotation(extensions, "externalId");
                String childRelationshipName = extensions.get("childRelationshipName");
                String label = extensions.get("label");
                String description = extensions.get("description");
                String formula = extensions.get("formula");
                TreatBlanksAs treatBlanksAs = getTreatBlanksAsFromForceAnnotation(extensions);
                boolean allowNulls = true;
                boolean unique = false;
                if (colmds != null && colmds.length > 0) {
                    colmd = colmds[0];
                    if (type == null) {
                        type = getFieldType(colmd, ammd);
                    }
                    if (precision == null) {
                        scale = colmd.getScale();
                        precision = colmd.getLength();
                    }
                    if (length == null) {
                        length = colmd.getLength();
                    }
                    allowNulls = colmd.getAllowsNull();
                    if (!allowNulls) {
                        // Too bad DataNucleus tries to be smart and add this annotation for various types.
                        // So, we go back to the actual annotations and make sure the user actually added
                        // the @Column(nullable=true)
                        Column columnAnnotation = PersistenceUtils.getMemberAnnotation(ammd.getMemberRepresented(), Column.class);
                        if (columnAnnotation != null) {
                            allowNulls = columnAnnotation.nullable();
                        } else {
                            allowNulls = true;
                        }
                    }
                    unique = colmd.getUnique();
                }
               
                if (startValue != null && type != FieldType.AutoNumber) {
                    throw new NucleusUserException("startValue attribute is only supported for AutoNumber fields types,"
                                                    + " field: " + ammd.getName()
View Full Code Here

    AbstractMemberMetaData fmd = mapping.getMemberMetaData();
    int roleForField = mapping.getRoleForMember();
    DatastoreContainerObject datastoreContainer = mapping.getDatastoreContainer();

    // Take the column MetaData from the component that this mappings role relates to
    ColumnMetaData colmd;
    ColumnMetaDataContainer columnContainer = fmd;
    if (roleForField == FieldRole.ROLE_COLLECTION_ELEMENT ||
        roleForField == FieldRole.ROLE_ARRAY_ELEMENT) {
      columnContainer = fmd.getElementMetaData();
    } else if (roleForField == FieldRole.ROLE_MAP_KEY) {
      columnContainer = fmd.getKeyMetaData();
    } else if (roleForField == FieldRole.ROLE_MAP_VALUE) {
      columnContainer = fmd.getValueMetaData();
    }

    DatastoreProperty prop;
    ColumnMetaData[] colmds;
    if (columnContainer != null
        && columnContainer.getColumnMetaData() != null
        && columnContainer.getColumnMetaData().length > datastoreFieldIndex) {
      colmd = columnContainer.getColumnMetaData()[datastoreFieldIndex];
      colmds = columnContainer.getColumnMetaData();
    } else {
      // If column specified add one (use any column name specified on field element)
      colmd = new ColumnMetaData();
      colmd.setName(fmd.getColumn());
      if (columnContainer != null) {
        columnContainer.addColumn(colmd);
        colmds = columnContainer.getColumnMetaData();
      } else {
        colmds = new ColumnMetaData[1];
        colmds[0] = colmd;
      }
    }

    // Generate the column identifier
    MappedStoreManager storeMgr = datastoreContainer.getStoreManager();
    IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
    DatastoreIdentifier identifier = null;
    if (colmd.getName() == null) {
      // No name specified, so generate the identifier from the field name
      if (roleForField == FieldRole.ROLE_FIELD) {
        identifier = idFactory.newIdentifier(IdentifierType.COLUMN, fmd.getName());
        int i = 0;
        while (datastoreContainer.hasDatastoreField(identifier)) {
          identifier = idFactory.newIdentifier(IdentifierType.COLUMN, fmd.getName() + "_" + i);
          i++;
        }
      } else if (roleForField == FieldRole.ROLE_COLLECTION_ELEMENT) {
        // Join table collection element
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_COLLECTION_ELEMENT);
      } else if (roleForField == FieldRole.ROLE_ARRAY_ELEMENT) {
        // Join table array element
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_ARRAY_ELEMENT);
      } else if (roleForField == FieldRole.ROLE_MAP_KEY) {
        // Join table map key
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_MAP_KEY);
      } else if (roleForField == FieldRole.ROLE_MAP_VALUE) {
        // Join table map value
        identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null, true,
            FieldRole.ROLE_MAP_VALUE);
      }

      colmd.setName(identifier.getIdentifierName());
    } else {
      // User has specified a name, so try to keep this unmodified
      identifier = idFactory.newDatastoreFieldIdentifier(colmds[datastoreFieldIndex].getName(),
          storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
          FieldRole.ROLE_CUSTOM);
    }

    // Create the column
    prop = (DatastoreProperty) datastoreContainer.addDatastoreField(javaType, identifier, mapping, colmd);

    if (fmd.isPrimaryKey()) {
      prop.setAsPrimaryKey();
    }

//    setDatastoreFieldNullability(fmd, colmd, col);
    if (fmd.getNullValue() == NullValue.DEFAULT) {
      // Users default should be applied if a null is to be inserted
      prop.setDefaultable();
      if (colmd.getDefaultValue() != null) {
        throw new UnsupportedOperationException("User-defined default not supported.");
      }
    }

    return prop;
View Full Code Here

    MappedStoreManager storeMgr = datastoreContainer.getStoreManager();

    DatastoreField prop;
    if (colmd == null) {
      // If column specified add one (use any column name specified on field element)
      colmd = new ColumnMetaData();
      colmd.setName(fmd.getColumn());
      fmd.addColumn(colmd);
    }

    IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
View Full Code Here

    this.storeMgr = table.getStoreManager();

    setIdentifier(identifier);
    if (colmd == null) {
      // Create a default ColumnMetaData since none provided
      columnMetaData = new ColumnMetaData();
    } else {
      columnMetaData = colmd;
    }

    // Uniqueness
View Full Code Here

      AbstractClassMetaData cmd) {
    datastoreIDMapping = new OIDMapping();
    datastoreIDMapping.initialize(dba, cmd.getFullClassName());

    // Create a ColumnMetaData in the container if none is defined
    ColumnMetaData colmd;
    if (columnContainer == null) {
      colmd = new ColumnMetaData();
    } else if (columnContainer.getColumnMetaData().length < 1) {
      colmd = new ColumnMetaData();
    } else {
      colmd = columnContainer.getColumnMetaData()[0];
    }
    if (colmd.getName() == null) {
      // Provide default column naming if none is defined
      if (refTable != null) {
        colmd.setName(storeMgr.getIdentifierFactory()
            .newDatastoreFieldIdentifier(refTable.getIdentifier().getIdentifierName(),
                this.storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(OID.class),
                FieldRole.ROLE_OWNER).getIdentifierName());
      } else {
        colmd.setName(
            storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(identifier.getIdentifierName(),
                this.storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(OID.class),
                FieldRole.ROLE_NONE).getIdentifierName());
      }
    }

    // Add the datastore identity column as the PK
    DatastoreField idColumn = addDatastoreField(OID.class.getName(),
        storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.COLUMN, colmd.getName()),
        datastoreIDMapping, colmd);
    idColumn.setAsPrimaryKey();

    // Set the identity column type based on the IdentityStrategy
    String strategyName = cmd.getIdentityMetaData().getValueStrategy().toString();
View Full Code Here

      return ammd.getElementMetaData().getColumnMetaData()[0];
    }
    return null;
  }
  private boolean isInsertable(AbstractMemberMetaData ammd) {
    ColumnMetaData cmd = getColumnMetaData(ammd);
    return cmd == null || cmd.getInsertable();
  }
View Full Code Here

    ColumnMetaData cmd = getColumnMetaData(ammd);
    return cmd == null || cmd.getInsertable();
  }

  private boolean isUpdatable(AbstractMemberMetaData ammd) {
    ColumnMetaData cmd = getColumnMetaData(ammd);
    return cmd == null || cmd.getUpdateable();
  }
View Full Code Here

                pushStack(collmd);
            }
            else if (localName.equals("column"))
            {
                MetaData md = getStack();
                ColumnMetaData colmd = new ColumnMetaData();
                colmd.setName(getAttr(attrs,"name"));
                colmd.setTarget(getAttr(attrs,"target"));
                colmd.setTargetMember(getAttr(attrs,"target-field"));
                colmd.setJdbcType(getAttr(attrs,"jdbc-type"));
                colmd.setSqlType(getAttr(attrs,"sql-type"));
                colmd.setLength(getAttr(attrs,"length"));
                colmd.setScale(getAttr(attrs,"scale"));
                colmd.setAllowsNull(getAttr(attrs,"allows-null"));
                colmd.setDefaultValue(getAttr(attrs,"default-value"));
                colmd.setInsertValue(getAttr(attrs,"insert-value"));
                if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.addColumn(colmd);
                }
View Full Code Here

    /* (non-Javadoc)
     * @see javax.jdo.metadata.ComponentMetadata#newColumnMetadata()
     */
    public ColumnMetadata newColumnMetadata()
    {
        ColumnMetaData internalColmd = getInternal().newUnmappedColumnMetaData();
        ColumnMetadataImpl colmd = new ColumnMetadataImpl(internalColmd);
        colmd.parent = this;
        return colmd;
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.metadata.ColumnMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.