* Return an instance of the recievers javaClass. Set the attributes of an instance
* from the values stored in the database row.
*/
public Object buildObject(ObjectBuildingQuery query, AbstractRecord databaseRow, JoinedAttributeManager joinManager) throws DatabaseException, QueryException {
// Profile object building.
AbstractSession session = query.getSession();
session.startOperationProfile(SessionProfiler.OBJECT_BUILDING);
Vector primaryKey = extractPrimaryKeyFromRow(databaseRow, session);
// Check for null primary key, this is not allowed.
if ((primaryKey == null) && (!query.hasPartialAttributeExpressions()) && (!getDescriptor().isAggregateCollectionDescriptor())) {
// Profile object building.
session.endOperationProfile(SessionProfiler.OBJECT_BUILDING);
//BUG 3168689: EJBQL: "Select Distinct s.customer from SpouseBean s"
//BUG 3168699: EJBQL: "Select s.customer from SpouseBean s where s.id = '6'"
//If we return either a single null, or a Collection containing at least
//one null, then we want the nulls returned/included if the indicated
//property is set in the query. (As opposed to throwing an Exception).
if (query.getProperty("return null if primary key is null") != null) {
return null;
} else {
throw QueryException.nullPrimaryKeyInBuildingObject(query, databaseRow);
}
}
ClassDescriptor concreteDescriptor = getDescriptor();
if (concreteDescriptor.hasInheritance() && concreteDescriptor.getInheritancePolicy().shouldReadSubclasses()) {
Class classValue = concreteDescriptor.getInheritancePolicy().classFromRow(databaseRow, session);
concreteDescriptor = session.getDescriptor(classValue);
if ((concreteDescriptor == null) && query.hasPartialAttributeExpressions()) {
concreteDescriptor = getDescriptor();
}
if (concreteDescriptor == null) {
// Profile object building.
session.endOperationProfile(SessionProfiler.OBJECT_BUILDING);
throw QueryException.noDescriptorForClassFromInheritancePolicy(query, classValue);
}
}
Object domainObject = null;
try {
if (session.isUnitOfWork()) {
// Do not wrap yet if in UnitOfWork, as there is still much more
// processing ahead.
domainObject = buildObjectInUnitOfWork(query, joinManager, databaseRow, (UnitOfWorkImpl)session, primaryKey, concreteDescriptor);
} else {
domainObject = buildObject(query, databaseRow, session, primaryKey, concreteDescriptor, joinManager);
// wrap the object if the query requires it.
if (query.shouldUseWrapperPolicy()) {
domainObject = concreteDescriptor.getObjectBuilder().wrapObject(domainObject, session);
}
}
} finally {
session.endOperationProfile(SessionProfiler.OBJECT_BUILDING);
}
return domainObject;
}