/** * INTERNAL: * Initialize the mapping. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if (getField() == null) { throw DescriptorException.fieldNameNotSetInMapping(this); } setField(getDescriptor().buildField(getField())); setFields(collectFields()); if (getValueConverter() != null) { getValueConverter().initialize(this, session); } }
/** * INTERNAL: * Clone the attribute from the clone and assign it to the backup. * For these mappings, this is the same as building the first clone. */ public void buildBackupClone(Object clone, Object backup, UnitOfWorkImpl unitOfWork) { this.buildClone(clone, backup, unitOfWork); }
/** * INTERNAL: * Clone the attribute from the original and assign it to the clone. */ @Override public void buildClone(Object original, CacheKey cacheKey, Object clone, Integer refreshCascade, AbstractSession cloningSession) { Object attributeValue = this.getAttributeValueFromObject(original); this.setAttributeValueInObject(clone, this.buildClonePart(attributeValue, cacheKey, cloningSession)); }
/** * INTERNAL: * Write the fields needed for insert into the template with null values. */ public void writeInsertFieldsIntoRow(AbstractRecord row, AbstractSession session) { if (this.isReadOnly()) { return; } row.put(this.getField(), null); }
if (this.isReadOnly()) { return; Object attributeValue = this.getAttributeValueFromObject(object); if (attributeValue == null) { row.put(this.getField(), null); return; ContainerPolicy cp = this.getContainerPolicy(); if (this.getValueConverter() != null) { element = getValueConverter().convertObjectValueToDataValue(element, session); fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session); row.put(this.getField(), fieldValue);
wasCacheUsed[0] = Boolean.TRUE; Object attributeValue = this.getAttributeValueFromObject(cached); return buildClonePart(attributeValue, cacheKey, executionSession); return getAttributeValueFromObject(row.getSopObject()); ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); if (fieldValue == null) { return cp.containerInstance(); Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue); if (fieldValues == null) { return cp.containerInstance(); for (Enumeration stream = fieldValues.elements(); stream.hasMoreElements();) { Object element = stream.nextElement(); if (this.getValueConverter() != null) { element = getValueConverter().convertDataValueToObjectValue(element, executionSession);
/** * PUBLIC: * Set the class each element in the database row's * collection should be converted to, before the collection * is inserted into the database. * This is optional - if left null, the elements will be added * to the database row's collection unconverted. */ public void setFieldElementClass(Class fieldElementClass) { TypeConversionConverter converter; if (getValueConverter() instanceof TypeConversionConverter) { converter = (TypeConversionConverter)getValueConverter(); } else { converter = new TypeConversionConverter(); setValueConverter(converter); } converter.setDataClass(fieldElementClass); }
/** * INTERNAL: * Build the nested collection from the database row. */ public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) throws DatabaseException { ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); if (fieldValue == null) { return cp.containerInstance(); } Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue); if (fieldValues == null) { return cp.containerInstance(); } Object result = cp.containerInstance(fieldValues.size()); for (Enumeration stream = fieldValues.elements(); stream.hasMoreElements();) { Object element = stream.nextElement(); if (this.getValueConverter() != null) { element = getValueConverter().convertDataValueToObjectValue(element, executionSession); } cp.addInto(element, result, sourceQuery.getSession()); } return result; }
/** * PUBLIC: * Indicates if there is a converter on the mapping. */ public boolean hasValueConverter() { return getValueConverter() != null; }
QName schemaType = (QName)xmlConversionManager.getDefaultJavaTypes().get(((AbstractCompositeDirectCollectionMapping)nextMapping).getAttributeElementClass()); if(schemaType != null) { ((XMLField)nextMapping.getField()).setSchemaType(schemaType); ((AbstractCompositeDirectCollectionMapping)nextMapping).setValueConverter(converter); ((AbstractCompositeDirectCollectionMapping)nextMapping).setContainerPolicy(getContainerPolicy()); }else{ if(converter != null){
/** * Return the fields handled by the mapping. */ protected Vector collectFields() { Vector fields = new Vector(1); fields.addElement(this.getField()); return fields; }
/** * ADVANCED: * This method is used to have an object removed from a collection once the changeSet is applied * The referenceKey parameter should only be used for direct Maps. */ public void simpleRemoveFromCollectionChangeRecord(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { DirectToFieldChangeRecord collectionChangeRecord = (DirectToFieldChangeRecord)changeSet.getAttributesToChanges().get(getAttributeName()); if (collectionChangeRecord == null) { //if there is no change for this attribute then create a changeSet for it. no need to modify the resulting // change record as it should be built from the clone which has the changes allready Object cloneObject = ((UnitOfWorkChangeSet)changeSet.getUOWChangeSet()).getUOWCloneForObjectChangeSet(changeSet); Object cloneCollection = this.getRealAttributeValueFromObject(cloneObject, session); collectionChangeRecord = (DirectToFieldChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { getContainerPolicy().removeFrom(changeSetToRemove, collectionChangeRecord.getNewValue(), session); } }
/** * Build and return a clone of the specified attribute value. */ protected Object buildClonePart(Object attributeValue, CacheKey parentCacheKey, AbstractSession cloningSession) { if (attributeValue == null) { return this.getContainerPolicy().containerInstance(); } else { if ((getValueConverter() == null) || (!getValueConverter().isMutable())) { return this.getContainerPolicy().cloneFor(attributeValue); } // Clone the values of the collection as well. Object cloneContainer = this.getContainerPolicy().containerInstance(); Object iterator = this.getContainerPolicy().iteratorFor(attributeValue); while (this.getContainerPolicy().hasNext(iterator)) { Object originalValue = this.getContainerPolicy().next(iterator, cloningSession); // Bug 4182377 - there was a typo in the conversion logic Object cloneValue = getValueConverter().convertDataValueToObjectValue(getValueConverter().convertObjectValueToDataValue(originalValue, cloningSession), cloningSession); this.getContainerPolicy().addInto(cloneValue, cloneContainer, cloningSession); } return cloneContainer; } }
/** * INTERNAL * Called when a DatabaseMapping is used to map the key in a collection. Returns the key. */ public Object createMapComponentFromRow(AbstractRecord dbRow, ObjectBuildingQuery query, CacheKey parentCacheKey, AbstractSession session, boolean isTargetProtected){ Object key = dbRow.get(getField()); if (getValueConverter() != null){ key = getValueConverter().convertDataValueToObjectValue(key, session); } return key; }
/** * INTERNAL: * If any part of the nested collection has changed, the whole thing is written. */ public void writeFromObjectIntoRowForUpdate(WriteObjectQuery writeQuery, AbstractRecord row) throws DescriptorException { AbstractSession session = writeQuery.getSession(); if (session.isUnitOfWork()) { if (this.compareObjects(writeQuery.getObject(), writeQuery.getBackupClone(), session)) { return;// nothing is changed, no work required } } this.writeFromObjectIntoRow(writeQuery.getObject(), row, session); }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { //since a minimal update for composites can't be done, we are only recording //an all-or-none change. Therefore, this can be treated as a simple direct //value. ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(cloneCollection); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, session), container, session); } DirectToFieldChangeRecord changeRecord = new DirectToFieldChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setNewValue(container); return changeRecord; }
/** * INTERNAL: * Build and return a new element based on the change set. */ public Object buildAddedElementFromChangeSet(Object changeSet, MergeManager mergeManager, AbstractSession targetSession) { return this.buildElementFromChangeSet(changeSet, mergeManager, targetSession); }
/** * INTERNAL: * Return the classifiction for the field contained in the mapping. * This is used to convert the row value to a consistent java value. * By default this is unknown. */ public Class getFieldClassification(DatabaseField fieldToClassify) { return getAttributeElementClass(); }
/** * INTERNAL: * Compare the non-null elements and return true if they are alike. */ public boolean compareElementsForChange(Object element1, Object element2, AbstractSession session) { return this.compareElements(element1, element2, session); }
if (this.isReadOnly()) { return; Object attributeValue = this.getAttributeValueFromObject(object); if (attributeValue == null) { row.put(this.getField(), null); return; ContainerPolicy cp = this.getContainerPolicy(); if (this.getValueConverter() != null) { element = getValueConverter().convertObjectValueToDataValue(element, session); fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session); row.put(this.getField(), fieldValue);