If you think the Android project worldwondersproject listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.ciandt.cursoandroid.worldwondersapp.manager;
/*www.java2s.com*/import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.CursorLoader;
import android.net.Uri;
import android.os.AsyncTask;
import com.ciandt.cursoandroid.worldwondersapp.listener.DatabaseOperatorCallback;
publicclass DatabaseManager {
privatefinal Context mContext;
public DatabaseManager(final Context context) {
this.mContext = context;
}
public Long insert(final Uri uri, final ContentValues contValues) {
ContentResolver contentResolver = mContext.getContentResolver();
return ContentUris.parseId(contentResolver.insert(uri, contValues));
}
public CursorLoader query(final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
returnnew CursorLoader(mContext, uri, projection, selection, selectionArgs, sortOrder);
}
publicvoid bulkInsert(final Uri uri,
final ContentValues[] contentValues,
finalboolean deleteBeforeInsert,
final String deleteSelecion,
final String[] deleteSelectionArgs,
final DatabaseOperatorCallback<Integer> integerDatabaseOperatorCallback) {
new AsyncTask<Void, Void, Integer>() {
@Override
protectedInteger doInBackground(Void... voids) {
ContentResolver contentResolver = mContext.getContentResolver();
if (deleteBeforeInsert) {
contentResolver.delete(uri, deleteSelecion, deleteSelectionArgs);
}
return contentResolver.bulkInsert(uri, contentValues);
}
@Override
protectedvoid onPostExecute(Integer integer) {
integerDatabaseOperatorCallback.onOperationSuccess(integer);
}
}.execute();
}
}