Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.DatabaseResults.first()


                DatabaseConnection.DEFAULT_RESULT_FLAGS);
        // 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
View Full Code Here


    CloseableIterator<Foo> iterator =
        dao.iterator(dao.queryBuilder().where().eq(Foo.VAL_COLUMN_NAME, foo.val).prepare());
    try {
      DatabaseResults results = iterator.getRawResults();
      assertTrue(results.first());
      assertTrue(results.getColumnCount() >= 4);
      int valIndex = results.findColumn(Foo.VAL_COLUMN_NAME);
      assertEquals(foo.val, results.getInt(valIndex));
      assertFalse(results.next());
    } finally {
View Full Code Here

      throws SQLException {
    CompiledStatement compiledStatement = preparedStmt.compile(databaseConnection, StatementType.SELECT);
    DatabaseResults results = null;
    try {
      results = compiledStatement.runQuery(objectCache);
      if (results.first()) {
        logger.debug("query-for-first of '{}' returned at least 1 result", preparedStmt.getStatement());
        return preparedStmt.mapRow(results);
      } else {
        logger.debug("query-for-first of '{}' returned at 0 results", preparedStmt.getStatement());
        return null;
View Full Code Here

  public long queryForLong(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt) throws SQLException {
    CompiledStatement compiledStatement = preparedStmt.compile(databaseConnection, StatementType.SELECT_LONG);
    DatabaseResults results = null;
    try {
      results = compiledStatement.runQuery(null);
      if (results.first()) {
        return results.getLong(0);
      } else {
        throw new SQLException("No result found in queryForLong: " + preparedStmt.getStatement());
      }
    } finally {
View Full Code Here

      compiledStatement =
          databaseConnection.compileStatement(query, StatementType.SELECT, noFieldTypes,
              DatabaseConnection.DEFAULT_RESULT_FLAGS);
      assignStatementArguments(compiledStatement, arguments);
      results = compiledStatement.runQuery(null);
      if (results.first()) {
        return results.getLong(0);
      } else {
        throw new SQLException("No result found in queryForLong: " + query);
      }
    } finally {
View Full Code Here

      if (queryAfter != null) {
        expect(
            conn.compileStatement(isA(String.class), isA(StatementType.class), isA(FieldType[].class),
                anyInt())).andReturn(stmt);
        results = createMock(DatabaseResults.class);
        expect(results.first()).andReturn(false);
        expect(stmt.runQuery(null)).andReturn(results);
        stmt.close();
        replay(results);
        rowC.incrementAndGet();
      }
View Full Code Here

    ConnectionSource cs = createMock(ConnectionSource.class);
    cs.releaseConnection(null);
    CompiledStatement stmt = createMock(CompiledStatement.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    expect(stmt.runQuery(null)).andReturn(results);
    expect(results.first()).andThrow(new SQLException("some database problem"));
    stmt.close();
    replay(stmt, results, cs);
    SelectIterator<Foo, Integer> iterator =
        new SelectIterator<Foo, Integer>(Foo.class, null, null, cs, null, stmt, "statement", null);
    iterator.hasNext();
View Full Code Here

    ConnectionSource cs = createMock(ConnectionSource.class);
    cs.releaseConnection(null);
    CompiledStatement stmt = createMock(CompiledStatement.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    expect(stmt.runQuery(null)).andReturn(results);
    expect(results.first()).andReturn(true);
    @SuppressWarnings("unchecked")
    GenericRowMapper<Foo> mapper = (GenericRowMapper<Foo>) createMock(GenericRowMapper.class);
    expect(mapper.mapRow(results)).andThrow(new SQLException("some result problem"));
    stmt.close();
    replay(stmt, mapper, cs, results);
View Full Code Here

  public void testRemoveThrow() throws Exception {
    ConnectionSource cs = createMock(ConnectionSource.class);
    cs.releaseConnection(null);
    CompiledStatement stmt = createMock(CompiledStatement.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    expect(results.first()).andReturn(true);
    expect(stmt.runQuery(null)).andReturn(results);
    @SuppressWarnings("unchecked")
    GenericRowMapper<Foo> mapper = (GenericRowMapper<Foo>) createMock(GenericRowMapper.class);
    Foo foo = new Foo();
    expect(mapper.mapRow(results)).andReturn(foo);
View Full Code Here

        connection.prepareStatement(statement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    try {
      statementSetArgs(stmt, args, argFieldTypes);
      DatabaseResults results = new JdbcDatabaseResults(stmt, stmt.executeQuery(), objectCache);
      logger.trace("{} statement is prepared and executed: {}", label, statement);
      if (!results.first()) {
        // no results at all
        return null;
      }
      T first = rowMapper.mapRow(results);
      if (results.next()) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.