package st.gaw.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

/**
 * A {@link SQLiteOpenHelper} class with a worker thread for all disk work
 * 
 * @param <E> Type of Objects that are stored in the main table
 */
public abstract class AsynchronousDatabase<E> extends AsynchronousDbHelper<E> {

	/**
	 * Constructor for the SQLite database with a worker thread
	 * @param context Used to open or create the database
	 * @param name Database filename on disk
	 * @param version Version number of the database (starting at 1); if the database is older,
	 *     {@link #onUpgrade} will be used to upgrade the database; if the database is
	 *     newer, {@link #onDowngrade} will be used to downgrade the database
	 * @param logger The {@link Logger} to use for all logs (can be null for the default Android logs)
	 */
	public AsynchronousDatabase(Context context, String name, int version, Logger logger) {
		super(context, name, version, logger, null);
	}

	/**
	 * Constructor for the SQLite database with a worker thread with the same signature as the base {@link SQLiteOpenHelper} constructor
	 * @param context Used to open or create the database
	 * @param name Database filename on disk
	 * @param factory to use for creating cursor objects, or null for the default
	 * @param version Version number of the database (starting at 1); if the database is older,
	 *     {@link #onUpgrade} will be used to upgrade the database; if the database is
	 *     newer, {@link #onDowngrade} will be used to downgrade the database
	 */
	public AsynchronousDatabase(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version, null, null);
	}

	@Override
	protected final void addCursorInMemory(Cursor c) {
		// do nothing
	}

	@Override
	protected final boolean shouldReloadAllData() {
		return false;
	}
}

@@ -13,16 +13,46 @@
 aw.db;%0A%0A
+import java.util.Collection;%0A%0A
 import a
@@ -1999,10 +1999,1596 @@
 lse;%0A%09%7D%0A
+%0A%09/**%0A%09 * Add a new element in the database (asynchronous)%0A%09 * %3Cp%3EHelper call for %7B@link #scheduleAddOperation(E)%7D%0A%09 * %3Cp%3EIf adding failed %7B@link InMemoryDbErrorHandler#onAddItemFailed(AsynchronousDbHelper, Object, android.content.ContentValues, Throwable) InMemoryDbErrorHandler.onAddItemFailed()%7D will be called%0A%09 * @param item to add%0A%09 * @see #scheduleAddOperation(E)%0A%09 */%0A%09public void add(E item) %7B%0A%09%09scheduleAddOperation(item);%0A%09%7D%0A%0A%09/**%0A%09 * Add new elements in the database (asynchronous)%0A%09 * %3Cp%3EHelper call for %7B@link #scheduleAddOperation(Collection)%7D%0A%09 * %3Cp%3E%7B@link InMemoryDbErrorHandler#onAddItemFailed(AsynchronousDbHelper, Object, android.content.ContentValues, Throwable) InMemoryDbErrorHandler.onAddItemFailed()%7D will be called for each addition failure%0A%09 * @param items to add%0A%09 * @see #scheduleAddOperation(Collection)%0A%09 */%0A%09public void addAll(Collection%3CE%3E items) %7B%0A%09%09scheduleAddOperation(items);%0A%09%7D%0A%0A%09/**%0A%09 * Update an element in the database%0A%09 * %3Cp%3EHelper call for %7B@link #scheduleUpdateOperation(E)%7D%0A%09 * @param item to update%0A%09 * @see #scheduleUpdateOperation(E)%0A%09 */%0A%09public void update(E item) %7B%0A%09%09scheduleUpdateOperation(item);%0A%09%7D%0A%0A%09/**%0A%09 * Remove an element from the database (asynchronous)%0A%09 * %3Cp%3EHelper call for %7B@link #scheduleRemoveOperation(E)%7D%0A%09 * %3Cp%3EIf the removal fails %7B@link InMemoryDbErrorHandler#onRemoveItemFailed(AsynchronousDbHelper, Object, Throwable) InMemoryDbErrorHandler.onRemoveItemFailed()%7D will be called%0A%09 * @param item to remove%0A%09 * @see #scheduleRemoveOperation(E)%0A%09 */%0A%09public void remove(E item) %7B%0A%09%09scheduleRemoveOperation(item);%0A%09%7D%0A%0A
 %7D%0A

add helper methods for adding/removing/updating items in the disk thread