yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

Support generating package-visible TableModels to encapsulate DB implementation from other java packages #129

Closed gallal closed 8 years ago

sbosley commented 8 years ago

Sorry, I don't think I quite understand what the feature request is here. Can you provide an example of what you want to generate and a brief explanation of why it would be useful?

jdkoren commented 8 years ago

If I understand this correctly, you'd like to be able to generate model classes that are declraed class MyModel and not public class MyModel?

gallal commented 8 years ago

@jdkoren exactly!

sbosley commented 8 years ago

@gallal I threw together a branch that implements this enhancement, but I think we need a little more convincing that this use case is worthwhile enough to warrant the extra complexity :) A package-private model class would have at least the following limitations:

  1. It would have to be declared in the same package as the database class it belongs to, in order to be able to provide the database with its Table object. (Or you could implement some hack by which another class in the package provides Tables to the DB class, but that sounds super messy).
  2. Database writes using that model class could only occur within that package.
  3. You could only construct queries/do DB reads on that table from within that package. Even if you passed a cursor to a class in some other package, you'd lose all the ability to read type-safely from that cursor, because the model's Property objects wouldn't be visible.

To me, these limitations sound like they would be a burden that limits good code organization and package structure, so I'd personally be inclined to keep all model objects public. If you are reading this though and thinking "yes, that's exactly what I want" then it would be great to hear more about the general use cases you have in mind where this kind of data hiding would be helpful -- I'm certainly open to merging the change if you can convince us it can be used for good!

sbosley commented 8 years ago

This issue hasn't seen any activity in a while so I'm going to close it. I'm still of the opinion that package private models don't have very many legitimate use cases given the limitations I outlined above. If anyone wants to try to convince me otherwise though, feel free to reopen the issue.