Package com.j256.ormlite.field

Examples of com.j256.ormlite.field.DataPersister


   * Create and return an {@link SelectIterator} for the class using a prepared statement.
   */
  public SelectIterator<T, ID> buildIterator(BaseDaoImpl<T, ID> classDao, ConnectionSource connectionSource,
      PreparedStmt<T> preparedStmt) throws SQLException {
    DatabaseConnection connection = connectionSource.getReadOnlyConnection();
    CompiledStatement compiledStatement = null;
    try {
      compiledStatement = preparedStmt.compile(connection);
      SelectIterator<T, ID> iterator =
          new SelectIterator<T, ID>(tableInfo.getDataClass(), classDao, preparedStmt, connectionSource,
              connection, compiledStatement, preparedStmt.getStatement());
      connection = null;
      compiledStatement = null;
      return iterator;
    } finally {
      if (compiledStatement != null) {
        compiledStatement.close();
      }
      if (connection != null) {
        connectionSource.releaseConnection(connection);
      }
    }
View Full Code Here


   * Return on old RawResults object associated with an internal iterator that matches the query argument.
   */
  public RawResults buildOldIterator(ConnectionSource connectionSource, String query) throws SQLException {
    logger.debug("executing raw results iterator for: {}", query);
    DatabaseConnection connection = connectionSource.getReadOnlyConnection();
    CompiledStatement compiledStatement = null;
    try {
      compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes);
      String[] columnNames = extractColumnNames(compiledStatement);
      RawResultsWrapper rawResults =
          new RawResultsWrapper(connectionSource, connection, query, 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);
      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

    this.limit = limit;
    this.type = type;
  }

  public CompiledStatement compile(DatabaseConnection databaseConnection) throws SQLException {
    CompiledStatement stmt = databaseConnection.compileStatement(statement, type, argFieldTypes);
    boolean ok = false;
    try {
      if (limit != null) {
        // we use this if SQL statement LIMITs are not supported by this database type
        stmt.setMaxRows(limit);
      }
      // set any arguments if we are logging our object
      Object[] argValues = null;
      if (logger.isLevelEnabled(Level.TRACE) && argHolders.length > 0) {
        argValues = new Object[argHolders.length];
      }
      for (int i = 0; i < argHolders.length; i++) {
        Object argValue = argHolders[i].getSqlArgValue();
        if (argValue == null) {
          stmt.setNull(i, argFieldTypes[i].getSqlType());
        } else {
          stmt.setObject(i, argValue, argFieldTypes[i].getSqlType());
        }
        if (argValues != null) {
          argValues[i] = argValue;
        }
      }
      logger.debug("prepared statement '{}' with {} args", statement, argHolders.length);
      if (argValues != null) {
        // need to do the (Object) cast to force args to be a single object
        logger.trace("prepared statement arguments: {}", (Object) argValues);
      }
      ok = true;
      return stmt;
    } finally {
      if (!ok) {
        stmt.close();
      }
    }
  }
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.