Java Reference
In-Depth Information
3. Key : A value that includes the key of any entity-group parent that is
being used and an application-generated string ID or a system-
generated numeric ID.
4. Key as Encoded String : Essentially, an encoded key to ensure
portability and still allow your application to take advantage of
Bigtable's entity groups.
If you want to implement your own key system, you simply use the createKey static
method of the KeyFactory class. You pass the method the kind and either an
application-assigned string or a system-assigned number, and the method returns
the appropriate Key instance. So, to create a key for an Order entity with the key
name "" you would use:
Key key = KeyFactory.createKey(Order.class.getSimpleName(),
" m");
Note If your implementation inadvertently creates a duplicate key for your entity, this new entity will
overwrite the existing entity in the datastore.
Listing 7-1 is an example JDO class with an automatically generated Long ID provided
by Bigtable with both persisted and non-persisted fields. The phone member is only
available within the scope of the object and is not persisted to the database. Entities
created from a database call will contain a null value for the phone member.
Listing 7-1. Sample JDO POJO
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PrimaryKey;
// Declares the class as capable of being stored and retrieved with JDO
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Contact {
// Required primary key populated automatically by JDO
Search WWH ::

Custom Search