Re: [appengine-java] preferred method of deleting child objects (quota/fees)

2010-09-20 Thread Ikai Lan
I wasn't aware setting the child objects to Null actually deleted objects -
doesn't that just orphan the child objects?

Either way, there should be no real difference in datastore CPU costs.

--
Ikai Lan
Developer Programs Engineer, Google App Engine
Blogger: http://googleappengine.blogspot.com
Reddit: http://www.reddit.com/r/appengine
Twitter: http://twitter.com/app_engine



On Sun, Sep 19, 2010 at 1:07 PM, haole mejoe...@gmail.com wrote:

 say i have a persistent parent class, Employee, with a collection of
 child objects, PhoneNumber:

 @PersistenceCapable(identityType = IdentityType.APPLICATION)
 class Employee implements Serializable
 {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id;

@Persistent(mappedBy = employee)
ListPhoneNumber phoneNumbers;
 }

 @PersistenceCapable(identityType = IdentityType.APPLICATION)
 class PhoneNumber implements Serializable
 {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;

@Persistent(mappedBy = phoneNumbers)
Employee employee;

@Persistent
Integer phoneNumber;
 }

 when deleting all child objects (PhoneNumber), there are two possible
 ways to do this:

 (1) set the collection of child objects on the parent object to an
 empty collection (or null):
 static void deletePhoneNumbers( Long p_employeeId, PersistentManager
 p_manager )
 {
Employee l_employee = p_manager.getObjectById( Employee.class,
 p_employeeId );
l_employee.phoneNumbers = new ArrayListPhoneNumber();
p_manager.makePersistent( l_employee );
 }

 or

 (2) delete all child objects belonging to the parent object:
 static void deletePhoneNumbers( Employee p_employee,
 PersistenceManager p_manager )
 {
Query l_query = p_manager.newQuery( PhoneNumber.class );
l_query.setFilter( employee == p_employee );
l_query.declareParameters( Employee p_employee );
l_query.deletePersistentAll( p_employee );
 }

 both ways seem to have the same effect. as one might expect, the
 collection of child objects in the parent array are removed and the
 child objects themselves are removed from the data store.

 my question is:

 as far as hits on the data store (and the quota/fees associated with
 those hits) are concerned, which incurs a greater number of calls
 against the datastore (and, subsequently, incurs more fees)?

 when you look at what's happening in the low-level API, do both ways
 of deleting child objects result in the same number of calls against
 the data store or is one way less costly than the other?

 --
 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.comgoogle-appengine-java%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-appengine-java?hl=en.



-- 
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] preferred method of deleting child objects (quota/fees)

2010-09-19 Thread haole
say i have a persistent parent class, Employee, with a collection of
child objects, PhoneNumber:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
class Employee implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id;

@Persistent(mappedBy = employee)
ListPhoneNumber phoneNumbers;
}

@PersistenceCapable(identityType = IdentityType.APPLICATION)
class PhoneNumber implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;

@Persistent(mappedBy = phoneNumbers)
Employee employee;

@Persistent
Integer phoneNumber;
}

when deleting all child objects (PhoneNumber), there are two possible
ways to do this:

(1) set the collection of child objects on the parent object to an
empty collection (or null):
static void deletePhoneNumbers( Long p_employeeId, PersistentManager
p_manager )
{
Employee l_employee = p_manager.getObjectById( Employee.class,
p_employeeId );
l_employee.phoneNumbers = new ArrayListPhoneNumber();
p_manager.makePersistent( l_employee );
}

or

(2) delete all child objects belonging to the parent object:
static void deletePhoneNumbers( Employee p_employee,
PersistenceManager p_manager )
{
Query l_query = p_manager.newQuery( PhoneNumber.class );
l_query.setFilter( employee == p_employee );
l_query.declareParameters( Employee p_employee );
l_query.deletePersistentAll( p_employee );
}

both ways seem to have the same effect. as one might expect, the
collection of child objects in the parent array are removed and the
child objects themselves are removed from the data store.

my question is:

as far as hits on the data store (and the quota/fees associated with
those hits) are concerned, which incurs a greater number of calls
against the datastore (and, subsequently, incurs more fees)?

when you look at what's happening in the low-level API, do both ways
of deleting child objects result in the same number of calls against
the data store or is one way less costly than the other?

-- 
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.