Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.AbstractClassMetaData


    {
        String columnOrdering = storeMgr.getStringProperty("datanucleus.rdbms.tableColumnOrder");
        if (columnOrdering.equalsIgnoreCase("superclass-first"))
        {
            // Superclasses persisted into this table
            AbstractClassMetaData parentCmd = theCmd.getSuperAbstractClassMetaData();
            if (parentCmd != null)
            {
                if (cmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.COMPLETE_TABLE)
                {
                    // Managed class requires all superclasses managed here too
                    initializeForClass(parentCmd, clr);
                }
                else if (parentCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE)
                {
                    // Superclass uses "subclass-table" so needs managing here
                    initializeForClass(parentCmd, clr);
                }
            }

            // Owning class
            manageClass(theCmd, clr);
        }
        else
        {
            // Owning class
            manageClass(theCmd, clr);

            // Superclasses persisted into this table
            AbstractClassMetaData parentCmd = theCmd.getSuperAbstractClassMetaData();
            if (parentCmd != null)
            {
                if (cmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.COMPLETE_TABLE)
                {
                    // Managed class requires all superclasses managed here too
                    initializeForClass(parentCmd, clr);
                }
                else if (parentCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE)
                {
                    // Superclass uses "subclass-table" so needs managing here
                    initializeForClass(parentCmd, clr);
                }
            }
View Full Code Here


    {
        // Run callbacks for all classes managed by this table
        Iterator<AbstractClassMetaData> cmdIter = managedClassMetaData.iterator();
        while (cmdIter.hasNext())
        {
            AbstractClassMetaData managedCmd = cmdIter.next();
            if (managingClassCurrent != null && managingClassCurrent.equals(managedCmd.getFullClassName()))
            {
                // We can't run callbacks for this class since it is still being initialised. Mark callbacks to run after it completes
                runCallbacksAfterManageClass = true;
                break;
            }

            Collection processedCallbacks = callbacksAppliedForManagedClass.get(managedCmd.getFullClassName());
            Collection c = (Collection)storeMgr.getSchemaCallbacks().get(managedCmd.getFullClassName());
            if (c != null)
            {
                if (processedCallbacks == null)
                {
                    processedCallbacks = new HashSet();
                    callbacksAppliedForManagedClass.put(managedCmd.getFullClassName(), processedCallbacks);
                }
                for (Iterator it = c.iterator(); it.hasNext();)
                {
                    AbstractMemberMetaData callbackMmd = (AbstractMemberMetaData) it.next();
                    if (processedCallbacks.contains(callbackMmd))
                    {
                        continue;
                    }
                    else
                    {
                        processedCallbacks.add(callbackMmd);
                    }

                    if (callbackMmd.getJoinMetaData() == null)
                    {
                        // 1-N FK relationship
                        AbstractMemberMetaData ownerFmd = callbackMmd;
                        if (ownerFmd.getMappedBy() != null)
                        {
                            // Bidirectional (element has a PC mapping to the owner)
                            // Check that the "mapped-by" field in the other class actually exists
                            AbstractMemberMetaData fmd = managedCmd.getMetaDataForMember(ownerFmd.getMappedBy());
                            if (fmd == null)
                            {
                                throw new NucleusUserException(LOCALISER.msg("057036",
                                    ownerFmd.getMappedBy(), managedCmd.getFullClassName(), ownerFmd.getFullFieldName()));
                            }

                            if (ownerFmd.getMap() != null && storeMgr.getBooleanProperty("datanucleus.rdbms.uniqueConstraints.mapInverse"))
                            {
                                initializeFKMapUniqueConstraints(ownerFmd);
View Full Code Here

        {
            // "complete-table" has no super table. All is persisted into this table
            return null;
        }

        AbstractClassMetaData superCmd = theCmd.getSuperAbstractClassMetaData();
        if (superCmd != null)
        {
            if (superCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.NEW_TABLE)
            {
                // This class has its own table, so return it.
                return (ClassTable) storeMgr.getDatastoreClass(superCmd.getFullClassName(), clr);
            }
            else if (superCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE)
            {
                // This class is mapped to the same table, so go up another level.
                return getSupertable(superCmd, clr);
            }
            else
View Full Code Here

        // Add on any user-required indices for the class(es) as a whole (subelement of <class>)
        Iterator<AbstractClassMetaData> cmdIter = managedClassMetaData.iterator();
        while (cmdIter.hasNext())
        {
            AbstractClassMetaData thisCmd = cmdIter.next();
            IndexMetaData[] classIndices = thisCmd.getIndexMetaData();
            if (classIndices != null)
            {
                for (int i=0;i<classIndices.length;i++)
                {
                    Index index = getIndexForIndexMetaData(classIndices[i]);
View Full Code Here

        // Add any user-required FKs for the class as a whole
        // <class><foreign-key>...</foreign-key></field>
        Iterator<AbstractClassMetaData> cmdIter = managedClassMetaData.iterator();
        while (cmdIter.hasNext())
        {
            AbstractClassMetaData thisCmd = cmdIter.next();
            ForeignKeyMetaData[] fkmds = thisCmd.getForeignKeyMetaData();
            if (fkmds != null)
            {
                for (int i=0;i<fkmds.length;i++)
                {
                    ForeignKey fk = getForeignKeyForForeignKeyMetaData(fkmds[i]);
View Full Code Here

        // Create the ForeignKey base details
        ForeignKey fk = new ForeignKey(fkmd.isDeferred());
        fk.setForMetaData(fkmd);

        // Find the target of the foreign-key
        AbstractClassMetaData acmd = cmd;
        if (fkmd.getTable() == null)
        {
            // Can't create a FK if we don't know where it goes to
            NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058105", acmd.getFullClassName()));
            return null;
        }
        DatastoreIdentifier tableId = storeMgr.getIdentifierFactory().newDatastoreContainerIdentifier(fkmd.getTable());
        ClassTable refTable = (ClassTable)storeMgr.getDatastoreClass(tableId);
        if (refTable == null)
        {
            // TODO Go to the datastore and query for this table to get the columns of the PK
            NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058106", acmd.getFullClassName(),
                fkmd.getTable()));
            return null;
        }
        PrimaryKey pk = refTable.getPrimaryKey();
        List targetCols = pk.getColumns();

        // Generate the columns for the source of the foreign-key
        List sourceCols = new ArrayList();
        ColumnMetaData[] colmds = fkmd.getColumnMetaData();
        AbstractMemberMetaData[] fmds = fkmd.getMemberMetaData();
        if (colmds != null && colmds.length > 0)
        {
            // FK specified via <column>
            for (int i=0;i<colmds.length;i++)
            {
                // Find the column and add to the source columns for the FK
                DatastoreIdentifier colId = storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(colmds[i].getName());
                Column sourceCol = columnsByName.get(colId);
                if (sourceCol == null)
                {
                    NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058107",
                        acmd.getFullClassName(), fkmd.getTable(), colmds[i].getName(), toString()));
                    return null;
                }
                sourceCols.add(sourceCol);
            }
        }
        else if (fmds != null && fmds.length > 0)
        {
            // FK specified via <field>
            for (int i=0;i<fmds.length;i++)
            {
                // Find the metadata for the actual field with the same name as this "foreign-key" field
                // and add all columns to the source columns for the FK
                AbstractMemberMetaData realFmd = getMetaDataForMember(fmds[i].getName());
                JavaTypeMapping fieldMapping = memberMappingsMap.get(realFmd);
                int countDatastoreFields = fieldMapping.getNumberOfDatastoreMappings();
                for (int j=0; j<countDatastoreFields; j++)
                {
                    // Add each column of this field to the FK definition
                    sourceCols.add(fieldMapping.getDatastoreMapping(j).getDatastoreField());
                }
            }
        }

        if (sourceCols.size() != targetCols.size())
        {
            // Different number of cols in this table and target table
            NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058108",
                acmd.getFullClassName(), fkmd.getTable(), "" + sourceCols.size(), "" + targetCols.size()));
        }

        // Add all column mappings to the ForeignKey
        if (sourceCols.size() > 0)
        {
View Full Code Here

        // Add on any user-required candidate keys for the class(es) as a whole (composite keys)
        Iterator<AbstractClassMetaData> cmdIter = managedClassMetaData.iterator();
        while (cmdIter.hasNext())
        {
            AbstractClassMetaData thisCmd = cmdIter.next();
            UniqueMetaData[] classCKs = thisCmd.getUniqueMetaData();
            if (classCKs != null)
            {
                for (int i=0;i<classCKs.length;i++)
                {
                    CandidateKey ck = getCandidateKeyForUniqueMetaData(classCKs[i]);
View Full Code Here

            {
                // Field not in primary class so may be in subclass so check all managed classes
                Iterator<AbstractClassMetaData> cmdIter = managedClassMetaData.iterator();
                while (cmdIter.hasNext())
                {
                    AbstractClassMetaData managedCmd = cmdIter.next();
                    mfmd = managedCmd.getMetaDataForMember(map_field_name);
                    if (mfmd != null)
                    {
                        break;
                    }
                }
            }
            if (mfmd == null)
            {
                // "mapped-by" refers to a field in our class that doesnt exist!
                throw new NucleusUserException(LOCALISER.msg("057036",
                    map_field_name, cmd.getFullClassName(), ownerMmd.getFullFieldName()));                      
            }

            if (mfmd != null)
            {
                if (ownerMmd.getJoinMetaData() == null)
                {
                    // Load field of key in value
                    if (ownerMmd.getKeyMetaData() != null && ownerMmd.getKeyMetaData().getMappedBy() != null)
                    {
                        // Key field is stored in the value table
                        AbstractMemberMetaData kmd = null;
                        String key_field_name = ownerMmd.getKeyMetaData().getMappedBy();
                        if (key_field_name != null)
                        {
                            kmd = cmd.getMetaDataForMember(key_field_name);
                        }
                        if (kmd == null)
                        {
                            // Field not in primary class so may be in subclass so check all managed classes
                            Iterator<AbstractClassMetaData> cmdIter = managedClassMetaData.iterator();
                            while (cmdIter.hasNext())
                            {
                                AbstractClassMetaData managedCmd = cmdIter.next();
                                kmd = managedCmd.getMetaDataForMember(key_field_name);
                                if (kmd != null)
                                {
                                    break;
                                }
                            }
View Full Code Here

        if (mmd == null)
        {
            Iterator<AbstractClassMetaData> iter = managedClassMetaData.iterator();
            while (iter.hasNext())
            {
                AbstractClassMetaData theCmd = iter.next();
                final AbstractMemberMetaData foundMmd = theCmd.getMetaDataForMember(memberName);
                if (foundMmd != null)
                {
                    if (mmd != null && (!mmd.toString().equalsIgnoreCase(foundMmd.toString()) || mmd.getType() != foundMmd.getType()))
                    {
                        final String errMsg = "Table " + getIdentifier() +
View Full Code Here

                    }
                    else
                    {
                        if (strategy == DiscriminatorStrategy.VALUE_MAP)
                        {
                            AbstractClassMetaData subclassCmd = storeMgr.getNucleusContext().getMetaDataManager()
                                .getMetaDataForClass(subclass, clr);
                            discrimMapping.setObject(ec, ps, MappingHelper.getMappingIndices(jdbcPosition,
                                discrimMapping),
                                subclassCmd.getInheritanceMetaData().getDiscriminatorMetaData().getValue());
                            jdbcPosition += discrimMapping.getNumberOfDatastoreMappings();
                        }
                    }
                }
            }
View Full Code Here

TOP

Related Classes of org.datanucleus.metadata.AbstractClassMetaData

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.