}
fieldDesc = (FieldDescriptor) fieldAndClass[0];
sourceClass = (ClassDescriptor) fieldAndClass[1];
ClassDescriptor clsDesc = fieldDesc.getClassDescriptor();
FieldDescriptorJDONature fieldJDONature = new FieldDescriptorJDONature(fieldDesc);
if (clsDesc != null) {
//we must add this table as a join
ClassDescriptorJDONature sourceClassJDONature =
new ClassDescriptorJDONature(sourceClass);
if (fieldJDONature.getManyKey() == null) {
//a many -> one relationship
FieldDescriptor foreignKey = clsDesc.getIdentity();
String sourceTableAlias = sourceClassJDONature.getTableName();
if (i > 1) {
sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
}
ClassDescriptorJDONature clsDescNature;
clsDescNature = new ClassDescriptorJDONature(clsDesc);
_queryExpr.addInnerJoin(
sourceClassJDONature.getTableName(),
new FieldDescriptorJDONature(fieldDesc).getSQLName(),
sourceTableAlias,
clsDescNature.getTableName(),
new FieldDescriptorJDONature(foreignKey).getSQLName(),
buildTableAlias(clsDescNature.getTableName(), path, i));
} else if (fieldJDONature.getManyTable() == null) {
//a one -> many relationship
FieldDescriptor identity = sourceClass.getIdentity();
String sourceTableAlias = sourceClassJDONature.getTableName();
if (i > 1) {
sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
}
ClassDescriptorJDONature clsDescNature;
clsDescNature = new ClassDescriptorJDONature(clsDesc);
_queryExpr.addInnerJoin(
sourceClassJDONature.getTableName(),
new FieldDescriptorJDONature(identity).getSQLName(),
sourceTableAlias,
clsDescNature.getTableName(),
fieldJDONature.getManyKey(),
buildTableAlias(clsDescNature.getTableName(), path, i));
} else {
//a many -> many relationship
FieldDescriptor identity = sourceClass.getIdentity();
FieldDescriptor foreignKey = clsDesc.getIdentity();
String manyTableAlias = fieldJDONature.getManyTable();
String sourceTableAlias = sourceClassJDONature.getTableName();
if (i > 1) {
manyTableAlias = buildTableAlias(manyTableAlias, path, i - 1);
sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
}
_queryExpr.addInnerJoin(
sourceClassJDONature.getTableName(),
new FieldDescriptorJDONature(identity).getSQLName(),
sourceTableAlias,
fieldJDONature.getManyTable(),
fieldJDONature.getManyKey(),
manyTableAlias);
ClassDescriptorJDONature clsDescNature;
clsDescNature = new ClassDescriptorJDONature(clsDesc);
_queryExpr.addInnerJoin(
fieldJDONature.getManyTable(),
new FieldDescriptorJDONature(fieldDesc).getSQLName(),
manyTableAlias,
clsDescNature.getTableName(),
new FieldDescriptorJDONature(foreignKey).getSQLName(),
buildTableAlias(clsDescNature.getTableName(), path, i));
}
sourceClass = clsDesc;
}
}