我的应用程序中有一个巨大的数据库(SQLite 引擎),我需要每周运行一次查询并缓存该查询的游标以便以后重新使用它,所以我编写了以下函数来保存我的游标,ObjectStream
但我我无法通过加载它,ObjectInputStream
因为它不可序列化!!!
关于如何完成此功能的任何想法?
public Cursor getCachedCursor(ReaderState state, String[] allowedColumns
, String sortType, int limit) throws IOException, ClassNotFoundException
{
File cacheFilePath = CacheManager.getCachePath(state.toString() + ".cached");
Cursor mCursor = null;
try
{
if (cacheFilePath == null)
{
FileOutputStream mFileOutputStream = new FileOutputStream(cacheFilePath);
ObjectOutputStream mObjectOutputStream = new ObjectOutputStream(mFileOutputStream);
mObjectOutputStream.writeObject(mDatabase.query(TABLE_NAME, allowedColumns, null, null
, null, null, sortType, String.valueOf(limit)));
mObjectOutputStream.close();
}
}
finally
{
FileInputStream mFileInputStream = new FileInputStream(cacheFilePath);
ObjectInputStream mObjectInputStream = new ObjectInputStream(mFileInputStream);
mCursor = (Cursor) mObjectInputStream.readObject();
mObjectInputStream.close();
}
return mCursor;
}