Search in sources :

Example 31 with ISqlTemplate

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 });
    }
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) Date(java.util.Date)

Example 32 with ISqlTemplate

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);
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Date(java.util.Date) Test(org.junit.Test)

Example 33 with ISqlTemplate

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);
        }
    }
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) Method(java.lang.reflect.Method) SqlException(org.jumpmind.db.sql.SqlException) SQLException(java.sql.SQLException)

Example 34 with ISqlTemplate

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)));
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) Test(org.junit.Test)

Example 35 with ISqlTemplate

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;
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) IExtensionPoint(org.jumpmind.extension.IExtensionPoint) INodeGroupExtensionPoint(org.jumpmind.symmetric.ext.INodeGroupExtensionPoint) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Aggregations

ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)35 Test (org.junit.Test)8 Row (org.jumpmind.db.sql.Row)7 Date (java.util.Date)6 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)5 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)5 DataGap (org.jumpmind.symmetric.model.DataGap)5 Table (org.jumpmind.db.model.Table)4 Column (org.jumpmind.db.model.Column)3 SqlException (org.jumpmind.db.sql.SqlException)3 DbExport (org.jumpmind.symmetric.io.data.DbExport)3 AbstractServiceTest (org.jumpmind.symmetric.service.impl.AbstractServiceTest)3 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Database (org.jumpmind.db.model.Database)2 DmlStatement (org.jumpmind.db.sql.DmlStatement)2 ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)2 SymmetricException (org.jumpmind.symmetric.SymmetricException)2