Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.CompiledStatement.runQuery()


      try {
        compiledStmt =
            connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
                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++;
        }
View Full Code Here


        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

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

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

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

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

  public void testNextThrow() 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()).andReturn(true);
    @SuppressWarnings("unchecked")
    GenericRowMapper<Foo> mapper = (GenericRowMapper<Foo>) createMock(GenericRowMapper.class);
    expect(mapper.mapRow(results)).andThrow(new SQLException("some result problem"));
    stmt.close();
View Full Code Here

    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);
    @SuppressWarnings("unchecked")
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.