Search in sources :

Example 1 with Sequence

use of jp.ossc.nimbus.service.sequence.Sequence in project nimbus by nimbus-org.

the class TransactionLoggingConnection method writeLog.

protected void writeLog(String sql, int queryType, PrepareValue[] params) throws SQLException {
    if (!isUpdateQuery(sql)) {
        return;
    }
    initTransactionStatement();
    Sequence sequence = this.sequence;
    if (sequence == null && sequenceServiceName != null) {
        try {
            sequence = (Sequence) ServiceManagerFactory.getServiceObject(sequenceServiceName);
        } catch (ServiceNotFoundException e) {
        }
    }
    if (sequence == null) {
        throw new SQLException("Sequence is null.");
    }
    final String seq = sequence.increment();
    if (params != null) {
        for (int i = 0; i < params.length; i++) {
            if (params[i] == null) {
                continue;
            }
            transactionParamInsertStatement.setString(1, seq);
            transactionParamInsertStatement.setInt(2, i + 1);
            setParam(params[i]);
            if (isBatch) {
                transactionParamInsertStatement.addBatch();
            } else {
                transactionParamInsertStatement.executeUpdate();
            }
        }
        if (isBatch && getAutoCommit()) {
            transactionParamInsertStatement.executeBatch();
        }
    }
    transactionInsertStatement.setString(1, seq);
    transactionInsertStatement.setCharacterStream(2, new CharArrayReader(sql.toCharArray()), sql.length());
    transactionInsertStatement.setInt(3, queryType);
    transactionInsertStatement.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
    transactionInsertStatement.setString(5, updateUser);
    if (!isBatch || getAutoCommit()) {
        transactionInsertStatement.executeUpdate();
    } else {
        transactionInsertStatement.addBatch();
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) SQLException(java.sql.SQLException) ServiceNotFoundException(jp.ossc.nimbus.core.ServiceNotFoundException) Sequence(jp.ossc.nimbus.service.sequence.Sequence) Timestamp(java.sql.Timestamp)

Aggregations

CharArrayReader (java.io.CharArrayReader)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 ServiceNotFoundException (jp.ossc.nimbus.core.ServiceNotFoundException)1 Sequence (jp.ossc.nimbus.service.sequence.Sequence)1