From: gumartinm Date: Thu, 2 Feb 2012 21:31:07 +0000 (+0100) Subject: Testing a SQLite provider. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=8b6d630f345b865059a17fa2b25aa1298912e4f0;p=JavaForFun Testing a SQLite provider. --- diff --git a/Android/Testing/Test3/AndroidManifest.xml b/Android/Testing/Test3/AndroidManifest.xml index 548eed8..311d2f6 100644 --- a/Android/Testing/Test3/AndroidManifest.xml +++ b/Android/Testing/Test3/AndroidManifest.xml @@ -39,6 +39,30 @@ + + + + + \ No newline at end of file diff --git a/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java b/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java new file mode 100644 index 0000000..4b6269a --- /dev/null +++ b/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java @@ -0,0 +1,36 @@ +package de.android.test3; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class IndexerOpenHelper extends SQLiteOpenHelper { + private static final String DBNAME = "mobiads"; + private static final int DATABASE_VERSION = 1; + private static final String TABLE_NAME = "indexer"; + private static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME + + "(_ID INTEGER NOT NULL, " + + "PATH TEXT(15) NOT NULL, " + + "PRIMARY KEY (_ID), " + + "UNIQUE (PATH), " + ")"; + + IndexerOpenHelper(Context context) { + super(context, DBNAME, null, DATABASE_VERSION); + } + + + /* + * Creates the data repository. This is called when the provider attempts to open the + * repository and SQLite reports that it doesn't exist. + */ + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(TABLE_CREATE); + } + + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } +} diff --git a/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java b/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java new file mode 100644 index 0000000..a1142e2 --- /dev/null +++ b/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java @@ -0,0 +1,86 @@ +/** + * + */ +package de.android.test3; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.net.Uri; + +/** + * + */ +public class IndexerProvider extends ContentProvider { + // Holds the database object + private SQLiteDatabase db; + /* + * Defines a handle to the database helper object. The MainDatabaseHelper class is defined + * in a following snippet. + */ + private IndexerOpenHelper mOpenHelper; + + + /* (non-Javadoc) + * @see android.content.ContentProvider#delete(android.net.Uri, java.lang.String, java.lang.String[]) + */ + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see android.content.ContentProvider#getType(android.net.Uri) + */ + @Override + public String getType(Uri uri) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see android.content.ContentProvider#insert(android.net.Uri, android.content.ContentValues) + */ + @Override + public Uri insert(Uri uri, ContentValues values) { + /* + * Gets a writeable database. This will trigger its creation if it doesn't already exist. + * + */ + db = mOpenHelper.getWritableDatabase(); + + return null; + } + + /* (non-Javadoc) + * @see android.content.ContentProvider#onCreate() + */ + @Override + public boolean onCreate() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see android.content.ContentProvider#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String) + */ + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see android.content.ContentProvider#update(android.net.Uri, android.content.ContentValues, java.lang.String, java.lang.String[]) + */ + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java index 369d809..becd13f 100644 --- a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java +++ b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java @@ -89,7 +89,7 @@ public class MobieAdHttpClient implements Runnable JSONArray finalResult = new JSONArray(tokener); for (int i = 0; i < finalResult.length(); i++) { JSONObject objects = finalResult.getJSONObject(i); - //Find out if that id is in the SQLITE database. + //Find out if that id is in the SQLite database. downloadAds((Integer) objects.get("id"), (String)objects.get("domain"), (String)objects.get("link")); } } @@ -136,7 +136,7 @@ public class MobieAdHttpClient implements Runnable } } finally { //instream will never be null in case of reaching this code, cause it was initialized outside try/catch block. - //In case of exception here, it is thrown to the superior layer. + //In case of exception here, it is thrown to the upper layer. instream.close(); } }