Package com.j256.ormlite.jdbc

Examples of com.j256.ormlite.jdbc.JdbcConnectionSource


    if (arguments.length > 0) {
      // need to do the (Object) cast to force args to be a single object
      logger.trace("query arguments: {}", (Object) arguments);
    }
    DatabaseConnection connection = connectionSource.getReadOnlyConnection();
    CompiledStatement compiledStatement = null;
    try {
      compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes);
      assignStatementArguments(compiledStatement, arguments);
      String[] columnNames = extractColumnNames(compiledStatement);
      GenericRawResults<String[]> rawResults =
          new RawResultsImpl<String[]>(connectionSource, connection, query, String[].class,
              compiledStatement, columnNames, this);
      compiledStatement = null;
      connection = null;
      return rawResults;
    } finally {
      if (compiledStatement != null) {
        compiledStatement.close();
      }
      if (connection != null) {
        connectionSource.releaseConnection(connection);
      }
    }
View Full Code Here


    if (arguments.length > 0) {
      // need to do the (Object) cast to force args to be a single object
      logger.trace("query arguments: {}", (Object) arguments);
    }
    DatabaseConnection connection = connectionSource.getReadOnlyConnection();
    CompiledStatement compiledStatement = null;
    try {
      compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes);
      assignStatementArguments(compiledStatement, arguments);
      String[] columnNames = extractColumnNames(compiledStatement);
      RawResultsImpl<UO> rawResults =
          new RawResultsImpl<UO>(connectionSource, connection, query, String[].class, compiledStatement,
              columnNames, new UserObjectRowMapper<UO>(rowMapper, columnNames, this));
      compiledStatement = null;
      connection = null;
      return rawResults;
    } finally {
      if (compiledStatement != null) {
        compiledStatement.close();
      }
      if (connection != null) {
        connectionSource.releaseConnection(connection);
      }
    }
View Full Code Here

    if (arguments.length > 0) {
      // need to do the (Object) cast to force args to be a single object
      logger.trace("query arguments: {}", (Object) arguments);
    }
    DatabaseConnection connection = connectionSource.getReadOnlyConnection();
    CompiledStatement compiledStatement = null;
    try {
      compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes);
      assignStatementArguments(compiledStatement, arguments);
      String[] columnNames = extractColumnNames(compiledStatement);
      RawResultsImpl<Object[]> rawResults =
          new RawResultsImpl<Object[]>(connectionSource, connection, query, Object[].class,
              compiledStatement, columnNames, new ObjectArrayRowMapper(columnTypes));
      compiledStatement = null;
      connection = null;
      return rawResults;
    } finally {
      if (compiledStatement != null) {
        compiledStatement.close();
      }
      if (connection != null) {
        connectionSource.releaseConnection(connection);
      }
    }
View Full Code Here

    logger.debug("running raw update statement: {}", statement);
    if (arguments.length > 0) {
      // need to do the (Object) cast to force args to be a single object
      logger.trace("update arguments: {}", (Object) arguments);
    }
    CompiledStatement compiledStatement =
        connection.compileStatement(statement, StatementType.UPDATE, noFieldTypes);
    try {
      assignStatementArguments(compiledStatement, arguments);
      return compiledStatement.runUpdate();
    } finally {
      compiledStatement.close();
    }
  }
View Full Code Here

    logger.debug("running raw execute statement: {}", statement);
    if (arguments.length > 0) {
      // need to do the (Object) cast to force args to be a single object
      logger.trace("execute arguments: {}", (Object) arguments);
    }
    CompiledStatement compiledStatement =
        connection.compileStatement(statement, StatementType.EXECUTE, noFieldTypes);
    try {
      assignStatementArguments(compiledStatement, arguments);
      return compiledStatement.runExecute();
    } finally {
      compiledStatement.close();
    }
  }
View Full Code Here

  /**
   * Update rows in the database.
   */
  public int update(DatabaseConnection databaseConnection, PreparedUpdate<T> preparedUpdate) throws SQLException {
    CompiledStatement stmt = preparedUpdate.compile(databaseConnection);
    try {
      return stmt.runUpdate();
    } finally {
      if (stmt != null) {
        stmt.close();
      }
    }
  }
View Full Code Here

  /**
   * Delete rows that match the prepared statement.
   */
  public int delete(DatabaseConnection databaseConnection, PreparedDelete<T> preparedDelete) throws SQLException {
    CompiledStatement stmt = preparedDelete.compile(databaseConnection);
    try {
      return stmt.runUpdate();
    } finally {
      if (stmt != null) {
        stmt.close();
      }
    }
  }
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

TOP

Related Classes of com.j256.ormlite.jdbc.JdbcConnectionSource

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.