Examples of DatabaseConnection


Examples of com.j256.ormlite.support.DatabaseConnection

    logger.debug("executing raw query for: {}", query);
    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));
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

    }
  }

  private static <T> int clearTable(ConnectionSource connectionSource, String tableName) throws SQLException {
    DatabaseType databaseType = connectionSource.getDatabaseType();
    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    StringBuilder sb = new StringBuilder(48);
    if (databaseType.isTruncateSupported()) {
      sb.append("TRUNCATE TABLE ");
    } else {
      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();
      }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

      TableInfo<T, ID> tableInfo, boolean ignoreErrors) throws SQLException {
    logger.info("dropping table '{}'", tableInfo.getTableName());
    List<String> statements = new ArrayList<String>();
    addDropIndexStatements(databaseType, tableInfo, statements);
    addDropTableStatements(databaseType, tableInfo, statements);
    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    try {
      return doStatements(connection, "drop", statements, ignoreErrors, false);
    } finally {
      connectionSource.releaseConnection(connection);
    }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

    DatabaseType databaseType = connectionSource.getDatabaseType();
    logger.info("creating table '{}'", tableInfo.getTableName());
    List<String> statements = new ArrayList<String>();
    List<String> queriesAfter = new ArrayList<String>();
    addCreateTableStatements(databaseType, tableInfo, statements, queriesAfter, ifNotExists);
    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    try {
      int stmtC = doStatements(connection, "create", statements, false, databaseType.isCreateTableReturnsZero());
      stmtC += doCreateTestQueries(connection, databaseType, queriesAfter);
      return stmtC;
    } finally {
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

    initialized = true;
  }

  public T queryForId(ID id) throws SQLException {
    checkForInitialized();
    DatabaseConnection connection = connectionSource.getReadOnlyConnection();
    try {
      return statementExecutor.queryForId(connection, id);
    } finally {
      connectionSource.releaseConnection(connection);
    }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

    }
  }

  public T queryForFirst(PreparedQuery<T> preparedQuery) throws SQLException {
    checkForInitialized();
    DatabaseConnection connection = connectionSource.getReadOnlyConnection();
    try {
      return statementExecutor.queryForFirst(connection, preparedQuery);
    } finally {
      connectionSource.releaseConnection(connection);
    }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

      if (data instanceof BaseDaoEnabled) {
        @SuppressWarnings("unchecked")
        BaseDaoEnabled<T, ID> daoEnabled = (BaseDaoEnabled<T, ID>) data;
        daoEnabled.setDao(this);
      }
      DatabaseConnection connection = connectionSource.getReadWriteConnection();
      try {
        return statementExecutor.create(connection, data);
      } finally {
        connectionSource.releaseConnection(connection);
      }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

    checkForInitialized();
    // ignore updating a null object
    if (data == null) {
      return 0;
    } else {
      DatabaseConnection connection = connectionSource.getReadWriteConnection();
      try {
        return statementExecutor.update(connection, data);
      } finally {
        connectionSource.releaseConnection(connection);
      }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

    checkForInitialized();
    // ignore updating a null object
    if (data == null) {
      return 0;
    } else {
      DatabaseConnection connection = connectionSource.getReadWriteConnection();
      try {
        return statementExecutor.updateId(connection, data, newId);
      } finally {
        connectionSource.releaseConnection(connection);
      }
View Full Code Here

Examples of com.j256.ormlite.support.DatabaseConnection

    }
  }

  public int update(PreparedUpdate<T> preparedUpdate) throws SQLException {
    checkForInitialized();
    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    try {
      return statementExecutor.update(connection, preparedUpdate);
    } finally {
      connectionSource.releaseConnection(connection);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.