Package com.j256.ormlite.field

Examples of com.j256.ormlite.field.DataPersister


      sb.append("DELETE FROM ");
    }
    databaseType.appendEscapedEntityName(sb, tableName);
    String statement = sb.toString();
    logger.info("clearing table '{}' with '{}", tableName, statement);
    CompiledStatement compiledStmt = null;
    try {
      compiledStmt = connection.compileStatement(statement, StatementType.EXECUTE, noFieldTypes);
      return compiledStmt.runExecute();
    } finally {
      if (compiledStmt != null) {
        compiledStmt.close();
      }
      connectionSource.releaseConnection(connection);
    }
  }
View Full Code Here


  private static int doStatements(DatabaseConnection connection, String label, Collection<String> statements,
      boolean ignoreErrors, boolean expectingZero) throws SQLException {
    int stmtC = 0;
    for (String statement : statements) {
      int rowC = 0;
      CompiledStatement compiledStmt = null;
      try {
        compiledStmt = connection.compileStatement(statement, StatementType.EXECUTE, noFieldTypes);
        rowC = compiledStmt.runUpdate();
        logger.info("executed {} table statement changed {} rows: {}", label, rowC, statement);
      } catch (SQLException e) {
        if (ignoreErrors) {
          logger.info("ignoring {} error '{}' for statement: {}", label, e.getMessage(), statement);
        } else {
          throw SqlExceptionUtil.create("SQL statement failed: " + statement, e);
        }
      } finally {
        if (compiledStmt != null) {
          compiledStmt.close();
        }
      }
      // sanity check
      if (rowC < 0) {
        throw new SQLException("SQL statement " + statement + " updated " + rowC
View Full Code Here

  private static int doCreateTestQueries(DatabaseConnection connection, DatabaseType databaseType,
      List<String> queriesAfter) throws SQLException {
    int stmtC = 0;
    // 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
        throw SqlExceptionUtil.create("executing create table after-query failed: " + query, e);
      } finally {
        // result set is closed by the statement being closed
        if (compiledStmt != null) {
          compiledStmt.close();
        }
      }
      stmtC++;
    }
    return stmtC;
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

        foreignIdField.assignField(foreignObject, val);
      } else {
        levelCounters.autoRefreshlevel++;
        try {
          // do we need to auto-refresh the field?
          DatabaseConnection databaseConnection = connectionSource.getReadOnlyConnection();
          try {
            foreignObject = mappedQueryForId.execute(databaseConnection, val);
          } finally {
            connectionSource.releaseConnection(databaseConnection);
          }
View Full Code Here

   * Same as {@link #callInTransaction(Callable)} except as a static method with a connection source.
   */
  public static <T> T callInTransaction(final ConnectionSource connectionSource, final Callable<T> callable)
      throws SQLException {

    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    try {
      boolean saved = connectionSource.saveSpecialConnection(connection);
      return callInTransaction(connection, saved, connectionSource.getDatabaseType(), callable);
    } finally {
      // we should clear aggressively
View Full Code Here

TOP

Related Classes of com.j256.ormlite.field.DataPersister

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.