Search in sources :

Example 16 with Row

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;
}
Also used : DmlStatement(org.jumpmind.db.sql.DmlStatement) Row(org.jumpmind.db.sql.Row)

Example 17 with 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);
}
Also used : DmlStatement(org.jumpmind.db.sql.DmlStatement) Row(org.jumpmind.db.sql.Row)

Example 18 with Row

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;
        }
    }
}
Also used : SqlException(org.jumpmind.db.sql.SqlException) DmlStatement(org.jumpmind.db.sql.DmlStatement) Row(org.jumpmind.db.sql.Row)

Example 19 with Row

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

Example 20 with Row

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;
    }
}
Also used : HashMap(java.util.HashMap) Row(org.jumpmind.db.sql.Row) Lock(org.jumpmind.symmetric.model.Lock)

Aggregations

Row (org.jumpmind.db.sql.Row)66 ArrayList (java.util.ArrayList)27 ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)23 Trigger (org.jumpmind.db.model.Trigger)19 JdbcSqlTemplate (org.jumpmind.db.sql.JdbcSqlTemplate)19 DmlStatement (org.jumpmind.db.sql.DmlStatement)13 Column (org.jumpmind.db.model.Column)11 Table (org.jumpmind.db.model.Table)9 Date (java.util.Date)8 HashMap (java.util.HashMap)7 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)7 Test (org.junit.Test)5 HashSet (java.util.HashSet)3 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)3 SqlException (org.jumpmind.db.sql.SqlException)3 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)3 Node (org.jumpmind.symmetric.model.Node)3 Map (java.util.Map)2 NotImplementedException (org.apache.commons.lang.NotImplementedException)2 Database (org.jumpmind.db.model.Database)2