Java Code Examples for com.j256.ormlite.stmt.StatementBuilder.StatementType#SELECT

The following examples show how to use com.j256.ormlite.stmt.StatementBuilder.StatementType#SELECT . 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: MappedPreparedQueryTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testLimit() throws Exception {
	Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, true);
	List<LocalFoo> foos = new ArrayList<LocalFoo>();
	LocalFoo foo = new LocalFoo();
	// create foo #1
	fooDao.create(foo);
	foos.add(foo);
	foo = new LocalFoo();
	// create foo #2
	fooDao.create(foo);
	foos.add(foo);

	TableInfo<LocalFoo, Integer> tableInfo = new TableInfo<LocalFoo, Integer>(databaseType, LocalFoo.class);
	MappedPreparedStmt<LocalFoo, Integer> preparedQuery = new MappedPreparedStmt<LocalFoo, Integer>(fooDao,
			tableInfo, "select * from " + TABLE_NAME, new FieldType[0], tableInfo.getFieldTypes(),
			new ArgumentHolder[0], 1L, StatementType.SELECT, false);

	checkResults(foos, preparedQuery, 1);
	preparedQuery = new MappedPreparedStmt<LocalFoo, Integer>(fooDao, tableInfo, "select * from " + TABLE_NAME,
			new FieldType[0], tableInfo.getFieldTypes(), new ArgumentHolder[0], null, StatementType.SELECT, false);
	checkResults(foos, preparedQuery, 2);
}
 
Example 2
Source File: JdbcCompiledStatementTest.java    From ormlite-jdbc with ISC License 5 votes vote down vote up
@Test
public void testGetColumnName() throws Exception {
	PreparedStatement preparedStatement = createMock(PreparedStatement.class);
	ResultSetMetaData metadata = createMock(ResultSetMetaData.class);
	expect(metadata.getColumnName(1)).andReturn("TEST_COLUMN1");
	expect(preparedStatement.getMetaData()).andReturn(metadata);
	preparedStatement.close();
	replay(metadata, preparedStatement);
	JdbcCompiledStatement stmt = new JdbcCompiledStatement(preparedStatement, StatementType.SELECT, false);
	assertEquals("TEST_COLUMN1", stmt.getColumnName(0));
	stmt.close();
	verify(preparedStatement, metadata);
}
 
Example 3
Source File: JdbcCompiledStatementTest.java    From ormlite-jdbc with ISC License 5 votes vote down vote up
@Test
public void testGetMoreResults() throws Exception {
	PreparedStatement preparedStatement = createMock(PreparedStatement.class);
	expect(preparedStatement.getMoreResults()).andReturn(Boolean.TRUE);
	preparedStatement.close();
	replay(preparedStatement);
	JdbcCompiledStatement stmt = new JdbcCompiledStatement(preparedStatement, StatementType.SELECT, false);
	stmt.getMoreResults();
	stmt.close();
	verify(preparedStatement);
}
 
Example 4
Source File: JdbcCompiledStatementTest.java    From ormlite-jdbc with ISC License 5 votes vote down vote up
@Test
public void testSetNull() throws Exception {
	PreparedStatement preparedStatement = createMock(PreparedStatement.class);
	preparedStatement.setNull(1, TypeValMapper.getTypeValForSqlType(SqlType.STRING));
	EasyMock.expectLastCall();
	preparedStatement.close();
	replay(preparedStatement);
	JdbcCompiledStatement stmt = new JdbcCompiledStatement(preparedStatement, StatementType.SELECT, false);
	stmt.setObject(0, null, SqlType.STRING);
	stmt.close();
	verify(preparedStatement);
}
 
Example 5
Source File: JdbcCompiledStatementTest.java    From ormlite-jdbc with ISC License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testExecuteUpdateWithSelectType() throws Exception {
	PreparedStatement preparedStatement = createMock(PreparedStatement.class);
	JdbcCompiledStatement stmt = new JdbcCompiledStatement(preparedStatement, StatementType.SELECT, false);
	stmt.runUpdate();
	stmt.close();
}
 
Example 6
Source File: MappedPreparedQueryTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testMapRow() throws Exception {
	Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, true);
	LocalFoo foo1 = new LocalFoo();
	fooDao.create(foo1);

	TableInfo<LocalFoo, Integer> tableInfo = new TableInfo<LocalFoo, Integer>(databaseType, LocalFoo.class);
	MappedPreparedStmt<LocalFoo, Integer> rowMapper =
			new MappedPreparedStmt<LocalFoo, Integer>(fooDao, tableInfo, null, new FieldType[0],
					tableInfo.getFieldTypes(), new ArgumentHolder[0], null, StatementType.SELECT, false);

	DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
	CompiledStatement stmt = null;
	try {
		stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, new FieldType[0],
				DatabaseConnection.DEFAULT_RESULT_FLAGS, true);

		DatabaseResults results = stmt.runQuery(null);
		while (results.next()) {
			LocalFoo foo2 = rowMapper.mapRow(results);
			assertEquals(foo1.id, foo2.id);
		}
	} finally {
		if (stmt != null) {
			stmt.close();
		}
		connectionSource.releaseConnection(conn);
	}
}
 
Example 7
Source File: MappedPreparedQueryTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testObjectNoConstructor() throws Exception {
	TableInfo<NoConstructor, Void> tableInfo =
			new TableInfo<NoConstructor, Void>(databaseType, NoConstructor.class);
	Dao<NoConstructor, Void> dao = createDao(NoConstructor.class, false);
	new MappedPreparedStmt<NoConstructor, Void>(dao, tableInfo, null, new FieldType[0], new FieldType[0],
			new ArgumentHolder[0], null, StatementType.SELECT, false);
}