[appengine-java] Re: Objectify - Twig - approaches to persistence

2010-04-17 Thread Michael Shtelma
I have another question also related to the thread :)) What about
support for many to many relationships?
Does Twig provide it?

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Objectify - Twig - approaches to persistence

2010-03-12 Thread Nacho Coloma
  You are increasing my suspicion that you've never actually performed
  schema migrations on big, rapidly changing datasets.

 You are increasing my suspicion that you like to make inflammatory  
 remarks without thinking them through just for the sake of trolling.  

I have one question more or less related to this thread. Why are both
Objectify and Twig tying the schema upgrade to the persistence
framework? As far as I can recall no persistence framework does this,
and it hasn't been that Hibernate didn't have the chance.

If I am following correctly, you are proposing to specify the
migration path in the persistence metadata, but I just don't get it.
Why?

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: Objectify - Twig - approaches to persistence

2010-03-12 Thread Jeff Schnitzer
Scott:  Nacho is the author of SimpleDS.

Schema migration is something that Hibernate and RDBMSes actually do
rather poorly.  The typical process is to prepare a series of scripts
(ALTER TABLE and then any relevant data transmogrification), shut down
the application, run the scripts, then bring up new code that
understands the new schema.  Hibernate may help provide the scripts,
but it won't prevent your downtime.

With large data volumes and significant changes, this process could
take a very very long time.

The schemaless nature of AppEngine makes migration both easier and
harder.  Any entity can have any shape, but there are no bulk
operations.  Furthermore, iterating through your dataset and resaving
each entity is a *very slow* operation.  Batch jobs on my entities
(which have very few indexes) convert less than 100 instances per
second.  Want to convert 1 million entities?  Nearly 3 hours.  10
million?  100 million?  The math is easy.

We designed the Objectify schema migration tools with the assumptions:

 1) You have vast quantities of data
 2) The data is changing rapidly
 3) Any amount of downtime is unacceptable

All transformations within a single entity are pretty easy and
straightforward using @AlsoLoad (on a field, lets you load the old
name as well as the new) or on a method parameter (lets you obtain the
raw data as whatever format you need, munge it, and save it to
whatever set of fields you care).

Condensing multiple entities into a single entity is also fairly
straightforward using @PostLoad and @PrePersist.  I'll provide an
example if you want.

Splitting apart one entity into multiple is by far the hardest
transformation, and there isn't any one solution that works for
everyone.  However, I have done it.  Here is one strategy:

 Starting Entity 
class Person {
@Id Long id;
String addressStreet;
String addressCity;
}

Goal: Create an Address entity and add a foreign key reference in Person.

 Translating Entity 
class Address {
@Id Long id;
String street;
String city;
}
class Person {
@Id Long id;
@LoadOnly String addressStreet;
@LoadOnly String addressCity;
KeyAddress address;

@PrePersist void onSave() {
if (addressStreet != null || addressCity != null) {
Address addy = new Address(addressStreet, addressCity);
address = ObjectifyService.begin().put(addy);
}
}
}

You might also need to implement the getAddressStreet() and
getAddresCity() methods with a check to the address Key and a load of
the Address object.

It's somewhat convoluted, but it does work.  Another alternative,
which gets rid of the complicated getAddressStreet() implementation is
to perform the conversion onLoad():

class Person {
@Id Long id;
@LoadOnly String addressStreet;
@LoadOnly String addressCity;
KeyAddress address;

@PostLoad void onLoad) {
if (addressStreet != null || addressCity != null) {
Address addy = new Address(addressStreet, addressCity);
address = ObjectifyService.begin().put(addy);
ObjectifyService.begin().put(this);
}
}
}

It really depends on the shape of your data and your query profile -
if your app reads a *lot* of entities, you might find the performance
profile of convert-on-save to be better.  Keep in mind that this type
of conversion is a worst case scenario.  Most other schema
migrations are fairly simple.

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Objectify - Twig - approaches to persistence

2010-03-11 Thread Bob
I've recently converted from JDO to Twig.  I've been able to remove an
optimization hack that queried the datastore every 15 minutes to cache
data from a 1+ minute operation.  I can now have end users execute
essentially that same logic in real time.

Have not tried Objectify so I can't comment on the comparison.  From a
framework perspective I'm in the camp of give me an easy and clean
way to do what I do 80% of the time, and a low-level way to do
anything else I need to do.

-Bob

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.