本文整理汇总了Java中com.j256.ormlite.support.DatabaseConnection类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseConnection类的具体用法?Java DatabaseConnection怎么用?Java DatabaseConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseConnection类属于com.j256.ormlite.support包,在下文中一共展示了DatabaseConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: memorySetUp
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
@Before
public void memorySetUp() throws SQLException, CyclicGroupError, CryptoError, MitroServletException {
// Create a fake SecretsBundle
TwoFactorSigningService.initialize(SecretsBundle.generateForTest());
groupToPrivateKeyMap = Maps.newHashMap();
JdbcConnectionSource connectionSource = new JdbcConnectionSource(DATABASE_URL);
connectionSource.getReadWriteConnection().executeStatement(
"DROP ALL OBJECTS", DatabaseConnection.DEFAULT_RESULT_FLAGS);
managerFactory = new ManagerFactory(DATABASE_URL, new Manager.Pool(),
ManagerFactory.IDLE_TXN_POLL_SECONDS, TimeUnit.SECONDS, ConnectionMode.READ_WRITE);
manager = managerFactory.newManager();
testIdentityKey = keyFactory.generate();
testIdentity = createIdentity("[email protected]", testIdentityKey);
testIdentityLoginToken = GetMyPrivateKey.makeLoginTokenString(testIdentity, null, null);
testIdentityLoginTokenSignature = testIdentityKey.sign(testIdentityLoginToken);
testIdentity2 = createIdentity("[email protected]", null);
testGroup = createGroupContainingIdentity(testIdentity);
manager.commitTransaction();
// remove the audit log that commit writes so that tests start with an empty log
connectionSource.getReadWriteConnection().executeStatement(
"DELETE FROM audit;", DatabaseConnection.DEFAULT_RESULT_FLAGS);
connectionSource.getReadWriteConnection().commit(null);
}
示例2: updateRows
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
private static <T, ID> int updateRows(DatabaseConnection paramDatabaseConnection, Class<T> paramClass, MappedDeleteCollection<T, ID> paramMappedDeleteCollection, Object[] paramArrayOfObject, ObjectCache paramObjectCache)
{
try
{
int i = paramDatabaseConnection.delete(paramMappedDeleteCollection.statement, paramArrayOfObject, paramMappedDeleteCollection.argFieldTypes);
if ((i > 0) && (paramObjectCache != null))
{
int j = paramArrayOfObject.length;
for (int k = 0; k < j; k++)
paramObjectCache.remove(paramClass, paramArrayOfObject[k]);
}
logger.debug("delete-collection with statement '{}' and {} args, changed {} rows", paramMappedDeleteCollection.statement, Integer.valueOf(paramArrayOfObject.length), Integer.valueOf(i));
if (paramArrayOfObject.length > 0)
logger.trace("delete-collection arguments: {}", paramArrayOfObject);
return i;
}
catch (SQLException localSQLException)
{
throw SqlExceptionUtil.create("Unable to run delete collection stmt: " + paramMappedDeleteCollection.statement, localSQLException);
}
}
示例3: delete
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public int delete(DatabaseConnection paramDatabaseConnection, T paramT, ObjectCache paramObjectCache)
{
try
{
Object[] arrayOfObject = getFieldObjects(paramT);
int i = paramDatabaseConnection.delete(this.statement, arrayOfObject, this.argFieldTypes);
logger.debug("delete data with statement '{}' and {} args, changed {} rows", this.statement, Integer.valueOf(arrayOfObject.length), Integer.valueOf(i));
if (arrayOfObject.length > 0)
logger.trace("delete arguments: {}", arrayOfObject);
if ((i > 0) && (paramObjectCache != null))
{
Object localObject = this.idField.extractJavaFieldToSqlArgValue(paramT);
paramObjectCache.remove(this.clazz, localObject);
}
return i;
}
catch (SQLException localSQLException)
{
throw SqlExceptionUtil.create("Unable to run delete stmt on object " + paramT + ": " + this.statement, localSQLException);
}
}
示例4: deleteById
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public int deleteById(DatabaseConnection paramDatabaseConnection, ID paramID, ObjectCache paramObjectCache)
{
try
{
Object[] arrayOfObject = new Object[1];
arrayOfObject[0] = convertIdToFieldObject(paramID);
int i = paramDatabaseConnection.delete(this.statement, arrayOfObject, this.argFieldTypes);
logger.debug("delete data with statement '{}' and {} args, changed {} rows", this.statement, Integer.valueOf(1), Integer.valueOf(i));
logger.trace("delete arguments: {}", arrayOfObject);
if ((i > 0) && (paramObjectCache != null))
paramObjectCache.remove(this.clazz, paramID);
return i;
}
catch (SQLException localSQLException)
{
throw SqlExceptionUtil.create("Unable to run deleteById stmt on id " + paramID + ": " + this.statement, localSQLException);
}
}
示例5: buildIterator
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的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);
}
}
示例6: 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();
}
}
示例7: ifExists
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public boolean ifExists(DatabaseConnection paramDatabaseConnection, ID paramID)
{
if (this.ifExistsQuery == null)
{
QueryBuilder localQueryBuilder = new QueryBuilder(this.databaseType, this.tableInfo, this.dao);
localQueryBuilder.selectRaw(new String[] { "COUNT(*)" });
localQueryBuilder.where().eq(this.tableInfo.getIdField().getColumnName(), new SelectArg());
this.ifExistsQuery = localQueryBuilder.prepareStatementString();
FieldType[] arrayOfFieldType = new FieldType[1];
arrayOfFieldType[0] = this.tableInfo.getIdField();
this.ifExistsFieldTypes = arrayOfFieldType;
}
long l = paramDatabaseConnection.queryForLong(this.ifExistsQuery, new Object[] { paramID }, this.ifExistsFieldTypes);
logger.debug("query of '{}' returned {}", this.ifExistsQuery, Long.valueOf(l));
return l != 0L;
}
示例8: queryForFirst
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的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();
}
}
示例9: queryForLong
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的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();
}
}
示例10: 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();
}
}
示例11: callBatchTasks
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public <CT> CT callBatchTasks(Callable<CT> paramCallable)
{
checkForInitialized();
DatabaseConnection localDatabaseConnection = this.connectionSource.getReadWriteConnection();
try
{
boolean bool = this.connectionSource.saveSpecialConnection(localDatabaseConnection);
Object localObject2 = this.statementExecutor.callBatchTasks(localDatabaseConnection, bool, paramCallable);
return localObject2;
}
finally
{
this.connectionSource.clearSpecialConnection(localDatabaseConnection);
this.connectionSource.releaseConnection(localDatabaseConnection);
}
}
示例12: countOf
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public long countOf(PreparedQuery<T> paramPreparedQuery)
{
checkForInitialized();
if (paramPreparedQuery.getType() != StatementBuilder.StatementType.SELECT_LONG)
throw new IllegalArgumentException("Prepared query is not of type " + StatementBuilder.StatementType.SELECT_LONG + ", did you call QueryBuilder.setCountOf(true)?");
DatabaseConnection localDatabaseConnection = this.connectionSource.getReadOnlyConnection();
try
{
long l = this.statementExecutor.queryForLong(localDatabaseConnection, paramPreparedQuery);
return l;
}
finally
{
this.connectionSource.releaseConnection(localDatabaseConnection);
}
}
示例13: create
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public int create(T paramT)
{
checkForInitialized();
if (paramT == null)
return 0;
if ((paramT instanceof BaseDaoEnabled))
((BaseDaoEnabled)paramT).setDao(this);
DatabaseConnection localDatabaseConnection = this.connectionSource.getReadWriteConnection();
try
{
int i = this.statementExecutor.create(localDatabaseConnection, paramT, this.objectCache);
return i;
}
finally
{
this.connectionSource.releaseConnection(localDatabaseConnection);
}
}
示例14: delete
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public int delete(T paramT)
{
checkForInitialized();
if (paramT == null)
return 0;
DatabaseConnection localDatabaseConnection = this.connectionSource.getReadWriteConnection();
try
{
int i = this.statementExecutor.delete(localDatabaseConnection, paramT, this.objectCache);
return i;
}
finally
{
this.connectionSource.releaseConnection(localDatabaseConnection);
}
}
示例15: deleteById
import com.j256.ormlite.support.DatabaseConnection; //导入依赖的package包/类
public int deleteById(ID paramID)
{
checkForInitialized();
if (paramID == null)
return 0;
DatabaseConnection localDatabaseConnection = this.connectionSource.getReadWriteConnection();
try
{
int i = this.statementExecutor.deleteById(localDatabaseConnection, paramID, this.objectCache);
return i;
}
finally
{
this.connectionSource.releaseConnection(localDatabaseConnection);
}
}