use of org.jumpmind.db.sql.ISqlTemplate in project symmetric-ds by JumpMind.
the class GroupletService method saveGrouplet.
public void saveGrouplet(Grouplet grouplet) {
ISqlTemplate sqlTemplate = platform.getSqlTemplate();
grouplet.setLastUpdateTime(new Date());
if (sqlTemplate.update(getSql("updateGroupletSql"), new Object[] { grouplet.getGroupletLinkPolicy().name(), grouplet.getDescription(), grouplet.getCreateTime(), grouplet.getLastUpdateBy(), grouplet.getLastUpdateTime(), grouplet.getGroupletId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR }) == 0) {
grouplet.setCreateTime(new Date());
sqlTemplate.update(getSql("insertGroupletSql"), new Object[] { grouplet.getGroupletLinkPolicy().name(), grouplet.getDescription(), grouplet.getCreateTime(), grouplet.getLastUpdateBy(), grouplet.getLastUpdateTime(), grouplet.getGroupletId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR });
}
}
use of org.jumpmind.db.sql.ISqlTemplate in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test09ExcludedColumnsFunctionality.
@Test
public void test09ExcludedColumnsFunctionality() throws Exception {
ITriggerRouterService service = getTriggerRouterService();
ISqlTemplate jdbcTemplate = getSqlTemplate();
assertEquals(1, jdbcTemplate.update("update sym_trigger set excluded_column_names='BOOLEAN_VALUE', last_update_time=? " + TEST_TRIGGER_WHERE_CLAUSE, new Object[] { new Date(System.currentTimeMillis() + 60000) }));
service.syncTriggers();
TriggerRouter triggerRouter = service.getTriggerRouterForTableForCurrentNode(null, null, TEST_TRIGGERS_TABLE, true).iterator().next();
assertEquals(jdbcTemplate.queryForInt("select count(*) from sym_trigger_hist where trigger_id='" + triggerRouter.getTrigger().getTriggerId() + "' and inactive_time is null"), 1, "We expected only one active record in the trigger_hist table for " + TEST_TRIGGERS_TABLE);
assertEquals(1, insert(INSERT2_VALUES, jdbcTemplate, getDbDialect()));
String csvString = getNextDataRow();
// DB2 captures decimal differently
csvString = csvString.replaceFirst("\"00001\\.\"", "\"1\"");
// Informix captures decimal differently
csvString = csvString.replaceFirst("\"1.0000000000000000\"", "\"1\"");
// ASA captures decimal differently
csvString = csvString.replaceFirst("\"1.000000\"", "\"1\"");
boolean match = csvString.endsWith(EXPECTED_INSERT2_CSV_ENDSWITH);
assertTrue(match, "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT2_CSV_ENDSWITH);
}
use of org.jumpmind.db.sql.ISqlTemplate in project symmetric-ds by JumpMind.
the class DefaultDatabaseWriter method bindVariables.
@Override
protected void bindVariables(Map<String, Object> variables) {
super.bindVariables(variables);
ISqlTemplate template = platform.getSqlTemplate();
Class<?> templateClass = template.getClass();
if (templateClass.getSimpleName().equals("JdbcSqlTemplate")) {
try {
Method method = templateClass.getMethod("getDataSource");
variables.put("DATASOURCE", method.invoke(template));
} catch (Exception e) {
log.warn("Had trouble looking up the datasource used by the sql template", e);
}
}
}
use of org.jumpmind.db.sql.ISqlTemplate in project symmetric-ds by JumpMind.
the class DatabasePlatformTest method testTableRebuild.
@Test
public void testTableRebuild() throws Exception {
Table table = new Table("TEST_REBUILD");
table.addColumn(new Column("ID1", true));
table.getColumnWithName("ID1").setTypeCode(Types.INTEGER);
table.getColumnWithName("ID1").setRequired(true);
table.addColumn(new Column("NOTES"));
table.getColumnWithName("NOTES").setTypeCode(Types.VARCHAR);
table.getColumnWithName("NOTES").setSize("20");
table.getColumnWithName("NOTES").setDefaultValue("1234");
Table origTable = (Table) table.clone();
Table tableFromDatabase = dropCreateAndThenReadTable(table);
assertNotNull(tableFromDatabase);
assertEquals(2, tableFromDatabase.getColumnCount());
ISqlTemplate template = platform.getSqlTemplate();
String delimiter = platform.getDatabaseInfo().getDelimiterToken();
delimiter = delimiter != null ? delimiter : "";
assertEquals(1, template.update(String.format("insert into %s%s%s values(?,?)", delimiter, tableFromDatabase.getName(), delimiter), 1, "test"));
table.addColumn(new Column("ID2", true));
table.getColumnWithName("ID2").setTypeCode(Types.VARCHAR);
table.getColumnWithName("ID2").setSize("20");
table.getColumnWithName("ID2").setRequired(true);
table.getColumnWithName("ID2").setDefaultValue("value");
table.addColumn(new Column("NOTES2"));
table.getColumnWithName("NOTES2").setTypeCode(Types.VARCHAR);
table.getColumnWithName("NOTES2").setSize("20");
table.getColumnWithName("NOTES2").setDefaultValue("1234");
// alter to add two columns that will cause a table rebuild
platform.alterTables(false, table);
tableFromDatabase = platform.getTableFromCache(table.getName(), true);
assertNotNull(tableFromDatabase);
assertEquals(4, tableFromDatabase.getColumnCount());
assertEquals(1, template.queryForLong(String.format("select count(*) from %s%s%s", delimiter, tableFromDatabase.getName(), delimiter)));
// alter to remove two columns that will cause a table rebuild
platform.alterTables(false, origTable);
tableFromDatabase = platform.getTableFromCache(origTable.getName(), true);
assertNotNull(tableFromDatabase);
assertEquals(2, tableFromDatabase.getColumnCount());
assertEquals(1, template.queryForLong(String.format("select count(*) from %s%s%s", delimiter, tableFromDatabase.getName(), delimiter)));
}
use of org.jumpmind.db.sql.ISqlTemplate in project symmetric-ds by JumpMind.
the class AbstractXmlPublisherExtensionPoint method readData.
protected List<String[]> readData(final Table table, String[] args) {
final IDatabasePlatform platform = engine.getDatabasePlatform();
List<String[]> rows = new ArrayList<String[]>();
final String[] columnNames = table.getColumnNames();
if (columnNames != null && columnNames.length > 0) {
StringBuilder builder = new StringBuilder("select ");
for (int i = 0; i < columnNames.length; i++) {
String columnName = columnNames[i];
if (i > 0) {
builder.append(",");
}
builder.append(columnName);
}
builder.append(" from ").append(table.getName()).append(" where ");
for (int i = 0; i < groupByColumnNames.size(); i++) {
String columnName = groupByColumnNames.get(i);
if (i > 0 && i < groupByColumnNames.size()) {
builder.append(" and ");
}
builder.append(columnName).append("=?");
}
ISqlTemplate template = platform.getSqlTemplate();
Object[] argObjs = platform.getObjectValues(engine.getSymmetricDialect().getBinaryEncoding(), args, table.getColumnsWithName(groupByColumnNames.toArray(new String[groupByColumnNames.size()])));
rows = template.query(builder.toString(), new ISqlRowMapper<String[]>() {
@Override
public String[] mapRow(Row row) {
return platform.getStringValues(engine.getSymmetricDialect().getBinaryEncoding(), table.getColumns(), row, false, false);
}
}, argObjs);
}
return rows;
}
Aggregations