use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class DbFill method selectSpecificRow.
private Row selectSpecificRow(ISqlTransaction tran, Table table, Column[] keyColumns, Object[] values) {
Row row = null;
DmlStatement stmt = platform.createDmlStatement(DmlType.SELECT, table.getCatalog(), table.getSchema(), table.getName(), keyColumns, table.getColumns(), null, textColumnExpression);
if (verbose) {
StringBuilder sb = null;
for (int i = 0; i < keyColumns.length; i++) {
sb = (sb == null) ? new StringBuilder() : sb.append(", ");
sb.append(keyColumns[i].getName()).append("=").append(values[i]);
}
log.info("Selecting row from {} where {}", table.getName(), sb.toString());
}
List<Row> rows = queryForRows(tran, stmt.getSql(), values, stmt.getTypes());
if (rows.size() != 0) {
int rowNum = getRand().nextInt(rows.size());
row = rows.get(rowNum);
} else {
StringBuilder sb = null;
for (int i = 0; i < keyColumns.length; i++) {
sb = (sb == null) ? new StringBuilder() : sb.append(", ");
sb.append(keyColumns[i].getName()).append("=").append(values[i]);
}
log.warn("Unable to find row from {} where {}", table.getName(), sb.toString());
}
return row;
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class DbFill method createDynamicRandomInsertSql.
public String createDynamicRandomInsertSql(Table table) {
DmlStatement insertStatement = createInsertDmlStatement(table);
Row row = createRandomInsertValues(insertStatement, table);
return insertStatement.buildDynamicSql(BinaryEncoding.HEX, row, false, true);
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class DbFill method deleteRandomRecord.
/**
* Delete a random row in the given table or delete all rows matching selectColumns
* in the given table.
*
* @param table Table to delete from.
* @param selectColumns If provided, the rows that match this criteria are deleted.
*/
private void deleteRandomRecord(ISqlTransaction tran, Table table) {
DmlStatement deleteStatement = createDeleteDmlStatement(table);
Row row = selectRandomRow(tran, table);
try {
tran.prepareAndExecute(deleteStatement.getSql(), row.toArray(table.getPrimaryKeyColumnNames()));
} catch (SqlException ex) {
log.info("Failed to delete from {}: {}", table.getName(), ex.getMessage());
if (continueOnError) {
if (debug) {
logRow(row);
log.info("", ex);
}
} else {
throw ex;
}
}
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class SqlPersistenceManagerTest method testInsert.
@Test
public void testInsert() {
Date date = new Date();
manager.insert(new A(1, date, "Hello"), null, null, "A");
Row row = getRow(1);
assertEquals(1, row.get("id"));
assertEquals("Hello", row.get("note"));
assertEquals(date, row.get("last_update_time"));
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class ClusterService method findLocks.
public Map<String, Lock> findLocks() {
if (isClusteringEnabled()) {
final Map<String, Lock> locks = new HashMap<String, Lock>();
sqlTemplate.query(getSql("findLocksSql"), new ISqlRowMapper<Lock>() {
public Lock mapRow(Row rs) {
Lock lock = new Lock();
lock.setLockAction(rs.getString("lock_action"));
lock.setLockType(rs.getString("lock_type"));
lock.setLockingServerId(rs.getString("locking_server_id"));
lock.setLockTime(rs.getDateTime("lock_time"));
lock.setSharedCount(rs.getInt("shared_count"));
lock.setSharedEnable(rs.getBoolean("shared_enable"));
lock.setLastLockingServerId(rs.getString("last_locking_server_id"));
lock.setLastLockTime(rs.getDateTime("last_lock_time"));
locks.put(lock.getLockAction(), lock);
return lock;
}
});
return locks;
} else {
return lockCache;
}
}
Aggregations