public void initialize (final DatabaseMapping aMapping, final Session aSession) { if (aMapping.isDirectToFieldMapping ()) { final AbstractDirectMapping aDirectMapping = (AbstractDirectMapping) aMapping; // Allow user to specify field type to override computed value. (i.e. // blob, nchar) if (aDirectMapping.getFieldClassification () == null) aDirectMapping.setFieldClassification (ClassConstants.TIME); } } }
/** * INTERNAL: * Return the class this key mapping maps or the descriptor for it * @return */ public Class getMapKeyTargetType(){ Class aClass = getAttributeAccessor().getAttributeClass(); // 294765: check the attributeClassification when the MapKey annotation is not specified if(null == aClass) { aClass = getAttributeClassification(); } return aClass; }
/** * INTERNAL: * Clone the attribute from the clone and assign it to the backup. */ public void buildBackupClone(Object clone, Object backup, UnitOfWorkImpl unitOfWork) { buildClone(clone, backup, unitOfWork); }
/** * INTERNAL: * Compare the attributes belonging to this mapping for the objects. */ @Override public boolean compareObjects(Object firstObject, Object secondObject, AbstractSession session) { Object firstValue = getAttributeValueFromObject(firstObject); Object secondValue = getAttributeValueFromObject(secondObject); return compareObjectValues(firstValue, secondValue, session); }
/** * INTERNAL: * Clone the attribute from the original and assign it to the clone. * If mutability is configured to be true, clone the attribute if it is an instance of * byte[], java.util.Calendar or java.util.Date (or their subclasses). */ public void buildCloneValue(Object original, Object clone, AbstractSession session) { Object attributeValue = getAttributeValueFromObject(original); attributeValue = buildCloneValue(attributeValue, session); setAttributeValueInObject(clone, attributeValue); }
/** * INTERNAL: * Compare the clone and backup clone values and return a change record if the value changed. */ @Override public ChangeRecord compareForChange(Object clone, Object backUp, ObjectChangeSet owner, AbstractSession session) { // same code as write from object into row for update if (owner.isNew()) { return internalBuildChangeRecord(getAttributeValueFromObject(clone), null, owner); } else if (!compareObjects(backUp, clone, session)) { Object oldValue = null; if (backUp != null && clone != backUp) { oldValue = getAttributeValueFromObject(backUp); } return internalBuildChangeRecord(getAttributeValueFromObject(clone), oldValue, owner); } return null; }
/** * INTERNAL: * The mapping is initialized with the given session. * This mapping is fully initialized after this. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if (getField() == null) { session.getIntegrityChecker().handleError(DescriptorException.fieldNameNotSetInMapping(this)); } if (keyTableForMapKey == null){ setField(getDescriptor().buildField(getField())); } else { setField(getDescriptor().buildField(getField(), keyTableForMapKey)); } setFields(collectFields()); if (getConverter() != null) { getConverter().initialize(this, session); } // Must unwrap Struct types on WLS. if (getField().getSqlType() == java.sql.Types.STRUCT) { getDescriptor().setIsNativeConnectionRequired(true); } }
/** * INTERNAL: * Set the mapping. */ public void initialize(DatabaseMapping mapping, Session session) { this.mapping = mapping; // CR#... Mapping must also have the field classification. if (getMapping().isDirectToFieldMapping()) { AbstractDirectMapping directMapping = (AbstractDirectMapping)getMapping(); // Allow user to specify field type to override computed value. (i.e. blob, nchar) if (directMapping.getFieldClassification() == null) { directMapping.setFieldClassification(getDataClass()); } // Set the object class from the attribute, if null. if (getObjectClass() == null) { setObjectClass(directMapping.getAttributeClassification()); } } }
/** * INTERNAL: * Merge changes from the source to the target object. This merge is only called when a changeSet for the target * does not exist or the target is uninitialized */ public void mergeIntoObject(Object target, boolean isTargetUnInitialized, Object source, MergeManager mergeManager) { // If merge into the unit of work, must only merge and raise the event is the value changed. if ((mergeManager.shouldMergeCloneIntoWorkingCopy() || mergeManager.shouldMergeCloneWithReferencesIntoWorkingCopy()) && this.descriptor.getObjectChangePolicy().isObjectChangeTrackingPolicy()) { // if it didn't change then there will be no event Object attributeValue = getAttributeValueFromObject(source); Object targetAttribute = getAttributeValueFromObject(target); if (!compareObjectValues(attributeValue, targetAttribute, mergeManager.getSession())) { setAttributeValueInObject(target, buildCloneValue(attributeValue, mergeManager.getSession())); //set the value first, if the owner is new ( or aggregate) the change set may be created directly //from the target. this.descriptor.getObjectChangePolicy().raiseInternalPropertyChangeEvent(target, getAttributeName(), targetAttribute, attributeValue); } } else { setAttributeValueInObject(target, buildCloneValue(getAttributeValueFromObject(source), mergeManager.getSession())); } }
/** * INTERNAL: * Initialize the attribute classification. * @Throws DescriptorException when attributeClassification is null */ public void preInitialize(AbstractSession session) throws DescriptorException { super.preInitialize(session); // Allow the attribute class to be set by the user. if (this.attributeClassification == null) { this.attributeClassification = getAttributeAccessor().getAttributeClass(); } this.attributeObjectClassification = Helper.getObjectClass(this.attributeClassification); // Initialize isMutable if not specified, default is false (assumes not mutable). if (this.isMutable == null) { if (getConverter() != null) { setIsMutable(getConverter().isMutable()); } else { setIsMutable(false); } // If mapping a temporal type, use the project mutable default. if (ClassConstants.UTILDATE.isAssignableFrom(getAttributeClassification()) || ClassConstants.CALENDAR.isAssignableFrom(getAttributeClassification())) { setIsMutable(session.getProject().getDefaultTemporalMutable()); } } }
super.convertClassNamesToClasses(classLoader); if (getAttributeClassificationName() != null) { Class attributeClass = null; try{ if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { attributeClass = AccessController.doPrivileged(new PrivilegedClassForName(getAttributeClassificationName(), true, classLoader)); } catch (PrivilegedActionException exception) { throw ValidationException.classNotFoundWhileConvertingClassNames(getAttributeClassificationName(), exception.getException()); attributeClass = PrivilegedAccessHelper.getClassForName(getAttributeClassificationName(), true, classLoader); throw ValidationException.classNotFoundWhileConvertingClassNames(getAttributeClassificationName(), exc); setAttributeClassification(attributeClass); setFieldClassification(fieldClassification);
super.convertClassNamesToClasses(classLoader); if (getAttributeClassificationName() != null) { Class attributeClass = null; try{ if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { attributeClass = (Class)AccessController.doPrivileged(new PrivilegedClassForName(getAttributeClassificationName(), true, classLoader)); } catch (PrivilegedActionException exception) { throw ValidationException.classNotFoundWhileConvertingClassNames(getAttributeClassificationName(), exception.getException()); attributeClass = org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(getAttributeClassificationName(), true, classLoader); throw ValidationException.classNotFoundWhileConvertingClassNames(getAttributeClassificationName(), exc); setAttributeClassification(attributeClass); setConverter(converter); setFieldClassification(fieldClassification);
/** * INTERNAL: * Return the mapping's attribute value from the row. * The execution session is passed for the case of building a UnitOfWork clone * directly from a row, the session set in the query will not know which platform to use * for converting the value. Allows the correct session to be passed in. */ @Override public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) { if (this.descriptor.getCachePolicy().isProtectedIsolation()) { if (this.isCacheable && isTargetProtected && cacheKey != null && cacheKey.getInvalidationState() != CacheKey.CACHE_KEY_INVALID) { Object cached = cacheKey.getObject(); if (cached != null) { if (wasCacheUsed != null){ wasCacheUsed[0] = Boolean.TRUE; } Object attributeValue = getAttributeValueFromObject(cached); return buildCloneValue(attributeValue, executionSession); } } } if (row.hasSopObject()) { return getAttributeValueFromObject(row.getSopObject()); } // PERF: Direct variable access. Object fieldValue = row.get(getField()); Object attributeValue = getObjectValue(fieldValue, executionSession); return attributeValue; }
/** * INTERNAL: * Return the class this key mapping maps or the descriptor for it * @return */ public Class getMapKeyTargetType() { Class aClass = getAttributeAccessor().getAttributeClass(); // 294765: check the attributeClassification when the MapKey annotation is not specified if (null == aClass) { aClass = getAttributeClassification(); } if (null == aClass) { aClass = getField().getType(); } return aClass; }
/** * INTERNAL: * Making any mapping changes necessary to use a the mapping as a map key after initializing the mapping. */ public void postInitializeMapKey(MappedKeyMapContainerPolicy policy) { if (getField().getType() == null) { getField().setType(getFieldClassification(getField())); } }
/** * INTERNAL: * Once descriptors are serialized to the remote session. All its mappings and reference descriptors are traversed. Usually * mappings are initialized and serialized reference descriptors are replaced with local descriptors if they already exist on the * remote session. */ public void remoteInitialization(DistributedSession session) { if (!isRemotelyInitialized()) { super.remoteInitialization(session); if (this.attributeClassification == null) { this.attributeClassification = getAttributeAccessor().getAttributeClass(); } this.attributeObjectClassification = Helper.getObjectClass(this.attributeClassification); } }
/** * INTERNAL: * Merge changes from the source to the target object. */ @Override public void mergeChangesIntoObject(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager, AbstractSession targetSession) { setAttributeValueInObject(target, buildCloneValue(((DirectToFieldChangeRecord)changeRecord).getNewValue(), mergeManager.getSession())); }
/** * INTERNAL: * Convert the attribute value to a field value. * Process any converter if defined, and check for null values. */ public Object getFieldValue(Object attributeValue, AbstractSession session) { // PERF: This method is a major performance code point, // so has been micro optimized and uses direct variable access. Object fieldValue = attributeValue; if ((this.nullValue != null) && (this.nullValue.equals(fieldValue))) { return null; } // Allow for user defined conversion to the object value. if (this.converter != null) { fieldValue = this.converter.convertObjectValueToDataValue(fieldValue, session); } Class fieldClassification = getFieldClassification(this.field); // PERF: Avoid conversion if not required. // EclipseLink bug 240407 - nulls not translated when writing to database if ((fieldValue == null) || (fieldClassification != fieldValue.getClass())) { try { fieldValue = session.getPlatform(this.descriptor.getJavaClass()).convertObject(fieldValue, fieldClassification); } catch (ConversionException exception) { throw ConversionException.couldNotBeConverted(this, this.descriptor, exception); } } return fieldValue; }
/** * Build a clone of the given element in a unitOfWork. */ public Object buildElementClone(Object attributeValue, Object parent, CacheKey cacheKey, Integer refreshCascade, AbstractSession cloningSession, boolean isExisting, boolean isFromSharedCache){ return buildCloneValue(attributeValue, cloningSession); }
/** * This method maintains idempotence on PUT by disallowing sequencing. * * @param descriptor descriptor of the entity passed in 'entity' parameter. * @param entity entity to process. * @return true if check is passed (no sequencing) */ private boolean checkIdempotence(ClassDescriptor descriptor, Object entity) { final AbstractDirectMapping sequenceMapping = descriptor.getObjectBuilder().getSequenceMapping(); if (sequenceMapping != null) { final Object value = sequenceMapping.getAttributeAccessor().getAttributeValueFromObject(entity); if (descriptor.getObjectBuilder().isPrimaryKeyComponentInvalid(value, descriptor.getPrimaryKeyFields().indexOf(descriptor.getSequenceNumberField())) || descriptor.getSequence().shouldAlwaysOverrideExistingValue()) { return false; } } return true; }