Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.gawst.asyncdb.source.typed;
  
  import  android.annotation.TargetApi;
  import  android.content.ContentValues;
  import  android.content.Context;
  import  android.database.Cursor;
  import  android.database.sqlite.SQLiteDatabase;
  import  android.database.sqlite.SQLiteOpenHelper;
  import  android.os.Build;
 import  android.support.annotation.NonNull;
 
 
 import java.io.File;

A org.gawst.asyncdb.DataSource backed by a android.database.sqlite.SQLiteOpenHelper storage.

Parameters:
<E> Type of the elements read from the CURSOR
<CURSOR> Wrapper around the raw Cursor read
Author(s):
Created by robUx4 on 11/01/2015.
 
 public abstract class TypedSqliteDataSource<E, CURSOR extends Cursor> extends TypedCursorDataSource<E, LongVoid, CURSOR> {
 
 	private final Context context;
 	private final SQLiteOpenHelper db;
 	private final String tableName;
 	private final String databaseName;

Constructor. (API v14 minimum)

Parameters:
context Context used to erase the database file in case it's corrupted.
db The SQL database used to read/write data.
tableName Name of the SQL table that contains the elements to read.
databaseElementHandler Handler to transform Cursor into E elements or E elements to selections.
 
 	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
 	public TypedSqliteDataSource(@NonNull Context context, @NonNull SQLiteOpenHelper db, @NonNull String tableName, @NonNull TypedDatabaseElementHandler<E, CURSOR> databaseElementHandler) {
 		this(contextdbtableNamedb.getDatabaseName(), databaseElementHandler);
 	}

Constructor.

Parameters:
context Context used to erase the database file in case it's corrupted.
db The SQL database used to read/write data.
tableName Name of the SQL table that contains the elements to read.
databaseName Name of the database file on disk, in case it's corrupted and needs to be erased.
databaseElementHandler Handler to transform Cursor into E elements or E elements to selections.
 
 	public TypedSqliteDataSource(@NonNull Context context, @NonNull SQLiteOpenHelper db, @NonNull String tableName, @NonNull String databaseName, @NonNull TypedDatabaseElementHandler<E, CURSOR> databaseElementHandler) {
 		super(databaseElementHandler);
 		this. = context;
 		this. = db;
 		this. = tableName;
 		this. = databaseName;
 	}
 
 	public Void getDatabaseId() {
 		return null;
 	}
 
 	public CURSOR query(String[] columnsString selectionString[] selectionArgsString groupByString havingString orderByString limit) {
 		//UIHandler.assertNotUIThread();
 		return wrapCursor(.getReadableDatabase().query(columnsselectionselectionArgsgroupByhavingorderBylimit));
 	}
 
 	public int clearAllData() {
 		UIHandler.assertNotUIThread();
 		int result = .getWritableDatabase().delete("1"null);
 		SQLiteDatabase.releaseMemory();
 		return result;
 	}
 
 	public Long insert(@NonNull ContentValues valuesthrows RuntimeException {
 		long id = .getWritableDatabase().insertOrThrow(nullvalues);
 		if (id == -1)
 			return null;
 		return id;
 	}
 
 	public int update(@NonNull ContentValues updateValuesString selectionString[] selectionArgs) {
 		return .getWritableDatabase().update(updateValuesselectionselectionArgs);
 	}
 
 	public int delete(String selectionString[] selectionArgs) {
 		UIHandler.assertNotUIThread();
 		return .getWritableDatabase().delete(selectionselectionArgs);
 	}
 
 	public void eraseSource() {
 		File corruptedDbFile = .getDatabasePath();
		corruptedDbFile.delete();
	}
	protected String getToStringHeader() {
		return "TypedSqlite:"++" table="+;
	}
New to GrepCode? Check out our FAQ X