Question about OrmLite cache

254 views
Skip to first unread message

Viktor Nyblom

unread,
Feb 19, 2013, 2:25:09 AM2/19/13
to robo...@googlegroups.com
I just started using the ORMlite module for cacheing (Gson for parsing json and Spring for networking) and I have a couple of questions about how this works.

1. From my understanding the caching takes place after loadDataFromNetwork, so whatever is returned from that method is what is run through the caching process, right?

2. The OrmLite documentation states that "if your foreign object has a generated-id which is provided by the database then you need to create it before you create any objects that reference it ", but from what I could deduce from the source code this is taken care of. Correct? If so, is there any limitation on how many levels of nesting I can have?

3. Is it possible to access and manipulate the database outside of the Robospice controll

4. What the hell am I doing wrong? =) The most simple use case is fetching a User with a UserName foreign field. Somewhat simplified the classes look like this:

public class User{

    @DatabaseField(generatedId=true)
    private int _id;

    @DatabaseField
    public String gender;

    @DatabaseField(foreign = true, foreignAutoRefresh = true)
    public UserName name;

}

public class UserName{

    @DatabaseField(generatedId=true)
    private int _id;

    @DatabaseField
    public String preferred;

}

The tables are created as the should and the gender field is persisted in the database but not the name field. I always get the default 0 and the username table is empty.

I know the ORMLite module is still in beta and I guess I should ask ORMLite specific questions on SO or ORMLite user groups, but I have to try. =) 

Thanks in advance
//Viktor


Stéphane Nicolas

unread,
Feb 19, 2013, 2:58:09 AM2/19/13
to robo...@googlegroups.com
Hello Viktor,

1. Yes

2. You a re right. This is take care of by RS. They are no limitations known till now.

3. You got a RoboSpiceDataBaseHelper for that. Also, note that RoboSpice caching is meant to be transparent and is completely encapsulated in the SpiceService. It should be possilbe to access the cache system (in your case the databse) directly through a shared reference to it (shared by the service and your activities). Also, in that case, nothing will prevent side-effects like concurrent access or database inconsistency. You will be on your own past that point.

4. I can't tell you what's wrong in your code. Did you check the robospice ormlite sample ? The only diffference I can see quickly is that we don't use underscores for id... Otherwise, do you have a github repo for your code so that we can work on it. 

And finally, yes, you are right, the orm lite module is still in beta. We developped that module for an app and we know it works but we didn't fully test or implement it, just enough for our needs up to now. We are pretty open to contributions for that module.

Stéphane


2013/2/19 Viktor Nyblom <viktor...@gmail.com>
//Viktor


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes RoboSpice.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 



--
Stéphane NICOLAS,
OCTO Technology 
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - blog.octo.com
www.usievents.com
...........................................................

Viktor Nyblom

unread,
Feb 19, 2013, 4:08:22 AM2/19/13
to robo...@googlegroups.com
Hi Stephane,

I appreciate the quick reply. The answers confirmed my picture of the workflow.

As for the code, I don't think I am allowed to share it (corporate policy), so I'll just have to go through it again. And again. And again... 

The samples were my starting point, but I noticed that only the persisted objects lies in ForeignCollections in the parent. Only the children have ForeignField with a reference to the parent (of the persisted fields that is). And I might be misinterpreting this, but it looks like the InDatabaseObjectPersister and it's testcases asumes that the DatabaseFields are collections. Don't know if I have the skills yet to contribute, though.

On a whole other subject, I must say that I like how you guys mavenize and modularize everything. It was a bit harder for me to get started but gave me a good reason to learn how to use Maven for real. Clone the samples, run mvn clean install and everything is setup properly. Beautiful. I saw something in another thread about putting dependencies in the libs folder, but this would probably just mess things up. Better to force the user to learn a good build tool.

//viktor

Stéphane Nicolas

unread,
Feb 22, 2013, 1:45:43 PM2/22/13
to robo...@googlegroups.com
Hi Viktor,

thanks for your kind words on RoboSpice's maven architecture. We learned all that recently and most on that comes from my colleagues @OCTO. 
It's  been a long transition but I do believe we hold a solid git / maven system and RoboSpice can now go main stream quietly as a very mature project for android. We improved a lot in meeting industrial quality standards.

You are right, we won't add the dependencies to the libs folder as they would be added twice by eclipse with m2-android connector (once by adt as jars in libs get in the final apk and twice by the maven connector as he will include the dependencies for the pom). And, as you know, such builds fail when dexing.

I am pretty sorry not to have time to investigate this issue right now, but we are really overloaded at work and I got other work pending for a conference on industrial build environments : Jérôme and I are gonna be @devoxx 2013 to present this. We opened 2 new GitHub projects rencently : Quality tool for Android and a sonar lint plugin. Feel free to join. ;)
Reply all
Reply to author
Forward
0 new messages