本文整理汇总了Java中com.j256.ormlite.dao.ObjectCache类的典型用法代码示例。如果您正苦于以下问题:Java ObjectCache类的具体用法?Java ObjectCache怎么用?Java ObjectCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectCache类属于com.j256.ormlite.dao包,在下文中一共展示了ObjectCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateRows
import com.j256.ormlite.dao.ObjectCache; //导入依赖的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);
}
}
示例2: delete
import com.j256.ormlite.dao.ObjectCache; //导入依赖的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);
}
}
示例3: deleteById
import com.j256.ormlite.dao.ObjectCache; //导入依赖的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);
}
}
示例4: buildIterator
import com.j256.ormlite.dao.ObjectCache; //导入依赖的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);
}
}
示例5: query
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
public List<T> query(ConnectionSource paramConnectionSource, PreparedStmt<T> paramPreparedStmt, ObjectCache paramObjectCache)
{
SelectIterator localSelectIterator = buildIterator(null, paramConnectionSource, paramPreparedStmt, paramObjectCache, -1);
try
{
ArrayList localArrayList = new ArrayList();
while (localSelectIterator.hasNextThrow())
localArrayList.add(localSelectIterator.nextThrow());
logger.debug("query of '{}' returned {} results", paramPreparedStmt.getStatement(), Integer.valueOf(localArrayList.size()));
return localArrayList;
}
finally
{
localSelectIterator.close();
}
}
示例6: queryForFirst
import com.j256.ormlite.dao.ObjectCache; //导入依赖的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();
}
}
示例7: queryRaw
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource paramConnectionSource, String paramString, RawRowMapper<UO> paramRawRowMapper, String[] paramArrayOfString, ObjectCache paramObjectCache)
{
logger.debug("executing raw query for: {}", paramString);
if (paramArrayOfString.length > 0)
logger.trace("query arguments: {}", paramArrayOfString);
DatabaseConnection localDatabaseConnection = paramConnectionSource.getReadOnlyConnection();
CompiledStatement localCompiledStatement = null;
try
{
localCompiledStatement = localDatabaseConnection.compileStatement(paramString, StatementBuilder.StatementType.SELECT, noFieldTypes);
assignStatementArguments(localCompiledStatement, paramArrayOfString);
UserObjectRowMapper localUserObjectRowMapper = new UserObjectRowMapper(paramRawRowMapper, this);
RawResultsImpl localRawResultsImpl = new RawResultsImpl(paramConnectionSource, localDatabaseConnection, paramString, [Ljava.lang.String.class, localCompiledStatement, localUserObjectRowMapper, paramObjectCache);
return localRawResultsImpl;
}
finally
{
if (localCompiledStatement != null)
localCompiledStatement.close();
if (localDatabaseConnection != null)
paramConnectionSource.releaseConnection(localDatabaseConnection);
}
}
示例8: AndroidDatabaseResults
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
public AndroidDatabaseResults(Cursor paramCursor, ObjectCache paramObjectCache)
{
this.cursor = paramCursor;
this.columnNames = paramCursor.getColumnNames();
if (this.columnNames.length >= 8)
{
this.columnNameMap = new HashMap();
for (int i = 0; i < this.columnNames.length; i++)
this.columnNameMap.put(this.columnNames[i], Integer.valueOf(i));
}
else
{
this.columnNameMap = null;
}
this.objectCache = paramObjectCache;
}
示例9: executeRefresh
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
/**
* Execute our refresh query statement and then update all of the fields in data with the fields from the result.
*
* @return 1 if we found the object in the table by id or 0 if not.
*/
public int executeRefresh(DatabaseConnection databaseConnection, T data, ObjectCache objectCache)
throws SQLException {
@SuppressWarnings("unchecked")
ID id = (ID) idField.extractJavaFieldValue(data);
// we don't care about the cache here
T result = super.execute(databaseConnection, id, null);
if (result == null) {
return 0;
}
// copy each field from the result into the passed in object
for (FieldType fieldType : resultsFieldTypes) {
if (fieldType != idField) {
fieldType.assignField(data, fieldType.extractJavaFieldValue(result), false, objectCache);
}
}
return 1;
}
示例10: updateRows
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
private static <T, ID> int updateRows(DatabaseConnection databaseConnection, Class<T> clazz,
MappedDeleteCollection<T, ID> deleteCollection, Object[] args, ObjectCache objectCache) throws SQLException {
try {
int rowC = databaseConnection.delete(deleteCollection.statement, args, deleteCollection.argFieldTypes);
if (rowC > 0 && objectCache != null) {
for (Object id : args) {
objectCache.remove(clazz, id);
}
}
logger.debug("delete-collection with statement '{}' and {} args, changed {} rows",
deleteCollection.statement, args.length, rowC);
if (args.length > 0) {
// need to do the (Object) cast to force args to be a single object
logger.trace("delete-collection arguments: {}", (Object) args);
}
return rowC;
} catch (SQLException e) {
throw SqlExceptionUtil.create("Unable to run delete collection stmt: " + deleteCollection.statement, e);
}
}
示例11: delete
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
/**
* Delete the object from the database.
*/
public int delete(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException {
try {
Object[] args = getFieldObjects(data);
int rowC = databaseConnection.delete(statement, args, argFieldTypes);
logger.debug("delete data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC);
if (args.length > 0) {
// need to do the (Object) cast to force args to be a single object
logger.trace("delete arguments: {}", (Object) args);
}
if (rowC > 0 && objectCache != null) {
Object id = idField.extractJavaFieldToSqlArgValue(data);
objectCache.remove(clazz, id);
}
return rowC;
} catch (SQLException e) {
throw SqlExceptionUtil.create("Unable to run delete stmt on object " + data + ": " + statement, e);
}
}
示例12: deleteById
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
/**
* Delete the object from the database.
*/
public int deleteById(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache) throws SQLException {
try {
Object[] args = new Object[] { convertIdToFieldObject(id) };
int rowC = databaseConnection.delete(statement, args, argFieldTypes);
logger.debug("delete data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC);
if (args.length > 0) {
// need to do the (Object) cast to force args to be a single object
logger.trace("delete arguments: {}", (Object) args);
}
if (rowC > 0 && objectCache != null) {
objectCache.remove(clazz, id);
}
return rowC;
} catch (SQLException e) {
throw SqlExceptionUtil.create("Unable to run deleteById stmt on id " + id + ": " + statement, e);
}
}
示例13: queryForFirst
import com.j256.ormlite.dao.ObjectCache; //导入依赖的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");
}
}
示例14: query
import com.j256.ormlite.dao.ObjectCache; //导入依赖的package包/类
/**
* Return a list of all of the data in the table that matches the {@link PreparedStmt}. Should be used carefully if
* the table is large. Consider using the {@link Dao#iterator} if this is the case.
*/
public List<T> query(ConnectionSource connectionSource, PreparedStmt<T> preparedStmt, ObjectCache objectCache)
throws SQLException {
SelectIterator<T, ID> iterator = buildIterator(/* no dao specified because no removes */null, connectionSource,
preparedStmt, objectCache, DatabaseConnection.DEFAULT_RESULT_FLAGS);
try {
List<T> results = new ArrayList<T>();
while (iterator.hasNextThrow()) {
results.add(iterator.nextThrow());
}
logger.debug("query of '{}' returned {} results", preparedStmt.getStatement(), results.size());
return results;
} finally {
IOUtils.closeThrowSqlException(iterator, "iterator");
}
}
示例15: buildIterator
import com.j256.ormlite.dao.ObjectCache; //导入依赖的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);
}
}
}