Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.CompiledStatement


  @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


  @Test(expected = IllegalStateException.class)
  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();
    replay(stmt, mapper, cs, results);
    SelectIterator<Foo, Integer> iterator =
        new SelectIterator<Foo, Integer>(Foo.class, null, mapper, cs, null, stmt, "statement", null);
    iterator.next();
  }
View Full Code Here

  @Test(expected = IllegalStateException.class)
  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);
    @SuppressWarnings("unchecked")
    Dao<Foo, Integer> dao = (Dao<Foo, Integer>) createMock(Dao.class);
    expect(dao.delete(foo)).andThrow(new SQLException("some dao problem"));
    stmt.close();
    replay(stmt, dao, results, mapper, cs);
    SelectIterator<Foo, Integer> iterator =
        new SelectIterator<Foo, Integer>(Foo.class, dao, mapper, cs, null, stmt, "statement", null);
    iterator.hasNext();
    iterator.next();
View Full Code Here

  /**
   * Satisfies the {@link SQLiteOpenHelper#onCreate(SQLiteDatabase)} interface method.
   */
  @Override
  public final void onCreate(SQLiteDatabase db) {
    ConnectionSource cs = getConnectionSource();
    /*
     * 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);
        clearSpecial = true;
      } catch (SQLException e) {
        throw new IllegalStateException("Could not save special connection", e);
      }
    }
    try {
      onCreate(db, cs);
    } finally {
      if (clearSpecial) {
        cs.clearSpecialConnection(conn);
      }
    }
  }
View Full Code Here

  /**
   * Satisfies the {@link SQLiteOpenHelper#onUpgrade(SQLiteDatabase, int, int)} interface method.
   */
  @Override
  public final void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    ConnectionSource cs = getConnectionSource();
    /*
     * 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);
        clearSpecial = true;
      } catch (SQLException e) {
        throw new IllegalStateException("Could not save special connection", e);
      }
    }
    try {
      onUpgrade(db, cs, oldVersion, newVersion);
    } finally {
      if (clearSpecial) {
        cs.clearSpecialConnection(conn);
      }
    }
  }
View Full Code Here

     */
    return getReadWriteConnection();
  }

  public DatabaseConnection getReadWriteConnection() throws SQLException {
    DatabaseConnection conn = getSavedConnection();
    if (conn != null) {
      return conn;
    }
    if (connection == null) {
      connection = new AndroidDatabaseConnection(helper.getWritableDatabase(), true);
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

    /*
     * 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

      @SuppressWarnings("unchecked")
      D castDao = (D) dao;
      return castDao;
    }

    DatabaseTable databaseTable = clazz.getAnnotation(DatabaseTable.class);
    if (databaseTable == null || databaseTable.daoClass() == Void.class
        || databaseTable.daoClass() == BaseDaoImpl.class) {
      @SuppressWarnings("deprecation")
      Dao<T, ?> daoTmp = BaseDaoImpl.createDao(connectionSource, clazz);
      dao = daoTmp;
    } else {
      Class<?> daoClass = databaseTable.daoClass();
      Constructor<?> daoConstructor = null;
      Object[] arguments = null;
      Constructor<?>[] constructors = daoClass.getConstructors();
      // look first for the constructor with a class parameter in case it is a generic dao
      for (Constructor<?> constructor : constructors) {
View Full Code Here

      @SuppressWarnings("unchecked")
      D castDao = (D) dao;
      return castDao;
    }

    DatabaseTable databaseTable = tableConfig.getDataClass().getAnnotation(DatabaseTable.class);
    if (databaseTable == null || databaseTable.daoClass() == Void.class
        || databaseTable.daoClass() == BaseDaoImpl.class) {
      @SuppressWarnings("deprecation")
      Dao<T, ?> daoTmp = BaseDaoImpl.createDao(connectionSource, tableConfig);
      dao = daoTmp;
    } else {
      Class<?> daoClass = databaseTable.daoClass();
      Constructor<?> constructor;
      try {
        constructor = daoClass.getConstructor(ConnectionSource.class, DatabaseTableConfig.class);
      } catch (Exception e) {
        throw SqlExceptionUtil.create(
View Full Code Here

TOP

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

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.