NSArray<String> k;
EOEntity rightEntity;
EOEntity leftEntity;
String relationshipKey = null;
EORelationship r;
if (leftAlias.equals("t0")) {
leftEntity = entity();
} else {
k = aliasesByRelationshipPath().allKeysForObject(leftAlias);
relationshipKey = k.count()>0? (String)k.lastObject() : "";
leftEntity = entityForKeyPath(relationshipKey);
}
if (rightAlias.equals("t0")) {
rightEntity = entity();
} else {
k = aliasesByRelationshipPath().allKeysForObject(rightAlias);
relationshipKey = k.count()>0? (String)k.lastObject() : "";
rightEntity = entityForKeyPath(relationshipKey);
}
if (relationshipKey == null) {
throw new IllegalStateException("Could not determine relationship for join.");
}
int dotIndex = relationshipKey.indexOf( "." );
relationshipKey = dotIndex == -1
? relationshipKey
: relationshipKey.substring( relationshipKey.lastIndexOf( "." ) + 1 );
r = rightEntity.anyRelationshipNamed( relationshipKey );
// fix from Michael Müller for the case Foo.fooBars.bar has a Bar.foo relationship (instead of Bar.foos)
if( r == null || r.destinationEntity() != leftEntity ) {
r = leftEntity.anyRelationshipNamed( relationshipKey );
}
//timc 2006-02-26 IMPORTANT or quotes are ignored and mixed case field names won't work
String rightTable;
String leftTable;
if(enableIdentifierQuoting()) {
rightTable = rightEntity.valueForSQLExpression(this);
leftTable = leftEntity.valueForSQLExpression(this);
} else {
rightTable = rightEntity.externalName();
leftTable = leftEntity.externalName();
}
JoinClause jc = new JoinClause();
jc.setTable1(leftTable, leftAlias);
switch (semantic) {
case EORelationship.LeftOuterJoin:
jc.op = " LEFT OUTER JOIN ";
break;
case EORelationship.RightOuterJoin:
jc.op = " RIGHT OUTER JOIN ";
break;
case EORelationship.FullOuterJoin:
jc.op = " FULL OUTER JOIN ";
break;
case EORelationship.InnerJoin:
jc.op = " INNER JOIN ";
break;
}
jc.table2 = rightTable + " " + rightAlias;
NSArray<EOJoin> joins = r.joins();
int joinsCount = joins.count();
NSMutableArray<String> joinStrings = new NSMutableArray<String>(joinsCount);
for( int i = 0; i < joinsCount; i++ ) {
EOJoin currentJoin = joins.objectAtIndex(i);
String left;