use of org.sql.generation.api.grammar.query.Ordering in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method processOrderBySegments.
protected void processOrderBySegments(OrderBy[] orderBy, SQLVendor vendor, QuerySpecificationBuilder builder) {
if (orderBy != null) {
QNameInfo[] qNames = new QNameInfo[orderBy.length];
QueryFactory q = vendor.getQueryFactory();
ColumnsFactory c = vendor.getColumnsFactory();
Integer tableIndex = 0;
for (Integer idx = 0; idx < orderBy.length; ++idx) {
if (orderBy[idx] != null) {
PropertyFunction<?> ref = orderBy[idx].property();
QualifiedName qName = QualifiedName.fromAccessor(ref.accessor());
QNameInfo info = this._state.qNameInfos().get().get(qName);
qNames[idx] = info;
if (info == null) {
throw new InternalError("No qName info found for qName [" + qName + "].");
}
tableIndex = this.traversePropertyPath(ref, 0, tableIndex + 1, vendor, builder.getFrom().getTableReferences().iterator().next(), JoinType.LEFT_OUTER);
Class<?> declaringType = ((Member) ref.accessor()).getDeclaringClass();
String colName;
Integer tableIdx;
if (Identity.class.equals(declaringType)) {
colName = DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME;
tableIdx = tableIndex - 1;
} else {
colName = DBNames.QNAME_TABLE_VALUE_COLUMN_NAME;
tableIdx = tableIndex;
}
Ordering ordering = Ordering.ASCENDING;
if (orderBy[idx].order() == Order.DESCENDING) {
ordering = Ordering.DESCENDING;
}
builder.getOrderBy().addSortSpecs(q.sortSpec(c.colName(TABLE_NAME_PREFIX + tableIdx, colName), ordering));
}
}
}
}
Aggregations