/** * PUBLIC: * Return the referenceDescriptor. This is a descriptor which is associated with * the reference class. */ public ClassDescriptor getReferenceClassDescriptor() { ClassDescriptor desc = getReferenceDescriptor(); if (desc instanceof ClassDescriptor) { return (ClassDescriptor)desc; } else { throw ValidationException.cannotCastToClass(desc, desc.getClass(), ClassDescriptor.class); } }
/** * resolveClass: Answer the class for the mapping associated with the my variableName in the ownerClass. * Answer null if the node represents a mapping that doesn't exist */ public Class resolveClass(GenerationContext context, Class ownerClass) { DatabaseMapping mapping; mapping = resolveMapping(context, ownerClass); // if we are working with a direct-to-field, or the mapping's null, // return the owner class // Returning the ownerClass when the mapping is null delegates error handling // to the query rather than me if ((mapping == null) || (mapping.isDirectToFieldMapping())) { return ownerClass; } ClassDescriptor descriptor = mapping.getReferenceDescriptor(); return (descriptor==null) ? null : descriptor.getJavaClass(); //return mapping.getReferenceDescriptor().getJavaClass(); }
/** * INTERNAL: * Iterate through a list of joined expressions and add the fields they represent to a list * of fields. */ protected void addSelectionFieldsForJoinedExpressions(List fields, List joinedExpressions) { for (int index = 0; index < joinedExpressions.size(); index++) { ObjectExpression objectExpression = (ObjectExpression)joinedExpressions.get(index); // Expression may not have been initialized. objectExpression.getBuilder().setSession(getSession().getRootSession(null)); objectExpression.getBuilder().setQueryClass(getReferenceClass()); ClassDescriptor descriptor = objectExpression.getMapping().getReferenceDescriptor(); fields.addAll(descriptor.getFields()); } }
/** * INTERNAL: * This method is for processing a single FieldResult, returning the DatabaseField it refers to. */ public DatabaseField processValueFromRecordForMapping(ClassDescriptor descriptor, String[] attributeNames, int currentLoc){ DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeNames[currentLoc]); if (mapping==null){throw QueryException.mappingForFieldResultNotFound(attributeNames,currentLoc);} currentLoc++; if (attributeNames.length!=currentLoc){ ClassDescriptor currentDescriptor = mapping.getReferenceDescriptor(); DatabaseField df= processValueFromRecordForMapping(currentDescriptor, attributeNames, currentLoc); if (mapping.isOneToOneMapping()){ return (DatabaseField)(((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(df)); } return df; }else{ //this is it.. return this mapping's field return (DatabaseField) mapping.getFields().firstElement(); } }
/** * INTERNAL: * This method is used when computing the indexes for joined mappings. * It iterates through a list of join expressions and adds an index that represents where the * fields represented by that expression will appear in the row returned by a read query. * * @see #computeJoiningMappingIndexes(boolean, AbstractSession) */ protected int computeIndexesForJoinedExpressions(List joinedExpressions, int currentIndex, AbstractSession session) { for (int index = 0; index < joinedExpressions.size(); index++) { ObjectExpression objectExpression = (ObjectExpression)joinedExpressions.get(index); // Ignore nested if ((objectExpression.getBaseExpression() == objectExpression.getBuilder()) && objectExpression.getMapping() != null && objectExpression.getMapping().isForeignReferenceMapping()) { getJoinedMappingIndexes_().put(objectExpression.getMapping(), new Integer(currentIndex)); } ClassDescriptor descriptor = objectExpression.getMapping().getReferenceDescriptor(); int nFields; if(objectExpression.isQueryKeyExpression() && ((QueryKeyExpression)objectExpression).isUsingOuterJoinForMultitableInheritance()) { nFields = descriptor.getAllFields().size(); } else { nFields = descriptor.getFields().size(); } currentIndex = currentIndex + nFields; } return currentIndex; }
/** * INTERNAL: * Simply check that the object is not already locked then pass it on to the locking method */ protected CacheKey checkAndLockObject(Object objectToLock, Map lockedObjects, DatabaseMapping mapping, AbstractSession session) { //the cachekey should always reference an object otherwise what would we be cloning. if ((objectToLock != null) && !lockedObjects.containsKey(objectToLock)) { Vector primaryKeysToLock = null; ClassDescriptor referenceDescriptor = null; if (mapping.getReferenceDescriptor().hasInheritance()) { referenceDescriptor = session.getDescriptor(objectToLock); } else { referenceDescriptor = mapping.getReferenceDescriptor(); } // Need to traverse aggregates, but not lock aggregates directly. if (referenceDescriptor.isAggregateDescriptor() || referenceDescriptor.isAggregateCollectionDescriptor()) { traverseRelatedLocks(objectToLock, lockedObjects, referenceDescriptor, session); } else { primaryKeysToLock = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(objectToLock, session); CacheKey toWaitOn = acquireLockAndRelatedLocks(objectToLock, lockedObjects, primaryKeysToLock, referenceDescriptor, session); if (toWaitOn != null) { return toWaitOn; } } } return null; }
while (cp.hasNext(iterator)) { Object object = cp.next(iterator, session); if (mapping.getReferenceDescriptor().hasWrapperPolicy()) { object = mapping.getReferenceDescriptor().getWrapperPolicy().unwrapObject(object, session); if (mapping.getReferenceDescriptor().hasWrapperPolicy()) { objectToLock = mapping.getReferenceDescriptor().getWrapperPolicy().unwrapObject(objectToLock, session);
/** */ private Object getType(DatabaseMapping mapping) { if (mapping == null) { return null; } Object type = null; if (mapping.isForeignReferenceMapping()) { ClassDescriptor descriptor = mapping.getReferenceDescriptor(); type = descriptor == null ? null : descriptor.getJavaClass(); } else if (mapping.isAggregateMapping()) { // Return the ClassDescriptor as the type representation in case // of an embeeded. This makese sure that any property or field // access of the embedded uses the correct mapping information and // not the shell of the descriptors as stored by the session. type = ((AggregateMapping)mapping).getReferenceDescriptor(); } else { type = mapping.getAttributeClassification(); } return type; }
targetTable = ((DirectCollectionMapping)outerExpression.getMapping()).getReferenceTable(); } else { targetTable = (DatabaseTable)outerExpression.getMapping().getReferenceDescriptor().getTables().firstElement(); writer.write(newAlias.getQualifiedName()); } else {// do normal outer stuff for Informix for (Enumeration target = outerExpression.getMapping().getReferenceDescriptor().getTables().elements(); target.hasMoreElements();) { DatabaseTable newTarget = (DatabaseTable)target.nextElement();
/** * INTERNAL: * This method is for processing all FieldResults for a mapping. Adds DatabaseFields to the passed in entityRecord */ public void getValueFromRecordForMapping(DatabaseRecord entityRecord,DatabaseMapping mapping, FieldResult fieldResult, DatabaseRecord databaseRecord){ ClassDescriptor currentDescriptor = mapping.getReferenceDescriptor(); /** check if this FieldResult contains any other FieldResults, process it if it doesn't */ if (fieldResult.getFieldResults()==null){ DatabaseField dbfield = processValueFromRecordForMapping(currentDescriptor,fieldResult.getMultipleFieldIdentifiers(),1); /** If it is a 1:1 mapping we need to do the target to source field conversion. If it is an aggregate, it is fine as it is*/ if (mapping.isOneToOneMapping()){ dbfield = (DatabaseField)(((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(dbfield)); } entityRecord.put(dbfield, databaseRecord.get(fieldResult.getColumnName())); return; } /** This processes each FieldResult stored in the collection of FieldResults individually */ Iterator fieldResults = fieldResult.getFieldResults().iterator(); while (fieldResults.hasNext()){ FieldResult tempFieldResult = ((FieldResult)fieldResults.next()); DatabaseField dbfield = processValueFromRecordForMapping(currentDescriptor,tempFieldResult.getMultipleFieldIdentifiers(),1); if (mapping.isOneToOneMapping()){ dbfield = (DatabaseField)(((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(dbfield)); } entityRecord.put(dbfield, databaseRecord.get(tempFieldResult.getColumnName())); } }
ObjectBuilder builder = mapping.getReferenceDescriptor().getObjectBuilder();
Object aggregate = mapping.getRealAttributeValueFromObject(toWriteInto, session); if (aggregate == null) { aggregate = mapping.getReferenceDescriptor().getJavaClass().newInstance(); mapping.setRealAttributeValueInObject(toWriteInto, aggregate); mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForAttributeName(keyElements[index].getAttributeName()); if (mapping == null) {// must be aggregate mapping = this.getDescriptor().getObjectBuilder().getMappingForField(field);
mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForAttributeName(pkElementArray[index].getAttributeName()); if (mapping == null) {// must be aggregate mapping = this.getDescriptor().getObjectBuilder().getMappingForField(pkElementArray[index].getDatabaseField());
public ClassDescriptor getDescriptor() { if (isAttribute()) { return null; } if (descriptor == null) { // Look first for query keys, then mappings. Ultimately we should have query keys // for everything and can dispense with the mapping part. ForeignReferenceQueryKey queryKey = (ForeignReferenceQueryKey)getQueryKeyOrNull(); if (queryKey != null) { descriptor = getSession().getDescriptor(queryKey.getReferenceClass()); return descriptor; } if (getMapping() == null) { throw QueryException.invalidQueryKeyInExpression(this); } // We assume this is either a foreign reference or an aggregate mapping descriptor = getMapping().getReferenceDescriptor(); if (getMapping().isVariableOneToOneMapping()) { throw QueryException.cannotQueryAcrossAVariableOneToOneMapping(getMapping(), descriptor); } } return descriptor; }
/** * INTERNAL: * Create an instance of the composite primary key class for the key object. */ public Object createPrimaryKeyInstance(Object key, AbstractSession session) { Object keyInstance = getPKClassInstance(); ObjectBuilder builder = getDescriptor().getObjectBuilder(); KeyElementAccessor[] pkElementArray = this.getKeyClassFields(getPKClass()); for (int index = 0; index < pkElementArray.length; index++) { KeyElementAccessor accessor = pkElementArray[index]; DatabaseMapping mapping = builder.getMappingForAttributeName(accessor.getAttributeName()); // With session validation, the mapping shouldn't be null at this // point, don't bother checking. while (mapping.isAggregateObjectMapping()) { mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForAttributeName(pkElementArray[index].getAttributeName()); if (mapping == null) { // must be aggregate mapping = builder.getMappingForField(accessor.getDatabaseField()); } } Object fieldValue = mapping.getRealAttributeValueFromObject(key, (oracle.toplink.essentials.internal.sessions.AbstractSession) session); accessor.setValue(keyInstance, fieldValue); } return keyInstance; }
normalizer.getStatement().getOuterJoinedMappingCriteria().addElement(null); normalizer.getStatement().getOuterJoinedAdditionalJoinCriteria().addElement(additionalExpressionCriteriaMap()); normalizer.getStatement().getDescriptorsForMultitableInheritanceOnly().add(getMapping().getReferenceDescriptor());
ClassDescriptor rd = mapping.getReferenceDescriptor(); if ((!shouldIterateOverWrappedObjects()) && (rd != null) && (rd.hasWrapperPolicy())) { return;
mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForField(((DirectQueryKey)queryKey).getField()); aggregateValue = mapping.getRealAttributeValueFromObject(aggregateValue, session);
newDescriptor = mapping.getReferenceDescriptor(); outerJoin = ((QueryKeyExpression)baseExp).shouldUseOuterJoin();
setDescriptor(mapping.getReferenceDescriptor()); if (getDescriptor().hasInheritance()){ ((QueryKeyExpression)getAttributeExpression()).setShouldUseOuterJoinForMultitableInheritance(true);