Java Code Examples for com.j256.ormlite.support.DatabaseResults#next()
The following examples show how to use
com.j256.ormlite.support.DatabaseResults#next() .
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 |
private void checkResults(List<LocalFoo> foos, MappedPreparedStmt<LocalFoo, Integer> preparedQuery, int expectedNum) throws SQLException { DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME); CompiledStatement stmt = null; try { stmt = preparedQuery.compile(conn, StatementType.SELECT); DatabaseResults results = stmt.runQuery(null); int fooC = 0; while (results.next()) { LocalFoo foo2 = preparedQuery.mapRow(results); assertEquals(foos.get(fooC).id, foo2.id); fooC++; } assertEquals(expectedNum, fooC); } finally { IOUtils.closeThrowSqlException(stmt, "compiled statement"); connectionSource.releaseConnection(conn); } }
Example 2
Source File: H2DatabaseConnection.java From ormlite-core with ISC License | 6 votes |
@Override public <T> Object queryForOne(String statement, Object[] args, FieldType[] argFieldTypes, GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException { PreparedStatement stmt = connection.prepareStatement(statement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); if (args != null) { statementSetArgs(stmt, args, argFieldTypes); } DatabaseResults results = new H2DatabaseResults(stmt.executeQuery(), objectCache, true); if (!results.next()) { // no results at all IOUtils.closeThrowSqlException(results, "results"); return null; } T first = rowMapper.mapRow(results); if (results.next()) { return MORE_THAN_ONE; } else { return first; } }
Example 3
Source File: ApsTableUtils.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
private static int doCreateTestQueries(DatabaseConnection connection, DatabaseType databaseType, List<String> queriesAfter) throws SQLException { int stmtC = 0; // now execute any test queries which test the newly created table for (String query : queriesAfter) { CompiledStatement compiledStmt = null; try { compiledStmt = connection.compileStatement(query, StatementBuilder.StatementType.SELECT, noFieldTypes); // we don't care about an object cache here DatabaseResults results = compiledStmt.runQuery(null); int rowC = 0; // count the results for (boolean isThereMore = results.first(); isThereMore; isThereMore = results.next()) { rowC++; } logger.debug("executing create table after-query got {} results: {}", rowC, query); } catch (SQLException e) { // we do this to make sure that the statement is in the exception throw SqlExceptionUtil.create("executing create table after-query failed: " + query, e); } finally { // result set is closed by the statement being closed if (compiledStmt != null) { compiledStmt.close(); } } stmtC++; } return stmtC; }
Example 4
Source File: TableUtils.java From ormlite-core with ISC License | 5 votes |
private static int doCreateTestQueries(DatabaseConnection connection, DatabaseType databaseType, List<String> queriesAfter) throws SQLException { int stmtC = 0; // now execute any test queries which test the newly created table for (String query : queriesAfter) { CompiledStatement compiledStmt = null; try { compiledStmt = connection.compileStatement(query, StatementType.SELECT, noFieldTypes, DatabaseConnection.DEFAULT_RESULT_FLAGS, false); // we don't care about an object cache here DatabaseResults results = compiledStmt.runQuery(null); int rowC = 0; // count the results for (boolean isThereMore = results.first(); isThereMore; isThereMore = results.next()) { rowC++; } logger.info("executing create table after-query got {} results: {}", rowC, query); } catch (SQLException e) { // we do this to make sure that the statement is in the exception throw SqlExceptionUtil.create("executing create table after-query failed: " + query, e); } finally { // result set is closed by the statement being closed IOUtils.closeThrowSqlException(compiledStmt, "compiled statement"); } stmtC++; } return stmtC; }
Example 5
Source File: SchemaUtils.java From ormlite-core with ISC License | 5 votes |
private static int doCreateTestQueries(DatabaseConnection connection, DatabaseType databaseType, List<String> queriesAfter) throws SQLException { int stmtC = 0; // now execute any test queries which test the newly created schema for (String query : queriesAfter) { CompiledStatement compiledStmt = null; try { compiledStmt = connection.compileStatement(query, StatementType.SELECT, noFieldTypes, DatabaseConnection.DEFAULT_RESULT_FLAGS, false); // we don't care about an object cache here DatabaseResults results = compiledStmt.runQuery(null); int rowC = 0; // count the results for (boolean isThereMore = results.first(); isThereMore; isThereMore = results.next()) { rowC++; } logger.info("executing create schema after-query got {} results: {}", rowC, query); } catch (SQLException e) { // we do this to make sure that the statement is in the exception throw SqlExceptionUtil.create("executing create schema after-query failed: " + query, e); } finally { // result set is closed by the statement being closed IOUtils.closeThrowSqlException(compiledStmt, "compiled statement"); } stmtC++; } return stmtC; }
Example 6
Source File: MappedPreparedQueryTest.java From ormlite-core with ISC License | 5 votes |
@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: RawRowMapperTest.java From ormlite-core with ISC License | 5 votes |
@Test public void testRawResultsMapper() throws Exception { Dao<Foo, Object> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); foo1.val = 12321; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = 754282321; assertEquals(1, dao.create(foo2)); QueryBuilder<Foo, Object> qb = dao.queryBuilder(); qb.selectColumns(Foo.ID_COLUMN_NAME, Foo.VAL_COLUMN_NAME); CloseableIterator<Foo> iterator = dao.iterator(); try { DatabaseResults results = iterator.getRawResults(); for (int count = 0; results.next(); count++) { Foo foo = dao.mapSelectStarRow(results); switch (count) { case 0 : assertEquals(foo1.id, foo.id); assertEquals(foo1.val, foo.val); break; case 1 : assertEquals(foo2.id, foo.id); assertEquals(foo2.val, foo.val); break; default : fail("Unknown entry in list"); } } } finally { iterator.close(); } }