Examples of ColumnMetadata


Examples of org.datanucleus.metadata.ColumnMetaData

        {
            // Nothing specified so don't provide ColumnMetaData and default to what we get
            return null;
        }

        ColumnMetaData colmd = new ColumnMetaData();
        colmd.setName(columnName);
        colmd.setTarget(target);
        colmd.setTargetMember(targetField);
        colmd.setJdbcType(jdbcType);
        colmd.setSqlType(sqlType);
        colmd.setLength(length);
        colmd.setScale(scale);
        colmd.setAllowsNull(allowsNull);
        colmd.setDefaultValue(defaultValue);
        colmd.setInsertValue(insertValue);
        colmd.setInsertable(insertable);
        colmd.setUpdateable(updateable);
        colmd.setUnique(unique);
        if (columnDdl != null)
        {
            colmd.setColumnDdl(columnDdl);
        }
        if (parent instanceof AbstractMemberMetaData)
        {
            AbstractMemberMetaData apmd = (AbstractMemberMetaData) parent;
            if (!StringUtils.isWhitespace(table))
            {
                apmd.setTable(table);
            }
            // apmd.addColumn(colmd);
            // update column settings if primary key, cannot be null
            colmd.setAllowsNull(Boolean.valueOf(apmd.isPrimaryKey() ? false : colmd.isAllowsNull()));
        }
        else if (parent instanceof KeyMetaData)
        {
            KeyMetaData keymd = (KeyMetaData) parent;
            AbstractMemberMetaData apmd = (AbstractMemberMetaData) keymd.getParent();
            if (!StringUtils.isWhitespace(table))
            {
                apmd.setTable(table);
            }
            colmd.setAllowsNull(colmd.isAllowsNull());
        }
        return colmd;
    }
View Full Code Here

Examples of org.datanucleus.metadata.ColumnMetaData

                        PrimaryKeyJoinColumn[] pkJoinCols = secTableAnns[j].pkJoinColumns();
                        if (pkJoinCols != null)
                        {
                            for (int k = 0; k < pkJoinCols.length; k++)
                            {
                                ColumnMetaData colmd = new ColumnMetaData();
                                colmd.setName(pkJoinCols[k].name());
                                colmd.setTarget(pkJoinCols[k].referencedColumnName());
                                joinmd.addColumn(colmd);
                            }
                        }
                        joins.add(joinmd);
                        cmd.addJoin(joinmd);

                        UniqueConstraint[] constrs = secTableAnns[j].uniqueConstraints();
                        if (constrs != null && constrs.length > 0)
                        {
                            for (int k=0;k<constrs.length;k++)
                            {
                                UniqueMetaData unimd = new UniqueMetaData();
                                unimd.setTable((String)annotationValues.get("table"));
                                for (int l=0;l<constrs[k].columnNames().length;l++)
                                {
                                    ColumnMetaData colmd = new ColumnMetaData();
                                    colmd.setName(constrs[k].columnNames()[l]);
                                    unimd.addColumn(colmd);
                                }
                                joinmd.setUniqueMetaData(unimd); // JDO only allows one unique
                            }
                        }
                    }
                }
            }
            else if (annName.equals(JPAAnnotationUtils.SECONDARY_TABLE))
            {
                JoinMetaData joinmd = new JoinMetaData();
                joinmd.setTable((String)annotationValues.get("name"));
                joinmd.setCatalog((String)annotationValues.get("catalog"));
                joinmd.setSchema((String)annotationValues.get("schema"));
                if (annotationValues.get("pkJoinColumns") != null)
                {
                    PrimaryKeyJoinColumn[] joinCols = (PrimaryKeyJoinColumn[])annotationValues.get("pkJoinColumns");
                    for (int j = 0; j < joinCols.length; j++)
                    {
                        ColumnMetaData colmd = new ColumnMetaData();
                        colmd.setName(joinCols[j].name());
                        colmd.setTarget(joinCols[j].referencedColumnName());
                        joinmd.addColumn(colmd);
                    }
                }
                joins.add(joinmd);
                cmd.addJoin(joinmd);

                UniqueConstraint[] constrs = (UniqueConstraint[])annotationValues.get("uniqueConstraints");
                if (constrs != null && constrs.length > 0)
                {
                    for (int j=0;j<constrs.length;j++)
                    {
                        UniqueMetaData unimd = new UniqueMetaData();
                        unimd.setTable((String)annotationValues.get("table"));
                        for (int k=0;k<constrs[j].columnNames().length;k++)
                        {
                            ColumnMetaData colmd = new ColumnMetaData();
                            colmd.setName(constrs[j].columnNames()[k]);
                            unimd.addColumn(colmd);
                        }
                        joinmd.setUniqueMetaData(unimd); // JDO only allows one unique
                    }
                }
View Full Code Here

Examples of org.datanucleus.metadata.ColumnMetaData

                    discriminatorMapping = new DiscriminatorStringMapping(dba, this,
                        mapMgr.getMapping(String.class));
                }
                else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP)
                {
                    ColumnMetaData disColmd = dismd.getColumnMetaData();
                    if (disColmd != null && disColmd.getJdbcType() != null)
                    {
                        if (disColmd.getJdbcType().equalsIgnoreCase("INTEGER") ||
                                disColmd.getJdbcType().equalsIgnoreCase("BIGINT") ||
                                disColmd.getJdbcType().equalsIgnoreCase("NUMERIC"))
                        {
                            discriminatorMapping = new DiscriminatorLongMapping(dba, this,
                                mapMgr.getMapping(Long.class));
                        }
                        else
                        {
                            discriminatorMapping = new DiscriminatorStringMapping(dba, this,
                                mapMgr.getMapping(String.class));
                        }
                    }
                    else
                    {
                        discriminatorMapping = new DiscriminatorStringMapping(dba, this,
                            mapMgr.getMapping(String.class));
                    }
                }
            }
            else
            {
                // Create discriminator column only in top most table that needs it
                ClassTable tableWithDiscrim = getTableWithDiscriminator();
                if (tableWithDiscrim == this)
                {
                    // No superclass with a discriminator so add it in this table
                    if (dismd.getStrategy() == DiscriminatorStrategy.CLASS_NAME)
                    {
                        discriminatorMapping = new DiscriminatorStringMapping(dba, this,
                            mapMgr.getMapping(String.class));
                    }
                    else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP)
                    {
                        ColumnMetaData disColmd = dismd.getColumnMetaData();
                        if (disColmd != null && disColmd.getJdbcType() != null)
                        {
                            if (disColmd.getJdbcType().equalsIgnoreCase("INTEGER") ||
                                    disColmd.getJdbcType().equalsIgnoreCase("BIGINT") ||
                                    disColmd.getJdbcType().equalsIgnoreCase("NUMERIC"))
                            {
                                discriminatorMapping = new DiscriminatorLongMapping(dba, this,
                                    mapMgr.getMapping(Long.class));
                            }
                            else
View Full Code Here

Examples of org.datanucleus.metadata.ColumnMetaData

        if (cols != null && cols.size() > 0)
        {
            Iterator colsIter = cols.iterator();
            while (colsIter.hasNext())
            {
                ColumnMetaData colmd = (ColumnMetaData)colsIter.next();

                // Create a column with the specified name and jdbc-type
                if (colmd.getJdbcType().equals("VARCHAR") && colmd.getLength() == null)
                {
                    colmd.setLength(storeMgr.getIntProperty("datanucleus.rdbms.stringDefaultLength"));
                }
                IdentifierFactory idFactory = getStoreManager().getIdentifierFactory();
                DatastoreIdentifier colIdentifier = idFactory.newIdentifier(IdentifierType.COLUMN, colmd.getName());
                Column col = (Column)addDatastoreField(null, colIdentifier, null, colmd);
                SQLTypeInfo sqlTypeInfo = storeMgr.getSQLTypeInfoForJDBCType(
                    JDBCUtils.getJDBCTypeForName(colmd.getJdbcType()));
                col.setTypeInfo(sqlTypeInfo);

                if (unmappedColumns == null)
                {
                    unmappedColumns = new HashSet();
                }

                if (NucleusLogger.DATASTORE.isDebugEnabled())
                {
                    NucleusLogger.DATASTORE.debug(LOCALISER.msg("057011",
                        col.toString(), colmd.getJdbcType()));
                }
                unmappedColumns.add(col);
            }
        }
    }
View Full Code Here

Examples of org.datanucleus.metadata.ColumnMetaData

                                }

                                if (!duplicate)
                                {
                                    // Create the relation discriminator column since we dont have this discriminator
                                    ColumnMetaData colmd = new ColumnMetaData();
                                    colmd.setName(colName);
                                    colmd.setAllowsNull(Boolean.TRUE); // Allow for elements not in any discriminated collection
                                    fkDiscrimMapping = storeMgr.getMappingManager().getMapping(String.class); // Only support String discriminators currently
                                    fkDiscrimMapping.setDatastoreContainer(this);
                                    ColumnCreator.createIndexColumn(fkDiscrimMapping, storeMgr, clr, this, colmd, false);
                                }

                                if (fkDiscrimMapping != null)
                                {
                                    getExternalFkDiscriminatorMappings().put(ownerFmd, fkDiscrimMapping);
                                }
                            }

                            // Add the order mapping as necessary
                            addOrderMapping(ownerFmd, orderMapping, clr);
                        }
                        else
                        {
                            // Unidirectional (element knows nothing about the owner)
                            String ownerClassName = ownerFmd.getAbstractClassMetaData().getFullClassName();
                            JavaTypeMapping fkMapping = new PersistableMapping();
                            fkMapping.setDatastoreContainer(this);
                            fkMapping.initialize(storeMgr, ownerClassName);
                            JavaTypeMapping fkDiscrimMapping = null;
                            JavaTypeMapping orderMapping = null;
                            boolean duplicate = false;

                            try
                            {
                                // Get the owner id mapping of the "1" end
                                DatastoreClass ownerTbl = storeMgr.getDatastoreClass(ownerClassName, clr);
                                if (ownerTbl == null)
                                {
                                    // Class doesn't have its own table (subclass-table) so find where it persists
                                    AbstractClassMetaData[] ownerParentCmds =
                                        storeMgr.getClassesManagingTableForClass(ownerFmd.getAbstractClassMetaData(), clr);
                                    if (ownerParentCmds.length > 1)
                                    {
                                        throw new NucleusUserException("Relation (" + ownerFmd.getFullFieldName() +
                                        ") with multiple related tables (using subclass-table). Not supported");
                                    }
                                    ownerClassName = ownerParentCmds[0].getFullClassName();
                                    ownerTbl = storeMgr.getDatastoreClass(ownerClassName, clr);
                                }

                                JavaTypeMapping ownerIdMapping = ownerTbl.getIdMapping();
                                ColumnMetaDataContainer colmdContainer = null;
                                if (ownerFmd.hasCollection() || ownerFmd.hasArray())
                                {
                                    // 1-N Collection/array
                                    colmdContainer = ownerFmd.getElementMetaData();
                                }
                                else if (ownerFmd.hasMap() && ownerFmd.getKeyMetaData() != null && ownerFmd.getKeyMetaData().getMappedBy() != null)
                                {
                                    // 1-N Map with key stored in the value
                                    colmdContainer = ownerFmd.getValueMetaData();
                                }
                                else if (ownerFmd.hasMap() && ownerFmd.getValueMetaData() != null && ownerFmd.getValueMetaData().getMappedBy() != null)
                                {
                                    // 1-N Map with value stored in the key
                                    colmdContainer = ownerFmd.getKeyMetaData();
                                }
                                CorrespondentColumnsMapper correspondentColumnsMapping =
                                    new CorrespondentColumnsMapper(colmdContainer, ownerIdMapping, true);
                                int countIdFields = ownerIdMapping.getNumberOfDatastoreMappings();
                                for (int i=0; i<countIdFields; i++)
                                {
                                    DatastoreMapping refDatastoreMapping = ownerIdMapping.getDatastoreMapping(i);
                                    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(refDatastoreMapping.getJavaTypeMapping().getJavaType());
                                    ColumnMetaData colmd = correspondentColumnsMapping.getColumnMetaDataByIdentifier(((Column)refDatastoreMapping.getDatastoreField()).getIdentifier());
                                    if (colmd == null)
                                    {
                                        throw new NucleusUserException(LOCALISER.msg("057035",
                                            ((Column)refDatastoreMapping.getDatastoreField()).getIdentifier(), toString())).setFatal();
                                    }

                                    DatastoreIdentifier identifier = null;
                                    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.getNucleusContext().getTypeManager().isDefaultEmbeddedType(mapping.getJavaType()),
                                            FieldRole.ROLE_OWNER);
                                    }
                                    else
                                    {
                                        // User-defined name
                                        identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName());
                                    }
                                    DatastoreField refColumn = addDatastoreField(mapping.getJavaType().getName(), identifier, mapping, colmd);
                                    ((Column)refDatastoreMapping.getDatastoreField()).copyConfigurationTo(refColumn);

                                    if (colmd == null || (colmd != null && colmd.getAllowsNull() == null) ||
                                            (colmd != null && colmd.getAllowsNull() != null && colmd.isAllowsNull()))
                                    {
                                        // User either wants it nullable, or haven't specified anything, so make it nullable
                                        refColumn.setNullable();
                                    }

                                    fkMapping.addDatastoreMapping(getStoreManager().getMappingManager().createDatastoreMapping(mapping, refColumn, refDatastoreMapping.getJavaTypeMapping().getJavaType().getName()));
                                    ((PersistableMapping)fkMapping).addJavaTypeMapping(mapping);
                                }
                            }
                            catch (DuplicateDatastoreFieldException dce)
                            {
                                // If the user hasnt specified "relation-discriminator-column" here we dont allow the sharing of columns
                                if (!ownerFmd.hasExtension("relation-discriminator-column"))
                                {
                                    throw dce;
                                }

                                // Find the FK using this column and use it instead of creating a new one since we're sharing
                                Iterator fkIter = getExternalFkMappings().entrySet().iterator();
                                fkMapping = null;
                                while (fkIter.hasNext())
                                {
                                    Map.Entry entry = (Map.Entry)fkIter.next();
                                    JavaTypeMapping existingFkMapping = (JavaTypeMapping)entry.getValue();
                                    for (int j=0;j<existingFkMapping.getNumberOfDatastoreMappings();j++)
                                    {
                                        if (existingFkMapping.getDatastoreMapping(j).getDatastoreField().getIdentifier().toString().equals(dce.getConflictingColumn().getIdentifier().toString()))
                                        {
                                            // The FK is shared (and so if it is a List we also share the index)
                                            fkMapping = existingFkMapping;
                                            fkDiscrimMapping = externalFkDiscriminatorMappings.get(entry.getKey());
                                            orderMapping = getExternalOrderMappings().get(entry.getKey());
                                            break;
                                        }
                                    }
                                }
                                if (fkMapping == null)
                                {
                                    // Should never happen since we know there is a col duplicating ours
                                    throw dce;
                                }
                                duplicate = true;
                            }

                            if (!duplicate && ownerFmd.hasExtension("relation-discriminator-column"))
                            {
                                // Create the relation discriminator column
                                String colName = ownerFmd.getValueForExtension("relation-discriminator-column");
                                if (colName == null)
                                {
                                    // No column defined so use a fallback name
                                    colName = "RELATION_DISCRIM";
                                }
                                ColumnMetaData colmd = new ColumnMetaData();
                                colmd.setName(colName);
                                colmd.setAllowsNull(Boolean.TRUE); // Allow for elements not in any discriminated collection
                                fkDiscrimMapping = storeMgr.getMappingManager().getMapping(String.class); // Only support String discriminators currently
                                fkDiscrimMapping.setDatastoreContainer(this);
                                ColumnCreator.createIndexColumn(fkDiscrimMapping, storeMgr, clr, this, colmd, false);
                            }
View Full Code Here

Examples of org.datanucleus.metadata.ColumnMetaData

        indexMapping.initialize(storeMgr, indexType.getName());
        indexMapping.setMemberMetaData(mmd);
        indexMapping.setDatastoreContainer(this);
        IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
        DatastoreIdentifier indexColumnName = null;
        ColumnMetaData colmd = null;

        // Allow for any user definition in OrderMetaData
        OrderMetaData omd = mmd.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.
                state = TABLE_STATE_INITIALIZED; // Not adding anything so just set table back to "initialised"
                JavaTypeMapping orderMapping = getMemberMapping(omd.getMappedBy());
                if (orderMapping == null)
                {
                    throw new NucleusUserException(LOCALISER.msg("057021",
                        mmd.getFullFieldName(), omd.getMappedBy()));
                }
                if (!(orderMapping instanceof IntegerMapping) && !(orderMapping instanceof LongMapping))
                {
                    throw new NucleusUserException(LOCALISER.msg("057022",
                        mmd.getFullFieldName(), omd.getMappedBy()));
                }
                return orderMapping;
            }

            String colName = null;
            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(mmd, null, null,
                storeMgr.getNucleusContext().getTypeManager().isDefaultEmbeddedType(indexType), FieldRole.ROLE_INDEX);
        }

        DatastoreField column = addDatastoreField(indexType.getName(), indexColumnName, indexMapping, colmd);
        if (colmd == null || (colmd != null && colmd.getAllowsNull() == null) ||
            (colmd != null && colmd.getAllowsNull() != null && colmd.isAllowsNull()))
        {
            // User either wants it nullable, or havent specified anything, so make it nullable
            column.setNullable();
        }
View Full Code Here

Examples of org.datanucleus.metadata.ColumnMetaData

                debugMapping(elementMapping);
            }
        }

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

Examples of org.datanucleus.metadata.ColumnMetaData

        setIdentifier(identifier);
        if (colmd == null)
        {
            // Create a default ColumnMetaData since none provided
            columnMetaData = new ColumnMetaData();
        }
        else
        {
            // TODO Consider making a copy here
            columnMetaData = colmd;
View Full Code Here

Examples of org.datanucleus.metadata.ColumnMetaData

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

Examples of org.datanucleus.metadata.ColumnMetaData

            }
        }
        if (orderRequired)
        {
            // Order (index) column is required (integer based)
            ColumnMetaData orderColmd = null;
            if (mmd.getOrderMetaData() != null &&
                mmd.getOrderMetaData().getColumnMetaData() != null &&
                mmd.getOrderMetaData().getColumnMetaData().length > 0)
            {
                // Specified "order" column info
                orderColmd = mmd.getOrderMetaData().getColumnMetaData()[0];
                if (orderColmd.getName() == null)
                {
                    orderColmd = new ColumnMetaData(orderColmd);
                    if (mmd.hasExtension("adapter-column-name"))
                    {
                        // Specified "extension" column name
                        // TODO Is this needed? The user can just specify <order column="...">
                        orderColmd.setName(mmd.getValueForExtension("adapter-column-name"));
                    }
                    else
                    {
                        // No column name so use default
                        DatastoreIdentifier id = storeMgr.getIdentifierFactory().newIndexFieldIdentifier(mmd);
                        orderColmd.setName(id.getIdentifierName());
                    }
                }
            }
            else
            {
                if (mmd.hasExtension("adapter-column-name"))
                {
                    // Specified "extension" column name
                    // TODO Is this needed? The user can just specify <order column="...">
                    orderColmd = new ColumnMetaData();
                    orderColmd.setName(mmd.getValueForExtension("adapter-column-name"));
                }
                else
                {
                    // No column name so use default
                    DatastoreIdentifier id = storeMgr.getIdentifierFactory().newIndexFieldIdentifier(mmd);
                    orderColmd = new ColumnMetaData();
                    orderColmd.setName(id.getIdentifierName());
                }
            }
            orderMapping = storeMgr.getMappingManager().getMapping(int.class); // JDO2 spec [18.5] order column is assumed to be "int"
            ColumnCreator.createIndexColumn(orderMapping, storeMgr, clr, this, orderColmd, pkRequired && !pkColsSpecified);
            if (NucleusLogger.DATASTORE.isDebugEnabled())
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.