asolfre / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

Add support for externalizing entity configuration in a configuration file #49

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to be able to configure my entity classes via an external file 
(something like the hibernate mapping files). The configuration with 
annotations is great but adds unnecessary dependencies on the Objectify 
framework. For example let's say I define the following class:

class Car {
    @Id String vin;
    String color;
    @Unindexed String unindexed;
}

If I want to use it outside of the GAE server application (for example in GWT 
or in Android or in whatever Java client that connects to the GAE server 
application) because of the @Unindexed annotation I have to include objectify 
as a dependency in the client application. Also because the @Id annotation I 
have to include another library. This may not seem so problematic in standard 
Java clients but on Android it does have a big impact on the size of the app.
The externalization of entity configuration to a different file would solve 
this problem. We could add this file during registration or the name of the 
mapping file could be implied from the name of the class.

Original issue reported on code.google.com by dilbert....@gmail.com on 28 Jul 2010 at 8:20

GoogleCodeExporter commented 9 years ago
While this isn't technically true with GWT (annotations get ignored), I can see 
your point about Android.  I can think of two "easy" solutions:

1) Create a jar which contains just the annotations, so you can have a tiny 
distribution.

2) Offer the notion of a mix-in class similar to how Jackson does.  Basically 
ObjectifyFactory.register() would take two classes - one, the class that's 
being registered and two, the class that is being introspected for 
registration.  The mix-in class is essentially the same as the basic class but 
with the relevant annotations added.

In practice I suspect #1 is probably the more convenient solution - maintaining 
parallel class hierarchies sucks.  But #2 does offer a lot of flexibility.

Original comment by lhori...@gmail.com on 28 Jul 2010 at 8:46

GoogleCodeExporter commented 9 years ago
#1 came to mind but I also thought it was a pain to maintain (pardon the pun). 
I didn't get #2 though. Could you elaborate a bit. An example perhaps. Thanks 
for Your time.

Original comment by dilbert....@gmail.com on 28 Jul 2010 at 9:11

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
There is an example for Jackson mix-in on 
http://www.cowtowncoder.com/blog/archives/2009/08/entry_305.html. So for the 
car example

class Car {
    @Id String vin;
    String color;
    @Unindexed String unindexed;
}

there would be an additional describing interface and the Car class could be 
free of any annotations.

interface MixIn
{
    @Objectify("vin") @ObjectifyId String vin();
    // or maybe: @Objectify(name="vin", id=true) String vin();
    @Objectify String color();
}

Later Car and MixIn is brought together.

I would like to free my JavaBeans from Objectify annotations too but I would be 
happy with a more simple API also. One can also consider using a builder style 
of describing the meta data. Maybe something like

ObjectifyService.register( YourEntity.class ).withId( "vin" );

That would be quite easy to implement.

Original comment by ullenb...@googlemail.com on 29 Jul 2010 at 8:54

GoogleCodeExporter commented 9 years ago
Hi ullenb... Thanks for the Jackson mix-in explanation. I like your idea about 
programmatic configuration.
BTW here is the group thread about this issue:
http://groups.google.com/group/objectify-appengine/browse_thread/thread/9348bf24
e4ddfe26/ 

Original comment by dilbert....@gmail.com on 30 Jul 2010 at 1:55

GoogleCodeExporter commented 9 years ago
I think an annotation-only jar would be best.

Original comment by matt...@jaggard.org.uk on 17 Nov 2011 at 10:59

GoogleCodeExporter commented 9 years ago
There is "client-jar" nant target which produces client only jar.

Original comment by rus...@walkmind.com on 28 Feb 2012 at 3:48