当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseConnection.compileStatement方法代码示例

本文整理汇总了Java中com.j256.ormlite.support.DatabaseConnection.compileStatement方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseConnection.compileStatement方法的具体用法?Java DatabaseConnection.compileStatement怎么用?Java DatabaseConnection.compileStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.j256.ormlite.support.DatabaseConnection的用法示例。


在下文中一共展示了DatabaseConnection.compileStatement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeRaw

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例2: queryForLong

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public long queryForLong(DatabaseConnection paramDatabaseConnection, String paramString, String[] paramArrayOfString)
{
  logger.debug("executing raw query for long: {}", paramString);
  if (paramArrayOfString.length > 0)
    logger.trace("query arguments: {}", paramArrayOfString);
  CompiledStatement localCompiledStatement = null;
  try
  {
    localCompiledStatement = paramDatabaseConnection.compileStatement(paramString, StatementBuilder.StatementType.SELECT, noFieldTypes);
    assignStatementArguments(localCompiledStatement, paramArrayOfString);
    DatabaseResults localDatabaseResults = localCompiledStatement.runQuery(null);
    if (localDatabaseResults.first())
    {
      long l = localDatabaseResults.getLong(0);
      return l;
    }
    throw new SQLException("No result found in queryForLong: " + paramString);
  }
  finally
  {
    if (localCompiledStatement != null)
      localCompiledStatement.close();
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:25,代码来源:StatementExecutor.java

示例3: updateRaw

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例4: clearTable

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例5: testDateStringResultInvalid

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例6: testEnumStringResultsNoFieldType

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

示例7: testSerializableInvalidResult

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例8: testEnumStringResultsNoFieldType

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例9: testSerializableInvalidResult

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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-core,代码行数:25,代码来源:SerializableTypeTest.java

示例10: queryForLong

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

示例11: queryRaw

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例12: testDateStringResultInvalid

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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(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);
	}
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:24,代码来源:DateStringTypeTest.java

示例13: updateRaw

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例14: executeRaw

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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

示例15: clearTable

import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的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


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