当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseConnection.commit方法代码示例

本文整理汇总了Java中com.j256.ormlite.support.DatabaseConnection.commit方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseConnection.commit方法的具体用法?Java DatabaseConnection.commit怎么用?Java DatabaseConnection.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.j256.ormlite.support.DatabaseConnection的用法示例。


在下文中一共展示了DatabaseConnection.commit方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInsertInBatches

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public void testInsertInBatches() throws Exception {
	final Dao<Foo, Integer> dao = createDao(Foo.class, true);
	logger.info("starting batch run using transactions directly");
	long before = System.currentTimeMillis();
	DatabaseConnection conn = dao.startThreadConnection();
	Savepoint savePoint = null;
	try {
		savePoint = conn.setSavePoint(null);
		for (int i = 0; i < 10000; i++) {
			Foo foo = new Foo();
			foo.stuff1 = Integer.toString(i);
			assertEquals(1, dao.create(foo));
			// every so often commit the transaction and then start the next one
			if (i % 1000 == 0) {
				conn.commit(savePoint);
				savePoint = conn.setSavePoint(null);
			}
		}
	} finally {
		// commit at the end
		conn.commit(savePoint);
		dao.endThreadConnection(conn);
	}
	long noBatchTimeMs = System.currentTimeMillis() - before;
	logger.info("bulk transaction run finished after {}ms", noBatchTimeMs);
}
 
开发者ID:j256,项目名称:ormlite-android-tests,代码行数:27,代码来源:BulkInsertTest.java

示例2: testTransactionManager

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTransactionManager() throws Exception {
	ConnectionSource connectionSource = createMock(ConnectionSource.class);
	DatabaseConnection conn = createMock(DatabaseConnection.class);
	expect(conn.isAutoCommitSupported()).andReturn(false);
	Savepoint savePoint = createMock(Savepoint.class);
	expect(savePoint.getSavepointName()).andReturn("name").anyTimes();
	expect(conn.setSavePoint(isA(String.class))).andReturn(savePoint);
	conn.commit(savePoint);
	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);
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:25,代码来源:TransactionManagerTest.java

示例3: testTransactionManagerTableName

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTransactionManagerTableName() throws Exception {
	ConnectionSource connectionSource = createMock(ConnectionSource.class);
	DatabaseConnection conn = createMock(DatabaseConnection.class);
	expect(conn.isAutoCommitSupported()).andReturn(false);
	Savepoint savePoint = createMock(Savepoint.class);
	expect(savePoint.getSavepointName()).andReturn("name").anyTimes();
	expect(conn.setSavePoint(isA(String.class))).andReturn(savePoint);
	conn.commit(savePoint);
	expect(connectionSource.getDatabaseType()).andReturn(databaseType);
	expect(connectionSource.getReadWriteConnection(FOO_TABLE_NAME)).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(FOO_TABLE_NAME, new Callable<Void>() {
		@Override
		public Void call() {
			return null;
		}
	});
	verify(connectionSource, conn, savePoint);
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:25,代码来源:TransactionManagerTest.java

示例4: testTransactionManagerSavePointNull

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTransactionManagerSavePointNull() throws Exception {
	ConnectionSource connectionSource = createMock(ConnectionSource.class);
	DatabaseConnection conn = createMock(DatabaseConnection.class);
	expect(conn.isAutoCommitSupported()).andReturn(false);
	expect(conn.setSavePoint(isA(String.class))).andReturn(null);
	conn.commit(null);
	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);
	TransactionManager tm = new TransactionManager(connectionSource);
	tm.callInTransaction(new Callable<Void>() {
		@Override
		public Void call() {
			return null;
		}
	});
	verify(connectionSource, conn);
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:23,代码来源:TransactionManagerTest.java

示例5: testTransactionManagerAutoCommitSupported

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTransactionManagerAutoCommitSupported() throws Exception {
	ConnectionSource connectionSource = createMock(ConnectionSource.class);
	DatabaseConnection conn = createMock(DatabaseConnection.class);
	expect(conn.isAutoCommitSupported()).andReturn(true);
	expect(conn.isAutoCommit()).andReturn(false);
	Savepoint savePoint = createMock(Savepoint.class);
	expect(savePoint.getSavepointName()).andReturn("name").anyTimes();
	expect(conn.setSavePoint(isA(String.class))).andReturn(savePoint);
	conn.commit(savePoint);
	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);
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:26,代码来源:TransactionManagerTest.java

示例6: commit

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
private static void commit(DatabaseConnection paramDatabaseConnection, Savepoint paramSavepoint)
{
  String str;
  if (paramSavepoint == null)
    str = null;
  else
    str = paramSavepoint.getSavepointName();
  paramDatabaseConnection.commit(paramSavepoint);
  if (str == null)
  {
    logger.debug("committed savePoint transaction");
    return;
  }
  logger.debug("committed savePoint transaction {}", str);
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:16,代码来源:TransactionManager.java

示例7: 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);
}
 
开发者ID:j256,项目名称:ormlite-android-tests,代码行数:41,代码来源:BulkInsertTest.java

示例8: commit

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
private static void commit(DatabaseConnection connection, Savepoint savePoint) throws SQLException {
	String name = (savePoint == null ? null : savePoint.getSavepointName());
	connection.commit(savePoint);
	if (name == null) {
		logger.debug("committed savePoint transaction");
	} else {
		logger.debug("committed savePoint transaction {}", name);
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:10,代码来源:TransactionManager.java

示例9: 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);
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:28,代码来源:TransactionManagerTest.java

示例10: commit

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public void commit(DatabaseConnection paramDatabaseConnection)
{
  paramDatabaseConnection.commit(null);
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:5,代码来源:BaseDaoImpl.java

示例11: commit

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Override
public void commit(DatabaseConnection connection) throws SQLException {
	connection.commit(null);
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:5,代码来源:BaseDaoImpl.java


注:本文中的com.j256.ormlite.support.DatabaseConnection.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。