Entity - 0 views
-
Entity is the fundamental unit of data storage. It has an immutable identifier (contained in the Key) object, a reference to an optional parent Entity, a kind (represented as an arbitrary string), and a set of zero or more typed properties.
-
setProperty public void setProperty(java.lang.String propertyName, java.lang.Object value) Sets the property named, propertyName, to value. As the value is stored in the datastore, it is converted to the datastore's native type. This may include widening, such as converting a Short to a Long. All Collections are prone to losing their sort order and their original types as they are stored in the datastore. For example, a TreeSet may be returned as a List from getProperty(java.lang.String), with an arbitrary re-ordering of elements. Overrides any existing value for this property, whether indexed or unindexed. Note that Blob and Text property values are never indexed by the built-in single property indexes. To store other types without being indexed, use #setUnindexedProperty. Parameters:value - may be one of the supported datatypes, a heterogenous Collection of one of the supported datatypes, or an UnindexedValue wrapping one of the supported datatypes. Throws: java.lang.IllegalArgumentException - If the value is not of a type that the data store supports.
KeyRange - 0 views
-
public final class KeyRangeextends java.lang.Objectimplements java.lang.Iterable<Key>, java.io.Serializable Represents a range of unique datastore identifiers from getStart().getId() to getEnd().getId() inclusive. The Keys returned by an instance of this class have been consumed in the datastore's id-space and are guaranteed never to be reused. This class can be used to construct Entities with Keys that have specific id values without fear of the datastore creating new records with those same ids at a later date. This can be helpful as part of a data migration or large bulk upload where you may need to preserve existing ids and relationships between entities. This class is threadsafe but the Iterators returned by iterator() are not.
Kinds, Names and IDs (Slim3) - 0 views
Creating, Getting and Deleting Data - Google App Engine - Google Code - 0 views
-
Every entity has a key that is unique over all entities in App Engine. A complete key includes several pieces of information, including the application ID, the kind, and an entity ID. (Keys also contain information about entity groups; see Transactions for more information.) An object's key is stored in a field on the instance. You identify the primary key field using the @PrimaryKey annotation. The app can provide the ID portion of the key as a string when the object is created, or it can allow the datastore to generate a numeric ID automatically. The complete key must be unique across all entities in the datastore. In other words, an object must have an ID that is unique across all objects of the same kind and with the same entity group parent (if any). You select the desired behavior of the key using the type of the field and annotations. If the class is used as a "child" class in a relationship, the key field must be of a type capable of representing an entity group parent: either a Key instance, or a Key value encoded as a string. See Transactions for more information on entity groups, and Relationships for more information on relationships. Tip: If the app creates a new object and gives it the same string ID as another object of the same kind (and the same entity group parent), saving the new object overwrites the other object in the datastore. To detect whether a string ID is already in use prior to creating a new object, you can use a transaction to attempt to get an entity with a given ID, then create one if it doesn't exist. See Transactions. There are 4 types of primary key fields:
Key - 0 views
-
public final class Keyextends java.lang.Objectimplements java.io.Serializable, java.lang.Comparable<Key> The primary key for a datastore entity. A datastore GUID. A Key instance uniquely identifies an entity across all apps, and includes all information necessary to fetch the entity from the datastore with DatastoreService.get(Key). You can create Key objects directly by using KeyFactory.createKey(java.lang.String, long) or getChild(java.lang.String, long). You can also retrieve the Key automatically created when you create a new Entity, or serialize Key objects, or use KeyFactory to convert them to and from websafe String values.
-
equals public boolean equals(java.lang.Object object) Compares two Key objects by comparing ids, kinds, parent and appIdNamespace. If both keys are assigned names rather than ids, compares names instead of ids. If neither key has an id or a name, the keys are only equal if they reference the same object.
-
compareTo public int compareTo(Key other) Compares two Key objects. The algorithm proceeds as follows: Turn each Key into an iterator where the first element returned is the top-most ancestor, the next element is the child of the previous element, and so on. The last element will be the Key we started with. Once we have assembled these two iterators (one for 'this' and one for the Key we're comparing to), consume them in parallel, comparing the next element from each iterator. If at any point the comparison of these two elements yields a non-zero result, return that as the result of the overall comparison. If we exhaust the iterator built from 'this' before we exhaust the iterator built from the other Key, we return less than. An example: app1.type1.4.app1.type2.9 < app1.type1.4.app1.type2.9.app1.type3.2 If we exhaust the iterator built from the other Key before we exhaust the iterator built from 'this', we return greater than. An example: app1.type1.4.app1.type2.9.app1.type3.2 > app1.type1.4.app1.type2.9 The relationship between individual Key Keys is performed by comparing app followed by kind followed by id. If both keys are assigned names rather than ids, compares names instead of ids. If neither key has an id or a name we return an arbitrary but consistent result. Assuming all other components are equal, all ids are less than all names.
Entity - 0 views
-
public void setProperty(java.lang.String propertyName, java.lang.Object value) Sets the property named, propertyName, to value. As the value is stored in the datastore, it is converted to the datastore's native type. This may include widening, such as converting a Short to a Long. All Collections are prone to losing their sort order and their original types as they are stored in the datastore. For example, a TreeSet may be returned as a List from getProperty(java.lang.String), with an arbitrary re-ordering of elements. Overrides any existing value for this property, whether indexed or unindexed. Note that Blob and Text property values are never indexed by the built-in single property indexes. To store other types without being indexed, use #setUnindexedProperty. Parameters:value - may be one of the supported datatypes, a heterogenous Collection of one of the supported datatypes, or an UnindexedValue wrapping one of the supported datatypes. Throws: java.lang.IllegalArgumentException - If the value is not of a type that the data store supports.
Gist - GitHub - 0 views
Entity ID and keyName identification scope - Google App Engine for Java - 0 views
-
'm guessing your tests were run locally because the counter in the local datastore does indeed have datastore scope. The scope of the counter in the prod datastore, however, is parent key + kind. This is described here: http://code.google.com/appengine/docs/java/datastore/creatinggettinga... If it's important to you that the scope of the generated ids match between dev and and prod please file an issue.
-
StringBuffer sb = new StringBuffer(); KeyRange range = ds.allocateIds("a", 2); for (Key key : range) { sb.append("\n a " + key.toString()); } range = ds.allocateIds("b", 2); for (Key key : range) { sb.append("\n b " + key.toString()); } Key parentKey = KeyFactory.createKey("c", 1); sb.append("\n c " + parentKey.toString()); range = ds.allocateIds(parentKey, "d", 2); for (Key key : range) { sb.append("\n d " + key.toString()); } System.out.println(sb.toString());
-
The URL I posted earlier in the thread explains it, but here's a little bit more detail: A parent entity plus a kind defines an id-space, so entities with the same parent and the same kind are guaranteed to have unique ids. For example, if you have an Entity with Parent:A Kind: Person Id: 10 you are guaranteed that no other entity with Parent A and Kind Person will be assigned an Id of 10. However, an entity with a different Parent and Kind Person or an entity with Parent A and a different Kind _can_ be assigned an Id of 10. The datastore pre-allocates batches of ids across multiple servers under-the-hood, so you can't make any assumptions about the Id that will get assigned in terms of contiguousness. The only safe assumption is that the id will be unique for that Parent/Kind combination.
- ...1 more annotation...
com.google.appengine.api.datastore - 0 views
-
If using the datastore API directly, a common pattern of usage is: // Get a handle on the datastore itself DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); // Lookup data by known key name Entity userEntity = datastore.get(KeyFactory.createKey("UserInfo", email)); // Or perform a query Query query = new Query("Task", userEntity); query.addFilter("dueDate", Query.FilterOperator.LESS_THAN, today); for (Entity taskEntity : datastore.prepare(query).asIterable()) { if ("done".equals(taskEntity.getProperty("status"))) { datastore.delete(taskEntity); } else { taskEntity.setProperty("status", "overdue"); datastore.put(taskEntity); } }
-
If using the datastore API directly, a common pattern of usage is: // Get a handle on the datastore itself DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); // Lookup data by known key name Entity userEntity = datastore.get(KeyFactory.createKey("UserInfo", email)); // Or perform a query Query query = new Query("Task", userEntity); query.addFilter("dueDate", Query.FilterOperator.LESS_THAN, today); for (Entity taskEntity : datastore.prepare(query).asIterable()) { if ("done".equals(taskEntity.getProperty("status"))) { datastore.delete(taskEntity); } else { taskEntity.setProperty("status", "overdue"); datastore.put(taskEntity); } }
App Engine Recipe - Bypass 500 put/delete and 1000 get limit - 0 views
Developer's Notes: Lists and Nulls in Google App Engine Datastore - 0 views
-
So the summary is: do not store nulls into Lists, otherwise you will get into a problem in future.
mindash-datastore - Project Hosting on Google Code - 0 views
-
This project is a framework for storing entities larger than 1MB using the Google App Engine low-level datastore API.
Parallel Asynchronous Datastore Commands with Twig 1.0 - Google App Engine for Java | G... - 1 views
-
Twig is an alternative to the standard persistence interfaces JDO and JPA, specifically designed to make the most of the underlying datastore's unique features.
-
Twig is the only interface to support direct unowned relationships so your code is not dependent on low-level datastore classes. It is the only interface to support OR queries by merging together multiple queries, sorting them and filtering out duplicates at the lowest level for performance.
-
Async datastore calls are not yet part of the low-level API. Twig uses the underlying Protocol Buffer layer classes to call ApiProxy.makeAsyncCall() instead of makeSyncCall. All the code is open source so you can check out how its done.
Async Datastore API - Google App Engine for Java | Google Groups - 0 views
-
> I'm still curious where does "method" name come from? That is just "Get" of "Put" or "RunQuery" etc. I have also checked in an implementation of Nick Johnsons ApiProxyHook which logs all this info: LoggingApiProxyDelegate. Its handy for seeing how what rpc calls are being made. If you want to discuss Twig specifics probably best to do that here http://groups.google.com/group/twig-persist
How to browse local Java App Engine datastore? - Stack Overflow - 0 views
-
protocol
-
ublic void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); final DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); final Query query = new Query("Table/Entity Name"); //query.addSort(Entity.KEY_RESERVED_PROPERTY, Query.SortDirection.DESCENDING); for (final Entity entity : datastore.prepare(query).asIterable()) { resp.getWriter().println(entity.getKey().toString()); final Map<String, Object> properties = entity.getProperties(); final String[] propertyNames = properties.keySet().toArray( new String[properties.size()]); for(final String propertyName : propertyNames) { resp.getWriter().println("-> " + propertyName + ": " + entity.getProperty(propertyName)); } }}
Low Level API - Batch Insert - Preserving Parent-Child Relationship - Google App Engine... - 0 views
-
It would need to be something like Transaction txn = dataStore.beginTransaction(); Key key = dataStore.put(txn, question); Entity a1 = new Entity("Answer", key); Entity a2 = new Entity("Answer", key); dataStore.put(txn, a1); dataStore.put(txn, a2); txn.commit();