Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.DatabaseResults


    /*
     * The method is called by Android database helper's get-database calls when Android detects that we need to
     * create or update the database. So we have to use the database argument and save a connection to it on the
     * AndroidConnectionSource, otherwise it will go recursive if the subclass calls getConnectionSource().
     */
    DatabaseConnection conn = cs.getSpecialConnection();
    boolean clearSpecial = false;
    if (conn == null) {
      conn = new AndroidDatabaseConnection(db, true);
      try {
        cs.saveSpecialConnection(conn);
View Full Code Here


    /*
     * The method is called by Android database helper's get-database calls when Android detects that we need to
     * create or update the database. So we have to use the database argument and save a connection to it on the
     * AndroidConnectionSource, otherwise it will go recursive if the subclass calls getConnectionSource().
     */
    DatabaseConnection conn = cs.getSpecialConnection();
    boolean clearSpecial = false;
    if (conn == null) {
      conn = new AndroidDatabaseConnection(db, true);
      try {
        cs.saveSpecialConnection(conn);
View Full Code Here

   * Return the first object that matches the {@link PreparedStmt} or null if none.
   */
  public T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt) throws SQLException {
    CompiledStatement stmt = preparedStmt.compile(databaseConnection);
    try {
      DatabaseResults results = stmt.runQuery();
      if (results.next()) {
        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

    // now execute any test queries which test the newly created table
    for (String query : queriesAfter) {
      CompiledStatement compiledStmt = null;
      try {
        compiledStmt = connection.compileStatement(query, StatementType.EXECUTE, noFieldTypes);
        DatabaseResults results = compiledStmt.runQuery();
        int rowC = 0;
        // count the results
        while (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

    Foo foo = new Foo();
    // it can't be null
    foo.name = nameArg + " not that";
    assertEquals(nameArg, fieldType.extractJavaFieldToSqlArgValue(foo));

    DatabaseResults resultMock = createMock(DatabaseResults.class);
    expect(resultMock.findColumn("name")).andReturn(0);
    expect(resultMock.wasNull(0)).andReturn(false);
    replay(resultMock);
    assertEquals(nameResult, fieldType.resultToJava(resultMock, new HashMap<String, Integer>()));
    verify(resultMock);
  }
View Full Code Here

  public void testNullPrimitiveThrow() throws Exception {
    Field field = ThrowIfNullNonPrimitive.class.getDeclaredField("primitive");
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, ThrowIfNullNonPrimitive.class.getSimpleName(), field,
            ThrowIfNullNonPrimitive.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    int fieldNum = 1;
    expect(results.findColumn(field.getName())).andReturn(fieldNum);
    expect(results.getInt(fieldNum)).andReturn(0);
    expect(results.wasNull(fieldNum)).andReturn(true);
    replay(results);
    fieldType.resultToJava(results, new HashMap<String, Integer>());
    verify(results);
  }
View Full Code Here

    assertTrue(fields.length >= 1);
    Field field = fields[0];
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, SerializableField.class.getSimpleName(), field,
            SerializableField.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    int fieldNum = 1;
    expect(results.findColumn(field.getName())).andReturn(fieldNum);
    expect(results.getTimestamp(fieldNum)).andReturn(null);
    expect(results.wasNull(fieldNum)).andReturn(true);
    replay(results);
    assertNull(fieldType.resultToJava(results, new HashMap<String, Integer>()));
    verify(results);
  }
View Full Code Here

    Field[] fields = InvalidType.class.getDeclaredFields();
    assertTrue(fields.length >= 1);
    Field field = fields[0];
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, InvalidType.class.getSimpleName(), field, InvalidType.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    int fieldNum = 1;
    expect(results.findColumn(field.getName())).andReturn(fieldNum);
    expect(results.wasNull(fieldNum)).andReturn(true);
    replay(results);
    assertNull(fieldType.resultToJava(results, new HashMap<String, Integer>()));
    verify(results);
  }
View Full Code Here

    foreignForeign.stuff = stuff;
    expect(
        connection.queryForOne(isA(String.class), isA(Object[].class), isA(FieldType[].class),
            isA(GenericRowMapper.class))).andReturn(foreignForeign);
    connectionSource.releaseConnection(connection);
    DatabaseResults results = createMock(DatabaseResults.class);
    ForeignAutoRefresh foreign = new ForeignAutoRefresh();
    replay(results, connectionSource, connection);
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, ForeignAutoRefresh.class.getSimpleName(), field,
            ForeignAutoRefresh.class);
View Full Code Here

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

      DatabaseResults results = stmt.runQuery();
      while (results.next()) {
        LocalFoo foo2 = rowMapper.mapRow(results);
        assertEquals(foo1.id, foo2.id);
      }
    } finally {
      if (stmt != null) {
View Full Code Here

TOP

Related Classes of com.j256.ormlite.support.DatabaseResults

Copyright © 2018 www.massapicom. 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.