Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GreenDaoExecutor: flag for identity scope #4

Merged
merged 1 commit into from Jul 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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