+ *
+ */
+@SuppressWarnings("nls")
+public class SqlContentProvider extends ContentProvider {
+
+ static {
+ AstridDependencyInjector.initialize();
+ }
+
+ // --- instance variables
+
+ private static UriMatcher uriMatcher;
+
+ @Autowired
+ private Database database;
+
+ @Autowired
+ private ExceptionService exceptionService;
+
+ @Override
+ public boolean onCreate() {
+ try {
+ database.openForWriting();
+ return database.getDatabase() != null;
+ } catch (Exception e) {
+ exceptionService.reportError("astrid-provider", e);
+ return false;
+ }
+ }
+
+ static {
+ uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+
+ uriMatcher.addURI(AstridApiConstants.PACKAGE + ".private",
+ "sql", 0);
+ }
+
+ public SqlContentProvider() {
+ DependencyInjectionService.getInstance().inject(this);
+
+ setReadPermission(AstridApiConstants.PERMISSION_READ);
+ setWritePermission(AstridApiConstants.PERMISSION_WRITE);
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ switch (uriMatcher.match(uri)) {
+ case 0:
+ return "vnd.android.cursor.dir/vnd.astrid";
+ default:
+ throw new IllegalArgumentException("Unsupported URI " + uri + " (" + uriMatcher.match(uri) + ")");
+ }
+ }
+
+ /* ======================================================================
+ * =========================================================== delete ===
+ * ====================================================================== */
+
+ /**
+ * Delete from given table
+ * @return number of rows deleted
+ */
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ throw new UnsupportedOperationException("unimplemented");
+ }
+
+ /* ======================================================================
+ * =========================================================== insert ===
+ * ====================================================================== */
+
+ /**
+ * Insert key/value pairs into given table
+ */
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ throw new UnsupportedOperationException("unimplemented");
+ }
+
+ /* ======================================================================
+ * =========================================================== update ===
+ * ====================================================================== */
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection,
+ String[] selectionArgs) {
+ throw new UnsupportedOperationException("unimplemented");
+ }
+
+ /* ======================================================================
+ * ============================================================ query ===
+ * ====================================================================== */
+
+ /**
+ * Query by task.
+ *
+ * Note that the "sortOrder" field actually can be used to append any
+ * sort of clause to your SQL query as long as it is not also the
+ * name of a column
+ */
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String sortOrder) {
+
+ Cursor cursor = database.rawQuery(selection, null);
+ return cursor;
+ }
+
+}