* operators are supported.
*/
protected void processOrderBy(CollectionMapping mapping) {
if (hasOrderBy()) {
String orderBy = getOrderBy();
MetadataDescriptor referenceDescriptor = getReferenceDescriptor();
if (orderBy.equals("")) {
// Default to the primary key field name(s).
List<String> orderByAttributes = referenceDescriptor.getIdOrderByAttributeNames();
if (referenceDescriptor.hasEmbeddedIdAttribute()) {
String embeddedIdAttributeName = referenceDescriptor.getEmbeddedIdAttributeName();
for (String orderByAttribute : orderByAttributes) {
mapping.addAggregateOrderBy(embeddedIdAttributeName, orderByAttribute, false);
}
} else {
for (String orderByAttribute : orderByAttributes) {
mapping.addOrderBy(orderByAttribute, false);
}
}
} else {
StringTokenizer commaTokenizer = new StringTokenizer(orderBy, ",");
while (commaTokenizer.hasMoreTokens()) {
StringTokenizer spaceTokenizer = new StringTokenizer(commaTokenizer.nextToken());
String propertyOrFieldName = spaceTokenizer.nextToken();
MetadataAccessor referenceAccessor = referenceDescriptor.getAccessorFor(propertyOrFieldName);
if (referenceAccessor == null) {
m_validator.throwInvalidOrderByValue(getJavaClass(), propertyOrFieldName, referenceDescriptor.getJavaClass(), getName());
}
String attributeName = referenceAccessor.getAttributeName();
String ordering = (spaceTokenizer.hasMoreTokens()) ? spaceTokenizer.nextToken() : MetadataConstants.ASCENDING;
if (referenceAccessor.isEmbedded()) {
for (String orderByAttributeName : referenceDescriptor.getOrderByAttributeNames()) {
mapping.addAggregateOrderBy(attributeName, orderByAttributeName, ordering.equals(MetadataConstants.DESCENDING));
}
} else {
mapping.addOrderBy(attributeName, ordering.equals(MetadataConstants.DESCENDING));
}