@Test public void testInsertStatement(){ Map<String, Object> x = new CaseInsensitiveMap(); x.put("testField", "testValue"); a(dialect.insert( Person.getMetaModel(), x)) .shouldBeEqual("INSERT INTO people (testField) VALUES ('testValue')"); x.put("testField2", "testValue2"); a(dialect.insert( Person.getMetaModel(), x)) .shouldBeEqual("INSERT INTO people (testField, testField2) VALUES ('testValue', 'testValue2')"); }
@Override public String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements) { StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' '); if (attributes.isEmpty()) { appendEmptyRow(metaModel, query); } else { boolean addIdGeneratorCode = (metaModel.getIdGeneratorCode() != null && attributes.get(metaModel.getIdName()) == null); query.append('('); if (addIdGeneratorCode) { query.append(metaModel.getIdName()).append(", "); } join(query, attributes.keySet(), ", "); query.append(") VALUES ("); if (addIdGeneratorCode) { query.append(metaModel.getIdGeneratorCode()).append(", "); } Iterator<Object> it = attributes.values().iterator(); appendValue(query, it.next()); while (it.hasNext()) { query.append(", "); appendValue(query, it.next(), replacements); } query.append(')'); } return query.toString(); }
DefaultDialect implements Dialect { @Override public String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements) { StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' '); if (attributes.isEmpty()) { appendEmptyRow(metaModel, query); } else { boolean addIdGeneratorCode = (metaModel.getIdGeneratorCode() != null && attributes.get(metaModel.getIdName()) == null); query.append('('); if (addIdGeneratorCode) { query.append(metaModel.getIdName()).append(", "); } join(query, attributes.keySet(), ", "); query.append(") VALUES ("); if (addIdGeneratorCode) { query.append(metaModel.getIdGeneratorCode()).append(", "); } Iterator<Object> it = attributes.values().iterator(); appendValue(query, it.next()); while (it.hasNext()) { query.append(", "); appendValue(query, it.next(), replacements); } query.append(')'); } return query.toString(); } }
DefaultDialect implements Dialect { @Override public String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements) { StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' '); if (attributes.isEmpty()) { appendEmptyRow(metaModel, query); } else { boolean addIdGeneratorCode = (metaModel.getIdGeneratorCode() != null && attributes.get(metaModel.getIdName()) == null); query.append('('); if (addIdGeneratorCode) { query.append(metaModel.getIdName()).append(", "); } join(query, attributes.keySet(), ", "); query.append(") VALUES ("); if (addIdGeneratorCode) { query.append(metaModel.getIdGeneratorCode()).append(", "); } Iterator<Object> it = attributes.values().iterator(); appendValue(query, it.next()); while (it.hasNext()) { query.append(", "); appendValue(query, it.next(), replacements); } query.append(')'); } return query.toString(); }  }
DefaultDialect implements Dialect { @Override public String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements) { StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' '); if (attributes.isEmpty()) { appendEmptyRow(metaModel, query); } else { boolean addIdGeneratorCode = (metaModel.getIdGeneratorCode() != null && attributes.get(metaModel.getIdName()) == null); query.append('('); if (addIdGeneratorCode) { query.append(metaModel.getIdName()).append(", "); } join(query, attributes.keySet(), ", "); query.append(") VALUES ("); if (addIdGeneratorCode) { query.append(metaModel.getIdGeneratorCode()).append(", "); } Iterator<Object> it = attributes.values().iterator(); appendValue(query, it.next()); while (it.hasNext()) { query.append(", "); appendValue(query, it.next(), replacements); } 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 insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements) { StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' '); if (attributes.isEmpty()) { appendEmptyRow(metaModel, query); } else { boolean addIdGeneratorCode = (metaModel.getIdGeneratorCode() != null && attributes.get(metaModel.getIdName()) == null); query.append('('); if (addIdGeneratorCode) { query.append(metaModel.getIdName()).append(", "); } join(query, attributes.keySet(), ", "); query.append(") VALUES ("); if (addIdGeneratorCode) { query.append(metaModel.getIdGeneratorCode()).append(", "); } Iterator<Object> it = attributes.values().iterator(); appendValue(query, it.next()); while (it.hasNext()) { query.append(", "); appendValue(query, it.next(), replacements); } 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);  }