Package org.jpox.metadata

Examples of org.jpox.metadata.ColumnMetaData


                {
                    m = dba.getMapping(clr.classForName(refColumn.getMapping().getType()), storeMgr);
                    ((PersistenceCapableMapping)masterMapping).addJavaTypeMapping(m);
                }

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

                // Add this application identity column
                DatastoreField idColumn = null;
                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(IdentifierFactory.COLUMN, userdefinedColumn.getName()),
                        m, refColumn.getMetaData());
                }
                else
                {
                    // No name provided so take same as superclass
View Full Code Here


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

        // Create a ColumnMetaData in the container if none is defined
        ColumnMetaData colmd = null;
        if (columnContainer == null)
        {
            colmd = new ColumnMetaData(null, (String)null);
        }
        else if (columnContainer.getColumnMetaData().length < 1)
        {
            colmd = new ColumnMetaData((MetaData)columnContainer, (String)null);
        }
        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().getIdentifier(),
                    this.storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(OID.class), FieldRole.ROLE_OWNER).getIdentifier());
            }
            else
            {
                colmd.setName(storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(identifier.getIdentifier(),
                    this.storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(OID.class), FieldRole.ROLE_NONE).getIdentifier());
            }
        }

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

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

            if (colName == null)
            {
                // No column defined so use a fallback name
                colName = "RELATION_DISCRIM";
            }
            ColumnMetaData colmd = new ColumnMetaData(null, colName);

            boolean relationDiscriminatorPk = false;
            if (fmd.hasExtension("relation-discriminator-pk") &&
                fmd.getValueForExtension("relation-discriminator-pk").equalsIgnoreCase("true"))
            {
                // Default this to not be part of the PK of the join table, but allow the user to override it
                relationDiscriminatorPk = true;
            }
            if (!relationDiscriminatorPk)
            {
                colmd.setAllowsNull(Boolean.TRUE); // Allow for elements not in any discriminated collection (when not PK)
            }

            // Create the mapping and its datastore column (only support String relation discriminators here)
            relationDiscriminatorMapping = dba.getMapping(String.class, storeMgr);
            ColumnCreator.createIndexColumn(relationDiscriminatorMapping, storeMgr, clr, this, colmd, relationDiscriminatorPk);
View Full Code Here

                debugMapping(elementMapping);
            }
        }

        // Add order mapping
        ColumnMetaData colmd = null;
        if (fmd.getOrderMetaData() != null && fmd.getOrderMetaData().getColumnMetaData() != null &&
            fmd.getOrderMetaData().getColumnMetaData().length > 0)
        {
            // Specified "order" column info
            colmd = fmd.getOrderMetaData().getColumnMetaData()[0];
        }
        else
        {
            // No column name so use default
            DatastoreIdentifier id =
                ((RDBMSIdentifierFactory)storeMgr.getIdentifierFactory()).newIndexFieldIdentifier();
            colmd = new ColumnMetaData(fmd, id.getIdentifier());
        }
        orderMapping = dba.getMapping(int.class, storeMgr); // JDO2 spec [18.5] order column is assumed to be "int"
        ColumnCreator.createIndexColumn(orderMapping, storeMgr, clr, this, colmd, pkRequired && !pkColsSpecified);
        if (JPOXLogger.DATASTORE.isDebugEnabled())
        {
View Full Code Here

                    new CorrespondentColumnsMapper(columnContainer, columnMetaData, m, true);
                for (int i=0; i<m.getNumberOfDatastoreFields(); i++)
                {
                    JavaTypeMapping refDatastoreMapping =
                        storeMgr.getDatastoreAdapter().getMapping(m.getDataStoreMapping(i).getJavaTypeMapping().getJavaType(), storeMgr);
                    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(fmd,
                                    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 = fmd.getRelatedMemberMetaData(clr);
                                // TODO Cater for more than 1 related field
                                identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd,
                                    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());
                        }

                        DatastoreField column = table.addDatastoreField(javaType.getName(), identifier, refDatastoreMapping, colmd);
                        ((Column) m.getDataStoreMapping(i).getDatastoreField()).copyConfigurationTo(column);
                        if (isPrimaryKey)
                        {
                            column.setAsPrimaryKey();
                        }
                        if (isNullable)
                        {
                            column.setNullable();
                        }

                        storeMgr.getMappingManager().createDatastoreMapping(refDatastoreMapping, storeMgr, column,
                            m.getDataStoreMapping(i).getJavaTypeMapping().getJavaTypeForDatastoreMapping(i));
                    }
                    catch (DuplicateColumnNameException ex)
                    {
                      throw new JPOXUserException("Cannot create column for field "+fmd.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 = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null,
View Full Code Here

            }
        }
        if (orderRequired)
        {
            // Order (index) column is required (integer based)
            ColumnMetaData orderColmd = null;
            if (fmd.getOrderMetaData() != null &&
                fmd.getOrderMetaData().getColumnMetaData() != null &&
                fmd.getOrderMetaData().getColumnMetaData().length > 0)
            {
                // Specified "order" column info
                orderColmd = fmd.getOrderMetaData().getColumnMetaData()[0];
            }
            else if (fmd.hasExtension("adapter-column-name"))
            {
                // Specified JPOX "extension" column name
                // TODO Why do we have this ? the user can just specify <order column="...">
                orderColmd = new ColumnMetaData(fmd, fmd.getValueForExtension("adapter-column-name"));
            }
            else
            {
                // No column name so use default
                DatastoreIdentifier id =
                    ((RDBMSIdentifierFactory)storeMgr.getIdentifierFactory()).newIndexFieldIdentifier();
                orderColmd = new ColumnMetaData(fmd, id.getIdentifier());
            }
            orderMapping = dba.getMapping(int.class, storeMgr); // JDO2 spec [18.5] order column is assumed to be "int"
            ColumnCreator.createIndexColumn(orderMapping, storeMgr, clr, this, orderColmd, pkRequired && !pkColsSpecified);
            if (JPOXLogger.DATASTORE.isDebugEnabled())
            {
View Full Code Here

            }
        }
        if (orderRequired)
        {
            // Order/Adapter (index) column is required (integer based)
            ColumnMetaData orderColmd = null;
            if (fmd.getOrderMetaData() != null &&
                fmd.getOrderMetaData().getColumnMetaData() != null &&
                fmd.getOrderMetaData().getColumnMetaData().length > 0)
            {
                // Specified "order" column info
                orderColmd = fmd.getOrderMetaData().getColumnMetaData()[0];
            }
            else if (fmd.hasExtension("adapter-column-name"))
            {
                // Specified JPOX "extension" column name
                // TODO Why do we have this ? the user can just specify <order column="...">
                orderColmd = new ColumnMetaData(fmd, fmd.getValueForExtension("adapter-column-name"));
            }
            else
            {
                // No column name so use default
                DatastoreIdentifier id =
                    ((RDBMSIdentifierFactory)storeMgr.getIdentifierFactory()).newIndexFieldIdentifier();
                orderColmd = new ColumnMetaData(fmd, id.getIdentifier());
            }
            orderMapping = dba.getMapping(int.class, storeMgr); // JDO2 spec [18.5] order column is assumed to be "int"
            ColumnCreator.createIndexColumn(orderMapping, storeMgr, clr, this, orderColmd, pkRequired && !pkColsSpecified);
            if (JPOXLogger.DATASTORE.isDebugEnabled())
            {
View Full Code Here

                columnNames.append(',');
                columnValues.append(',');
            }
            Column col = (Column)fld;
            columnNames.append(fld.getIdentifier());
            ColumnMetaData colmd = (ColumnMetaData)col.getMetaData();
            String value = colmd.getInsertValue();
            if (colmd.getJdbcType().equals("VARCHAR") || colmd.getJdbcType().equals("CHAR"))
            {
                // String-based so add quoting
                value = "\"" + value + "\"";
            }
            columnValues.append(value);
View Full Code Here

TOP

Related Classes of org.jpox.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.