else {
descriptor.visitProperties(visitor);
}
// add remaining needed attrs from DbEntity
DbEntity table = getRootDbEntity();
for (final DbAttribute dba : table.getPrimaryKeys()) {
appendColumn(columns, null, dba, attributes, null);
}
// special handling of a disjoint query...
// TODO, Andrus 11/17/2005 - resultPath mechanism is generic and should probably
// be moved in the superclass (SelectQuery), replacing customDbAttributes.
if (query instanceof PrefetchSelectQuery) {
// for each relationship path add closest FK or PK, for each attribute path,
// add specified column
for (String path : ((PrefetchSelectQuery) query).getResultPaths()) {
Expression pathExp = oe.translateToDbPath(Expression.fromString(path));
// add joins and find terminating element
resetJoinStack();
PathComponent<DbAttribute, DbRelationship> lastComponent = null;
for (PathComponent<DbAttribute, DbRelationship> component : table
.resolvePath(pathExp, getPathAliases())) {
// do not add join for the last DB Rel
if (component.getRelationship() != null && !component.isLast()) {
dbRelationshipAdded(component.getRelationship(), component
.getJoinType(), null);
}
lastComponent = component;
}
String labelPrefix = pathExp.toString().substring("db:".length());
// process terminating element
if (lastComponent != null) {
DbRelationship relationship = lastComponent.getRelationship();
if (relationship != null) {
// add last join
if (relationship.isToMany()) {
dbRelationshipAdded(relationship, JoinType.INNER, null);
}
for (DbJoin j : relationship.getJoins()) {
DbAttribute attribute = relationship.isToMany() ? j
.getTarget() : j.getSource();
// note that we my select a source attribute, but label it as
// target for simplified snapshot processing
appendColumn(
columns,
null,
attribute,
attributes,
labelPrefix + '.' + j.getTargetName());
}
}
else {
// label prefix already includes relationship name
appendColumn(
columns,
null,
lastComponent.getAttribute(),
attributes,
labelPrefix);
}
}
}
}
// handle joint prefetches directly attached to this query...
if (query.getPrefetchTree() != null) {
for (PrefetchTreeNode prefetch : query.getPrefetchTree().adjacentJointNodes()) {
// for each prefetch add all joins plus columns from the target entity
Expression prefetchExp = Expression.fromString(prefetch.getPath());
Expression dbPrefetch = oe.translateToDbPath(prefetchExp);
resetJoinStack();
DbRelationship r = null;
for (PathComponent<DbAttribute, DbRelationship> component : table
.resolvePath(dbPrefetch, getPathAliases())) {
r = component.getRelationship();
dbRelationshipAdded(r, JoinType.INNER, null);
}