forked from dooreelko/MeditationTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sasfed
authored and
sasfed
committed
May 19, 2011
0 parents
commit 32ba7a5
Showing
163 changed files
with
5,354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="doo.jpa" | ||
android:versionCode="1" | ||
android:versionName="1.0"> | ||
<application android:icon="@drawable/icon" android:label="@string/app_name"> | ||
|
||
|
||
</application> | ||
|
||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
> | ||
<TextView | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/hello" | ||
/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="hello">Hello World!</string> | ||
<string name="app_name"></string> | ||
</resources> |
43 changes: 43 additions & 0 deletions
43
Jpandroid/src/com/meditationtracker/persistence/helpers/ReflectionHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.meditationtracker.persistence.helpers; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Id; | ||
|
||
import android.provider.BaseColumns; | ||
|
||
public class ReflectionHelper { | ||
|
||
public static Map<String, Field> getPersistenceColumnNamesForClass(Class<?> clazz) { | ||
Map<String, Field> result = new HashMap<String, Field>(); | ||
for (Field f : getPersistenceColumnsForClass(clazz)) | ||
{ | ||
Column columnAnn = f.getAnnotation(Column.class); | ||
if (columnAnn != null) | ||
result.put(columnAnn.name(), f); | ||
else | ||
if (f.getAnnotation(Id.class) != null) | ||
result.put(BaseColumns._ID, f); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected static List<Field> getPersistenceColumnsForClass(Class<?> clazz) { | ||
List<Field> result = new ArrayList<Field>(); | ||
for (Field f : clazz.getFields()) { | ||
if (f.getAnnotation(Column.class) != null || f.getAnnotation(Id.class) != null) | ||
{ | ||
result.add(f); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
Jpandroid/src/com/meditationtracker/persistence/jpa/Entity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.meditationtracker.persistence.jpa; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.sql.ResultSet; | ||
import java.sql.ResultSetMetaData; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.meditationtracker.persistence.helpers.ReflectionHelper; | ||
import doo.util.functional.Collection; | ||
import doo.util.functional.Folder; | ||
|
||
public class Entity { | ||
private String hash; | ||
private Class<?> clazz = null; | ||
private Map<String, Field> columns; | ||
|
||
public Entity(Class<?> clazz) { | ||
this.clazz = clazz; | ||
hash = buildHash(clazz); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T createInstance(ResultSet row) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SQLException { | ||
if (clazz == null) | ||
throw new IllegalArgumentException("Entity was initialized without a class, cannot create one."); | ||
|
||
return fillObject((T)clazz.getConstructor((Class[])null).newInstance(), row); | ||
} | ||
|
||
private <T> T fillObject(T obj, ResultSet row) throws SQLException, IllegalArgumentException, IllegalAccessException { | ||
ResultSetMetaData metaData = row.getMetaData(); | ||
for (int x=0; x<metaData.getColumnCount(); x++) { | ||
Field f = columns.get(metaData.getColumnLabel(x)); | ||
|
||
f.setAccessible(true); | ||
f.set(obj, row.getObject(x)); | ||
} | ||
|
||
return obj; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hash.hashCode(); | ||
} | ||
|
||
public static String buildHash(ResultSet row) throws SQLException { | ||
List<String> columns = new ArrayList<String>(); | ||
|
||
ResultSetMetaData rowMetaData = row.getMetaData(); | ||
for(int x = 0; x<rowMetaData.getColumnCount(); x++) { | ||
columns.add(rowMetaData.getColumnName(x)); | ||
} | ||
|
||
return sortAndJoinForHash(columns); | ||
} | ||
|
||
public String buildHash(Class<?> clazz) { | ||
columns = ReflectionHelper.getPersistenceColumnNamesForClass(clazz); | ||
List<String> colNames = new ArrayList<String>(columns.keySet()); | ||
|
||
return sortAndJoinForHash(colNames); | ||
} | ||
|
||
private static String sortAndJoinForHash(List<String> list) { | ||
Collections.sort(list); | ||
return Collection.fold(list, "|", new Folder<String, String>() { | ||
public String fold(String accumulator, String current) { | ||
return accumulator += current + "|"; | ||
} | ||
|
||
}); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
Jpandroid/src/com/meditationtracker/persistence/jpa/EntityManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.meditationtracker.persistence.jpa; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.HashMap; | ||
|
||
|
||
public class EntityManager { | ||
private static HashMap<Integer, Entity> entities; | ||
|
||
public static void registerEntity(Class<?> clazz) { | ||
Entity entity = new Entity(clazz); | ||
entities.put(entity.hashCode(), entity); | ||
} | ||
|
||
public static Entity getEntityInfo(ResultSet row) throws SQLException { | ||
return entities.get(Entity.buildHash(row)); | ||
} | ||
|
||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
Jpandroid/src/com/meditationtracker/persistence/jpa/JpaHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.meditationtracker.persistence.jpa; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import org.apache.commons.dbutils.ResultSetHandler; | ||
|
||
|
||
public class JpaHandler<T extends Object> implements ResultSetHandler<T>{ | ||
|
||
public T handle(ResultSet row) throws SQLException { | ||
Entity info = EntityManager.getEntityInfo(row); | ||
|
||
T result; | ||
try { | ||
result = info.createInstance(row); | ||
|
||
return result; | ||
} catch (Exception e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
|
||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.meditationtracker" android:versionCode="4" android:versionName="Mantra"> | ||
<application android:icon="@drawable/launcher_48" | ||
android:label="@string/app_name" android:debuggable="false" android:theme="@android:style/Theme.Light.NoTitleBar"> | ||
<activity android:name=".MainActivity" 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="SettingsActivity" android:theme="@android:style/Theme.Light"></activity> | ||
<activity android:name="NewOrEditPracticeDBActivity"></activity> | ||
<activity android:name="NewOrEditPracticeScreenActivity"></activity> | ||
<activity android:name="PracticeActivity"></activity> | ||
<activity android:name="ScheduleActivity"></activity> | ||
<activity android:name="ImagePicker"></activity> | ||
<provider android:name="PracticeImageProvider" | ||
android:authorities="com.meditationtracker.imageProvider"></provider> | ||
<activity android:name="SessionActivity"></activity> | ||
</application> | ||
<uses-sdk android:minSdkVersion="3" /> | ||
<uses-permission android:name="android.permission.VIBRATE" /> | ||
<!-- uses-permission android:name="android.permission.INTERNET" / --> | ||
</manifest> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.