Examples of DatabaseResults


Examples of com.j256.ormlite.support.DatabaseResults

    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);
    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;
    }
  }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseResults

    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);
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseResults

   * Return the first object that matches the {@link PreparedStmt} or null if none.
   */
  public T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt, ObjectCache objectCache)
      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

Examples of com.j256.ormlite.support.DatabaseResults

  /**
   * Return a long value from a prepared query.
   */
  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 {
      IOUtils.closeThrowSqlException(results, "results");
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseResults

    if (arguments.length > 0) {
      // need to do the (Object) cast to force args to be a single object
      logger.trace("query arguments: {}", (Object) arguments);
    }
    CompiledStatement compiledStatement = null;
    DatabaseResults results = null;
    try {
      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 {
      IOUtils.closeThrowSqlException(results, "results");
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseResults

    PreparedQuery<Foo> prepared = dao.queryBuilder().prepare();
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement compiled = null;
    try {
      compiled = prepared.compile(conn, StatementType.SELECT);
      DatabaseResults results = compiled.runQuery(null);
      assertTrue(results.next());
      Foo result = dao.mapSelectStarRow(results);
      assertEquals(foo.id, result.id);
      GenericRowMapper<Foo> mapper = dao.getSelectStarRowMapper();
      result = mapper.mapRow(results);
      assertEquals(foo.id, result.id);
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseResults

  @Test(expected = RuntimeException.class)
  public void testMapSelectStarRowThrow() throws Exception {
    @SuppressWarnings("unchecked")
    Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
    RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
    DatabaseResults results = createMock(DatabaseResults.class);
    expect(dao.mapSelectStarRow(results)).andThrow(new SQLException("Testing catch"));
    replay(dao);
    rtDao.mapSelectStarRow(results);
    verify(dao);
  }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseResults

  private void testStatement(ConnectionSource connectionSource, DatabaseType databaseType, String statement,
      String queryAfter, int rowN, boolean throwExecute, Callable<Integer> callable) throws Exception {
    DatabaseConnection conn = createMock(DatabaseConnection.class);
    CompiledStatement stmt = createMock(CompiledStatement.class);
    DatabaseResults results = null;
    final AtomicInteger rowC = new AtomicInteger(1);
    if (throwExecute) {
      expect(conn.compileStatement(isA(String.class), isA(StatementType.class), isA(FieldType[].class), anyInt())).andThrow(
          new SQLException("you asked us to!!"));
    } else {
      expect(conn.compileStatement(isA(String.class), isA(StatementType.class), isA(FieldType[].class), anyInt())).andReturn(
          stmt);
      expect(stmt.runExecute()).andReturn(rowN);
      stmt.close();
      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

Examples of com.j256.ormlite.support.DatabaseResults

    assertEquals(1, dao.queryForAll().size());

    @SuppressWarnings("unchecked")
    SelectIterator<Foo, String> iterator = (SelectIterator<Foo, String>) dao.iterator();
    DatabaseResults results = iterator.getRawResults();
    assertTrue(results.next());
    iterator.close();
  }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseResults

  @Test(expected = IllegalStateException.class)
  public void testHasNextThrow() throws Exception {
    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
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.