/** * Override method in superclass in order to set the session on the record. * Each mapping is recursed to assign values from the Record to the attributes in the domain object. */ @Override public void buildAttributesIntoObject(Object domainObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, FetchGroup executionFetchGroup, boolean forRefresh, AbstractSession targetSession) throws DatabaseException { ((XMLRecord)databaseRow).setSession(query.getSession().getExecutionSession(query)); super.buildAttributesIntoObject(domainObject, cacheKey, databaseRow, query, joinManager, executionFetchGroup, forRefresh, targetSession); }
/** * Override method in superclass in order to set the session on the record. * Each mapping is recursed to assign values from the Record to the attributes in the domain object. */ public void buildAttributesIntoObject(Object domainObject, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, boolean forRefresh) throws DatabaseException { ((XMLRecord)databaseRow).setSession(query.getSession().getExecutionSession(query)); super.buildAttributesIntoObject(domainObject, databaseRow, query, joinManager, forRefresh); }
/** * Override method in superclass in order to set the session on the record. * Each mapping is recursed to assign values from the Record to the attributes in the domain object. */ @Override public void buildAttributesIntoObject(Object domainObject, CacheKey cacheKey, AbstractRecord databaseRow, ObjectBuildingQuery query, JoinedAttributeManager joinManager, FetchGroup executionFetchGroup, boolean forRefresh, AbstractSession targetSession) throws DatabaseException { ((XMLRecord)databaseRow).setSession(query.getSession().getExecutionSession(query)); super.buildAttributesIntoObject(domainObject, cacheKey, databaseRow, query, joinManager, executionFetchGroup, forRefresh, targetSession); }
/** * 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, CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected, Object container) throws DatabaseException { ClassDescriptor descriptor = sourceQuery.getSession().getClassDescriptor(getReferenceClass()); if(container == null){ readFromRowIntoObject(databaseRow, joinManager, targetObject, parentCacheKey, sourceQuery, executionSession, isTargetProtected); } // for each source xmlField, get the value from the row and store for (Iterator fieldIt = getFields().iterator(); fieldIt.hasNext();) { XMLField fld = (XMLField) fieldIt.next(); // Object fieldValue = databaseRow.getValues(fld); if ((fieldValue == null) || (fieldValue instanceof String) || !(fieldValue instanceof Vector)) { return container; } // 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. for (Iterator valIt = ((Vector) fieldValue).iterator(); valIt.hasNext();) { Object nextValue = valIt.next(); DOMRecord domRecord = (DOMRecord) databaseRow; this.buildReference(domRecord.getCurrentObject(), fld, nextValue, sourceQuery.getSession(), container, domRecord.getReferenceResolver()); } } return null; }
AbstractSession executionSession = query.getSession().getExecutionSession(query);
/** * INTERNAL: * Builds a shallow original object. Only direct attributes and primary * keys are populated. In this way the minimum original required for * instantiating a working copy clone can be built without placing it in * the shared cache (no concern over cycles). * @param original later the input to buildCloneFromRow */ @Override public void buildShallowOriginalFromRow(AbstractRecord record, Object original, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) { // In this case we know it is a primary key mapping, so hope that it // is essentially a direct mapping. If it is a 1-1 with a // no-indirection pointer back to original, then will get a stack // overflow. // Only solution to this is to trigger the transformation using the root // session. UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)query.getSession(); query.setSession(unitOfWork.getParent()); try { readFromRowIntoObject(record, joinManager, original, null, query, executionSession, false); } finally { query.setSession(unitOfWork); } }
/** * INTERNAL: * Builds a shallow original object. Only direct attributes and primary * keys are populated. In this way the minimum original required for * instantiating a working copy clone can be built without placing it in * the shared cache (no concern over cycles). * @parameter original later the input to buildCloneFromRow */ public void buildShallowOriginalFromRow(AbstractRecord record, Object original, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) { // In this case we know it is a primary key mapping, so hope that it // is essentially a direct mapping. If it is a 1-1 with a // no-indirection pointer back to original, then will get a stack // overflow. // Only solution to this is to trigger the transformation using the root // session. UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)query.getSession(); query.setSession(unitOfWork.getParent()); try { readFromRowIntoObject(record, joinManager, original, query, executionSession); } finally { query.setSession(unitOfWork); } }
/** * INTERNAL: * Builds a shallow original object. Only direct attributes and primary * keys are populated. In this way the minimum original required for * instantiating a working copy clone can be built without placing it in * the shared cache (no concern over cycles). * @param original later the input to buildCloneFromRow */ @Override public void buildShallowOriginalFromRow(AbstractRecord record, Object original, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) { // In this case we know it is a primary key mapping, so hope that it // is essentially a direct mapping. If it is a 1-1 with a // no-indirection pointer back to original, then will get a stack // overflow. // Only solution to this is to trigger the transformation using the root // session. UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)query.getSession(); query.setSession(unitOfWork.getParent()); try { readFromRowIntoObject(record, joinManager, original, null, query, executionSession, false); } finally { query.setSession(unitOfWork); } }
/** * 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; }
/** * INTERNAL: * Extract value from the row and set the attribute to the value in the object. */ public Object readFromRowIntoObject(AbstractRecord row, JoinedAttributeManager joinManager, Object object, ObjectBuildingQuery query, AbstractSession executionSession) throws DatabaseException { if (isWriteOnly()) { return null; } Object attributeValue = getIndirectionPolicy().valueFromMethod(object, row, query.getSession()); try { getAttributeAccessor().setAttributeValueInObject(object, attributeValue); } catch (DescriptorException exception) { exception.setMapping(this); throw exception; } return attributeValue; }
/** * Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it. */ public Object buildWorkingCopyCloneFromRow(Record row, ObjectBuildingQuery query, Vector primaryKey, UnitOfWork uow) throws DescriptorException { // For now must preserve CMP code which builds heavy clones with a context. // Also preserve for clients who use the copy policy. ObjectBuilder builder = getDescriptor().getObjectBuilder(); if (getWorkingCopyMethodName() != null) { Object original = builder.buildNewInstance(); builder.buildAttributesIntoShallowObject(original, (AbstractRecord)row, query); return buildWorkingCopyClone(original, query.getSession()); } else { return builder.buildNewInstance(); } }
/** * Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it. */ @Override public Object buildWorkingCopyCloneFromRow(Record row, ObjectBuildingQuery query, Object primaryKey, UnitOfWork uow) throws DescriptorException { // For now must preserve CMP code which builds heavy clones with a context. // Also preserve for clients who use the copy policy. ObjectBuilder builder = getDescriptor().getObjectBuilder(); if (getWorkingCopyMethodName() != null) { Object original = builder.buildNewInstance(); builder.buildAttributesIntoShallowObject(original, (AbstractRecord)row, query); return buildWorkingCopyClone(original, query.getSession()); } else { return builder.buildNewInstance(); } }
/** * Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it. */ @Override public Object buildWorkingCopyCloneFromRow(Record row, ObjectBuildingQuery query, Object primaryKey, UnitOfWork uow) throws DescriptorException { // For now must preserve CMP code which builds heavy clones with a context. // Also preserve for clients who use the copy policy. ObjectBuilder builder = getDescriptor().getObjectBuilder(); if (getWorkingCopyMethodName() != null) { Object original = builder.buildNewInstance(); builder.buildAttributesIntoShallowObject(original, (AbstractRecord)row, query); return buildWorkingCopyClone(original, query.getSession()); } else { return builder.buildNewInstance(); } }
/** * Return an instance of the receivers javaClass. Set the attributes of an instance * from the values stored in the database row. */ public Object buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager) { InheritancePolicy inheritancePolicy = null; if (this.descriptor.hasInheritance()) { inheritancePolicy = this.descriptor.getInheritancePolicy(); } AbstractSession session = query.getSession(); session.startOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL); Object domainObject = null; try { domainObject = buildObject(query, databaseRow, joinManager, session, this.descriptor, inheritancePolicy, session.isUnitOfWork(), query.shouldCacheQueryResults(), query.shouldUseWrapperPolicy()); } finally { session.endOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL); } return domainObject; }
/** * Return an instance of the receivers javaClass. Set the attributes of an instance * from the values stored in the database row. */ public Object buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager) { InheritancePolicy inheritancePolicy = null; if (this.descriptor.hasInheritance()) { inheritancePolicy = this.descriptor.getInheritancePolicy(); } AbstractSession session = query.getSession(); session.startOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL); Object domainObject = null; try { domainObject = buildObject(query, databaseRow, joinManager, session, this.descriptor, inheritancePolicy, session.isUnitOfWork(), query.shouldCacheQueryResults(), query.shouldUseWrapperPolicy()); } finally { session.endOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL); } return domainObject; }
protected void postBuildAttributesIntoObjectEvent(Object domainObject, AbstractRecord databaseRow, ObjectBuildingQuery query, boolean forRefresh) { DescriptorEventManager descriptorEventManager = this.descriptor.getDescriptorEventManager(); if(descriptorEventManager.hasAnyEventListeners()) { // Need to run post build or refresh selector, currently check with the query for this, // I'm not sure which should be called it case of refresh building a new object, currently refresh is used... org.eclipse.persistence.descriptors.DescriptorEvent event = new DescriptorEvent(domainObject); event.setQuery(query); event.setSession(query.getSession()); event.setRecord(databaseRow); if (forRefresh) { //this method can be called from different places within TopLink. We may be //executing refresh query but building the object not refreshing so we must //throw the appropriate event. //bug 3325315 event.setEventCode(DescriptorEventManager.PostRefreshEvent); } else { event.setEventCode(DescriptorEventManager.PostBuildEvent); } descriptorEventManager.executeEvent(event); } }
protected void postBuildAttributesIntoObjectEvent(Object domainObject, AbstractRecord databaseRow, ObjectBuildingQuery query, boolean forRefresh) { DescriptorEventManager descriptorEventManager = this.descriptor.getDescriptorEventManager(); if(descriptorEventManager.hasAnyEventListeners()) { // Need to run post build or refresh selector, currently check with the query for this, // I'm not sure which should be called it case of refresh building a new object, currently refresh is used... org.eclipse.persistence.descriptors.DescriptorEvent event = new DescriptorEvent(domainObject); event.setQuery(query); event.setSession(query.getSession()); event.setRecord(databaseRow); if (forRefresh) { //this method can be called from different places within TopLink. We may be //executing refresh query but building the object not refreshing so we must //throw the appropriate event. //bug 3325315 event.setEventCode(DescriptorEventManager.PostRefreshEvent); } else { event.setEventCode(DescriptorEventManager.PostBuildEvent); } descriptorEventManager.executeEvent(event); } }
/** * INTERNAL: * Append the temporal selection to the query selection criteria. */ protected ReadQuery prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) { if (getHistoryPolicy() != null) { if (targetQuery == getSelectionQuery()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); } if (targetQuery.getSelectionCriteria() == getSelectionQuery().getSelectionCriteria()) { targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); } if (sourceQuery.getSession().getAsOfClause() != null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(sourceQuery.getSession().getAsOfClause()); } else if (((ObjectLevelReadQuery)targetQuery).getAsOfClause() == null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(AsOfClause.NO_CLAUSE); } Expression temporalExpression = (this).getHistoryPolicy().additionalHistoryExpression(targetQuery.getSelectionCriteria().getBuilder()); targetQuery.setSelectionCriteria(targetQuery.getSelectionCriteria().and(temporalExpression)); } return targetQuery; } }
/** * INTERNAL: * Append the temporal selection to the query selection criteria. */ @Override protected ReadQuery prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) { if (getHistoryPolicy() != null) { if (targetQuery == getSelectionQuery()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); } if (targetQuery.getSelectionCriteria() == getSelectionQuery().getSelectionCriteria()) { targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); } if (sourceQuery.getSession().getAsOfClause() != null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(sourceQuery.getSession().getAsOfClause()); } else if (((ObjectLevelReadQuery)targetQuery).getAsOfClause() == null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(AsOfClause.NO_CLAUSE); } Expression temporalExpression = (this).getHistoryPolicy().additionalHistoryExpression(targetQuery.getSelectionCriteria().getBuilder(), targetQuery.getSelectionCriteria().getBuilder()); targetQuery.setSelectionCriteria(targetQuery.getSelectionCriteria().and(temporalExpression)); } return targetQuery; } }
/** * INTERNAL: * Append the temporal selection to the query selection criteria. */ @Override protected ReadQuery prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) { if (getHistoryPolicy() != null) { if (targetQuery == getSelectionQuery()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); } if (targetQuery.getSelectionCriteria() == getSelectionQuery().getSelectionCriteria()) { targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); } if (sourceQuery.getSession().getAsOfClause() != null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(sourceQuery.getSession().getAsOfClause()); } else if (((ObjectLevelReadQuery)targetQuery).getAsOfClause() == null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(AsOfClause.NO_CLAUSE); } Expression temporalExpression = (this).getHistoryPolicy().additionalHistoryExpression(targetQuery.getSelectionCriteria().getBuilder(), targetQuery.getSelectionCriteria().getBuilder()); targetQuery.setSelectionCriteria(targetQuery.getSelectionCriteria().and(temporalExpression)); } return targetQuery; } }