* used in the ordering must correspond to columns for which comparison
* operators are supported.
*/
protected void processOrderBy(CollectionMapping mapping) {
if (m_orderBy != null) {
MetadataDescriptor referenceDescriptor = getReferenceDescriptor();
if (m_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(m_orderBy, ",");
while (commaTokenizer.hasMoreTokens()) {
StringTokenizer spaceTokenizer = new StringTokenizer(commaTokenizer.nextToken());
String propertyOrFieldName = spaceTokenizer.nextToken();
MappingAccessor referenceAccessor = referenceDescriptor.getAccessorFor(propertyOrFieldName);
if (referenceAccessor == null) {
throw ValidationException.invalidOrderByValue(propertyOrFieldName, referenceDescriptor.getJavaClass(), getAccessibleObjectName(), getJavaClass());
}
String attributeName = referenceAccessor.getAttributeName();
String ordering = (spaceTokenizer.hasMoreTokens()) ? spaceTokenizer.nextToken() : ASCENDING;
if (referenceAccessor.isEmbedded()) {
for (String orderByAttributeName : referenceDescriptor.getOrderByAttributeNames()) {
mapping.addAggregateOrderBy(attributeName, orderByAttributeName, ordering.equals(DESCENDING));
}
} else {
mapping.addOrderBy(attributeName, ordering.equals(DESCENDING));
}