Search in sources :

Example 1 with FetchPlan

use of org.datanucleus.FetchPlan in project datanucleus-rdbms by datanucleus.

the class FKListStore method validateElementForWriting.

/**
 * Method to validate that an element is valid for writing to the datastore.
 * TODO Minimise differences to super.validateElementForWriting()
 * @param op ObjectProvider for the List
 * @param element The element to validate
 * @param index The position that the element is being stored at in the list
 * @return Whether the element was inserted
 */
protected boolean validateElementForWriting(final ObjectProvider op, final Object element, final int index) {
    final Object newOwner = op.getObject();
    ComponentInfo info = getComponentInfoForElement(element);
    final DatastoreClass elementTable;
    if (storeMgr.getNucleusContext().getMetaDataManager().isPersistentInterface(elementType)) {
        elementTable = storeMgr.getDatastoreClass(storeMgr.getNucleusContext().getMetaDataManager().getImplementationNameForPersistentInterface(elementType), clr);
    } else {
        elementTable = storeMgr.getDatastoreClass(element.getClass().getName(), clr);
    }
    final JavaTypeMapping orderMapping;
    if (info != null) {
        orderMapping = info.getDatastoreClass().getExternalMapping(ownerMemberMetaData, MappingType.EXTERNAL_INDEX);
    } else {
        orderMapping = this.orderMapping;
    }
    // Check if element is ok for use in the datastore, specifying any external mappings that may be required
    boolean inserted = super.validateElementForWriting(op.getExecutionContext(), element, new FieldValues() {

        public void fetchFields(ObjectProvider elemOP) {
            // Find the (element) table storing the FK back to the owner
            if (elementTable != null) {
                JavaTypeMapping externalFKMapping = elementTable.getExternalMapping(ownerMemberMetaData, MappingType.EXTERNAL_FK);
                if (externalFKMapping != null) {
                    // The element has an external FK mapping so set the value it needs to use in the INSERT
                    elemOP.setAssociatedValue(externalFKMapping, op.getObject());
                }
                if (relationDiscriminatorMapping != null) {
                    elemOP.setAssociatedValue(relationDiscriminatorMapping, relationDiscriminatorValue);
                }
                if (orderMapping != null && index >= 0) {
                    if (ownerMemberMetaData.getOrderMetaData() != null && ownerMemberMetaData.getOrderMetaData().getMappedBy() != null) {
                        // Order is stored in a field in the element so update it
                        // We support mapped-by fields of types int/long/Integer/Long currently
                        Object indexValue = null;
                        if (orderMapping.getMemberMetaData().getTypeName().equals(ClassNameConstants.JAVA_LANG_LONG) || orderMapping.getMemberMetaData().getTypeName().equals(ClassNameConstants.LONG)) {
                            indexValue = Long.valueOf(index);
                        } else {
                            indexValue = Integer.valueOf(index);
                        }
                        elemOP.replaceFieldMakeDirty(orderMapping.getMemberMetaData().getAbsoluteFieldNumber(), indexValue);
                    } else {
                        // Order is stored in a surrogate column so save its vaue for the element to use later
                        elemOP.setAssociatedValue(orderMapping, Integer.valueOf(index));
                    }
                }
            }
            if (ownerMemberMetaData.getMappedBy() != null) {
                // TODO This is ManagedRelations - move into RelationshipManager
                // Managed Relations : 1-N bidir, so make sure owner is correct at persist
                // TODO Support DOT notation in mappedBy
                ObjectProvider ownerHolderOP = elemOP;
                int ownerFieldNumberInHolder = -1;
                if (ownerMemberMetaData.getMappedBy().indexOf('.') > 0) {
                    AbstractMemberMetaData otherMmd = null;
                    AbstractClassMetaData otherCmd = info.getAbstractClassMetaData();
                    String remainingMappedBy = ownerMemberMetaData.getMappedBy();
                    while (remainingMappedBy.indexOf('.') > 0) {
                        int dotPosition = remainingMappedBy.indexOf('.');
                        String thisMappedBy = remainingMappedBy.substring(0, dotPosition);
                        otherMmd = otherCmd.getMetaDataForMember(thisMappedBy);
                        Object holderValueAtField = ownerHolderOP.provideField(otherMmd.getAbsoluteFieldNumber());
                        ownerHolderOP = op.getExecutionContext().findObjectProviderForEmbedded(holderValueAtField, ownerHolderOP, otherMmd);
                        remainingMappedBy = remainingMappedBy.substring(dotPosition + 1);
                        otherCmd = storeMgr.getMetaDataManager().getMetaDataForClass(otherMmd.getTypeName(), clr);
                        if (remainingMappedBy.indexOf('.') < 0) {
                            otherMmd = otherCmd.getMetaDataForMember(remainingMappedBy);
                            ownerFieldNumberInHolder = otherMmd.getAbsoluteFieldNumber();
                        }
                    }
                } else {
                    ownerFieldNumberInHolder = info.getAbstractClassMetaData().getAbsolutePositionOfMember(ownerMemberMetaData.getMappedBy());
                }
                Object currentOwner = ownerHolderOP.provideField(ownerFieldNumberInHolder);
                if (currentOwner == null) {
                    // No owner, so correct it
                    NucleusLogger.PERSISTENCE.info(Localiser.msg("056037", op.getObjectAsPrintable(), ownerMemberMetaData.getFullFieldName(), StringUtils.toJVMIDString(ownerHolderOP.getObject())));
                    ownerHolderOP.replaceFieldMakeDirty(ownerFieldNumberInHolder, newOwner);
                } else if (currentOwner != newOwner && op.getReferencedPC() == null) {
                    // Inconsistent owner, so throw exception
                    throw new NucleusUserException(Localiser.msg("056038", op.getObjectAsPrintable(), ownerMemberMetaData.getFullFieldName(), StringUtils.toJVMIDString(ownerHolderOP.getObject()), StringUtils.toJVMIDString(currentOwner)));
                }
            }
        }

        public void fetchNonLoadedFields(ObjectProvider op) {
        }

        public FetchPlan getFetchPlanForLoading() {
            return null;
        }
    });
    return inserted;
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ObjectProvider(org.datanucleus.state.ObjectProvider) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass) FieldValues(org.datanucleus.store.FieldValues) FetchPlan(org.datanucleus.FetchPlan) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 2 with FetchPlan

use of org.datanucleus.FetchPlan in project datanucleus-rdbms by datanucleus.

the class MapKeySetStore method getSQLStatementForIterator.

/**
 * Method to generate an SQLStatement for iterating through keys of the map.
 * Populates the iteratorMappingDef and iteratorMappingParams.
 * Creates a statement that selects the key table(s), and adds any necessary join to the containerTable
 * if that is not the key table. If the key is embedded then selects the table it is embedded in.
 * Adds a restriction on the ownerMapping of the containerTable so we can restrict to the owner object.
 * @param ownerSM StateManager for the owner object
 * @return The SQLStatement
 */
protected SelectStatement getSQLStatementForIterator(DNStateManager ownerSM) {
    SelectStatement sqlStmt = null;
    ExecutionContext ec = ownerSM.getExecutionContext();
    final ClassLoaderResolver clr = ec.getClassLoaderResolver();
    final Class keyCls = clr.classForName(elementType);
    SQLTable containerSqlTbl = null;
    MapType mapType = getOwnerMemberMetaData().getMap().getMapType();
    FetchPlan fp = ec.getFetchPlan();
    if (elementCmd != null && elementCmd.getDiscriminatorStrategyForTable() != null && elementCmd.getDiscriminatorStrategyForTable() != DiscriminatorStrategy.NONE) {
        // Map<PC, ?> where key has discriminator
        if (ClassUtils.isReferenceType(keyCls)) {
            // Take the metadata for the first implementation of the reference type
            String[] clsNames = storeMgr.getNucleusContext().getMetaDataManager().getClassesImplementingInterface(elementType, clr);
            Class[] cls = new Class[clsNames.length];
            for (int j = 0; j < clsNames.length; j++) {
                cls[j] = clr.classForName(clsNames[j]);
            }
            sqlStmt = new DiscriminatorStatementGenerator(storeMgr, clr, cls, true, null, null).getStatement(ec);
        } else {
            sqlStmt = new DiscriminatorStatementGenerator(storeMgr, clr, clr.classForName(elementInfo[0].getClassName()), true, null, null).getStatement(ec);
        }
        containerSqlTbl = sqlStmt.getPrimaryTable();
        iterateUsingDiscriminator = true;
        if (mapType == MapType.MAP_TYPE_VALUE_IN_KEY) {
            // Select key fields
            containerSqlTbl = sqlStmt.getPrimaryTable();
            iteratorMappingDef = new StatementClassMapping();
            SQLStatementHelper.selectFetchPlanOfSourceClassInStatement(sqlStmt, iteratorMappingDef, fp, sqlStmt.getPrimaryTable(), elementCmd, fp.getMaxFetchDepth());
        } else {
            // MAP_TYPE_KEY_IN_VALUE, MAP_TYPE_JOIN
            // Join to join table and select key fields
            JavaTypeMapping keyIdMapping = sqlStmt.getPrimaryTable().getTable().getIdMapping();
            containerSqlTbl = sqlStmt.join(JoinType.INNER_JOIN, sqlStmt.getPrimaryTable(), keyIdMapping, containerTable, null, elementMapping, null, null, true);
            iteratorMappingDef = new StatementClassMapping();
            SQLStatementHelper.selectFetchPlanOfSourceClassInStatement(sqlStmt, iteratorMappingDef, fp, sqlStmt.getPrimaryTable(), elementCmd, fp.getMaxFetchDepth());
        }
    } else {
        if (mapType == MapType.MAP_TYPE_VALUE_IN_KEY) {
            // Select of key in key table (allow union of possible key types)
            iteratorMappingDef = new StatementClassMapping();
            UnionStatementGenerator stmtGen = new UnionStatementGenerator(storeMgr, clr, keyCls, true, null, null);
            stmtGen.setOption(SelectStatementGenerator.OPTION_SELECT_DN_TYPE);
            iteratorMappingDef.setNucleusTypeColumnName(UnionStatementGenerator.DN_TYPE_COLUMN);
            sqlStmt = stmtGen.getStatement(ec);
            containerSqlTbl = sqlStmt.getPrimaryTable();
            SQLStatementHelper.selectFetchPlanOfSourceClassInStatement(sqlStmt, iteratorMappingDef, fp, sqlStmt.getPrimaryTable(), elementCmd, fp.getMaxFetchDepth());
        } else {
            // MAP_TYPE_KEY_IN_VALUE, MAP_TYPE_JOIN
            if (elementCmd != null) {
                // Select of key table, joining to join table
                iteratorMappingDef = new StatementClassMapping();
                UnionStatementGenerator stmtGen = new UnionStatementGenerator(storeMgr, clr, keyCls, true, null, null);
                stmtGen.setOption(SelectStatementGenerator.OPTION_SELECT_DN_TYPE);
                iteratorMappingDef.setNucleusTypeColumnName(UnionStatementGenerator.DN_TYPE_COLUMN);
                sqlStmt = stmtGen.getStatement(ec);
                JavaTypeMapping keyIdMapping = sqlStmt.getPrimaryTable().getTable().getIdMapping();
                containerSqlTbl = sqlStmt.join(JoinType.INNER_JOIN, sqlStmt.getPrimaryTable(), keyIdMapping, containerTable, null, elementMapping, null, null, true);
                SQLStatementHelper.selectFetchPlanOfSourceClassInStatement(sqlStmt, iteratorMappingDef, fp, sqlStmt.getPrimaryTable(), elementCmd, fp.getMaxFetchDepth());
            } else {
                // Select of key in join table
                sqlStmt = new SelectStatement(storeMgr, containerTable, null, null);
                sqlStmt.setClassLoaderResolver(clr);
                containerSqlTbl = sqlStmt.getPrimaryTable();
                SQLTable elemSqlTblForKey = containerSqlTbl;
                if (elementMapping.getTable() != containerSqlTbl.getTable()) {
                    elemSqlTblForKey = sqlStmt.getTableForDatastoreContainer(elementMapping.getTable());
                    if (elemSqlTblForKey == null) {
                        // Add join to element table
                        elemSqlTblForKey = sqlStmt.join(JoinType.INNER_JOIN, sqlStmt.getPrimaryTable(), sqlStmt.getPrimaryTable().getTable().getIdMapping(), elementMapping.getTable(), null, elementMapping.getTable().getIdMapping(), null, null, true);
                    }
                }
                sqlStmt.select(elemSqlTblForKey, elementMapping, null);
            }
        }
    }
    // Apply condition on owner field to filter by owner
    SQLExpressionFactory exprFactory = storeMgr.getSQLExpressionFactory();
    SQLTable ownerSqlTbl = SQLStatementHelper.getSQLTableForMappingOfTable(sqlStmt, containerSqlTbl, ownerMapping);
    SQLExpression ownerExpr = exprFactory.newExpression(sqlStmt, ownerSqlTbl, ownerMapping);
    SQLExpression ownerVal = exprFactory.newLiteralParameter(sqlStmt, ownerMapping, null, "OWNER");
    sqlStmt.whereAnd(ownerExpr.eq(ownerVal), true);
    // Input parameter(s) - the owner
    int inputParamNum = 1;
    StatementMappingIndex ownerIdx = new StatementMappingIndex(ownerMapping);
    if (sqlStmt.getNumberOfUnions() > 0) {
        // Add parameter occurrence for each union of statement
        for (int j = 0; j < sqlStmt.getNumberOfUnions() + 1; j++) {
            int[] paramPositions = new int[ownerMapping.getNumberOfColumnMappings()];
            for (int k = 0; k < ownerMapping.getNumberOfColumnMappings(); k++) {
                paramPositions[k] = inputParamNum++;
            }
            ownerIdx.addParameterOccurrence(paramPositions);
        }
    } else {
        int[] paramPositions = new int[ownerMapping.getNumberOfColumnMappings()];
        for (int k = 0; k < ownerMapping.getNumberOfColumnMappings(); k++) {
            paramPositions[k] = inputParamNum++;
        }
        ownerIdx.addParameterOccurrence(paramPositions);
    }
    iteratorMappingParams = new StatementParameterMapping();
    iteratorMappingParams.addMappingForParameter("owner", ownerIdx);
    return sqlStmt;
}
Also used : StatementParameterMapping(org.datanucleus.store.rdbms.query.StatementParameterMapping) SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) FetchPlan(org.datanucleus.FetchPlan) StatementMappingIndex(org.datanucleus.store.rdbms.query.StatementMappingIndex) MapType(org.datanucleus.metadata.MapMetaData.MapType) StatementClassMapping(org.datanucleus.store.rdbms.query.StatementClassMapping) UnionStatementGenerator(org.datanucleus.store.rdbms.sql.UnionStatementGenerator) SelectStatement(org.datanucleus.store.rdbms.sql.SelectStatement) ExecutionContext(org.datanucleus.ExecutionContext) SQLTable(org.datanucleus.store.rdbms.sql.SQLTable) DiscriminatorStatementGenerator(org.datanucleus.store.rdbms.sql.DiscriminatorStatementGenerator) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass)

Example 3 with FetchPlan

use of org.datanucleus.FetchPlan in project datanucleus-rdbms by datanucleus.

the class MappingHelper method getObjectForApplicationIdentity.

/**
 * Get the persistent object instance for a class using application identity defined by the provided result set columns
 * @param ec ExecutionContext
 * @param mapping The mapping in which this is returned
 * @param rs the ResultSet
 * @param resultIndexes indexes in the result set to retrieve
 * @param cmd the AbstractClassMetaData
 * @return the persistent object instance
 */
public static Object getObjectForApplicationIdentity(final ExecutionContext ec, JavaTypeMapping mapping, final ResultSet rs, int[] resultIndexes, AbstractClassMetaData cmd) {
    ClassLoaderResolver clr = ec.getClassLoaderResolver();
    // Abstract class
    if (cmd instanceof ClassMetaData && ((ClassMetaData) cmd).isAbstract() && cmd.getObjectidClass() != null) {
        return getObjectForAbstractClass(ec, mapping, rs, resultIndexes, cmd);
    }
    // Create a ResultSetGetter with the data for the primary key column(s) of this class solely
    int totalMemberCount = cmd.getNoOfManagedMembers() + cmd.getNoOfInheritedManagedMembers();
    final StatementMappingIndex[] statementExpressionIndex = new StatementMappingIndex[totalMemberCount];
    DatastoreClass datastoreClass = mapping.getStoreManager().getDatastoreClass(cmd.getFullClassName(), clr);
    final int[] pkMemberPositions = cmd.getPKMemberPositions();
    int paramIndex = 0;
    for (int i = 0; i < pkMemberPositions.length; ++i) {
        AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkMemberPositions[i]);
        JavaTypeMapping m = datastoreClass.getMemberMapping(mmd);
        statementExpressionIndex[mmd.getAbsoluteFieldNumber()] = new StatementMappingIndex(m);
        int[] expressionsIndex = new int[m.getNumberOfColumnMappings()];
        for (int j = 0; j < expressionsIndex.length; j++) {
            expressionsIndex[j] = resultIndexes[paramIndex++];
        }
        statementExpressionIndex[mmd.getAbsoluteFieldNumber()].setColumnPositions(expressionsIndex);
    }
    final StatementClassMapping resultMappings = new StatementClassMapping();
    for (int i = 0; i < pkMemberPositions.length; i++) {
        resultMappings.addMappingForMember(pkMemberPositions[i], statementExpressionIndex[pkMemberPositions[i]]);
    }
    // TODO Use any other (non-PK) param values
    final FieldManager resultsFM = new ResultSetGetter(ec, rs, resultMappings, cmd);
    Object id = IdentityUtils.getApplicationIdentityForResultSetRow(ec, cmd, null, false, resultsFM);
    Class type = ec.getClassLoaderResolver().classForName(cmd.getFullClassName());
    return ec.findObject(id, new FieldValues() {

        public void fetchFields(DNStateManager sm) {
            sm.replaceFields(pkMemberPositions, resultsFM);
        }

        public void fetchNonLoadedFields(DNStateManager sm) {
            sm.replaceNonLoadedFields(pkMemberPositions, resultsFM);
        }

        public FetchPlan getFetchPlanForLoading() {
            return ec.getFetchPlan();
        }
    }, type, false, true);
}
Also used : FieldManager(org.datanucleus.store.fieldmanager.FieldManager) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) StatementMappingIndex(org.datanucleus.store.rdbms.query.StatementMappingIndex) FetchPlan(org.datanucleus.FetchPlan) StatementClassMapping(org.datanucleus.store.rdbms.query.StatementClassMapping) ResultSetGetter(org.datanucleus.store.rdbms.fieldmanager.ResultSetGetter) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass) DNStateManager(org.datanucleus.state.DNStateManager) FieldValues(org.datanucleus.store.FieldValues) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 4 with FetchPlan

use of org.datanucleus.FetchPlan in project tests by datanucleus.

the class FetchPlanTest method testNestedFetchGroupsAgain.

/**
 * Test nested fetch groups.
 * TODO Merge this with the test above
 */
public void testNestedFetchGroupsAgain() {
    FetchPlan fp = getFetchPlan();
    PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
    MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
    // test parent with fetch-group = group1
    AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP1Sub.class, new ClassLoaderResolverImpl());
    fp.addGroup("1");
    fp.removeGroup(FetchPlan.DEFAULT);
    FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
    int[] fieldsInFP = fpc.getMemberNumbers();
    assertEquals("should have 2 fields in fetchplan", 2, fieldsInFP.length);
    // check if fields are in the FP
    BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
    assertTrue("name should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("name")));
    assertTrue("room should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("room")));
}
Also used : FetchPlanForClass(org.datanucleus.FetchPlanForClass) BitSet(java.util.BitSet) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 5 with FetchPlan

use of org.datanucleus.FetchPlan in project tests by datanucleus.

the class FetchPlanTest method testPostLoad.

/**
 * Test the use of "postload"
 */
public void testPostLoad() throws Exception {
    FetchPlan fp = getFetchPlan();
    PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
    MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
    AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
    // --------------------------------------
    // all fields in DFG
    // --------------------------------------
    FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
    boolean[] loadedFields = new boolean[14];
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group width postLoad + DFG
    // --------------------------------------
    fp.addGroup("groupD");
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group width postLoad
    // --------------------------------------
    fp.addGroup("groupD");
    fp.removeGroup(FetchPlan.DEFAULT);
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group without postLoad
    // --------------------------------------
    fp.addGroup("groupC");
    fp.removeGroup("groupD");
    fp.removeGroup(FetchPlan.DEFAULT);
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertFalse("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group width postLoad
    // --------------------------------------
    fp.addGroup("groupAll");
    fp.removeGroup("groupC");
    fp.removeGroup(FetchPlan.DEFAULT);
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
}
Also used : FetchPlanForClass(org.datanucleus.FetchPlanForClass) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

FetchPlan (org.datanucleus.FetchPlan)28 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)15 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)13 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)12 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)10 ExecutionContext (org.datanucleus.ExecutionContext)9 FetchPlanForClass (org.datanucleus.FetchPlanForClass)9 FieldValues (org.datanucleus.store.FieldValues)8 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)7 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)7 BitSet (java.util.BitSet)6 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)5 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)5 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)5 MetaDataManager (org.datanucleus.metadata.MetaDataManager)5 DNStateManager (org.datanucleus.state.DNStateManager)5 StatementClassMapping (org.datanucleus.store.rdbms.query.StatementClassMapping)5 StatementMappingIndex (org.datanucleus.store.rdbms.query.StatementMappingIndex)5 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)4 MapType (org.datanucleus.metadata.MapMetaData.MapType)4