/** INTERNAL: */ public Vector getForeignKeyRows(AbstractRecord row) { Vector subRows = new Vector(); if (getForeignKeyGroupingElement() == null) { if (this.getSourceForeignKeyFields().size() > 0) { Object values = row.getValues((DatabaseField) this.getSourceForeignKeyFields().get(0)); if (values != null) { if (values instanceof Vector) { int valuesSize = ((Vector) values).size(); for (int j = 0; j < valuesSize; j++) { XMLRecord newRecord = new DOMRecord("test"); newRecord.setSession(((XMLRecord) row).getSession()); newRecord.put(this.getSourceForeignKeyFields().get(0), ((Vector) values).get(j)); subRows.add(newRecord); } } else { XMLRecord newRecord = new DOMRecord("test"); newRecord.setSession(((XMLRecord) row).getSession()); newRecord.put(getSourceForeignKeyFields().get(0), values); subRows.add(newRecord); } } } } else { subRows = (Vector) row.getValues(getForeignKeyGroupingElement()); } return subRows; }
/** INTERNAL: Get a value from the object and set that in the respective field of the row. */ @Override public Object valueFromObject(Object object, DatabaseField field, AbstractSession session) { // First check if the value can be obtained from the value holder's row. AbstractRecord referenceRow = getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object)); if (referenceRow != null) { Object value = referenceRow.get(field); // Must ensure the classification to get a cache hit. try { value = session.getDatasourcePlatform().convertObject(value, getFieldClassification(field)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } return value; } // 2.5.1.6 PWK. added to support batch reading on variable one to ones Object referenceObject = getRealAttributeValueFromObject(object, session); String queryKeyName = (String) getSourceToTargetQueryKeyNames().get(field); ClassDescriptor objectDescriptor = session.getDescriptor(referenceObject.getClass()); DatabaseField targetField = objectDescriptor.getObjectBuilder().getTargetFieldForQueryKeyName(queryKeyName); if (targetField == null) { return null; } return objectDescriptor .getObjectBuilder() .extractValueFromObjectForField(referenceObject, targetField, session); }
/** * INTERNAL: Return the value of the field from the row or a value holder on the query to obtain * the object. Check for batch + aggregation reading. */ @Override public Object valueFromRow( AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) throws DatabaseException { // If any field in the foreign key is null then it means there are no referenced objects for (Enumeration enumeration = getFields().elements(); enumeration.hasMoreElements(); ) { DatabaseField field = (DatabaseField) enumeration.nextElement(); if (row.get(field) == null) { return getIndirectionPolicy().nullValueFromRow(); } } if (getTypeField() != null) { // If the query used batched reading, return a special value holder, // or retrieve the object from the query property. if (sourceQuery.isReadAllQuery() && (((ReadAllQuery) sourceQuery).isAttributeBatchRead(getDescriptor(), getAttributeName()) || shouldUseBatchReading())) { return batchedValueFromRow(row, ((ReadAllQuery) sourceQuery)); } // If the field is empty we cannot load the object because we do not know what class it will // be if (row.get(getTypeField()) == null) { return getIndirectionPolicy().nullValueFromRow(); } Class implementerClass = (Class) getImplementorForType(row.get(getTypeField()), executionSession); ReadObjectQuery query = (ReadObjectQuery) getSelectionQuery().clone(); query.setReferenceClass(implementerClass); query.setSelectionCriteria(getSelectionCriteria()); query.setDescriptor(null); // Must set to null so the right descriptor is used if (sourceQuery.isObjectLevelReadQuery() && (sourceQuery.shouldCascadeAllParts() || (sourceQuery.shouldCascadePrivateParts() && isPrivateOwned()) || (sourceQuery.shouldCascadeByMapping() && this.cascadeRefresh))) { query.setShouldRefreshIdentityMapResult(sourceQuery.shouldRefreshIdentityMapResult()); query.setCascadePolicy(sourceQuery.getCascadePolicy()); query.setShouldMaintainCache(sourceQuery.shouldMaintainCache()); // For flashback. if (((ObjectLevelReadQuery) sourceQuery).hasAsOfClause()) { query.setAsOfClause(((ObjectLevelReadQuery) sourceQuery).getAsOfClause()); } // CR #4365 - used to prevent infinit recursion on refresh object cascade all query.setQueryId(sourceQuery.getQueryId()); } return getIndirectionPolicy().valueFromQuery(query, row, executionSession); } else { return super.valueFromRow(row, joinManager, sourceQuery, executionSession); } }
/** INTERNAL: Clone the row and its values. */ public AbstractRecord clone() { try { AbstractRecord clone = (AbstractRecord) super.clone(); clone.fields = (Vector) this.fields.clone(); clone.values = (Vector) this.values.clone(); return clone; } catch (CloneNotSupportedException exception) { throw new InternalError(); } }
/** INTERNAL: Write fields needed for insert into the template for with null values. */ public void writeInsertFieldsIntoRow(AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeInsertFieldsIntoRow(row, session); } }
/** * INTERNAL: This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ public void writeFromObjectIntoRowForShallowInsertWithChangeRecord( ChangeRecord changeRecord, AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeFromObjectIntoRowForShallowInsertWithChangeRecord(changeRecord, row, session); } }
/** * INTERNAL: Build and return the nested database row from the specified field value. The field * value better be an Struct. */ public AbstractRecord buildNestedRowFromFieldValue(Object fieldValue) throws DatabaseException { AbstractRecord row = new DatabaseRecord(); Object[] attributes = (Object[]) fieldValue; for (int index = 0; index < getOrderedFields().size(); index++) { DatabaseField field = (DatabaseField) getOrderedFields().elementAt(index); row.put(field, attributes[index]); } return row; }
/** INTERNAL: Get a value from the object and set that in the respective field of the row. */ protected void writeFromNullObjectIntoRow(AbstractRecord record) { if (isReadOnly()) { return; } if (isForeignKeyRelationship()) { Enumeration foreignKeys = getForeignKeyFields().elements(); while (foreignKeys.hasMoreElements()) { record.put((DatabaseField) foreignKeys.nextElement(), null); } } if (getTypeField() != null) { record.put(getTypeField(), null); } }
/** INTERNAL: */ @Override public void writeFromObjectIntoRow( Object object, AbstractRecord row, AbstractSession session, WriteType writeType) throws DescriptorException { if (this.isReadOnly()) { return; } Object attributeValue = this.getAttributeValueFromObject(object); if (attributeValue == null) { row.put(this.getField(), null); return; } ContainerPolicy cp = this.getContainerPolicy(); Vector nestedRows = new Vector(cp.sizeFor(attributeValue)); Object iter = cp.iteratorFor(attributeValue); if (null != iter) { while (cp.hasNext(iter)) { Object element = cp.next(iter, session); // convert the value - if necessary element = convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller()); if (element == null) { XMLNullRepresentationType nullRepresentation = getNullPolicy().getMarshalNullRepresentation(); if (nullRepresentation == XMLNullRepresentationType.XSI_NIL) { nestedRows.add(XMLRecord.NIL); } else if (nullRepresentation == XMLNullRepresentationType.EMPTY_NODE) { Node emptyNode = XPathEngine.getInstance() .createUnownedElement(((XMLRecord) row).getDOM(), (XMLField) field); DOMRecord nestedRow = new DOMRecord(emptyNode); nestedRows.add(nestedRow); } } else { nestedRows.addElement(buildCompositeRow(element, session, row, writeType)); } } } Object fieldValue = null; if (!nestedRows.isEmpty()) { fieldValue = this.getDescriptor() .buildFieldValueFromNestedRows(nestedRows, getStructureName(), session); } row.put(this.getField(), fieldValue); }
/** INTERNAL: Write the attribute value from the object to the row. */ public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session) { // for each xmlField on this mapping for (Iterator fieldIt = getFields().iterator(); fieldIt.hasNext(); ) { XMLField xmlField = (XMLField) fieldIt.next(); ContainerPolicy cp = getContainerPolicy(); Object collection = getAttributeAccessor().getAttributeValueFromObject(object); if (collection == null) { return; } Object fieldValue; Object objectValue; String stringValue = ""; QName schemaType; Object iterator = cp.iteratorFor(collection); if (usesSingleNode()) { while (cp.hasNext(iterator)) { objectValue = cp.next(iterator, session); fieldValue = buildFieldValue(objectValue, xmlField, session); if (fieldValue != null) { schemaType = getSchemaType(xmlField, fieldValue, session); String newValue = getValueToWrite(schemaType, fieldValue, session); if (newValue != null) { stringValue += newValue; if (cp.hasNext(iterator)) { stringValue += SPACE; } } } } if (!(stringValue.equals(""))) { row.put(xmlField, stringValue); } } else { ArrayList keyValues = new ArrayList(); while (cp.hasNext(iterator)) { objectValue = cp.next(iterator, session); fieldValue = buildFieldValue(objectValue, xmlField, session); if (fieldValue != null) { schemaType = getSchemaType(xmlField, fieldValue, session); stringValue = getValueToWrite(schemaType, fieldValue, session); // row.add(xmlField, stringValue); keyValues.add(stringValue); } } row.put(xmlField, keyValues); } } }
// operation should be either INSERT or UPDATE protected void trimModifyRow(AbstractRecord modifyRow, int operation) { if ((modifyRow == null) || modifyRow.isEmpty()) { return; } Collection fields = main[operation][RETURN_ONLY]; if ((fields == null) || fields.isEmpty()) { return; } for (int i = modifyRow.size() - 1; i >= 0; i--) { DatabaseField field = modifyRow.getFields().get(i); if (fields.contains(field)) { modifyRow.remove(field); } } }
/** * INTERNAL: Return the value of the field from the row or a value holder on the query to obtain * the object. Check for batch + aggregation reading. */ public Object valueFromRow( AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) throws DatabaseException { Ref ref = (Ref) row.get(getField()); if (ref == null) { return null; } Struct struct; try { ((DatabaseAccessor) executionSession.getAccessor()).incrementCallCount(executionSession); java.sql.Connection connection = ((DatabaseAccessor) executionSession.getAccessor()).getConnection(); struct = (Struct) executionSession.getPlatform().getRefValue(ref, executionSession, connection); } catch (java.sql.SQLException exception) { throw DatabaseException.sqlException(exception, executionSession, false); } AbstractRecord targetRow = ((ObjectRelationalDataTypeDescriptor) getReferenceDescriptor()) .buildRowFromStructure(struct); ((DatabaseAccessor) executionSession.getAccessor()).decrementCallCount(); return getReferenceDescriptor().getObjectBuilder().buildObject(query, targetRow, joinManager); }
/** INTERNAL: Write fields needed for insert into the template for with null values. */ public void writeInsertFieldsIntoRow(AbstractRecord record, AbstractSession session) { if (isReadOnly()) { return; } record.put(getField(), null); }
/** INTERNAL: Build a ADT structure from the row data. */ public Struct buildStructureFromRow( AbstractRecord row, AbstractSession session, java.sql.Connection connection) throws DatabaseException { Struct structure; boolean reconnected = false; try { if (connection == null) { ((DatabaseAccessor) session.getAccessor()).incrementCallCount(session); reconnected = true; connection = ((DatabaseAccessor) session.getAccessor()).getConnection(); } Object[] fields = new Object[getOrderedFields().size()]; for (int index = 0; index < getOrderedFields().size(); index++) { DatabaseField field = (DatabaseField) getOrderedFields().elementAt(index); fields[index] = row.get(field); } structure = session.getPlatform().createStruct(getStructureName(), fields, session, connection); } catch (java.sql.SQLException exception) { throw DatabaseException.sqlException(exception, session, false); } finally { if (reconnected) { ((DatabaseAccessor) session.getAccessor()).decrementCallCount(); } } return structure; }
/** * INTERNAL: This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ public void writeFromObjectIntoRowForShallowInsertWithChangeRecord( ChangeRecord changeRecord, AbstractRecord record, AbstractSession session) { if (isReadOnly()) { return; } record.put(getField(), null); }
/** Build a collection of database rows from the Record returned from the interaction. */ public Vector buildRows(Record record, EISAccessor accessor) { Vector rows = null; if (record == null) { return new Vector(0); } AbstractRecord row = accessor.getEISPlatform().createDatabaseRowFromDOMRecord(record, this, accessor); if (getOutputResultPath().length() > 0) { Vector values = (Vector) row.getValues(getOutputResultPath()); if (values == null) { values = new Vector(0); } rows = values; } else { rows = new Vector(1); rows.add(row); } return rows; }
/** INTERNAL: Get a value from the object and set that in the respective field of the row. */ @Override public void writeFromObjectIntoRowForWhereClause( ObjectLevelModifyQuery query, AbstractRecord record) { if (isReadOnly()) { return; } Object object; if (query.isDeleteObjectQuery()) { object = query.getObject(); } else { object = query.getBackupClone(); } Object referenceObject = getRealAttributeValueFromObject(object, query.getSession()); if (referenceObject == null) { writeFromNullObjectIntoRow(record); } else { if (isForeignKeyRelationship()) { Enumeration sourceFields = getForeignKeyFields().elements(); ClassDescriptor descriptor = query.getSession().getDescriptor(referenceObject.getClass()); while (sourceFields.hasMoreElements()) { DatabaseField sourceKey = (DatabaseField) sourceFields.nextElement(); String targetQueryKey = (String) getSourceToTargetQueryKeyNames().get(sourceKey); DatabaseField targetKeyField = descriptor.getObjectBuilder().getFieldForQueryKeyName(targetQueryKey); if (targetKeyField == null) { throw DescriptorException.variableOneToOneMappingIsNotDefinedProperly( this, descriptor, targetQueryKey); } Object referenceValue = descriptor .getObjectBuilder() .extractValueFromObjectForField( referenceObject, targetKeyField, query.getSession()); record.put(sourceKey, referenceValue); } } if (getTypeField() != null) { record.put(getTypeField(), getTypeForImplementor(referenceObject.getClass())); } } }
/** INTERNAL: Get a value from the object and set that in the respective field of the row. */ public void writeFromObjectIntoRow( Object object, AbstractRecord record, AbstractSession session) { if (isReadOnly()) { return; } Object referenceObject = getRealAttributeValueFromObject(object, session); if (referenceObject == null) { // Fix for 2730536, must put something in modify row, even if it is null. record.put(getField(), null); return; } Ref ref = ((ObjectRelationalDataTypeDescriptor) getReferenceDescriptor()) .getRef(referenceObject, session); record.put(getField(), ref); }
/** Build a database row from the record returned from the interaction. */ public AbstractRecord buildRow(Record record, EISAccessor accessor) { if (record == null) { return null; } AbstractRecord row = accessor.getEISPlatform().createDatabaseRowFromDOMRecord(record, this, accessor); if (row == null) { return null; } if (getOutputResultPath().length() > 0) { row = (AbstractRecord) row.get(getOutputResultPath()); // Handle the case were the output row is mapped into a database row of values. } else if (hasOutputArguments()) { row = createXMLRecord(getOutputRootElementName()); for (int index = 0; index < getOutputArgumentNames().size(); index++) { DatabaseField field = (DatabaseField) getOutputArguments().get(index); row.put(field, row.get(getOutputArgumentNames().get(index))); } } return row; }
/** * INTERNAL: The results are *not* in a cursor, build the collection. Cache the results in * temporaryCachedQueryResults. */ protected Object executeNonCursor() throws DatabaseException { Vector rows = getQueryMechanism().executeSelect(); Object results = null; if (this.resultType == MAP) { results = getContainerPolicy().buildContainerFromVector(rows, this.session); } else if (this.resultType == VALUE) { if (!rows.isEmpty()) { AbstractRecord record = (AbstractRecord) rows.get(0); // Use get with field for XML records. results = record.get(record.getFields().get(0)); if (getValueConverter() != null) { results = getValueConverter().convertDataValueToObjectValue(results, this.session); } } } else { int size = rows.size(); ContainerPolicy containerPolicy = getContainerPolicy(); results = containerPolicy.containerInstance(size); if (containerPolicy.shouldAddAll()) { if (size > 0) { List values = new ArrayList(size); for (int index = 0; index < size; index++) { AbstractRecord row = (AbstractRecord) rows.get(index); Object value = buildObject(row); values.add(value); } containerPolicy.addAll(values, results, this.session, rows, this); } } else { for (int index = 0; index < size; index++) { AbstractRecord row = (AbstractRecord) rows.get(index); Object value = buildObject(row); containerPolicy.addInto(value, results, this.session, row, this); } } } // Bug 6135563 - cache DataReadQuery results verbatim, as ObjectBuilder is not invoked cacheResult(results); return results; }
/** * INTERNAL: Get the appropriate attribute value from the object and put it in the appropriate * field of the database row. Loop through the reference objects and extract the primary keys and * put them in the vector of "nested" rows. */ public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session) { if (!isForeignKeyRelationship) { return; } if (((getSourceForeignKeysToTargetKeys()) == null) || (getSourceForeignKeysToTargetKeys().size() == 0)) { return; } if (this.isReadOnly()) { return; } AbstractRecord referenceRow = this.getIndirectionPolicy().extractReferenceRow(this.getAttributeValueFromObject(object)); if (referenceRow != null) { // the reference objects have not been instantiated - use the value from the original row if (getForeignKeyGroupingElement() != null) { row.put( this.getForeignKeyGroupingElement(), referenceRow.getValues(this.getForeignKeyGroupingElement())); } else if (getSourceForeignKeyFields().size() > 0) { DatabaseField foreignKeyField = (DatabaseField) getSourceForeignKeyFields().get(0); row.put(foreignKeyField, referenceRow.getValues(foreignKeyField)); } return; } ContainerPolicy cp = this.getContainerPolicy(); // extract the keys from the objects Object attributeValue = this.getRealCollectionAttributeValueFromObject(object, session); Vector nestedRows = new Vector(cp.sizeFor(attributeValue)); if (getForeignKeyGroupingElement() != null) { for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter); ) { XMLRecord nestedRow = this.extractKeyRowFromReferenceObject(cp.next(iter, session), session, (XMLRecord) row); nestedRows.addElement(nestedRow); } row.add(this.getForeignKeyGroupingElement(), nestedRows); } else { DatabaseField singleField = (DatabaseField) getSourceForeignKeyFields().get(0); DatabaseField pkField = (DatabaseField) getSourceForeignKeysToTargetKeys().get(singleField); for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter); ) { Object singleValue = getReferenceDescriptor() .getObjectBuilder() .extractValueFromObjectForField(cp.next(iter, session), pkField, session); row.add(singleField, singleValue); } } }
/** * INTERNAL: Get a value from the object and set that in the respective field of the row. If the * mapping id target foreign key, you must only write the type into the roe, the rest will be * updated when the object itself is written */ @Override public void writeFromObjectIntoRowWithChangeRecord( ChangeRecord changeRecord, AbstractRecord record, AbstractSession session) { if (isReadOnly()) { return; } ObjectChangeSet changeSet = (ObjectChangeSet) ((ObjectReferenceChangeRecord) changeRecord).getNewValue(); if (changeSet == null) { writeFromNullObjectIntoRow(record); } else { Object referenceObject = changeSet.getUnitOfWorkClone(); if (isForeignKeyRelationship()) { Enumeration sourceFields = getForeignKeyFields().elements(); ClassDescriptor descriptor = session.getDescriptor(referenceObject.getClass()); while (sourceFields.hasMoreElements()) { DatabaseField sourceKey = (DatabaseField) sourceFields.nextElement(); String targetQueryKey = (String) getSourceToTargetQueryKeyNames().get(sourceKey); DatabaseField targetKeyField = descriptor.getObjectBuilder().getFieldForQueryKeyName(targetQueryKey); if (targetKeyField == null) { throw DescriptorException.variableOneToOneMappingIsNotDefinedProperly( this, descriptor, targetQueryKey); } Object referenceValue = descriptor .getObjectBuilder() .extractValueFromObjectForField(referenceObject, targetKeyField, session); record.put(sourceKey, referenceValue); } } if (getTypeField() != null) { record.put(getTypeField(), getTypeForImplementor(referenceObject.getClass())); } } }
/** * INTERNAL: Extract the primary key values from the row, then create an * org.eclipse.persistence.internal.oxm.Reference instance and stored it on the session's * org.eclipse.persistence.internal.oxm.ReferenceResolver. */ public Object readFromRowIntoObject( AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object targetObject, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) throws DatabaseException { ClassDescriptor descriptor = sourceQuery.getSession().getClassDescriptor(getReferenceClass()); ContainerPolicy cp = this.getContainerPolicy(); Vector pkFieldNames = referenceDescriptor.getPrimaryKeyFieldNames(); Vector primaryKeyValues = new Vector(); primaryKeyValues.setSize(pkFieldNames.size()); HashMap primaryKeyMap = new HashMap(); // for each source xmlField, get the value from the row and store for (Iterator fieldIt = getFields().iterator(); fieldIt.hasNext(); ) { XMLField fld = (XMLField) fieldIt.next(); XMLField tgtFld = (XMLField) getSourceToTargetKeyFieldAssociations().get(fld); Object fieldValue = databaseRow.getValues(fld); if ((fieldValue == null) || (fieldValue instanceof String) || !(fieldValue instanceof Vector)) { return cp.containerInstance(); } // fix for bug# 5687430 // need to get the actual type of the target (i.e. int, String, etc.) // and use the converted value when checking the cache. XMLConversionManager xmlConversionManager = (XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager(); Vector newValues = new Vector(); for (Iterator valIt = ((Vector) fieldValue).iterator(); valIt.hasNext(); ) { for (StringTokenizer stok = new StringTokenizer((String) valIt.next()); stok.hasMoreTokens(); ) { Object value = xmlConversionManager.convertObject( stok.nextToken(), descriptor.getTypedField(tgtFld).getType()); if (value != null) { newValues.add(value); } } } primaryKeyMap.put(tgtFld.getXPath(), newValues); } // store the Reference instance on the resolver for use during mapping resolution phase ReferenceResolver resolver = ReferenceResolver.getInstance(sourceQuery.getSession()); if (resolver != null) { resolver.addReference(new Reference(this, targetObject, referenceClass, primaryKeyMap)); } return null; }
/** INTERNAL: Get a value from the object and set that in the respective field of the row. */ public void writeFromObjectIntoRowWithChangeRecord( ChangeRecord changeRecord, AbstractRecord record, AbstractSession session) { if (isReadOnly()) { return; } ObjectChangeSet changeSet = (ObjectChangeSet) ((ObjectReferenceChangeRecord) changeRecord).getNewValue(); Object referenceObject = changeSet.getUnitOfWorkClone(); if (referenceObject == null) { return; } Ref ref = ((ObjectRelationalDataTypeDescriptor) getReferenceDescriptor()) .getRef(referenceObject, session); record.put(getField(), ref); }
/** INTERNAL: Build the result value for the row. */ public Object buildObject(AbstractRecord row) { if (this.resultType == AUTO) { List values = row.getValues(); if (values.size() == 1) { return row.getValues().get(0); } else { return row.getValues().toArray(); } } else if (this.resultType == ARRAY) { return row.getValues().toArray(); } else if (this.resultType == ATTRIBUTE) { // Use get with field for XML records. Object value = row.get(row.getFields().get(0)); if (getValueConverter() != null) { value = getValueConverter().convertDataValueToObjectValue(value, this.session); } return value; } return row; }
/** * INTERNAL: Merge the provided row into this row. Existing field values in this row will be * replaced with values from the provided row. Fields not in this row will be added from provided * row. Values not in provided row will remain in this row. */ public void mergeFrom(AbstractRecord row) { for (int index = 0; index < row.size(); ++index) { this.put(row.getFields().get(index), row.getValues().get(index)); } }
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session) { XMLRecord record = (XMLRecord) row; XMLMarshaller marshaller = record.getMarshaller(); Object attributeValue = getAttributeValueFromObject(object); ContainerPolicy cp = this.getContainerPolicy(); Vector elements = new Vector(cp.sizeFor(attributeValue)); XMLField field = (XMLField) getField(); NamespaceResolver resolver = field.getNamespaceResolver(); boolean isAttribute = field.getLastXPathFragment().isAttribute(); String prefix = null; XMLField includeField = null; if (!isAttribute) { if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) { field = (XMLField) getField(); // If the field's resolver is non-null and has an entry for XOP, // use it - otherwise, create a new resolver, set the XOP entry, // on it, and use it instead. // We do this to avoid setting the XOP namespace declaration on // a given field or descriptor's resolver, as it is only required // on the current element if (resolver != null) { prefix = resolver.resolveNamespaceURI(XMLConstants.XOP_URL); } if (prefix == null) { prefix = XMLConstants.XOP_PREFIX; // "xop"; resolver = new NamespaceResolver(); resolver.put(prefix, XMLConstants.XOP_URL); } includeField = new XMLField(prefix + XMLConstants.COLON + INCLUDE + "/@href"); includeField.setNamespaceResolver(resolver); } } XMLField textField = new XMLField(field.getXPath() + '/' + XMLConstants.TEXT); textField.setNamespaceResolver(field.getNamespaceResolver()); textField.setSchemaType(field.getSchemaType()); // field = textField; boolean inline = false; for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter); ) { Object element = cp.next(iter, session); element = getValueToWrite(element, object, record, field, includeField, session); if (element.getClass() == ClassConstants.ABYTE) { inline = true; } if (element != null) { elements.addElement(element); } } Object fieldValue = null; if (!elements.isEmpty()) { fieldValue = this.getDescriptor() .buildFieldValueFromDirectValues(elements, elementDataTypeName, session); } if (inline) { row.put(textField, fieldValue); } else { row.put(field, fieldValue); } }
public Object valueFromRow( AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) { ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); if (fieldValue == null) { if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); return container != null ? container : cp.containerInstance(); } else { return cp.containerInstance(); } } Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue); if (fieldValues == null) { if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); return container != null ? container : cp.containerInstance(); } else { return cp.containerInstance(); } } Object result = null; if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); result = container != null ? container : cp.containerInstance(); } else { result = cp.containerInstance(fieldValues.size()); } for (Enumeration stream = fieldValues.elements(); stream.hasMoreElements(); ) { Object element = stream.nextElement(); // PERF: Direct variable access. // Object value = row.get(field); // Object fieldValue = null; XMLUnmarshaller unmarshaller = ((XMLRecord) row).getUnmarshaller(); if (element instanceof String) { if (this.isSwaRef() && (unmarshaller.getAttachmentUnmarshaller() != null)) { fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler((String) element); } else if (!this.isSwaRef()) { // should be base64 byte[] bytes = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()) .convertSchemaBase64ToByteArray(element); fieldValue = bytes; } } else { // this was an element, so do the XOP/SWAREF/Inline binary cases for an element XMLRecord record = (XMLRecord) element; record.setSession(executionSession); if ((unmarshaller.getAttachmentUnmarshaller() != null) && unmarshaller.getAttachmentUnmarshaller().isXOPPackage() && !this.isSwaRef() && !this.shouldInlineBinaryData()) { // look for the include element: String xpath = XMLConstants.EMPTY_STRING; // need a prefix for XOP String prefix = null; NamespaceResolver descriptorResolver = ((XMLDescriptor) getDescriptor()).getNamespaceResolver(); if (descriptorResolver != null) { prefix = descriptorResolver.resolveNamespaceURI(XMLConstants.XOP_URL); } if (prefix == null) { prefix = XMLConstants.XOP_PREFIX; } NamespaceResolver tempResolver = new NamespaceResolver(); tempResolver.put(prefix, XMLConstants.XOP_URL); xpath = prefix + XMLConstants.COLON + INCLUDE + "/@href"; XMLField field = new XMLField(xpath); field.setNamespaceResolver(tempResolver); String includeValue = (String) record.get(field); if (element != null && includeValue != null) { if ((getAttributeElementClass() == ClassConstants.ABYTE) || (getAttributeElementClass() == ClassConstants.APBYTE)) { fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray(includeValue); } else { fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(includeValue); } } else { // If we didn't find the Include element, check for inline fieldValue = record.get(XMLConstants.TEXT); // should be a base64 string fieldValue = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()) .convertSchemaBase64ToByteArray(fieldValue); } } else if ((unmarshaller.getAttachmentUnmarshaller() != null) && isSwaRef()) { String refValue = (String) record.get(XMLConstants.TEXT); if (refValue != null) { fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(refValue); } } else { fieldValue = record.get(XMLConstants.TEXT); // should be a base64 string fieldValue = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()) .convertSchemaBase64ToByteArray(fieldValue); } } Object attributeValue = fieldValue; if (getValueConverter() != null) { if (getValueConverter() instanceof XMLConverter) { attributeValue = ((XMLConverter) getValueConverter()) .convertDataValueToObjectValue(fieldValue, executionSession, unmarshaller); } else { attributeValue = getValueConverter().convertDataValueToObjectValue(fieldValue, executionSession); } } cp.addInto(attributeValue, result, query.getSession()); } return result; }
public Object valueFromRow( AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException { ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); // BUG#2667762 there could be whitespace in the row instead of null if ((fieldValue == null) || (fieldValue instanceof String)) { if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); return container != null ? container : cp.containerInstance(); } else { return cp.containerInstance(); } } Vector nestedRows = this.getDescriptor().buildNestedRowsFromFieldValue(fieldValue, executionSession); if (nestedRows == null) { if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); return container != null ? container : cp.containerInstance(); } else { return cp.containerInstance(); } } Object result = null; if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); result = container != null ? container : cp.containerInstance(); } else { result = cp.containerInstance(nestedRows.size()); } for (Enumeration stream = nestedRows.elements(); stream.hasMoreElements(); ) { XMLRecord nestedRow = (XMLRecord) stream.nextElement(); Object objectToAdd; if (getNullPolicy().valueIsNull((Element) nestedRow.getDOM())) { objectToAdd = null; } else { objectToAdd = buildObjectFromNestedRow( nestedRow, joinManager, sourceQuery, executionSession, isTargetProtected); } cp.addInto(objectToAdd, result, sourceQuery.getSession()); if (null != getContainerAccessor()) { Object currentObject = ((XMLRecord) row).getCurrentObject(); if (this.inverseReferenceMapping.getContainerPolicy() == null) { getContainerAccessor().setAttributeValueInObject(objectToAdd, currentObject); } else { Object backpointerContainer = getContainerAccessor().getAttributeValueFromObject(objectToAdd); if (backpointerContainer == null) { backpointerContainer = this.inverseReferenceMapping.getContainerPolicy().containerInstance(); getContainerAccessor().setAttributeValueInObject(objectToAdd, backpointerContainer); } this.inverseReferenceMapping .getContainerPolicy() .addInto(currentObject, backpointerContainer, executionSession); } } } return result; }