Skip to content

Commit

Permalink
check in to master
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavo committed Jun 11, 2012
1 parent 7dd7c39 commit 23fb416
Show file tree
Hide file tree
Showing 73 changed files with 1,600 additions and 1,190 deletions.
9 changes: 5 additions & 4 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="com.perfectworldprogramming.mobile.orm"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>

<instrumentation android:targetPackage="com.perfectworldprogramming.mobile.orm" android:name="android.test.InstrumentationTestRunner" />

Expand All @@ -12,22 +12,23 @@
<uses-library android:name="android.test.runner" />
</application-->

<uses-permission android:name="android.permission.PERSISTENT_ACTIVITY"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Mainnnnnnperfectworldprogramming.mobile.orm.Main"
<activity android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".test.Main" />

<uses-library android:name="android.test.runner" />
</application>

<!--instrumentation android:label="ORM Unit Tests"
android:targetPackage="com.perfectworldprogramming.mobile.orm.test"
android:name="android.test.InstrumentationTestRunner" /--><!-- com.perfectworldprogramming.mobile.orm.test.MyInstrumentationTestRunner -->

<uses-permission android:name="android.permission.PERSISTENT_ACTIVITY"/>

</manifest>
Binary file not shown.
Binary file not shown.
Binary file modified bin/classes/com/perfectworldprogramming/mobile/orm/Main.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
46 changes: 23 additions & 23 deletions gen/com/perfectworldprogramming/mobile/orm/R.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.perfectworldprogramming.mobile.orm;

public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.perfectworldprogramming.mobile.orm;

public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
6 changes: 3 additions & 3 deletions proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
-keepclasseswithmembers class * {
native <methods>;
}

-keepclasseswithmembernames class * {
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

Expand Down
110 changes: 57 additions & 53 deletions src/com/perfectworldprogramming/mobile/orm/AndroidSQLiteTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

import java.util.List;

import com.perfectworldprogramming.mobile.orm.exception.DataAccessException;
import com.perfectworldprogramming.mobile.orm.exception.EmptySQLStatementException;
import com.perfectworldprogramming.mobile.orm.exception.NoRowsReturnedException;
import com.perfectworldprogramming.mobile.orm.interfaces.CursorExtractor;
import com.perfectworldprogramming.mobile.orm.interfaces.CursorRowMapper;
import com.perfectworldprogramming.mobile.orm.interfaces.JdbcOperations;
import com.perfectworldprogramming.mobile.orm.reflection.DomainClassAnalyzer;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
Expand All @@ -18,6 +10,13 @@
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteStatement;

import com.perfectworldprogramming.mobile.orm.exception.DataAccessException;
import com.perfectworldprogramming.mobile.orm.exception.EmptySQLStatementException;
import com.perfectworldprogramming.mobile.orm.exception.NoRowsReturnedException;
import com.perfectworldprogramming.mobile.orm.interfaces.CursorExtractor;
import com.perfectworldprogramming.mobile.orm.interfaces.JdbcOperations;
import com.perfectworldprogramming.mobile.orm.reflection.DomainClassAnalyzer;

/**
* For queries that return Cursors will use the CursorAdapter class to convert the Cursor into your Domain object, either via
* Annotations you put in your domain objects to map to the tables, or via CursorRowMapper or CursorExtractor implementations.
Expand All @@ -29,19 +28,24 @@
*/
public class AndroidSQLiteTemplate implements JdbcOperations {
private SQLiteDatabase sqLiteDatabase;
private DomainClassAnalyzer domainClassAnalyzer = new DomainClassAnalyzer();
private CursorAdapter cursorAdapter = new CursorAdapter();
private final DomainClassAnalyzer domainClassAnalyzer = new DomainClassAnalyzer();
private final CursorAdapter cursorAdapter = new CursorAdapter();

public AndroidSQLiteTemplate(SQLiteDatabase sqLiteDatabase) {
this.sqLiteDatabase = sqLiteDatabase;
}

public Object mapQueryParameter(Object value, Class<?> clazz, String columnName)
{
return this.domainClassAnalyzer.mapQueryParameter(value, clazz, columnName);
}

@Override
public long insert(Object object) {
ContentValues values = domainClassAnalyzer.createContentValues(object);
long id = sqLiteDatabase.insert(object.getClass().getSimpleName(),
null, values);
// the insert method used above doesn't through an exception if it can't insert, but returns -1 as the result.
// the insert method used above doesn't throw an exception if it can't insert, but returns -1 as the result.
if (id != -1) {
domainClassAnalyzer.setIdToNewObject(object, id);
} else {
Expand Down Expand Up @@ -178,14 +182,14 @@ public String queryForString(String sql, Object... args) {
}

//** All Implementations below call their corresponding executeFor* private methods for a more central exception handling
@Override
public <T> T queryForObject(String sql, CursorRowMapper<T> cursorRowMapper, Object... args) {
if (cursorRowMapper == null) {
throw new IllegalArgumentException();
}
sql = replaceParametersInStatement(sql, args);
return executeForSingleObject(sql, cursorRowMapper);
}
// @Override
// public <T> T queryForObject(String sql, Class<T> clazz, Object... args) {
// if (cursorRowMapper == null) {
// throw new IllegalArgumentException();
// }
// sql = replaceParametersInStatement(sql, args);
// return executeForSingleObject(sql, cursorRowMapper);
// }

@Override
public <T> T queryForObject(String sql, Class<T> clazz, Object... args) {
Expand Down Expand Up @@ -218,14 +222,14 @@ public <T> List<T> query(String sql, Class<T> clazz, Object... args) {
return executeForList(sql, clazz);
}

@Override
public <T> List<T> query(String sql, CursorRowMapper<T> cursorRowMapper, Object... args) {
if (cursorRowMapper == null) {
throw new IllegalArgumentException();
}
sql = replaceParametersInStatement(sql, args);
return executeForList(sql, cursorRowMapper);
}
// @Override
// public <T> List<T> query(String sql, CursorRowMapper<T> cursorRowMapper, Object... args) {
// if (cursorRowMapper == null) {
// throw new IllegalArgumentException();
// }
// sql = replaceParametersInStatement(sql, args);
// return executeForList(sql, cursorRowMapper);
// }

private <T> T executeForSingleObject(String sql, CursorExtractor<T> cursorExtractor) {
if (sql == null || "".equals(sql)) {
Expand All @@ -245,18 +249,18 @@ private <T> T executeForSingleObject(String sql, CursorExtractor<T> cursorExtrac
}
}

private <T> T executeForSingleObject(String sql, CursorRowMapper<T> cursorRowMapper) {
if (cursorRowMapper == null) {
throw new IllegalArgumentException();
}
Cursor cursor = null;
try {
cursor = sqLiteDatabase.rawQuery(sql, null);
return cursorAdapter.adaptFromCursor(cursor, cursorRowMapper);
} catch (SQLiteException se) {
throw new DataAccessException(se.getMessage());
}
}
// private <T> T executeForSingleObject(String sql, CursorRowMapper<T> cursorRowMapper) {
// if (cursorRowMapper == null) {
// throw new IllegalArgumentException();
// }
// Cursor cursor = null;
// try {
// cursor = sqLiteDatabase.rawQuery(sql, null);
// return cursorAdapter.adaptFromCursor(cursor, cursorRowMapper);
// } catch (SQLiteException se) {
// throw new DataAccessException(se.getMessage());
// }
// }

private <T> T executeForSingleObject(String sql, Class<T> clazz) {
Cursor cursor = null;
Expand All @@ -268,20 +272,20 @@ private <T> T executeForSingleObject(String sql, Class<T> clazz) {
}
}

private <T> List<T> executeForList(String sql, CursorRowMapper<T> cursorRowMapper) {
if (cursorRowMapper == null) {
throw new IllegalArgumentException();
}
Cursor cursor = null;
try {
cursor = sqLiteDatabase.rawQuery(sql, null);
return cursorAdapter.adaptListFromCursor(cursor, cursorRowMapper);
} catch (SQLiteException se) {
throw new DataAccessException(se.getMessage());
} catch (Exception e) {
throw new DataAccessException("Unable to execute query. Please check your sql for incorrect sql grammer.");
}
}
// private <T> List<T> executeForList(String sql, CursorRowMapper<T> cursorRowMapper) {
// if (cursorRowMapper == null) {
// throw new IllegalArgumentException();
// }
// Cursor cursor = null;
// try {
// cursor = sqLiteDatabase.rawQuery(sql, null);
// return cursorAdapter.adaptListFromCursor(cursor, cursorRowMapper);
// } catch (SQLiteException se) {
// throw new DataAccessException(se.getMessage());
// } catch (Exception e) {
// throw new DataAccessException("Unable to execute query. Please check your sql for incorrect sql grammer.");
// }
// }

private <T> List<T> executeForList(String sql, Class<T> clazz) {
Cursor cursor = null;
Expand Down
Loading

0 comments on commit 23fb416

Please sign in to comment.