Question

I'm currently into evaluating GreenDAO for my application. I'm facing the following problem.

My app consists of several modules (seperated in packages, e.g. "com.example.app.results", "com.example.app.synchronization"). Some of them have no dependencies, some of them have dependencies on other modules (e.g. synchronization has a dependency on results, whereas results has no dependency).

What I would like to model is the following:

Module results has Entity MyResult (attributes: name, value).

Module synchronization has Entity MyResultSynchronization (attributes: MyResult (reference), date).

final Schema schema = new Schema(1, "com.example.app");

final Entity myresult = schema.addEntity("results.MyResult");
final Property myresultId = myresult.addIdProperty().getProperty();
myresult.addStringProperty("name");
myresult.addStringProperty("value");

final Entity myResultSynchronization = schema.addEntity("synchronization.MyResultSynchronization");
myResultSynchronization.addIdProperty();
myResultSynchronization.addDateProperty("date");
myResultSynchronization.addToOne(myresult, myresultId);

but - $entityPackage.$name does not what I expected it to do (neither did $package\$name ;-)).

My question is: Am I forced to have all entities of my app in a single package? Is what I'm trying to do feasible by creating multiple Schemas - but than again, is it possible to use the relate-feature between two (or more) schemas? What is the "right" way to do it? (Is there one?)

Was it helpful?

Solution

Indeed all entities have to be in the same package.

Normally you use a structure like

 com.example.myapp.data

Where you put everything for managing your database, especially your entity classes. Inside you can let greendao create a dao package where it will put everything needed to access your data (base).

Of course you can enforce your naning schema by making multiple sxhemas in greendao. But the schemas will be independent: They won't use the same database and you won't be able to link them together with toOne () for example.

If you still want to use your naming schema you can generate everything to an intermediate package and move them to your desired packages manually. But you would have to repeat this upon every change to your database schema, which is more often than one may think at first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top