本文整理汇总了Java中com.j256.ormlite.support.DatabaseConnection.setAutoCommit方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseConnection.setAutoCommit方法的具体用法?Java DatabaseConnection.setAutoCommit怎么用?Java DatabaseConnection.setAutoCommit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.support.DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection.setAutoCommit方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeConnection
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
/**
* Make a connection to the database.
*
* @param logger
* This is here so we can use the right logger associated with the sub-class.
*/
@SuppressWarnings("resource")
protected DatabaseConnection makeConnection(Logger logger) throws SQLException {
Properties properties = new Properties();
if (username != null) {
properties.setProperty("user", username);
}
if (password != null) {
properties.setProperty("password", password);
}
DatabaseConnection connection = new JdbcDatabaseConnection(DriverManager.getConnection(url, properties));
// by default auto-commit is set to true
connection.setAutoCommit(true);
if (connectionProxyFactory != null) {
connection = connectionProxyFactory.createProxy(connection);
}
logger.debug("opened connection to {} got #{}", url, connection.hashCode());
return connection;
}
示例2: testSetAutoCommit
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testSetAutoCommit() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
try {
DatabaseConnection conn1 = pooled.getReadOnlyConnection(null);
conn1.setAutoCommit(false);
pooled.releaseConnection(conn1);
DatabaseConnection conn2 = pooled.getReadOnlyConnection(null);
assertSame(conn1, conn2);
assertTrue(conn2.isAutoCommit());
} finally {
pooled.close();
}
}
示例3: testAutoCommit
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public void testAutoCommit() throws Exception {
final Dao<Foo, Integer> dao = createDao(Foo.class, true);
logger.info("starting autocommit(true) no-batch run");
long before = System.currentTimeMillis();
doInserts(dao);
long noBatchTimeMs = System.currentTimeMillis() - before;
logger.info("bulk autocommit(true) run finished after {}ms", noBatchTimeMs);
// ------------------------------------------------------
logger.info("starting autocommit(false) batch run");
before = System.currentTimeMillis();
DatabaseConnection conn = dao.startThreadConnection();
try {
conn.setAutoCommit(false);
doInserts(dao);
} finally {
conn.setAutoCommit(true);
dao.endThreadConnection(conn);
}
long batchTimeMs = System.currentTimeMillis() - before;
logger.info("bulk autocommit(false) run finished after {}ms", batchTimeMs);
assertTrue(batchTimeMs < noBatchTimeMs);
// ------------------------------------------------------
logger.info("starting setSavePoint batch run");
before = System.currentTimeMillis();
conn = dao.startThreadConnection();
Savepoint savePoint = null;
try {
savePoint = conn.setSavePoint(null);
doInserts(dao);
} finally {
// commit at the end
conn.commit(savePoint);
dao.endThreadConnection(conn);
}
noBatchTimeMs = System.currentTimeMillis() - before;
logger.info("setSavePoint run finished after {}ms", noBatchTimeMs);
}
示例4: testConnectionMethods
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testConnectionMethods() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
DatabaseConnection conn = null;
try {
conn = dao.startThreadConnection();
assertTrue(dao.isAutoCommit(conn));
dao.setAutoCommit(conn, false);
assertFalse(dao.isAutoCommit(conn));
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
assertNotNull(dao.queryForId(foo.id));
dao.rollBack(conn);
assertNull(dao.queryForId(foo.id));
foo = new Foo();
assertEquals(1, dao.create(foo));
assertNotNull(dao.queryForId(foo.id));
dao.commit(conn);
assertNotNull(dao.queryForId(foo.id));
dao.rollBack(conn);
assertNotNull(dao.queryForId(foo.id));
} finally {
if (conn != null) {
conn.setAutoCommit(true);
dao.endThreadConnection(conn);
}
}
}
示例5: testTransactionManagerAutoCommitOn
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTransactionManagerAutoCommitOn() throws Exception {
ConnectionSource connectionSource = createMock(ConnectionSource.class);
DatabaseConnection conn = createMock(DatabaseConnection.class);
expect(conn.isAutoCommitSupported()).andReturn(true);
expect(conn.isAutoCommit()).andReturn(true);
conn.setAutoCommit(false);
Savepoint savePoint = createMock(Savepoint.class);
expect(savePoint.getSavepointName()).andReturn("name").anyTimes();
expect(conn.setSavePoint(isA(String.class))).andReturn(savePoint);
conn.commit(savePoint);
conn.setAutoCommit(true);
expect(connectionSource.getDatabaseType()).andReturn(databaseType);
expect(connectionSource.getReadWriteConnection(null)).andReturn(conn);
expect(connectionSource.saveSpecialConnection(conn)).andReturn(true);
connectionSource.clearSpecialConnection(conn);
connectionSource.releaseConnection(conn);
replay(connectionSource, conn, savePoint);
TransactionManager tm = new TransactionManager(connectionSource);
tm.callInTransaction(new Callable<Void>() {
@Override
public Void call() {
return null;
}
});
verify(connectionSource, conn, savePoint);
}
示例6: callBatchTasks
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public <CT> CT callBatchTasks(DatabaseConnection paramDatabaseConnection, boolean paramBoolean, Callable<CT> paramCallable)
{
if (this.databaseType.isBatchUseTransaction())
return TransactionManager.callInTransaction(paramDatabaseConnection, paramBoolean, this.databaseType, paramCallable);
int i = 0;
try
{
boolean bool1 = paramDatabaseConnection.isAutoCommitSupported();
i = 0;
if (bool1)
{
boolean bool2 = paramDatabaseConnection.isAutoCommit();
i = bool2;
if (bool2)
{
paramDatabaseConnection.setAutoCommit(false);
logger.debug("disabled auto-commit on table {} before batch tasks", this.tableInfo.getTableName());
}
}
try
{
Object localObject2 = paramCallable.call();
return localObject2;
}
catch (SQLException localSQLException)
{
throw localSQLException;
}
catch (Exception localException)
{
throw SqlExceptionUtil.create("Batch tasks callable threw non-SQL exception", localException);
}
}
finally
{
if (i != 0)
{
paramDatabaseConnection.setAutoCommit(true);
logger.debug("re-enabled auto-commit on table {} after batch tasks", this.tableInfo.getTableName());
}
}
}
示例7: setAutoCommit
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public void setAutoCommit(DatabaseConnection paramDatabaseConnection, boolean paramBoolean)
{
paramDatabaseConnection.setAutoCommit(paramBoolean);
}
示例8: callInTransaction
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public static <T> T callInTransaction(DatabaseConnection paramDatabaseConnection, boolean paramBoolean, DatabaseType paramDatabaseType, Callable<T> paramCallable)
{
int i = 0;
if (!paramBoolean);
try
{
boolean bool1 = paramDatabaseType.isNestedSavePointsSupported();
i = 0;
int j = 0;
Object localObject2 = null;
if (bool1)
{
boolean bool2 = paramDatabaseConnection.isAutoCommitSupported();
i = 0;
if (bool2)
{
boolean bool3 = paramDatabaseConnection.isAutoCommit();
i = bool3;
if (bool3)
{
paramDatabaseConnection.setAutoCommit(false);
logger.debug("had to set auto-commit to false");
}
}
Savepoint localSavepoint = paramDatabaseConnection.setSavePoint("ORMLITE" + savePointCounter.incrementAndGet());
localObject2 = localSavepoint;
if (localSavepoint == null)
logger.debug("started savePoint transaction");
else
logger.debug("started savePoint transaction {}", localObject2.getSavepointName());
j = 1;
}
try
{
Object localObject3 = paramCallable.call();
if (j != 0)
commit(paramDatabaseConnection, localObject2);
return localObject3;
}
catch (SQLException localSQLException)
{
if (j != 0)
rollBack(paramDatabaseConnection, localObject2);
throw localSQLException;
}
catch (Exception localException)
{
if (j != 0)
rollBack(paramDatabaseConnection, localObject2);
throw SqlExceptionUtil.create("Transaction callable threw non-SQL exception", localException);
}
}
finally
{
if (i != 0)
{
paramDatabaseConnection.setAutoCommit(true);
logger.debug("restored auto-commit to true");
}
}
}
示例9: setAutoCommit
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Override
public void setAutoCommit(DatabaseConnection connection, boolean autoCommit) throws SQLException {
connection.setAutoCommit(autoCommit);
}