Slim3 Datastore‎ > ‎Overview‎ > ‎

Data Modeling

Datastore entities are schemaless: Two entities of the same kind are not obligated to have the same properties, or use the same value types for the same properties. The application is responsible for ensuring that entities conform to a schema when needed. For this purpose, Slim3 includes a data modeling features that make enforcing a schema easy.

In Slim3, a model describes a kind of entity, including the types and configuration for its properties. An application defines a model using JavaBeans, with class attributes describing the properties. Entities of a kind are represented by instances of the corresponding model class, with instance attributes representing the property values. An entity can be created by calling the constructor of the class, then stored by calling the put() method.

@Model
public class
Employee {
@Attribute(primaryKey = true)
private Key key;
private String name;
private String role;
private Date hireDate;
private Boolean newHireTrainingCompleted;
...
}

Employee e = new Employee();
e.setRole("manager");
e.setHireDate(new Date());
Datastore.put(e);

The Slim3 Datastore API provides an interface for query. A query returns entities in the form of instances of the model classes that can be modified and put back into the datastore. A meta data of model like EmployeeMeta is created by Annotation Processing Tool automatically.

List<Employee> employees = Datastore.query(Employee.class).asList();
for (Employee emp : employees) {
emp.setNewHireTrainingCompleted(true);
}
Datastore.put(employees);

Next...

Continue to Entities and Properties.

Comments