Skip to content

Commit

Permalink
really close cursor. cleanup finalize.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattelacchiato committed Mar 11, 2012
1 parent 95fc3d9 commit a93d8b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .classpath
Expand Up @@ -3,5 +3,5 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
4 changes: 2 additions & 2 deletions default.properties → project.properties
Expand Up @@ -4,9 +4,9 @@
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# "ant.properties", and override values to adapt the script to your
# project structure.

android.library=true
# Project target.
target=android-3
android.library=true
37 changes: 18 additions & 19 deletions src/main/java/de/splitstudio/androidb/Table.java
Expand Up @@ -436,11 +436,10 @@ public static SQLiteDatabase getDb() {
* @return <code>true</code>, when filling was successful.
*/
protected boolean fillFirstAndClose(final Cursor c) {
if (!c.moveToFirst()) {
return false;
}

try {
if (!c.moveToFirst()) {
return false;
}
fill(c);
} finally {
c.close();
Expand Down Expand Up @@ -476,10 +475,10 @@ public boolean fill(final Cursor c) {
* method.
*/
public static <T extends Table> List<T> fillAll(final Class<T> klaas, final Cursor c) {
ArrayList<T> list = new ArrayList<T>();
Constructor<T> constructor = ReflectionHelper.getConstructor(klaas);

try {
ArrayList<T> list = new ArrayList<T>();
Constructor<T> constructor = ReflectionHelper.getConstructor(klaas);

while (c.moveToNext()) {
T table = constructor.newInstance();
if (table.fill(c)) {
Expand All @@ -488,12 +487,12 @@ public static <T extends Table> List<T> fillAll(final Class<T> klaas, final Curs
Log.w(TAG, "Could not fill table " + klaas + " with cursor " + c);
}
}
return list;
} catch (Exception e) {
throw new RuntimeException("This should not happen. Could not instantiate claas " + klaas, e);
} finally {
c.close();
}
return list;
}

public static <T extends Table> T find(final Class<T> klaas, final long id) {
Expand Down Expand Up @@ -647,17 +646,17 @@ public boolean equals(final Object obj) {
return true;
}

@Override
protected void finalize() throws Throwable {
if (db != null && db.isOpen()) {
Log.w(
TAG,
String.format(
"Finalizing Table object %s, but DB is still open. This is no problem until you call closeDB() for your own. Take care to avoid memory leaks!",
getTableName()));
}
super.finalize();
}
// @Override
// protected void finalize() throws Throwable {
// if (db != null && db.isOpen()) {
// Log.w(
// TAG,
// String.format(
// "Finalizing Table object %s, but DB is still open. This is no problem until you call closeDB() for your own. Take care to avoid memory leaks!",
// getTableName()));
// }
// super.finalize();
// }

/**
* Closes the DB instance. You have to close the DB for your own, it won't get called on {@link #finalize()}!
Expand Down

0 comments on commit a93d8b9

Please sign in to comment.