[appengine-java] Re: Possible to Add Child to Owned One to Many Relationship Without Loading All Children?

2009-10-21 Thread leszek

You hit the nail on the head. As far as I know there is nothing like
sequence in Google App Engine. Either you need to have another
entity with a counter and increase it in transactional way. Or you can
use memcache.

http://code.google.com/intl/pl/appengine/docs/java/javadoc/com/google/appengine/api/memcache/MemcacheService.html

There is a method:

java.lang.Long  increment(java.lang.Object key, long delta)
  Atomically fetches, increments, and stores a given integral
value.
---

Pay attention to atomically. May be this can be used for generating
sequential and avoid bottleneck in the case of datastore entity and
additional transaction. But because of the risk of memcache expiring
this method needs some more elaboration.
--~--~-~--~~~---~--~~
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-java@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: Possible to Add Child to Owned One to Many Relationship Without Loading All Children?

2009-10-21 Thread Nacho Coloma

Maybe what you are looking for is DatastoreService.allocateIds().

On Oct 21, 9:35 am, leszek leszek.ptokar...@gmail.com wrote:
 You hit the nail on the head. As far as I know there is nothing like
 sequence in Google App Engine. Either you need to have another
 entity with a counter and increase it in transactional way. Or you can
 use memcache.

 http://code.google.com/intl/pl/appengine/docs/java/javadoc/com/google...

 There is a method:
 
 java.lang.Long  increment(java.lang.Object key, long delta)
           Atomically fetches, increments, and stores a given integral
 value.
 ---

 Pay attention to atomically. May be this can be used for generating
 sequential and avoid bottleneck in the case of datastore entity and
 additional transaction. But because of the risk of memcache expiring
 this method needs some more elaboration.
--~--~-~--~~~---~--~~
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-java@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: Possible to Add Child to Owned One to Many Relationship Without Loading All Children?

2009-10-21 Thread lent

Thanks Nacho.  I asked the same question in google appengine chat irc
and got the same answer.  Will have to use the allocate id feature in
low level api.

Len

On Oct 21, 7:41 am, Nacho Coloma icol...@gmail.com wrote:
 Maybe what you are looking for is DatastoreService.allocateIds().

 On Oct 21, 9:35 am, leszek leszek.ptokar...@gmail.com wrote:



  You hit the nail on the head. As far as I know there is nothing like
  sequence in Google App Engine. Either you need to have another
  entity with a counter and increase it in transactional way. Or you can
  use memcache.

 http://code.google.com/intl/pl/appengine/docs/java/javadoc/com/google...

  There is a method:
  
  java.lang.Long  increment(java.lang.Object key, long delta)
            Atomically fetches, increments, and stores a given integral
  value.
  ---

  Pay attention to atomically. May be this can be used for generating
  sequential and avoid bottleneck in the case of datastore entity and
  additional transaction. But because of the risk of memcache expiring
  this method needs some more elaboration.- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
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-java@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: Possible to Add Child to Owned One to Many Relationship Without Loading All Children?

2009-10-20 Thread leszek

I'm afraid that it is not possible.
But if the purpose of your relationship is only to manage child class
in a transactional way you don't need to keep them as a part of child
relationship.

Simply use Key type and set 'parent' part of the child' key being the
same and you can manage them in the same transaction.
--~--~-~--~~~---~--~~
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-java@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: Possible to Add Child to Owned One to Many Relationship Without Loading All Children?

2009-10-20 Thread lent

Thanks leszek.  We are going do what you suggest (the JPA
equivalent).

In order to generate the unique part of the child's key, I'm wondering
if there is a way to use sequence in JPA.  In JDO, I think you can do
something like:

Sequence seq = pm.getSequence(child.sequence);
long id = seq.nextValue();

Does anyone know if  there is an equivalent to this in JPA, i.e. to
get direct access to a sequence?

Thanks,
Len


On Oct 20, 4:04 am, leszek leszek.ptokar...@gmail.com wrote:
 Look at the code snippet below:

 // entity class

 @PersistenceCapable(identityType = IdentityType.APPLICATION)
 public class ChildEnt {

     @PrimaryKey
     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 //   �...@extension(vendorName=datanucleus, key=gae.encoded-
 pk,value=true)
     private Key encodedKey;

     private String info;

         public Key getEncodedKey() {
                 return encodedKey;
         }

         public void setEncodedKey(Key encodedKey) {
                 this.encodedKey = encodedKey;
         }

         public String getInfo() {
                 return info;
         }

         public void setInfo(String info) {
                 this.info = info;
         }

 }

 // transaction code

         PersistenceManager pm = PMF.get().getPersistenceManager();

         Key parkey = KeyFactory.createKey(Parent,P01);

         ChildEnt e1 = new ChildEnt();
         ChildEnt e2 = new ChildEnt();
         ChildEnt e3 = new ChildEnt();
         Key k1 = KeyFactory.createKey(parkey,ChildEnt.class.getSimpleName(),
 1);
         Key k2 = KeyFactory.createKey(parkey,ChildEnt.class.getSimpleName(),
 2);
         Key k3 = KeyFactory.createKey(parkey,ChildEnt.class.getSimpleName(),
 3);
         e1.setEncodedKey(k1);
         e1.setInfo(info1);
         e2.setEncodedKey(k2);
         e2.setInfo(info2);
         e3.setEncodedKey(k3);
         e3.setInfo(info3);
         pm.currentTransaction().begin();
         pm.makePersistent(e1);
         pm.makePersistent(e2);
         pm.makePersistent(e3);
         pm.currentTransaction().commit();
         pm.close();
--~--~-~--~~~---~--~~
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-java@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
-~--~~~~--~~--~--~---