Search in sources :

Example 6 with DmlStatement

use of org.jumpmind.db.sql.DmlStatement 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 7 with DmlStatement

use of org.jumpmind.db.sql.DmlStatement in project symmetric-ds by JumpMind.

the class DbFill method createDynamicRandomDeleteSql.

public String createDynamicRandomDeleteSql(Table table) {
    DmlStatement deleteStatement = createDeleteDmlStatement(table);
    Row row = selectRandomRow(table);
    return deleteStatement.buildDynamicDeleteSql(BinaryEncoding.HEX, row, false, true);
}
Also used : DmlStatement(org.jumpmind.db.sql.DmlStatement) Row(org.jumpmind.db.sql.Row)

Example 8 with DmlStatement

use of org.jumpmind.db.sql.DmlStatement 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 9 with DmlStatement

use of org.jumpmind.db.sql.DmlStatement in project symmetric-ds by JumpMind.

the class DbFill method updateRandomRecord.

private void updateRandomRecord(Table table) {
    DmlStatement updStatement = createUpdateDmlStatement(table);
    Row row = createRandomUpdateValues(updStatement, table);
    try {
        platform.getSqlTemplate().update(updStatement.getSql(), row.toArray(table.getColumnNames()));
        if (verbose) {
            log.info("Successful update in " + table.getName());
        }
    } catch (SqlException ex) {
        log.info("Failed to process {} with values of {}", updStatement.getSql(), ArrayUtils.toString(row.toArray(table.getColumnNames())));
        if (continueOnError) {
            if (debug) {
                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 10 with DmlStatement

use of org.jumpmind.db.sql.DmlStatement in project symmetric-ds by JumpMind.

the class DbFill method createDynamicRandomUpdateSql.

public String createDynamicRandomUpdateSql(Table table) {
    DmlStatement updStatement = createUpdateDmlStatement(table);
    Row row = createRandomUpdateValues(updStatement, table);
    return updStatement.buildDynamicSql(BinaryEncoding.HEX, row, false, true);
}
Also used : DmlStatement(org.jumpmind.db.sql.DmlStatement) Row(org.jumpmind.db.sql.Row)

Aggregations

DmlStatement (org.jumpmind.db.sql.DmlStatement)25 Row (org.jumpmind.db.sql.Row)19 Table (org.jumpmind.db.model.Table)12 Column (org.jumpmind.db.model.Column)10 SqlException (org.jumpmind.db.sql.SqlException)10 ArrayList (java.util.ArrayList)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)3 Date (java.util.Date)2 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)2 Timestamp (java.sql.Timestamp)1 LinkedHashMap (java.util.LinkedHashMap)1 ForeignKey (org.jumpmind.db.model.ForeignKey)1 Reference (org.jumpmind.db.model.Reference)1 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)1 ParseException (org.jumpmind.exception.ParseException)1 DataEventType (org.jumpmind.symmetric.io.data.DataEventType)1 ConflictException (org.jumpmind.symmetric.io.data.writer.ConflictException)1 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)1 IParameterService (org.jumpmind.symmetric.service.IParameterService)1