• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CompiledStatement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.j256.ormlite.support.CompiledStatement的典型用法代码示例。如果您正苦于以下问题:Java CompiledStatement类的具体用法?Java CompiledStatement怎么用?Java CompiledStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CompiledStatement类属于com.j256.ormlite.support包,在下文中一共展示了CompiledStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: buildIterator

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
public SelectIterator<T, ID> buildIterator(BaseDaoImpl<T, ID> paramBaseDaoImpl, ConnectionSource paramConnectionSource, PreparedStmt<T> paramPreparedStmt, ObjectCache paramObjectCache, int paramInt)
{
  DatabaseConnection localDatabaseConnection = paramConnectionSource.getReadOnlyConnection();
  CompiledStatement localCompiledStatement = null;
  try
  {
    localCompiledStatement = paramPreparedStmt.compile(localDatabaseConnection, StatementBuilder.StatementType.SELECT, paramInt);
    Class localClass = this.tableInfo.getDataClass();
    String str = paramPreparedStmt.getStatement();
    SelectIterator localSelectIterator = new SelectIterator(localClass, paramBaseDaoImpl, paramPreparedStmt, paramConnectionSource, localDatabaseConnection, localCompiledStatement, str, paramObjectCache);
    return localSelectIterator;
  }
  finally
  {
    if (localCompiledStatement != null)
      localCompiledStatement.close();
    if (localDatabaseConnection != null)
      paramConnectionSource.releaseConnection(localDatabaseConnection);
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:21,代码来源:StatementExecutor.java


示例2: executeRaw

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
public int executeRaw(DatabaseConnection paramDatabaseConnection, String paramString, String[] paramArrayOfString)
{
  logger.debug("running raw execute statement: {}", paramString);
  if (paramArrayOfString.length > 0)
    logger.trace("execute arguments: {}", paramArrayOfString);
  CompiledStatement localCompiledStatement = paramDatabaseConnection.compileStatement(paramString, StatementBuilder.StatementType.EXECUTE, noFieldTypes);
  try
  {
    assignStatementArguments(localCompiledStatement, paramArrayOfString);
    int i = localCompiledStatement.runExecute();
    return i;
  }
  finally
  {
    localCompiledStatement.close();
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:18,代码来源:StatementExecutor.java


示例3: queryForFirst

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
public T queryForFirst(DatabaseConnection paramDatabaseConnection, PreparedStmt<T> paramPreparedStmt, ObjectCache paramObjectCache)
{
  CompiledStatement localCompiledStatement = paramPreparedStmt.compile(paramDatabaseConnection, StatementBuilder.StatementType.SELECT);
  try
  {
    DatabaseResults localDatabaseResults = localCompiledStatement.runQuery(paramObjectCache);
    if (localDatabaseResults.first())
    {
      logger.debug("query-for-first of '{}' returned at least 1 result", paramPreparedStmt.getStatement());
      Object localObject2 = paramPreparedStmt.mapRow(localDatabaseResults);
      return localObject2;
    }
    logger.debug("query-for-first of '{}' returned at 0 results", paramPreparedStmt.getStatement());
    return null;
  }
  finally
  {
    localCompiledStatement.close();
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:21,代码来源:StatementExecutor.java


示例4: queryForLong

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
public long queryForLong(DatabaseConnection paramDatabaseConnection, PreparedStmt<T> paramPreparedStmt)
{
  CompiledStatement localCompiledStatement = paramPreparedStmt.compile(paramDatabaseConnection, StatementBuilder.StatementType.SELECT_LONG);
  try
  {
    DatabaseResults localDatabaseResults = localCompiledStatement.runQuery(null);
    if (localDatabaseResults.first())
    {
      long l = localDatabaseResults.getLong(0);
      return l;
    }
    throw new SQLException("No result found in queryForLong: " + paramPreparedStmt.getStatement());
  }
  finally
  {
    localCompiledStatement.close();
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:19,代码来源:StatementExecutor.java


示例5: updateRaw

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
public int updateRaw(DatabaseConnection paramDatabaseConnection, String paramString, String[] paramArrayOfString)
{
  logger.debug("running raw update statement: {}", paramString);
  if (paramArrayOfString.length > 0)
    logger.trace("update arguments: {}", paramArrayOfString);
  CompiledStatement localCompiledStatement = paramDatabaseConnection.compileStatement(paramString, StatementBuilder.StatementType.UPDATE, noFieldTypes);
  try
  {
    assignStatementArguments(localCompiledStatement, paramArrayOfString);
    int i = localCompiledStatement.runUpdate();
    return i;
  }
  finally
  {
    localCompiledStatement.close();
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:18,代码来源:StatementExecutor.java


示例6: clearTable

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
public static int clearTable(ConnectionSource connectionSource, String tableName) throws SQLException {
    FieldType[] noFieldTypes = new FieldType[0];
    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();
    Log.i("DatabaseHelper", "clearing table '" + tableName + "' with '" + statement + "'");
    CompiledStatement compiledStmt = null;
    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    try {
        compiledStmt =
                connection.compileStatement(statement, StatementBuilder.StatementType.EXECUTE, noFieldTypes,
                        DatabaseConnection.DEFAULT_RESULT_FLAGS);
        return compiledStmt.runExecute();
    } finally {
        if (compiledStmt != null) {
            compiledStmt.close();
        }
        connectionSource.releaseConnection(connection);
    }
}
 
开发者ID:padc,项目名称:DevConSummit,代码行数:27,代码来源:Util.java


示例7: testDateStringResultInvalid

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
@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(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);
	}
}
 
开发者ID:j256,项目名称:ormlite-tests,代码行数:25,代码来源:BaseDataTypeTest.java


示例8: testSerializableInvalidResult

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
@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(connectionSource, 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);
	}
}
 
开发者ID:j256,项目名称:ormlite-tests,代码行数:27,代码来源:BaseDataTypeTest.java


示例9: testEnumStringResultsNoFieldType

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
@Test
public void testEnumStringResultsNoFieldType() throws Exception {
	Class<LocalEnumString> clazz = LocalEnumString.class;
	Dao<LocalEnumString, Object> dao = createDao(clazz, 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);
	}
}
 
开发者ID:j256,项目名称:ormlite-tests,代码行数:27,代码来源:BaseDataTypeTest.java


示例10: queryForFirst

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
/**
 * Return the first object that matches the {@link PreparedStmt} or null if none.
 */
public T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt, ObjectCache objectCache)
		throws SQLException {
	CompiledStatement compiledStatement = preparedStmt.compile(databaseConnection, StatementType.SELECT);
	DatabaseResults results = null;
	try {
		compiledStatement.setMaxRows(1);
		results = compiledStatement.runQuery(objectCache);
		if (results.first()) {
			logger.debug("query-for-first of '{}' returned at least 1 result", preparedStmt.getStatement());
			return preparedStmt.mapRow(results);
		} else {
			logger.debug("query-for-first of '{}' returned at 0 results", preparedStmt.getStatement());
			return null;
		}
	} finally {
		IOUtils.closeThrowSqlException(results, "results");
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:23,代码来源:StatementExecutor.java


示例11: queryForLong

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
/**
 * Return a long value from a prepared query.
 */
public long queryForLong(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt) throws SQLException {
	CompiledStatement compiledStatement = preparedStmt.compile(databaseConnection, StatementType.SELECT_LONG);
	DatabaseResults results = null;
	try {
		results = compiledStatement.runQuery(null);
		if (results.first()) {
			return results.getLong(0);
		} else {
			throw new SQLException("No result found in queryForLong: " + preparedStmt.getStatement());
		}
	} finally {
		IOUtils.closeThrowSqlException(results, "results");
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:19,代码来源:StatementExecutor.java


示例12: buildIterator

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
/**
 * 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, ObjectCache objectCache, int resultFlags) throws SQLException {
	DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
	CompiledStatement compiledStatement = null;
	try {
		compiledStatement = preparedStmt.compile(connection, StatementType.SELECT, resultFlags);
		SelectIterator<T, ID> iterator = new SelectIterator<T, ID>(tableInfo.getDataClass(), classDao, preparedStmt,
				connectionSource, connection, compiledStatement, preparedStmt.getStatement(), objectCache);
		connection = null;
		compiledStatement = null;
		return iterator;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:22,代码来源:StatementExecutor.java


示例13: queryRaw

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
/**
 * Return a results object associated with an internal iterator that returns String[] results.
 */
public GenericRawResults<String[]> queryRaw(ConnectionSource connectionSource, String query, 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);
		GenericRawResults<String[]> rawResults = new RawResultsImpl<String[]>(connectionSource, connection, query,
				String[].class, compiledStatement, this, objectCache);
		compiledStatement = null;
		connection = null;
		return rawResults;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:29,代码来源:StatementExecutor.java


示例14: updateRaw

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
/**
 * 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");
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:19,代码来源:StatementExecutor.java


示例15: executeRaw

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
/**
 * 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");
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:19,代码来源:StatementExecutor.java


示例16: SelectIterator

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
/**
 * If the statement parameter is null then this won't log information
 */
public SelectIterator(Class<?> dataClass, Dao<T, ID> classDao, GenericRowMapper<T> rowMapper,
		ConnectionSource connectionSource, DatabaseConnection connection, CompiledStatement compiledStmt,
		String statement, ObjectCache objectCache) throws SQLException {
	this.dataClass = dataClass;
	this.classDao = classDao;
	this.rowMapper = rowMapper;
	this.connectionSource = connectionSource;
	this.connection = connection;
	this.compiledStmt = compiledStmt;
	this.results = compiledStmt.runQuery(objectCache);
	this.statement = statement;
	if (statement != null) {
		logger.debug("starting iterator @{} for '{}'", hashCode(), statement);
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:19,代码来源:SelectIterator.java


示例17: clearTable

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
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);
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:23,代码来源:TableUtils.java


示例18: checkResults

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
private void checkResults(List<LocalFoo> foos, MappedPreparedStmt<LocalFoo, Integer> preparedQuery, int expectedNum)
		throws SQLException {
	DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
	CompiledStatement stmt = null;
	try {
		stmt = preparedQuery.compile(conn, StatementType.SELECT);
		DatabaseResults results = stmt.runQuery(null);
		int fooC = 0;
		while (results.next()) {
			LocalFoo foo2 = preparedQuery.mapRow(results);
			assertEquals(foos.get(fooC).id, foo2.id);
			fooC++;
		}
		assertEquals(expectedNum, fooC);
	} finally {
		IOUtils.closeThrowSqlException(stmt, "compiled statement");
		connectionSource.releaseConnection(conn);
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:20,代码来源:MappedPreparedQueryTest.java


示例19: testHasNextThrow

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testHasNextThrow() throws Exception {
	ConnectionSource cs = createMock(ConnectionSource.class);
	cs.releaseConnection(null);
	CompiledStatement stmt = createMock(CompiledStatement.class);
	DatabaseResults results = createMock(DatabaseResults.class);
	expect(stmt.runQuery(null)).andReturn(results);
	expect(results.first()).andThrow(new SQLException("some database problem"));
	stmt.close();
	replay(stmt, results, cs);
	SelectIterator<Foo, Integer> iterator =
			new SelectIterator<Foo, Integer>(Foo.class, null, null, cs, null, stmt, "statement", null);
	try {
		iterator.hasNext();
	} finally {
		iterator.close();
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:19,代码来源:SelectIteratorTest.java


示例20: testNextThrow

import com.j256.ormlite.support.CompiledStatement; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testNextThrow() throws Exception {
	ConnectionSource cs = createMock(ConnectionSource.class);
	cs.releaseConnection(null);
	CompiledStatement stmt = createMock(CompiledStatement.class);
	DatabaseResults results = createMock(DatabaseResults.class);
	expect(stmt.runQuery(null)).andReturn(results);
	expect(results.first()).andThrow(new SQLException("some result problem"));
	@SuppressWarnings("unchecked")
	GenericRowMapper<Foo> mapper = (GenericRowMapper<Foo>) createMock(GenericRowMapper.class);
	stmt.close();
	replay(stmt, mapper, cs, results);
	SelectIterator<Foo, Integer> iterator =
			new SelectIterator<Foo, Integer>(Foo.class, null, mapper, cs, null, stmt, "statement", null);
	try {
		iterator.hasNext();
	} finally {
		iterator.close();
	}
	verify(stmt, mapper, cs, results);
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:22,代码来源:SelectIteratorTest.java



注:本文中的com.j256.ormlite.support.CompiledStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EValidatorRegistrar类代码示例发布时间:2022-05-23
下一篇:
Java XSGrammarBucket类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap