Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.gawst.asyncdb;
  
  
  import  android.content.ContentValues;
  import  android.database.Cursor;
  import  android.os.Handler;
  import  android.os.Looper;

Class similar to Android's AsyncQueryHandler to work with an org.gawst.asyncdb.AsynchronousDbHelper instead of a ContentProvider source

See also:
AsyncDbHelperHandler AsyncDbHelperHandler for a ready to use version
org.gawst.asyncdb.typed.TypedAsyncDatabaseHandler TypedAsyncDatabaseHandler
 
 public class AsyncDatabaseHandler<INSERT_ID, DATABASE_ID> {
 
 	private final AsynchronousDbHelper<?, INSERT_ID> asynchronousDbHelper;
 	private static final Handler mHandler = new Handler(Looper.getMainLooper());
 	protected final TypedDatabaseSource<INSERT_ID, DATABASE_ID, ?> dataSource;

Constructor.

Parameters:
asynchronousDbHelper The org.gawst.asyncdb.AsynchronousDbHelper database to work with.
dataSource The org.gawst.asyncdb.source.typed.TypedDatabaseSource source used by the asynchronousDbHelper.
 
 	public AsyncDatabaseHandler(AsynchronousDbHelper<?, INSERT_ID> asynchronousDbHelperTypedDatabaseSource<INSERT_ID, DATABASE_ID, ?> dataSource) {
 		this. = asynchronousDbHelper;
 		this. = dataSource;
 	}
 
 	private void checkDatabaseId(DATABASE_ID databaseId) {
 		if (databaseId != null && databaseId != .getDatabaseId())
 			throw new IllegalArgumentException("wrong database id " + databaseId + " expected " + .getDatabaseId() + " try startRunnable()");
 	}
 
 	public AsynchronousDbHelper<?, INSERT_ID> getAsynchronousDbHelper() {
 	}
 
 	public TypedDatabaseSource<INSERT_ID, DATABASE_ID, ?> getDataSource() {
 		return ;
 	}

This method begins an asynchronous query. When the query is done onQueryComplete is called.

Parameters:
token A token passed into onQueryComplete to identify the query.
cookie An object that gets passed into onQueryComplete
projection A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.
orderBy How to order the rows, formatted as an SQL ORDER BY
 
 	public void startQuery(final int tokenfinal Object cookie,
 	                       final String[] projectionfinal String selectionfinal String[] selectionArgs,
 	                       final String orderBy) {
 		startQuery(tokencookieprojectionselectionselectionArgsorderBynull);
 	}

Deprecated, the uri field will be ignored, the one from org.gawst.asyncdb.source.typed.TypedDatabaseSource will be used.

This method begins an asynchronous query. When the query is done onQueryComplete is called.

Parameters:
token A token passed into onQueryComplete to identify the query.
cookie An object that gets passed into onQueryComplete
databaseId
projection A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.
orderBy How to order the rows, formatted as an SQL ORDER BY
See also:
startQuery(int, Object, String[], String, String[], String)
 
 	public void startQuery(final int tokenfinal Object cookie, DATABASE_ID databaseId,
 	                       final String[] projectionfinal String selectionfinal String[] selectionArgs,
 	                       final String orderBy) {
 		startQuery(tokencookiedatabaseIdprojectionselectionselectionArgsorderBynull);
 	}

This method begins an asynchronous query. When the query is done onQueryComplete is called.

Parameters:
token A token passed into onQueryComplete to identify the query.
cookie An object that gets passed into onQueryComplete
projection A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.
orderBy How to order the rows, formatted as an SQL ORDER BY
limit Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
	public void startQuery(final int tokenfinal Object cookie,
	                       final String[] projectionfinal String selectionfinal String[] selectionArgs,
	                       final String orderByfinal String limit) {
		startQuery(tokencookie.getDatabaseId(), projectionselectionselectionArgsorderBylimit);
	}

Deprecated, the uri field will be ignored, the one from org.gawst.asyncdb.source.typed.TypedDatabaseSource will be used.

This method begins an asynchronous query. When the query is done onQueryComplete is called.

Parameters:
token A token passed into onQueryComplete to identify the query.
cookie An object that gets passed into onQueryComplete
databaseId
projection A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.
orderBy How to order the rows, formatted as an SQL ORDER BY
limit Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
See also:
startQuery(int, Object, String[], String, String[], String, String)
	public void startQuery(final int tokenfinal Object cookie, DATABASE_ID databaseId,
	                       final String[] projectionfinal String selectionfinal String[] selectionArgs,
	                       final String orderByfinal String limit) {
		checkDatabaseId(databaseId);
			public void runInMemoryDbOperation(AsynchronousDbHelper<?, ?> db) {
				Cursor cursor1;
				try {
					cursor1 = .query(projectionselectionselectionArgsnullnullorderBylimit);
catch (Exception e) {
					cursor1 = null;
				}
				final Cursor cursor = cursor1;
				.post(new Runnable() {
					public void run() {
						onQueryComplete(tokencookiecursor);
					}
				});
			}
		});
	}

Deprecated, the uri field will be ignored, the one from org.gawst.asyncdb.source.typed.TypedDatabaseSource will be used.

This method begins an asynchronous insert. When the insert operation is done onInsertComplete is called.

Parameters:
token A token passed into onInsertComplete to identify the insert operation.
cookie An object that gets passed into onInsertComplete
databaseId the Uri passed to the insert operation.
initialValues the ContentValues parameter passed to the insert operation.
See also:
startInsert(int, Object, android.content.ContentValues)
	public void startInsert(final int tokenfinal Object cookie, DATABASE_ID databaseId,
	                        final ContentValues initialValues) {
		checkDatabaseId(databaseId);
		startInsert(tokencookieinitialValues);
	}

This method begins an asynchronous insert. When the insert operation is done onInsertComplete is called.

Parameters:
token A token passed into onInsertComplete to identify the insert operation.
cookie An object that gets passed into onInsertComplete
initialValues the ContentValues parameter passed to the insert operation.
	public void startInsert(final int tokenfinal Object cookie,
	                        final ContentValues initialValues) {
			public void runInMemoryDbOperation(AsynchronousDbHelper<?, ?> db) {
				INSERT_ID inserted1 = null;
				try {
					inserted1 = .insert(initialValues);
catch (Exception e) {
					inserted1 = null;
finally {
					if (inserted1 != null) {
					}
				}
				final INSERT_ID insertId = inserted1;
				.post(new Runnable() {
					public void run() {
						onInsertComplete(tokencookieinsertId);
					}
				});
			}
		});
	}

Deprecated, the uri field will be ignored, the one from org.gawst.asyncdb.source.typed.TypedDatabaseSource will be used.

This method begins an asynchronous update. When the update operation is done onUpdateComplete is called.

Parameters:
token A token passed into onUpdateComplete to identify the update operation.
cookie An object that gets passed into onUpdateComplete
databaseId the Uri passed to the update operation.
values the ContentValues parameter passed to the update operation.
See also:
startUpdate(int, Object, android.content.ContentValues, String, String[])
	public void startUpdate(final int tokenfinal Object cookie, DATABASE_ID databaseId,
	                        final ContentValues valuesfinal String selectionfinal String[] selectionArgs) {
		checkDatabaseId(databaseId);
		startUpdate(tokencookievaluesselectionselectionArgs);
	}

This method begins an asynchronous update. When the update operation is done onUpdateComplete is called.

Parameters:
token A token passed into onUpdateComplete to identify the update operation.
cookie An object that gets passed into onUpdateComplete
values the ContentValues parameter passed to the update operation.
	public void startUpdate(final int tokenfinal Object cookie,
	                        final ContentValues valuesfinal String selectionfinal String[] selectionArgs) {
			public void runInMemoryDbOperation(AsynchronousDbHelper<?, ?> db) {
				int cursor1;
				try {
					cursor1 = .update(valuesselectionselectionArgs);
catch (Exception e) {
					cursor1 = 0;
				}
				final int cursor = cursor1;
				.post(new Runnable() {
					public void run() {
						onUpdateComplete(tokencookiecursor);
					}
				});
			}
		});
	}

Deprecated, the uri field will be ignored, the one from org.gawst.asyncdb.source.typed.TypedDatabaseSource will be used.

This method begins an asynchronous delete. When the delete operation is done onDeleteComplete is called.

Parameters:
token A token passed into onDeleteComplete to identify the delete operation.
cookie An object that gets passed into onDeleteComplete
databaseId the Uri passed to the delete operation.
selection the where clause.
See also:
startDelete(int, Object, String, String[])
	public void startDelete(final int tokenfinal Object cookie, DATABASE_ID databaseId,
	                        final String selectionfinal String[] selectionArgs) {
		checkDatabaseId(databaseId);
		startDelete(tokencookieselectionselectionArgs);
	}

This method begins an asynchronous delete. When the delete operation is done onDeleteComplete is called.

Parameters:
token A token passed into onDeleteComplete to identify the delete operation.
cookie An object that gets passed into onDeleteComplete
selection the where clause.
	public void startDelete(final int tokenfinal Object cookie,
	                        final String selectionfinal String[] selectionArgs) {
			public void runInMemoryDbOperation(AsynchronousDbHelper<?, ?> db) {
				int cursor1;
				try {
					cursor1 = .delete(selectionselectionArgs);
catch (Exception e) {
					cursor1 = 0;
				}
				final int cursor = cursor1;
				.post(new Runnable() {
					public void run() {
						onDeleteComplete(tokencookiecursor);
					}
				});
			}
		});
	}

This method begins an asynchronous processing of the Runnable. When the operation is done onRunnableCompleted is called.

Parameters:
token A token passed into onRunnableCompleted to identify the operation.
cookie An object that gets passed into onRunnableCompleted
job The Runnable to run.
	public final void startRunnable(final int tokenfinal Object cookiefinal Runnable job) {
			public void runInMemoryDbOperation(AsynchronousDbHelper<?, ?> db) {
				job.run();
				.post(new Runnable() {
					public void run() {
						onRunnableCompleted(tokencookie);
					}
				});
			}
		});
	}

Called when an asynchronous query is completed. The receiver is responsible to close the Cursor. Called in the UI thread

Parameters:
token the token to identify the query, passed in from startQuery.
cookie the cookie object passed in from startQuery.
cursor The cursor holding the results from the query.
	protected void onQueryComplete(int tokenObject cookie, Cursor cursor) {
		// Empty
	}

Called when an asynchronous insert is completed. Called in the UI thread

Parameters:
token the token to identify the query, passed in from startInsert.
cookie the cookie object that's passed in from startInsert.
insertId the uri returned from the insert operation.
	protected void onInsertComplete(int tokenObject cookie, INSERT_ID insertId) {
		// Empty
	}

Called when an asynchronous update is completed. Called in the UI thread

Parameters:
token the token to identify the query, passed in from startUpdate.
cookie the cookie object that's passed in from startUpdate.
result the result returned from the update operation
	protected void onUpdateComplete(int tokenObject cookieint result) {
		// Empty
	}

Called when an asynchronous delete is completed. Called in the UI thread

Parameters:
token the token to identify the query, passed in from startDelete.
cookie the cookie object that's passed in from startDelete.
result the result returned from the delete operation
	protected void onDeleteComplete(int tokenObject cookieint result) {
		// Empty
	}

Called when an asynchronous Runnable is completed. Called in the UI thread

Parameters:
token the token to identify the query, passed in from startRunnable.
cookie the cookie object that's passed in from startRunnable.
	protected void onRunnableCompleted(int tokenObject cookie) {
		// Empty
	}
New to GrepCode? Check out our FAQ X