org.jumpmind.db.sql
Class JdbcSqlTransaction

java.lang.Object
  extended by org.jumpmind.db.sql.JdbcSqlTransaction
All Implemented Interfaces:
ISqlTransaction
Direct Known Subclasses:
MsSqlJdbcSqlTransaction

public class JdbcSqlTransaction
extends Object
implements ISqlTransaction

TODO Support Oracle's non-standard way of batching


Field Summary
protected  Connection connection
           
protected  boolean inBatchMode
           
protected  JdbcSqlTemplate jdbcSqlTemplate
           
protected static org.slf4j.Logger log
           
protected  List<Object> markers
           
protected  boolean oldAutoCommitValue
           
protected  String psql
           
protected  PreparedStatement pstmt
           
 
Constructor Summary
JdbcSqlTransaction(JdbcSqlTemplate jdbcSqlTemplate)
           
 
Method Summary
 int addRow(Object marker, Object[] args, int[] argTypes)
           
 void allowInsertIntoAutoIncrementColumns(boolean value, Table table, String quote)
           
 void close()
           
 void commit()
           
 int execute(String sql)
           
protected
<T> T
executeCallback(IConnectionCallback<T> callback)
           
 int flush()
           
 Connection getConnection()
           
 List<Object> getUnflushedMarkers(boolean clear)
           
protected  void init()
           
 long insertWithGeneratedKey(String sql, String column, String sequenceName, Object[] args, int[] types)
           
 boolean isInBatchMode()
           
protected  void logSql(String sql, Object[] args)
           
protected  int normalizeUpdateCount(int value)
          According to the executeUpdate() javadoc -2 means that the result was successful, but that the number of rows affected is unknown.
 void prepare(String sql)
           
 int prepareAndExecute(String sql, Object... args)
           
 int prepareAndExecute(String sql, Object[] args, int[] types)
           
<T> List<T>
query(String sql, ISqlRowMapper<T> mapper, Map<String,Object> namedParams)
           
<T> List<T>
query(String sql, ISqlRowMapper<T> mapper, Object[] args, int[] types)
           
 int queryForInt(String sql, Object... args)
           
 long queryForLong(String sql, Object... args)
           
<T> T
queryForObject(String sql, Class<T> clazz, Object... args)
           
protected  void removeMarkersThatWereSuccessful(BatchUpdateException ex)
           
 void rollback()
           
protected  void rollback(boolean clearMarkers)
           
 void setInBatchMode(boolean useBatching)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.slf4j.Logger log

inBatchMode

protected boolean inBatchMode

connection

protected Connection connection

psql

protected String psql

pstmt

protected PreparedStatement pstmt

jdbcSqlTemplate

protected JdbcSqlTemplate jdbcSqlTemplate

oldAutoCommitValue

protected boolean oldAutoCommitValue

markers

protected List<Object> markers
Constructor Detail

JdbcSqlTransaction

public JdbcSqlTransaction(JdbcSqlTemplate jdbcSqlTemplate)
Method Detail

logSql

protected void logSql(String sql,
                      Object[] args)

init

protected void init()

setInBatchMode

public void setInBatchMode(boolean useBatching)
Specified by:
setInBatchMode in interface ISqlTransaction

isInBatchMode

public boolean isInBatchMode()
Specified by:
isInBatchMode in interface ISqlTransaction

commit

public void commit()
Specified by:
commit in interface ISqlTransaction

rollback

public void rollback()
Specified by:
rollback in interface ISqlTransaction

rollback

protected void rollback(boolean clearMarkers)

close

public void close()
Specified by:
close in interface ISqlTransaction

flush

public int flush()
Specified by:
flush in interface ISqlTransaction

queryForInt

public int queryForInt(String sql,
                       Object... args)
Specified by:
queryForInt in interface ISqlTransaction

queryForLong

public long queryForLong(String sql,
                         Object... args)
Specified by:
queryForLong in interface ISqlTransaction

queryForObject

public <T> T queryForObject(String sql,
                            Class<T> clazz,
                            Object... args)
Specified by:
queryForObject in interface ISqlTransaction

query

public <T> List<T> query(String sql,
                         ISqlRowMapper<T> mapper,
                         Map<String,Object> namedParams)
Specified by:
query in interface ISqlTransaction

query

public <T> List<T> query(String sql,
                         ISqlRowMapper<T> mapper,
                         Object[] args,
                         int[] types)
Specified by:
query in interface ISqlTransaction

execute

public int execute(String sql)
Specified by:
execute in interface ISqlTransaction

prepareAndExecute

public int prepareAndExecute(String sql,
                             Object[] args,
                             int[] types)
Specified by:
prepareAndExecute in interface ISqlTransaction

prepareAndExecute

public int prepareAndExecute(String sql,
                             Object... args)
Specified by:
prepareAndExecute in interface ISqlTransaction

executeCallback

protected <T> T executeCallback(IConnectionCallback<T> callback)

normalizeUpdateCount

protected final int normalizeUpdateCount(int value)
According to the executeUpdate() javadoc -2 means that the result was successful, but that the number of rows affected is unknown. since we know that only one row is suppose to be affected, we'll default to 1.

Parameters:
value -

removeMarkersThatWereSuccessful

protected void removeMarkersThatWereSuccessful(BatchUpdateException ex)

prepare

public void prepare(String sql)
Specified by:
prepare in interface ISqlTransaction

addRow

public int addRow(Object marker,
                  Object[] args,
                  int[] argTypes)
Specified by:
addRow in interface ISqlTransaction

getUnflushedMarkers

public List<Object> getUnflushedMarkers(boolean clear)
Specified by:
getUnflushedMarkers in interface ISqlTransaction

getConnection

public Connection getConnection()

allowInsertIntoAutoIncrementColumns

public void allowInsertIntoAutoIncrementColumns(boolean value,
                                                Table table,
                                                String quote)
Specified by:
allowInsertIntoAutoIncrementColumns in interface ISqlTransaction

insertWithGeneratedKey

public long insertWithGeneratedKey(String sql,
                                   String column,
                                   String sequenceName,
                                   Object[] args,
                                   int[] types)
Specified by:
insertWithGeneratedKey in interface ISqlTransaction


Copyright © 2007-2013 JumpMind, Inc.. All Rights Reserved.