* 1. get the parent property
* 2. list all the properties following the expected one in the parent property
* 3. calculate the lowest index and insert the property
*/
if (pc == null)
throw new MappingException("dotted notation in <return-join> or <load_collection> not yet supported");
int dotIndex = name.lastIndexOf( '.' );
String reducedName = name.substring( 0, dotIndex );
Value value = pc.getRecursiveProperty( reducedName ).getValue();
Iterator parentPropIter;
if ( value instanceof Component ) {
Component comp = (Component) value;
parentPropIter = comp.getPropertyIterator();
}
else if ( value instanceof ToOne ) {
ToOne toOne = (ToOne) value;
PersistentClass referencedPc = mappings.getClass( toOne.getReferencedEntityName() );
if ( toOne.getReferencedPropertyName() != null ) {
try {
parentPropIter = ( (Component) referencedPc.getRecursiveProperty( toOne.getReferencedPropertyName() ).getValue() ).getPropertyIterator();
} catch (ClassCastException e) {
throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
}
}
else {
try {
if ( referencedPc.getIdentifierMapper() == null ) {
parentPropIter = ( (Component) referencedPc.getIdentifierProperty().getValue() ).getPropertyIterator();
}
else {
parentPropIter = referencedPc.getIdentifierMapper().getPropertyIterator();
}
}
catch (ClassCastException e) {
throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
}
}
}
else {
throw new MappingException("dotted notation reference neither a component nor a many/one to one");
}
boolean hasFollowers = false;
List followers = new ArrayList();
while ( parentPropIter.hasNext() ) {
String currentPropertyName = ( (Property) parentPropIter.next() ).getName();
String currentName = reducedName + '.' + currentPropertyName;
if (hasFollowers) {
followers.add( currentName );
}
if ( name.equals( currentName ) ) hasFollowers = true;
}
int index = propertyNames.size();
int followersSize = followers.size();
for (int loop = 0 ; loop < followersSize ; loop++) {
String follower = (String) followers.get(loop);
int currentIndex = getIndexOfFirstMatchingProperty(propertyNames, follower);
index = currentIndex != -1 && currentIndex < index ? currentIndex : index;
}
propertyNames.add(index, name);
properties.add(index, propertyresult);
}
}
Set uniqueReturnProperty = new HashSet();
iterator = properties.iterator();
while ( iterator.hasNext() ) {
Element propertyresult = (Element) iterator.next();
String name = propertyresult.attributeValue("name");
if ( "class".equals(name) ) {
throw new MappingException(
"class is not a valid property name to use in a <return-property>, use <return-discriminator> instead"
);
}
//TODO: validate existing of property with the chosen name. (secondpass )
ArrayList allResultColumns = getResultColumns(propertyresult);
if ( allResultColumns.isEmpty() ) {
throw new MappingException(
"return-property for alias " + alias +
" must specify at least one column or return-column name"
);
}
if ( uniqueReturnProperty.contains( name ) ) {
throw new MappingException(
"duplicate return-property for property " + name +
" on alias " + alias
);
}
uniqueReturnProperty.add(name);