Tabnine Logo
DatabaseConnection.compileStatement
Code IndexAdd Tabnine to your IDE (free)

How to use
compileStatement
method
in
com.j256.ormlite.support.DatabaseConnection

Best Java code snippets using com.j256.ormlite.support.DatabaseConnection.compileStatement (Showing top 20 results out of 315)

origin: j256/ormlite-core

@Override
public CompiledStatement compileStatement(String statement, StatementType type, FieldType[] argFieldTypes,
    int resultFlags, boolean cacheStore) throws SQLException {
  if (proxy == null) {
    return null;
  } else {
    return proxy.compileStatement(statement, type, argFieldTypes, resultFlags, cacheStore);
  }
}
origin: com.j256.ormlite/ormlite-core

@Override
public CompiledStatement compileStatement(String statement, StatementType type, FieldType[] argFieldTypes,
    int resultFlags, boolean cacheStore) throws SQLException {
  if (proxy == null) {
    return null;
  } else {
    return proxy.compileStatement(statement, type, argFieldTypes, resultFlags, cacheStore);
  }
}
origin: j256/ormlite-core

@Override
public CompiledStatement compile(DatabaseConnection databaseConnection, StatementType type, int resultFlags)
    throws SQLException {
  if (this.type != type) {
    throw new SQLException("Could not compile this " + this.type + " statement since the caller is expecting a "
        + type + " statement.  Check your QueryBuilder methods.");
  }
  CompiledStatement stmt =
      databaseConnection.compileStatement(statement, type, argFieldTypes, resultFlags, cacheStore);
  // this may return null if the stmt had to be closed
  return assignStatementArguments(stmt);
}
origin: com.j256.ormlite/ormlite-core

@Override
public CompiledStatement compile(DatabaseConnection databaseConnection, StatementType type, int resultFlags)
    throws SQLException {
  if (this.type != type) {
    throw new SQLException("Could not compile this " + this.type + " statement since the caller is expecting a "
        + type + " statement.  Check your QueryBuilder methods.");
  }
  CompiledStatement stmt =
      databaseConnection.compileStatement(statement, type, argFieldTypes, resultFlags, cacheStore);
  // this may return null if the stmt had to be closed
  return assignStatementArguments(stmt);
}
origin: com.j256.ormlite/ormlite-core

private static <T> int clearTable(ConnectionSource connectionSource, String tableName) throws SQLException {
  DatabaseType databaseType = connectionSource.getDatabaseType();
  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;
  DatabaseConnection connection = connectionSource.getReadWriteConnection(tableName);
  try {
    compiledStmt = connection.compileStatement(statement, StatementType.EXECUTE, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
    return compiledStmt.runExecute();
  } finally {
    IOUtils.closeThrowSqlException(compiledStmt, "compiled statement");
    connectionSource.releaseConnection(connection);
  }
}
origin: j256/ormlite-core

private static <T> int clearTable(ConnectionSource connectionSource, String tableName) throws SQLException {
  DatabaseType databaseType = connectionSource.getDatabaseType();
  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;
  DatabaseConnection connection = connectionSource.getReadWriteConnection(tableName);
  try {
    compiledStmt = connection.compileStatement(statement, StatementType.EXECUTE, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
    return compiledStmt.runExecute();
  } finally {
    IOUtils.closeThrowSqlException(compiledStmt, "compiled statement");
    connectionSource.releaseConnection(connection);
  }
}
origin: j256/ormlite-core

@Test
public void testCompileStatementStringStatementTypeFieldTypeArrayInt() throws Exception {
  DatabaseConnection conn = createMock(DatabaseConnection.class);
  String statement = "select foo from bar";
  StatementType type = StatementType.DELETE;
  int flags = 11253123;
  expect(conn.compileStatement(statement, type, null, flags, false)).andReturn(null);
  conn.close();
  DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn);
  replay(conn);
  proxy.compileStatement(statement, type, null, flags, false);
  proxy.close();
  verify(conn);
}
origin: j256/ormlite-core

/**
 * Return the number of rows affected.
 */
public int updateRaw(DatabaseConnection connection, String statement, String[] arguments) throws SQLException {
  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,
      DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
  try {
    assignStatementArguments(compiledStatement, arguments);
    return compiledStatement.runUpdate();
  } finally {
    IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
  }
}
origin: com.j256.ormlite/ormlite-core

/**
 * Return true if it worked else false.
 */
public int executeRaw(DatabaseConnection connection, String statement, String[] arguments) throws SQLException {
  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, DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
  try {
    assignStatementArguments(compiledStatement, arguments);
    return compiledStatement.runExecute();
  } finally {
    IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
  }
}
origin: j256/ormlite-core

/**
 * Return true if it worked else false.
 */
public int executeRaw(DatabaseConnection connection, String statement, String[] arguments) throws SQLException {
  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, DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
  try {
    assignStatementArguments(compiledStatement, arguments);
    return compiledStatement.runExecute();
  } finally {
    IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
  }
}
origin: com.j256.ormlite/ormlite-core

/**
 * Return the number of rows affected.
 */
public int updateRaw(DatabaseConnection connection, String statement, String[] arguments) throws SQLException {
  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,
      DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
  try {
    assignStatementArguments(compiledStatement, arguments);
    return compiledStatement.runUpdate();
  } finally {
    IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
  }
}
origin: j256/ormlite-core

/**
 * Return a long from a raw query with String[] arguments.
 */
public long queryForLong(DatabaseConnection databaseConnection, String query, String[] arguments)
    throws SQLException {
  logger.debug("executing raw query for long: {}", 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);
  }
  CompiledStatement compiledStatement = null;
  DatabaseResults results = null;
  try {
    compiledStatement = databaseConnection.compileStatement(query, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
    assignStatementArguments(compiledStatement, arguments);
    results = compiledStatement.runQuery(null);
    if (results.first()) {
      return results.getLong(0);
    } else {
      throw new SQLException("No result found in queryForLong: " + query);
    }
  } finally {
    IOUtils.closeThrowSqlException(results, "results");
    IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
  }
}
origin: j256/ormlite-core

/**
 * Return a results object associated with an internal iterator is mapped by the user's rowMapper.
 */
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
    RawRowObjectMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache) throws SQLException {
  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(tableInfo.getTableName());
  CompiledStatement compiledStatement = null;
  try {
    compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
    assignStatementArguments(compiledStatement, arguments);
    RawResultsImpl<UO> rawResults = new RawResultsImpl<UO>(connectionSource, connection, query, String[].class,
        compiledStatement, new UserRawRowObjectMapper<UO>(rowMapper, columnTypes), objectCache);
    compiledStatement = null;
    connection = null;
    return rawResults;
  } finally {
    IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
    if (connection != null) {
      connectionSource.releaseConnection(connection);
    }
  }
}
origin: j256/ormlite-core

/**
 * Return a results object associated with an internal iterator that returns Object[] results.
 */
public GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
    String[] arguments, ObjectCache objectCache) throws SQLException {
  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(tableInfo.getTableName());
  CompiledStatement compiledStatement = null;
  try {
    compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
    assignStatementArguments(compiledStatement, arguments);
    RawResultsImpl<Object[]> rawResults = new RawResultsImpl<Object[]>(connectionSource, connection, query,
        Object[].class, compiledStatement, new ObjectArrayRowMapper(columnTypes), objectCache);
    compiledStatement = null;
    connection = null;
    return rawResults;
  } finally {
    IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
    if (connection != null) {
      connectionSource.releaseConnection(connection);
    }
  }
}
origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testSerializableInvalidResult() throws Exception {
  Class<LocalByteArray> clazz = LocalByteArray.class;
  Dao<LocalByteArray, Object> dao = createDao(clazz, true);
  LocalByteArray foo = new LocalByteArray();
  foo.byteField = new byte[] { 1, 2, 3, 4, 5 };
  assertEquals(1, dao.create(foo));
  DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
  CompiledStatement stmt = null;
  try {
    stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
    DatabaseResults results = stmt.runQuery(null);
    assertTrue(results.next());
    FieldType fieldType = FieldType.createFieldType(databaseType, TABLE_NAME,
        LocalSerializable.class.getDeclaredField(SERIALIZABLE_COLUMN), LocalSerializable.class);
    DataType.SERIALIZABLE.getDataPersister().resultToJava(fieldType, results, results.findColumn(BYTE_COLUMN));
  } finally {
    if (stmt != null) {
      stmt.close();
    }
    connectionSource.releaseConnection(conn);
  }
}
origin: j256/ormlite-core

@Test
public void testSerializableNoValue() throws Exception {
  Class<LocalSerializable> clazz = LocalSerializable.class;
  Dao<LocalSerializable, Object> dao = createDao(clazz, true);
  LocalSerializable foo = new LocalSerializable();
  foo.serializable = null;
  assertEquals(1, dao.create(foo));
  DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
  CompiledStatement stmt = null;
  try {
    stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
    DatabaseResults results = stmt.runQuery(null);
    assertTrue(results.next());
    FieldType fieldType = FieldType.createFieldType(databaseType, TABLE_NAME,
        clazz.getDeclaredField(SERIALIZABLE_COLUMN), clazz);
    assertNull(DataType.SERIALIZABLE.getDataPersister().resultToJava(fieldType, results,
        results.findColumn(SERIALIZABLE_COLUMN)));
  } finally {
    if (stmt != null) {
      stmt.close();
    }
    connectionSource.releaseConnection(conn);
  }
}
origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testDateStringResultInvalid() throws Exception {
  Class<LocalString> clazz = LocalString.class;
  Dao<LocalString, Object> dao = createDao(clazz, true);
  LocalString foo = new LocalString();
  foo.string = "not a date format";
  assertEquals(1, dao.create(foo));
  DatabaseConnection conn = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
  CompiledStatement stmt = null;
  try {
    stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
    DatabaseResults results = stmt.runQuery(null);
    assertTrue(results.next());
    int colNum = results.findColumn(STRING_COLUMN);
    DataType.DATE_STRING.getDataPersister().resultToJava(null, results, colNum);
  } finally {
    if (stmt != null) {
      stmt.close();
    }
    connectionSource.releaseConnection(conn);
  }
}
origin: j256/ormlite-core

@Test
public void testMapRow() throws Exception {
  Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, true);
  LocalFoo foo1 = new LocalFoo();
  fooDao.create(foo1);
  TableInfo<LocalFoo, Integer> tableInfo = new TableInfo<LocalFoo, Integer>(databaseType, LocalFoo.class);
  MappedPreparedStmt<LocalFoo, Integer> rowMapper =
      new MappedPreparedStmt<LocalFoo, Integer>(fooDao, tableInfo, null, new FieldType[0],
          tableInfo.getFieldTypes(), new ArgumentHolder[0], null, StatementType.SELECT, false);
  DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
  CompiledStatement stmt = null;
  try {
    stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, new FieldType[0],
        DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
    DatabaseResults results = stmt.runQuery(null);
    while (results.next()) {
      LocalFoo foo2 = rowMapper.mapRow(results);
      assertEquals(foo1.id, foo2.id);
    }
  } finally {
    if (stmt != null) {
      stmt.close();
    }
    connectionSource.releaseConnection(conn);
  }
}
origin: j256/ormlite-core

@Test
public void testEnumStringResultsNoFieldType() throws Exception {
  Dao<LocalEnumString, Object> dao = createDao(LocalEnumString.class, true);
  OurEnum val = OurEnum.SECOND;
  LocalEnumString foo = new LocalEnumString();
  foo.ourEnum = val;
  assertEquals(1, dao.create(foo));
  DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
  CompiledStatement stmt = null;
  try {
    stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
    DatabaseResults results = stmt.runQuery(null);
    assertTrue(results.next());
    assertEquals(val.toString(), DataType.ENUM_STRING.getDataPersister().resultToJava(null, results,
        results.findColumn(ENUM_COLUMN)));
  } finally {
    if (stmt != null) {
      stmt.close();
    }
    connectionSource.releaseConnection(conn);
  }
}
origin: j256/ormlite-core

@Test
public void testEnumIntResultsNoFieldType() throws Exception {
  Class<LocalEnumInt> clazz = LocalEnumInt.class;
  Dao<LocalEnumInt, Object> dao = createDao(clazz, true);
  OurEnum val = OurEnum.SECOND;
  LocalEnumInt foo = new LocalEnumInt();
  foo.ourEnum = val;
  assertEquals(1, dao.create(foo));
  DatabaseConnection conn = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
  CompiledStatement stmt = null;
  try {
    stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
        DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
    DatabaseResults results = stmt.runQuery(null);
    assertTrue(results.next());
    assertEquals(val.ordinal(), DataType.ENUM_INTEGER.getDataPersister().resultToJava(null, results,
        results.findColumn(ENUM_COLUMN)));
  } finally {
    if (stmt != null) {
      stmt.close();
    }
    connectionSource.releaseConnection(conn);
  }
}
com.j256.ormlite.supportDatabaseConnectioncompileStatement

Javadoc

Like compileStatement(String, StatementType, FieldType[]) except the caller can specify the result flags.

Popular methods of DatabaseConnection

  • executeStatement
    Execute a statement directly on the connection.
  • isAutoCommit
    Return if auto-commit is currently enabled.
  • setAutoCommit
    Set the auto-commit to be on (true) or off (false). Setting auto-commit to true may or may-not cause
  • commit
    Commit all changes since the savepoint was created. If savePoint is null then commit all outstanding
  • setSavePoint
    Start a save point with a certain name. It can be a noop if savepoints are not supported.
  • close
  • closeQuietly
    Close the connection to the database but swallow any exceptions.
  • insert
    Perform a SQL update while with the associated SQL statement, arguments, and types. This will possib
  • isAutoCommitSupported
    Return if auto-commit is supported.
  • queryForLong
    Perform a query whose result should be a single long-integer value.
  • rollback
    Roll back all changes since the savepoint was created. If savePoint is null then roll back all outst
  • delete
    Perform a SQL delete with the associated SQL statement, arguments, and types.
  • rollback,
  • delete,
  • isClosed,
  • isTableExists,
  • queryForOne,
  • update,
  • releaseSavePoint

Popular in Java

  • Running tasks concurrently on multiple threads
  • onCreateOptionsMenu (Activity)
  • startActivity (Activity)
  • getApplicationContext (Context)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now