Java Code Examples for com.j256.ormlite.dao.Dao#countOf()

The following examples show how to use com.j256.ormlite.dao.Dao#countOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableUtilsTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testCreateTable() throws Exception {
	Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, false);
	// first we create the table
	createTable(LocalFoo.class, false);
	// test it out
	assertEquals(0, fooDao.queryForAll().size());
	// now we drop it
	dropTable(LocalFoo.class, true);
	try {
		fooDao.countOf();
		fail("Was expecting a SQL exception");
	} catch (Exception expected) {
		// expected
	}
	// now create it again
	createTable(LocalFoo.class, false);
	assertEquals(0, fooDao.queryForAll().size());
	dropTable(LocalFoo.class, true);
}
 
Example 2
Source File: TableUtilsTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testCreateTableIfNotExists() throws Exception {
	dropTable(LocalFoo.class, true);
	Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, false);
	try {
		fooDao.countOf();
		fail("Should have thrown an exception");
	} catch (Exception e) {
		// ignored
	}
	TableUtils.createTableIfNotExists(connectionSource, LocalFoo.class);
	assertEquals(0, fooDao.countOf());
	// should not throw
	TableUtils.createTableIfNotExists(connectionSource, LocalFoo.class);
	assertEquals(0, fooDao.countOf());
}
 
Example 3
Source File: TableUtilsTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testCreateTableConfigIfNotExists() throws Exception {
	dropTable(LocalFoo.class, true);
	Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, false);
	try {
		fooDao.countOf();
		fail("Should have thrown an exception");
	} catch (Exception e) {
		// ignored
	}
	DatabaseTableConfig<LocalFoo> tableConfig = DatabaseTableConfig.fromClass(databaseType, LocalFoo.class);
	TableUtils.createTableIfNotExists(connectionSource, tableConfig);
	assertEquals(0, fooDao.countOf());
	// should not throw
	TableUtils.createTableIfNotExists(connectionSource, tableConfig);
	assertEquals(0, fooDao.countOf());
}