Show HN: Realm for Android
realm.io
realm.io
the `android-apt` dependency needs to be switched to 1.4 else you get:
A problem occurred configuring project ':cachetest'.
> No such property: projectDependencies for class: com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated
Edit #1: Is there any way to instantiate my RealmObject from JSON? I'm currently using GSON to take API calls <--> POJOs, I can't figure out any way to do this using Realm since models "must be instantiated from the Realm using the realm.createObject() instance method".Edit #2: Okay I have no idea how to use this. Given a list of `Object`, how do I make a `RealmList` of it? Do I have to use Realm.createObject? Is there not any way of just taking a couple already instantiated versions of an object and jamming them into a `RealmList`?
I was really excited about trying this out (the Stack Exchange app currently has a 37ms delay on a cold start to get the list of all of our sites back into active memory) but this does not look like it's going to be easy to use.
We do support JSON (and GSON) — you can see it at work in our gridViewExample (https://github.com/realm/realm-java/tree/master/examples/gri...)
I wish Java would take a hint from C# properties through :(
You have to use Realm.createObject because objects are strongly tied to one Realm at a time. We could introduce standalone objects you can create with regular constructors but you’d be a really heft performance hit there.
RealmLists are mostly used to model relationships at this point, so you could add them to a another model like (http://realm.io/docs/java/0.70.1/#relationships) although eventually we do want to introduce standalone RealmLists.
What would you expect to use multiple RealmObjects in a single RealmList for? (Just so we can learn from your use-case.)
Also, one of the examples (GridViewExample) in the release reads JSON data with GSON.
I'm still very much interested in Realm, and LOVE having a competitor to SQLite. But don't mislead your customers.
[1]: https://news.ycombinator.com/item?id=8043332 where seepel finds SQLite to be more than twice as fast as Realm after that one change to the benchmark.
I just checked our Android code and we are reusing compiled statements in our benchmarks (Inserts only since compiled statements are not available for multi-column queries, afawk). Here’s the code we use for inserts:
public void testBatchInserts() throws PerformanceTestException {
SQLiteStatement stmt = db.compileStatement("INSERT INTO "
+ EmployeeDatabaseHelper.TABLE_EMPLOYEES + " VALUES(?1, ?2, ?3, ?4)");
db.beginTransaction();
for (int row = 0; row < getNumInserts(); row++) {
stmt.clearBindings();
stmt.bindString(2, getEmployeeName(row));
stmt.bindLong(3, getEmployeeAge(row));
stmt.bindLong(4, getEmployeeHiredStatus(row));
stmt.executeInsert();
}
db.setTransactionSuccessful();
db.endTransaction();
}
So there you go: no intention to mislead. Us overlooking prepared statements when we originally benched iOS was definitely a regrettable error but we do try to improve. Thanks for helping us along the way.Would you have the source code for the benchmarks available somewhere? On the iOS post there was a link, but I didn't see it on the android one.
EDIT: typos.
EDIT 2: clearly referencing that this message was about iOS and pointing to the other comment for Android.
Thanks again for looking into it and updating the material - far too many groups just gloss over (glaring) problems with their micro benchmarks, and it just sours all their future claims. Glad you're not one of them :)
I do agree that net syncing would definitely be a killer feature for me as well, but it's probably not the case for the average project ( which probably uses custom web services for crud on the serve side).
Thanks!
[1]: http://developer.android.com/reference/android/os/Parcelable... [2]: http://developer.android.com/training/basics/activity-lifecy...
I'll need to read more to judge it on other grounds.
Realm reduced the core size by approximately 90%, and while I've given up the cross-platform part (target platforms were iOS, OS X and Windows; obviously not focussed on Windows at this point), the code clarity and ease with which I can change data structures makes this approach so much better.
Are you guys looking at supporting Windows/C#/.NET at this stage, because while I don't develop much software for it, it does come up occasionally, and it would be good to use it throughout.
Is this a SQLite replacement, in that it is its own database, or a CoreData replacement, in that it's "just" a nice API over some other persistence layer (afaik, CoreData gives you a nice consistent API over a number of concrete persistence implementations, with SQLite being one such implementation)
I'd love to know a bit more about this. What drove the decision to roll your own? Seeing as how SQLite is pretty mature and widely deployed, my first instinct if I wanted to tackle this problem would just have been to write the best damn ORM I could on top of SQLite.
Error:Exception thrown while constructing Processor object: io/realm/processor/RealmProcessor : Unsupported major.minor version 51.0
The nice thing is you can then make have e.g. common C++ code shared between your mobile app platforms (as quite a few do), and share state/data easily between C++ & Java or C++ & ObjC/Swift in one app. No fuss, one API, one shared datamodel, fully threadsafe between languages.
Would that be useful?
So this kind of flow would be pretty simple right?
1. C++ cross-platform layer receives a text message, records it in the realmDB.
2. Java/ObjC UI watcher on that realmDB table automatically gets a callback update.
3. UI gets updated with the new message being displayed.
4. The app gets killed because of a crash, the new message is still safely recorded in the realmDB, user sees it on app relaunch.
Same terms there?
db.beginTransaction();
for (int row = 0; row < getNumInserts(); row++) {
stmt.clearBindings();
stmt.bindString(2, getEmployeeName(row));
stmt.bindLong(3, getEmployeeAge(row));
stmt.bindLong(4, getEmployeeHiredStatus(row));
stmt.executeInsert();
}
db.setTransactionSuccessful();
db.endTransaction();