Search in sources :

Example 1 with KeyData

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());
    }
}
Also used : InverseForeignKeyData(com.querydsl.sql.codegen.support.InverseForeignKeyData) ForeignKeyData(com.querydsl.sql.codegen.support.ForeignKeyData) PrimaryKeyData(com.querydsl.sql.codegen.support.PrimaryKeyData) KeyData(com.querydsl.sql.codegen.support.KeyData)

Aggregations

ForeignKeyData (com.querydsl.sql.codegen.support.ForeignKeyData)1 InverseForeignKeyData (com.querydsl.sql.codegen.support.InverseForeignKeyData)1 KeyData (com.querydsl.sql.codegen.support.KeyData)1 PrimaryKeyData (com.querydsl.sql.codegen.support.PrimaryKeyData)1