use of com.querydsl.sql.codegen.support.KeyData in project querydsl by querydsl.
the class MetaDataSerializer method serializeForeignKeys.
protected void serializeForeignKeys(EntityType model, CodeWriter writer, Collection<? extends KeyData> foreignKeys, boolean inverse) throws IOException {
for (KeyData foreignKey : foreignKeys) {
String fieldName;
if (inverse) {
fieldName = namingStrategy.getPropertyNameForInverseForeignKey(foreignKey.getName(), model);
} else {
fieldName = namingStrategy.getPropertyNameForForeignKey(foreignKey.getName(), model);
}
StringBuilder value = new StringBuilder();
if (inverse) {
value.append("createInvForeignKey(");
} else {
value.append("createForeignKey(");
}
if (foreignKey.getForeignColumns().size() == 1) {
value.append(namingStrategy.getPropertyName(foreignKey.getForeignColumns().get(0), model));
value.append(", \"" + foreignKey.getParentColumns().get(0) + "\"");
} else {
StringBuilder local = new StringBuilder();
StringBuilder foreign = new StringBuilder();
for (int i = 0; i < foreignKey.getForeignColumns().size(); i++) {
if (i > 0) {
local.append(", ");
foreign.append(", ");
}
local.append(namingStrategy.getPropertyName(foreignKey.getForeignColumns().get(i), model));
foreign.append("\"" + foreignKey.getParentColumns().get(i) + "\"");
}
value.append("Arrays.asList(" + local + "), Arrays.asList(" + foreign + ")");
}
value.append(")");
Type type = new ClassType(ForeignKey.class, foreignKey.getType());
writer.publicFinal(type, fieldName, value.toString());
}
}
Aggregations