* 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.hasEmbeddedId()) {
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(m_orderBy, orderByAttributeName, ordering.equals(DESCENDING));
}
} else if (referenceAccessor.getClassAccessor().isEmbeddableAccessor()) {
// We have a specific order by from an embeddable, we need to rip off
// the last bit of a dot notation if specified and pass in the chained