Skip to content

Commit

Permalink
Merge pull request #4 from greenrobot/greendao-identy-scope
Browse files Browse the repository at this point in the history
GreenDaoExecutor: flag for identity scope
  • Loading branch information
kpgalligan committed Jul 14, 2016
2 parents cbf4745 + 0a3ee1c commit 1761923
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
import java.util.LinkedList;
import java.util.List;

import de.greenrobot.dao.identityscope.IdentityScopeType;

import static com.littleinc.orm_benchmark.util.Util.getRandomString;

public class GreenDaoExecutor implements BenchmarkExecutable {

private static final String TAG = "GreenDaoExecutor";

/**
* The identity scope tracks all entity objects to assure the same object is returned for one specific ID.
* Of course this comes with some overhead (map with weak references): thus it should only be used for comparing to
* other ORMs that also have a similar feature (e.g. caches).
*/
private boolean USE_IDENTITY_SCOPE = false;

private static String DB_NAME = "greendao_db";

private DataBaseHelper mHelper;
Expand All @@ -36,7 +44,8 @@ public long createDbStructure() throws SQLException {
long start = System.nanoTime();
SQLiteDatabase db = mHelper.getWritableDatabase();
if (mDaoSession == null) {
mDaoSession = new DaoMaster(db).newSession();
mDaoSession = new DaoMaster(db).newSession(USE_IDENTITY_SCOPE ?
IdentityScopeType.Session : IdentityScopeType.None);
} else {
DaoMaster.createAllTables(db, true);
}
Expand Down Expand Up @@ -84,7 +93,9 @@ public void run() {
}
});
long time = System.nanoTime() - start;
mDaoSession.clear();
if(USE_IDENTITY_SCOPE) {
mDaoSession.clear();
}
return time;
}

Expand All @@ -95,7 +106,9 @@ public long readWholeData() throws SQLException {
// Logging should be outside of time measurement, but others tests do it too
Log.d(GreenDaoExecutor.class.getSimpleName(), "Read, " + size + " rows");
long time = System.nanoTime() - start;
mDaoSession.clear();
if(USE_IDENTITY_SCOPE) {
mDaoSession.clear();
}
return time;
}

Expand Down

0 comments on commit 1761923

Please sign in to comment.