Creating a model

To store a model in the datastore, you call Datastore.put() method, passing it the instance.
Employee employee = new Employee();
...
Datastore.put(employee);

You can store a model asynchronously as follows:
Employee employee = new Employee();
...
Future<Key> future = Datastore.putAsync(employee);
// Do something
...
// Get the result
Key key = future.get();

The call to Datastore.put() without transaction is synchronous, and doesn't return until the object is saved and indexes are updated.

To save multiple models, call the Datastore.put() method with a Collection of models or an array of models. This method is more efficient than a series of individual Datastore.put() invocations.

List<Employee> list = new ArrayList<Employee>();
for (int i = 0; i < 100; i++) {
    Employee emp = new Employee();
    ...
    list.add(emp);
}
Datastore.put(list);

Employee emp = new Employee();
...
Employee emp2 = new Employee();
...
Datastore.put(emp, emp2);

Next...

Continue to Getting a model by Key.


Comments