本文整理汇总了Java中com.j256.ormlite.support.DatabaseConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseConnection.close方法的具体用法?Java DatabaseConnection.close怎么用?Java DatabaseConnection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.support.DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDscsGetReadWriteUP
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testDscsGetReadWriteUP() throws Exception {
DataSource dataSource = createMock(DataSource.class);
Connection conn = createMock(Connection.class);
conn.close();
String userName = "user";
String password = "password";
expect(dataSource.getConnection()).andReturn(null);
expect(dataSource.getConnection()).andReturn(null);
expect(dataSource.getConnection(userName, password)).andReturn(conn);
replay(dataSource, conn);
DataSourceConnectionSource dcs = new DataSourceConnectionSource(dataSource, DEFAULT_DATABASE_URL);
DatabaseConnection jdbcConn = dcs.getReadOnlyConnection(TABLE_NAME, userName, password);
jdbcConn.close();
dcs.close();
verify(dataSource, conn);
}
示例2: testTransaction
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTransaction() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
try {
DatabaseConnection conn1 = pooled.getReadOnlyConnection(null);
DatabaseConnection conn2 = pooled.getReadWriteConnection(null);
pooled.saveSpecialConnection(conn2);
DatabaseConnection conn3 = pooled.getReadWriteConnection(null);
assertSame(conn2, conn3);
pooled.releaseConnection(conn3);
pooled.releaseConnection(conn1);
DatabaseConnection conn4 = pooled.getReadWriteConnection(null);
assertSame(conn2, conn4);
pooled.releaseConnection(conn4);
pooled.clearSpecialConnection(conn2);
DatabaseConnection conn5 = pooled.getReadWriteConnection(null);
assertSame(conn1, conn5);
conn1.close();
conn2.close();
conn3.close();
conn4.close();
conn5.close();
} finally {
pooled.close();
}
}
示例3: testQueryForFirstThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testQueryForFirstThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
int equal = 21313;
foo.equal = equal;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.queryForFirst(dao.queryBuilder().prepare());
} finally {
connectionSource.releaseConnection(conn);
}
}
示例4: testTestConnectionThatWasClosed
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testTestConnectionThatWasClosed() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
String pingStatement = pooled.getDatabaseType().getPingStatement();
try {
DatabaseConnection conn1 = pooled.getReadWriteConnection(null);
conn1.queryForLong(pingStatement);
pooled.releaseConnection(conn1);
// close it behind the pool's back, bad dog
conn1.close();
DatabaseConnection conn2 = pooled.getReadWriteConnection(null);
assertSame(conn1, conn2);
conn2.queryForLong(pingStatement);
} finally {
pooled.close();
}
}
示例5: testTestClosedConnectionWithTesting
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTestClosedConnectionWithTesting() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
String pingStatement = pooled.getDatabaseType().getPingStatement();
pooled.setTestBeforeGet(true);
try {
DatabaseConnection conn1 = pooled.getReadWriteConnection(null);
conn1.queryForLong(pingStatement);
pooled.releaseConnection(conn1);
// close it behind the pool's back, bad dog
conn1.close();
DatabaseConnection conn2 = pooled.getReadWriteConnection(null);
assertNotSame(conn1, conn2);
conn2.queryForLong(pingStatement);
pooled.releaseConnection(conn2);
DatabaseConnection conn3 = pooled.getReadWriteConnection(null);
assertSame(conn2, conn3);
conn3.queryForLong(pingStatement);
pooled.releaseConnection(conn3);
} finally {
pooled.close();
}
}
示例6: testQueryForIdThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testQueryForIdThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
int equal = 21313;
foo.equal = equal;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.queryForId(foo.id);
} finally {
connectionSource.releaseConnection(conn);
}
}
示例7: testIsTableExistsThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testIsTableExistsThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.isTableExists();
} finally {
connectionSource.releaseConnection(conn);
}
}
示例8: testDscsGetReadWrite
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testDscsGetReadWrite() throws Exception {
DataSource dataSource = createMock(DataSource.class);
Connection conn = createMock(Connection.class);
conn.close();
expect(dataSource.getConnection()).andReturn(null);
expect(dataSource.getConnection()).andReturn(null);
expect(dataSource.getConnection()).andReturn(conn);
replay(dataSource, conn);
DataSourceConnectionSource dcs = new DataSourceConnectionSource(dataSource, DEFAULT_DATABASE_URL);
DatabaseConnection jdbcConn = dcs.getReadWriteConnection(TABLE_NAME);
jdbcConn.close();
dcs.close();
verify(dataSource, conn);
}
示例9: testUpdateRawThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testUpdateRawThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.updateRaw("DELETE FROM FOO");
} finally {
connectionSource.releaseConnection(conn);
}
}
示例10: testReleaseAlreadyClosed
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testReleaseAlreadyClosed() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
try {
DatabaseConnection conn1 = pooled.getReadOnlyConnection(null);
conn1.close();
pooled.releaseConnection(conn1);
} finally {
pooled.close();
}
}
示例11: testDeleteIdsThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testDeleteIdsThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
List<Integer> foos = new ArrayList<Integer>();
foos.add(foo.id);
dao.deleteIds(foos);
} finally {
connectionSource.releaseConnection(conn);
}
}
示例12: testExecuteRawThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testExecuteRawThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.executeRaw("TRUNCATE TABLE FOO");
} finally {
connectionSource.releaseConnection(conn);
}
}
示例13: testIteratorPreparedThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testIteratorPreparedThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.iterator(dao.queryBuilder().prepare());
} finally {
connectionSource.releaseConnection(conn);
}
}
示例14: testCreateThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testCreateThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.create(foo);
} finally {
connectionSource.releaseConnection(conn);
}
}
示例15: testUpdateThrow
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testUpdateThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.update(foo);
} finally {
connectionSource.releaseConnection(conn);
}
}