// only go up to the index of the selection class.
cutoffIndex = classIndex + 1;
}
for (int t = 0; t < cutoffIndex; t++)
{
ObjectRepresentation rep = oStack.getRepresentation(t);
if (rep.getNonNullPropertyCount() > 0)
{
minIndex = Math.min(t, minIndex);
maxIndex = Math.max(t, maxIndex);
}
}
for (int t = minIndex; t <= maxIndex; t++)
{
ObjectRepresentation rep = oStack.getRepresentation(t);
if (t > minIndex)
{
// this also automatically adds rep to the list of tables to
// join
sp.getIdStatementGenerator().addLinkStatement(oStack.getRepresentation(t - 1), rep);
}
else
{
// because rep needs to be added to the join statements
sp.getIdStatementGenerator().addPropertyTableToJoin(rep.getTableName(), rep.getAsName());
}
// iterate over the non-null values
for (Integer x : rep)
{
Object property = rep.getPropertyValue(x);
String propertyName = rep.getPropertyName(x);
StringBuilder conditional = new StringBuilder(rep.getAsName());
conditional.append(".");
conditional.append(propertyName);
if (rep.isPrimitive(x))
{
// the value is a primitive, so insert it directly
conditional.append(sel.getRelationalRepresentation());
if (sel.takesPlaceholder())
{
conditional.append("?");
sp.addConditionalStatement(conditional.toString(), property);
}
else
{
sp.addConditionalStatement(conditional.toString());
}
}
else
{
// the value is complex, insert a reference
Long id = (long) System.identityHashCode(property);
if (rep.getDelayedInsertionBuffer().isKnown(id))
{
break;
}
rep.getDelayedInsertionBuffer().addId(id);
ObjectStack propertyStack = new ObjectStack(adapter, property.getClass(), property,
rep.getDelayedInsertionBuffer());
nameStack(rep.getAsName() + "." + propertyName, propertyStack);
Class<?> propertyClass = rep.getReturnType(x);
if (propertyClass.isInterface())
{
propertyClass = Object.class;
}
ObjectRepresentation propertyRep = propertyStack.getRepresentation(propertyClass);
conditional.append(" = ");
conditional.append(propertyRep.getAsName());
conditional.append(".");
conditional.append(Defaults.ID_COL);
sp.addConditionalStatement(conditional.toString());
// is this query using strict inheritance?
// is the property and the property class different?