Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.ColumnMetaData


          m = storeMgr.getMappingManager()
              .getMapping(clr.classForName(refColumn.getJavaTypeMapping().getType()));
          ((PersistenceCapableMapping) masterMapping).addJavaTypeMapping(m);
        }

        ColumnMetaData userdefinedColumn = null;
        if (userdefinedCols != null) {
          for (ColumnMetaData userdefinedCol : userdefinedCols) {
            if (refColumn.getIdentifier().toString().equals(userdefinedCol.getTarget())) {
              userdefinedColumn = userdefinedCol;
              break;
            }
          }
          if (userdefinedColumn == null && nextUserdefinedCol < userdefinedCols.length) {
            userdefinedColumn = userdefinedCols[nextUserdefinedCol++];
          }
        }

        // Add this application identity column
        DatastoreField idColumn;
        if (userdefinedColumn != null) {
          // User has provided a name for this column
          // Currently we only use the column namings from the users definition but we could easily
          // take more of their details.
          idColumn = addDatastoreField(refColumn.getStoredJavaType(),
              storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.COLUMN,
                  userdefinedColumn.getName()),
              m, refColumn.getColumnMetaData());
        } else {
          // No name provided so take same as superclass
          idColumn = addDatastoreField(refColumn.getStoredJavaType(), refColumn.getIdentifier(),
              m, refColumn.getColumnMetaData());
View Full Code Here


          int countIdFields = ownerIdMapping.getNumberOfDatastoreFields();
          for (int i = 0; i < countIdFields; i++) {
            DatastoreMapping refDatastoreMapping = ownerIdMapping.getDataStoreMapping(i);
            JavaTypeMapping mapping = storeMgr.getMappingManager()
                    .getMapping(refDatastoreMapping.getJavaTypeMapping().getJavaType());
            ColumnMetaData colmd = correspondentColumnsMapping.getColumnMetaDataByIdentifier(
                    refDatastoreMapping.getDatastoreField().getIdentifier());
            if (colmd == null) {
              throw new FatalNucleusUserException(
                  String.format("Primary Key column \"%s\" for table \"%s\" is not mapped.",
                  refDatastoreMapping.getDatastoreField().getIdentifier(),
                  toString()));
            }

            DatastoreIdentifier identifier;
            IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
            if (colmd.getName() == null || colmd.getName().length() < 1) {
              // No user provided name so generate one
              identifier = idFactory.newForeignKeyFieldIdentifier(
                  ownerFmd, null, refDatastoreMapping.getDatastoreField().getIdentifier(),
                  storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(mapping.getJavaType()),
                  FieldRole.ROLE_OWNER);
            } else {
              // User-defined name
              identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName());
            }
            // When we have an inherited relationship we end up
            // trying to add an owner property twice - once from the super-class
            // and once from the sub-class.  This generates an exception for
            // duplicate property names.  To avoid this we check to see if
            // the table already has a property with this name before attempting
            // to add the mapping
            if (!datastorePropertiesByName.containsKey(identifier.getIdentifierName())) {
              DatastoreProperty refColumn =
                  addDatastoreField(mapping.getJavaType().getName(), identifier, mapping, colmd);
              refDatastoreMapping.getDatastoreField().copyConfigurationTo(refColumn);

              if ((colmd.getAllowsNull() == null) ||
                  (colmd.getAllowsNull() != null && colmd.isAllowsNull())) {
                // User either wants it nullable, or havent specified anything, so make it nullable
                refColumn.setNullable();
              }
              AbstractClassMetaData acmd =
                  storeMgr.getMetaDataManager().getMetaDataForClass(ownerIdMapping.getType(), clr);
              // this is needed for one-to-many sets
              addOwningClassMetaData(colmd.getName(), acmd);
              fkMapping.addDataStoreMapping(getStoreManager().getMappingManager()
                  .createDatastoreMapping(mapping, refColumn,
                                          refDatastoreMapping.getJavaTypeMapping().getJavaType().getName()));
              ((PersistenceCapableMapping) fkMapping).addJavaTypeMapping(mapping);
            }
View Full Code Here

    Class indexType = Integer.class;
    JavaTypeMapping indexMapping = new IndexMapping();
    indexMapping.initialize(dba, indexType.getName());
    IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
    DatastoreIdentifier indexColumnName = null;
    ColumnMetaData colmd = null;

    // Allow for any user definition in OrderMetaData
    OrderMetaData omd = fmd.getOrderMetaData();
    if (omd != null) {
      colmd =
          (omd.getColumnMetaData() != null && omd.getColumnMetaData().length > 0 ? omd
              .getColumnMetaData()[0] : null);
      if (omd.getMappedBy() != null) {
        // User has defined ordering using the column(s) of an existing field.
        JavaTypeMapping orderMapping = getMemberMapping(omd.getMappedBy());
        if (orderMapping == null) {
          throw new NucleusUserException(String.format(
              "Field \"{0}\" has an <order> defined to be persisted into the columns in the element table for element field \"{1}\". This field is not found in the element class.",
              fmd.getFullFieldName(), omd.getMappedBy()));
        }
        if (!(orderMapping instanceof IntegerMapping) && !(orderMapping instanceof LongMapping)) {
          throw new NucleusUserException(
              String.format(
                  "Field \"{0}\" has an <order> defined to be persisted into the column of field \"{1}\". This field is of an invalid type. Must be an int/Integer.",
                  fmd.getFullFieldName(), omd.getMappedBy()));
        }
        return orderMapping;
      }

      String colName;
      if (omd.getColumnMetaData() != null && omd.getColumnMetaData().length > 0
          && omd.getColumnMetaData()[0].getName() != null) {
        // User-defined name so create an identifier using it
        colName = omd.getColumnMetaData()[0].getName();
        indexColumnName = idFactory.newDatastoreFieldIdentifier(colName);
      }
    }
    if (indexColumnName == null) {
      // No name defined so generate one
      indexColumnName = idFactory.newForeignKeyFieldIdentifier(
          fmd, null, null,
          storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(indexType),
          FieldRole.ROLE_INDEX);
    }

    // if the relationship is in a base class with multiple subclasses, each
    // subclass will try to add the index column.  We need to avoid adding
    // the same column twice.
    DatastoreField column = datastorePropertiesByName.get(indexColumnName.getIdentifierName());
    if (column == null) {
      column = addDatastoreField(indexType.getName(), indexColumnName, indexMapping, colmd);
    }
    if (colmd == null || (colmd.getAllowsNull() == null) ||
        (colmd.getAllowsNull() != null && colmd.isAllowsNull())) {
      // User either wants it nullable, or havent specified anything, so make it nullable
      column.setNullable();
    }

    DatastoreFKMapping fkMapping =
View Full Code Here

                    new CorrespondentColumnsMapper(columnContainer, columnMetaData, m, true);
                for (int i=0; i<m.getNumberOfDatastoreFields(); i++)
                {
                    JavaTypeMapping refDatastoreMapping =
                        storeMgr.getMappingManager().getMapping(m.getDataStoreMapping(i).getJavaTypeMapping().getJavaType());
                    ColumnMetaData colmd = correspondentColumnsMapping.getColumnMetaDataByIdentifier(
                        m.getDataStoreMapping(i).getDatastoreField().getIdentifier());
                    try
                    {
                        DatastoreIdentifier identifier = null;
                        if (colmd.getName() == null)
                        {
                            // User hasn't provided a name, so we use default naming
                            if (isReferenceField)
                            {
                                // Create reference identifier
                                identifier = idFactory.newReferenceFieldIdentifier(mmd,
                                    storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(javaType, clr),
                                    m.getDataStoreMapping(i).getDatastoreField().getIdentifier(),
                                    storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(javaType), fieldRole);
                            }
                            else
                            {
                                // Create join table identifier (FK using destination table identifier)
                                AbstractMemberMetaData[] relatedMmds = mmd.getRelatedMemberMetaData(clr);
                                // TODO Cater for more than 1 related field
                                identifier = idFactory.newJoinTableFieldIdentifier(mmd,
                                    relatedMmds != null ? relatedMmds[0] : null,
                                    m.getDataStoreMapping(i).getDatastoreField().getIdentifier(),
                                    storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(javaType), fieldRole);
                            }
                        }
                        else
                        {
                            // User defined name, so we use that.
                            identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName());
                        }

                        // Only add the column if not currently present
                        DatastoreField column = table.addDatastoreField(javaType.getName(), identifier, refDatastoreMapping, colmd);
                        m.getDataStoreMapping(i).getDatastoreField().copyConfigurationTo(column);
                        if (isPrimaryKey)
                        {
                            column.setAsPrimaryKey();
                        }
                        if (isNullable)
                        {
                            column.setNullable();
                        }

                        storeMgr.getMappingManager().createDatastoreMapping(refDatastoreMapping, column,
                            m.getDataStoreMapping(i).getJavaTypeMapping().getJavaTypeForDatastoreMapping(i));
                    }
                    catch (DuplicateDatastoreFieldException ex)
                    {
                      throw new NucleusUserException("Cannot create column for field "+mmd.getFullFieldName()+" column metadata "+colmd,ex);
                    }
                    ((PersistenceCapableMapping) container).addJavaTypeMapping(refDatastoreMapping);
                }
            }
        }
        else
        {
            // Non-PC mapping
            // Add column for the field
            DatastoreField column = null;
            ColumnMetaData colmd = null;
            if (columnMetaData != null && columnMetaData.length > 0)
            {
                colmd = columnMetaData[0];
            }

            DatastoreIdentifier identifier = null;
            if (colmd != null && colmd.getName() != null)
            {
                // User specified name
                identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName());
            }
            else
            {
                // No user-supplied name so generate one
                identifier = idFactory.newJoinTableFieldIdentifier(mmd, null, null,
View Full Code Here

                // Create physical datastore columns where we require a FK link to the related table.
                if (createDatastoreMappings)
                {
                    // Find the Column MetaData that maps to the referenced datastore field
                    ColumnMetaData colmd = correspondentColumnsMapping.getColumnMetaDataByIdentifier(
                        refDatastoreMapping.getDatastoreField().getIdentifier());
                    if (colmd == null)
                    {
                        throw new NucleusUserException(LOCALISER.msg("041038",
                            refDatastoreMapping.getDatastoreField().getIdentifier(), toString())).setFatal();
View Full Code Here

                    throw new NucleusUserException(LOCALISER.msg("020005",
                        columnsName, "" + i)).setFatal();
                }

                // Create a new ColumnMetaData since user hasn't provided enough
                ColumnMetaData colmd = new ColumnMetaData();
                if (updateContainer)
                {
                    columnContainer.addColumn(colmd);
                }
                putColumn(sideBidentifier, colmd);
            }
        }
        else
        {
            columnsName = null;
            for (int i = 0; i < mappingSideB.getNumberOfDatastoreFields(); i++)
            {
                final DatastoreIdentifier sideBidentifier;
                sideBidentifier = mappingSideB.getDataStoreMapping(i).getDatastoreField().getIdentifier();

                // Create a new ColumnMetaData since user hasn't provided enough
                ColumnMetaData colmd = new ColumnMetaData();
                putColumn(sideBidentifier, colmd);
            }
        }
    }
View Full Code Here

                    throw new NucleusUserException(LOCALISER.msg("020005",
                        columnsName, "" + i)).setFatal();
                }

                // Create a new ColumnMetaData since user hasn't provided enough
                ColumnMetaData colmd = new ColumnMetaData();
                if (updateContainer)
                {
                    columnContainer.addColumn(colmd);
                }
                putColumn(sideBidentifier, colmd);
            }
        }
        else
        {
            columnsName = null;
            for (int i = 0; i < mappingSideB.getNumberOfDatastoreFields(); i++)
            {
                final DatastoreIdentifier sideBidentifier;
                sideBidentifier = mappingSideB.getDataStoreMapping(i).getDatastoreField().getIdentifier();

                // Create a new ColumnMetaData since user hasn't provided enough
                ColumnMetaData colmd = new ColumnMetaData();
                putColumn(sideBidentifier, colmd);
            }
        }
    }
View Full Code Here

     * This creates the column in the table.
     */
    protected void prepareDatastoreMapping()
    {
        MappingManager mmgr = datastoreContainer.getStoreManager().getMappingManager();
        ColumnMetaData colmd = null;
        if (mmd.getValueMetaData() != null && mmd.getValueMetaData().getColumnMetaData() != null &&
            mmd.getValueMetaData().getColumnMetaData().length > 0)
        {
            colmd = mmd.getValueMetaData().getColumnMetaData()[0];
        }
View Full Code Here

        DatastoreIdentifier id = null;
        if (dismd.getColumnMetaData() == null)
        {
            // No column name so generate a default
            id = idFactory.newDiscriminatorFieldIdentifier();
            ColumnMetaData colmd = new ColumnMetaData();
            colmd.setName(id.getIdentifierName());
            dismd.setColumnMetaData(colmd);
        }
        else
        {
            // Column metadata defined
            ColumnMetaData colmd = dismd.getColumnMetaData();
            if (colmd.getName() == null)
            {
                // No name defined so create one and set it
                id = idFactory.newDiscriminatorFieldIdentifier();
                colmd.setName(id.getIdentifierName());
            }
            else
            {
                // Name defined so just generate identifier
                id = idFactory.newDatastoreFieldIdentifier(colmd.getName());
            }
        }

        DatastoreField column = datastoreContainer.addDatastoreField(getType(), id, this, dismd.getColumnMetaData());
        datastoreContainer.getStoreManager().getMappingManager().createDatastoreMapping(delegate, column,
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.