@Test public void testMany2ManyAssoc() { String expectedJoinQuery = "SELECT " + "programmers_projects.*, " + "t.assignment_id AS programmer_id " + "FROM " + "programmers_projects " + "INNER JOIN issue_assignments t ON programmers_projects.id = t.programmer_id " + "WHERE t.assignment_id IN (?)"; Many2ManyAssociation association = new Many2ManyAssociation( Programmer.class, Assignment.class, "issue_assignments", "assignment_id", "programmer_id"); String query = dialect.selectManyToManyAssociation( association, "programmer_id", 1); a(query).shouldBeEqual(expectedJoinQuery); }
@Override public String selectManyToManyAssociation(Many2ManyAssociation association, String sourceFkColumnName, int questionsCount) { String targetTable = metaModelOf(association.getTargetClass()).getTableName(); StringBuilder query = new StringBuilder().append("SELECT ").append(targetTable).append(".*, t.") .append(association.getSourceFkName()).append(" AS ").append(sourceFkColumnName).append(" FROM ") .append(targetTable).append(" INNER JOIN ").append(association.getJoin()).append(" t ON ") .append(targetTable).append('.').append(association.getTargetPk()).append(" = t.") .append(association.getTargetFkName()).append(" WHERE t.").append(association.getSourceFkName()) .append(" IN ("); appendQuestions(query, questionsCount); query.append(')'); return query.toString(); }
DefaultDialect implements Dialect { @Override public String selectManyToManyAssociation(Many2ManyAssociation association, String sourceFkColumnName, int questionsCount) { String targetTable = metaModelOf(association.getTargetClass()).getTableName(); StringBuilder query = new StringBuilder().append("SELECT ").append(targetTable).append(".*, t.") .append(association.getSourceFkName()).append(" AS ").append(sourceFkColumnName).append(" FROM ") .append(targetTable).append(" INNER JOIN ").append(association.getJoin()).append(" t ON ") .append(targetTable).append('.').append(association.getTargetPk()).append(" = t.") .append(association.getTargetFkName()).append(" WHERE t.").append(association.getSourceFkName()) .append(" IN ("); appendQuestions(query, questionsCount); query.append(')'); return query.toString(); } }
DefaultDialect implements Dialect { @Override public String selectManyToManyAssociation(Many2ManyAssociation association, String sourceFkColumnName, int questionsCount) { String targetTable = metaModelOf(association.getTargetClass()).getTableName(); StringBuilder query = new StringBuilder().append("SELECT ").append(targetTable).append(".*, t.") .append(association.getSourceFkName()).append(" AS ").append(sourceFkColumnName).append(" FROM ") .append(targetTable).append(" INNER JOIN ").append(association.getJoin()).append(" t ON ") .append(targetTable).append('.').append(association.getTargetPk()).append(" = t.") .append(association.getTargetFkName()).append(" WHERE t.").append(association.getSourceFkName()) .append(" IN ("); appendQuestions(query, questionsCount); query.append(')'); return query.toString(); }  }
DefaultDialect implements Dialect { @Override public String selectManyToManyAssociation(Many2ManyAssociation association, String sourceFkColumnName, int questionsCount) { String targetTable = metaModelOf(association.getTargetClass()).getTableName(); StringBuilder query = new StringBuilder().append("SELECT ").append(targetTable).append(".*, t.") .append(association.getSourceFkName()).append(" AS ").append(sourceFkColumnName).append(" FROM ") .append(targetTable).append(" INNER JOIN ").append(association.getJoin()).append(" t ON ") .append(targetTable).append('.').append(association.getTargetPk()).append(" = t.") .append(association.getTargetFkName()).append(" WHERE t.").append(association.getSourceFkName()) .append(" IN ("); appendQuestions(query, questionsCount); query.append(')'); return query.toString(); }  @Override String selectStar(String table); @Override String selectStar(String table, String where); @Override String selectStarParametrized(String table, String ... parameters); @Override String formSelect(String tableName, String[] columns, String subQuery, List<String> orderBys, long limit, long offset); @Override Object overrideDriverTypeConversion(MetaModel mm, String attributeName, Object value); @Override String selectCount(String from); @Override String selectCount(String table, String where); @Override String selectExists(MetaModel metaModel); @Override String selectManyToManyAssociation(Many2ManyAssociation association, String sourceFkColumnName, int questionsCount); @Override String insertManyToManyAssociation(Many2ManyAssociation association); @Override String insertParametrized(MetaModel metaModel, List<String> columns, boolean containsId); @Override String deleteManyToManyAssociation(Many2ManyAssociation association); @Override String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements); @Override String update(MetaModel metaModel, Map<String, Object> attributes, String ... replacements); }
DefaultDialect implements Dialect { @Override public String selectManyToManyAssociation(Many2ManyAssociation association, String sourceFkColumnName, int questionsCount) { String targetTable = metaModelOf(association.getTargetClass()).getTableName(); StringBuilder query = new StringBuilder().append("SELECT ").append(targetTable).append(".*, t.") .append(association.getSourceFkName()).append(" AS ").append(sourceFkColumnName).append(" FROM ") .append(targetTable).append(" INNER JOIN ").append(association.getJoin()).append(" t ON ") .append(targetTable).append('.').append(association.getTargetPk()).append(" = t.") .append(association.getTargetFkName()).append(" WHERE t.").append(association.getSourceFkName()) .append(" IN ("); appendQuestions(query, questionsCount); query.append(')'); return query.toString(); }  @Override String selectStar(String table); @Override String selectStar(String table, String where); @Override String selectStarParametrized(String table, String ... parameters); @Override String formSelect(String tableName, String[] columns, String subQuery, List<String> orderBys, long limit, long offset); @Override Object overrideDriverTypeConversion(MetaModel mm, String attributeName, Object value); @Override String selectCount(String from); @Override String selectCount(String table, String where); @Override String selectExists(MetaModel metaModel); @Override String selectManyToManyAssociation(Many2ManyAssociation association, String sourceFkColumnName, int questionsCount); @Override String insertManyToManyAssociation(Many2ManyAssociation association); @Override String insertParametrized(MetaModel metaModel, List<String> columns, boolean containsId); @Override String deleteManyToManyAssociation(Many2ManyAssociation association); @Override String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements); @Override String update(MetaModel metaModel, Map<String, Object> attributes, String ... replacements);  }