/** * INTERNAL: * Return the classifiction for the field contained in the mapping. * This is used to convert the row value to a consistent java value. */ public Class getFieldClassification(DatabaseField fieldToClassify) throws DescriptorException { DatabaseMapping mapping = getMappingForField(fieldToClassify); if (mapping == null) { // Means that the mapping is read-only or the classification is unknown, // this is normally not an issue as the classification is only really used for primary keys // and only when the database type can be different and not polymorphic than the object type. return null; } return mapping.getFieldClassification(fieldToClassify); }
/** * Return the base mapping for the given DatabaseField. */ public DatabaseMapping getBaseMappingForField(DatabaseField databaseField) { DatabaseMapping mapping = getMappingForField(databaseField); // Drill down through the mappings until we get the direct mapping to the databaseField. while (mapping.isAggregateObjectMapping()) { mapping = ((AggregateObjectMapping)mapping).getReferenceDescriptor().getObjectBuilder().getMappingForField(databaseField); } return mapping; }
/** * INTERNAL: * returns the mapping from the writelock field. * returns null if not found */ protected DatabaseMapping mappingFromLockField() { return descriptor.getObjectBuilder().getMappingForField(getWriteLockField()); }
/** * Return the base value that is mapped to for given field. */ public Object getParentObjectForField(DatabaseField databaseField, Object domainObject) { Object valueIntoObject = domainObject; DatabaseMapping mapping = getMappingForField(databaseField); // Drill down through the aggregate mappings to get to the direct to field mapping. while (mapping.isAggregateObjectMapping()) { valueIntoObject = mapping.getAttributeValueFromObject(valueIntoObject); mapping = ((AggregateMapping)mapping).getReferenceDescriptor().getObjectBuilder().getMappingForField(databaseField); } return valueIntoObject; }
/** * INTERNAL: * Assign values from objectRow to the object through all the mappings corresponding to the field. */ public void assignReturnValueForField(Object object, ReadObjectQuery query, AbstractRecord row, DatabaseField field, Collection handledMappings) { DatabaseMapping mapping = getMappingForField(field); if (mapping != null) { assignReturnValueToMapping(object, query, row, field, mapping, handledMappings); } Vector mappingVector = getReadOnlyMappingsForField(field); if (mappingVector != null) { for (int j = 0; j < mappingVector.size(); j++) { mapping = (DatabaseMapping)mappingVector.elementAt(j); assignReturnValueToMapping(object, query, row, field, mapping, handledMappings); } } }
/** * Return the base value that is mapped to for given field. */ public Object getBaseValueForField(DatabaseField databaseField, Object domainObject) { Object valueIntoObject = domainObject; DatabaseMapping mapping = getMappingForField(databaseField); // Drill down through the aggregate mappings to get to the direct to field mapping. while (mapping.isAggregateObjectMapping()) { valueIntoObject = mapping.getAttributeValueFromObject(valueIntoObject); mapping = ((AggregateMapping)mapping).getReferenceDescriptor().getObjectBuilder().getMappingForField(databaseField); } return mapping.getAttributeValueFromObject(valueIntoObject); }
/** * INTERNAL: * Add a primary key join column (secondary field). * If this contain primary keys and the descriptor(or its subclass) has multiple tables * (secondary tables or joined inheritance strategy), this should also know the primary key * join columns to handle some cases properly. */ public void addPrimaryKeyJoinField(DatabaseField primaryKeyField, DatabaseField secondaryField) { // now it doesn't need to manage this as a separate table here, // it's enough just to add the mapping to ObjectBuilder.mappingsByField ObjectBuilder builder = getReferenceDescriptor().getObjectBuilder(); DatabaseMapping mapping = builder.getMappingForField(primaryKeyField); if (mapping != null) { builder.getMappingsByField().put(secondaryField, mapping); } } }
/** * INTERNAL: * Return the classification for the field contained in the mapping. * This is used to convert the row value to a consistent Java value. */ public Class getFieldClassification(DatabaseField fieldToClassify) { DatabaseMapping mapping = getReferenceDescriptor().getObjectBuilder().getMappingForField(fieldToClassify); if (mapping == null) { return null;// Means that the mapping is read-only } return mapping.getFieldClassification(fieldToClassify); }
protected void updateChangeSet(ClassDescriptor desc, ObjectChangeSet objectChangeSet, DatabaseField field, Object object, Collection handledMappings) { DatabaseMapping mapping; Vector mappingVector = desc.getObjectBuilder().getReadOnlyMappingsForField(field); if (mappingVector != null) { for (int j = 0; j < mappingVector.size(); j++) { mapping = (DatabaseMapping)mappingVector.elementAt(j); updateChangeSet(mapping, objectChangeSet, field, object, handledMappings); } } mapping = desc.getObjectBuilder().getMappingForField(field); if (mapping != null) { updateChangeSet(mapping, objectChangeSet, field, object, handledMappings); } }
/** * INTERNAL: * Return the classifiction for the field contained in the mapping. * This is used to convert the row value to a consistent java value. */ public Class getFieldClassification(DatabaseField fieldToClassify) throws DescriptorException { DatabaseField fieldInTarget = (DatabaseField)getSourceToTargetKeyFields().get(fieldToClassify); if (fieldInTarget == null) { return null;// Can be registered as multiple table secondary field mapping } DatabaseMapping mapping = getReferenceDescriptor().getObjectBuilder().getMappingForField(fieldInTarget); if (mapping == null) { return null;// Means that the mapping is read-only } return mapping.getFieldClassification(fieldInTarget); }
/** * INTERNAL: * Prepare fetch group for read query */ public void prepareFetchGroupForReadQuery(FetchGroup fetchGroup, ObjectLevelReadQuery query) { //version stored in object, add the version attribute to the fetch group attribute list if (isStoredInObject()) { String verAttributeName = descriptor.getObjectBuilder().getMappingForField(writeLockField).getAttributeName(); fetchGroup.addAttribute(verAttributeName); } else {//stored in cache, add the version field to the select fields if (!query.getAdditionalFields().contains(writeLockField)) { query.addAdditionalField(writeLockField); } } } }
DatabaseMapping mapping = getMappingForField(secondaryKeyField); if (mapping == null) { throw DescriptorException.missingMappingForField(secondaryKeyField, getDescriptor());
/** * Validates the object builder. This is done once the object builder initialized and descriptor * fires this validation. */ public void validate(AbstractSession session) throws DescriptorException { if (getDescriptor().usesSequenceNumbers()) { if (getMappingForField(getDescriptor().getSequenceNumberField()) == null) { throw DescriptorException.mappingForSequenceNumberField(getDescriptor()); } } }
public DatabaseMapping getMappingFromQueryKey() { QueryKey queryKey = getQueryKeyOrNull(); if ((queryKey == null) || (!(queryKey instanceof DirectQueryKey))) { throw QueryException.cannotConformExpression(); } mapping = queryKey.getDescriptor().getObjectBuilder().getMappingForField(((DirectQueryKey)queryKey).getField()); if (mapping == null) { throw QueryException.cannotConformExpression(); } return mapping; }
DatabaseMapping aggregatedFieldMapping = aggregateObjectBuilder.getMappingForField(field);
/** * INTERNAL: * Return the value for in memory comparison. * This is only valid for valueable expressions. */ public Object valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean isObjectUnregistered) { // Joins not supported. if (getBuilder() != getBaseExpression()) { throw QueryException.cannotConformExpression(); } // For bug 2780817 get the mapping directly from the object. In EJB 2.0 // inheritance, each child must override mappings defined in an abstract // class with its own. DatabaseMapping mapping = session.getDescriptor(object.getClass()).getObjectBuilder().getMappingForField(getField()); if (mapping == null) { throw QueryException.cannotConformExpression(); } return mapping.valueFromObject(object, getField(), session); }
DatabaseMapping mapping = this.getDescriptor().getObjectBuilder().getMappingForAttributeName(pkElementArray[index].getAttributeName()); if (mapping == null) { mapping = this.getDescriptor().getObjectBuilder().getMappingForField(pkElementArray[index].getDatabaseField()); mapping = this.getDescriptor().getObjectBuilder().getMappingForField(pkElementArray[index].getDatabaseField());
/** * Extract the value of the primary key attribute from the specified object. */ public Object extractValueFromObjectForField(Object domainObject, DatabaseField field, AbstractSession session) throws DescriptorException { // Allow for inheritance, the concrete descriptor must always be used. ClassDescriptor descriptor = null;//this variable will be assigned in the final if (getDescriptor().hasInheritance() && (domainObject.getClass() != getDescriptor().getJavaClass()) && ((descriptor = session.getDescriptor(domainObject)).getJavaClass() != getDescriptor().getJavaClass())) { return descriptor.getObjectBuilder().extractValueFromObjectForField(domainObject, field, session); } else { DatabaseMapping mapping = getMappingForField(field); if (mapping == null) { throw DescriptorException.missingMappingForField(field, getDescriptor()); } return mapping.valueFromObject(domainObject, field, session); } }
DatabaseMapping mapping = this.getDescriptor().getObjectBuilder().getMappingForAttributeName(keyElements[index].getAttributeName()); if (mapping == null) {// must be aggregate mapping = this.getDescriptor().getObjectBuilder().getMappingForField(field); mapping = this.getDescriptor().getObjectBuilder().getMappingForField(field);
/** * 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; }