private Entry findEntryInDatabase(final String stringUrl) { final long hash = Utils.crc64Long(stringUrl); final String whereArgs[] = {String.valueOf(hash), stringUrl}; final Cursor cursor = mDatabase.query( TABLE_NAME, QUERY_PROJECTION, WHERE_HASH_AND_URL, whereArgs, null, null, null); try { if (cursor.moveToNext()) { final File file = new File(cursor.getString(QUERY_INDEX_DATA)); final long id = cursor.getInt(QUERY_INDEX_ID); Entry entry = null; synchronized (mEntryMap) { entry = mEntryMap.get(stringUrl); if (entry == null) { entry = new Entry(id, file); mEntryMap.put(stringUrl, entry); } } return entry; } } finally { cursor.close(); } return null; }
private synchronized long insertEntry(final String url, final File file) { final long size = file.length(); mTotalBytes += size; final ContentValues values = new ContentValues(); final String hashCode = String.valueOf(Utils.crc64Long(url)); values.put(Columns.DATA, file.getAbsolutePath()); values.put(Columns.HASH_CODE, hashCode); values.put(Columns.CONTENT_URL, url); values.put(Columns.CONTENT_SIZE, size); values.put(Columns.LAST_UPDATED, System.currentTimeMillis()); return mDatabase.insert(TABLE_NAME, "", values); }