Data Stores

DataStores connect a data model to a persistence layer and provide transactions that make all persistence operationsatomic in a single request.

Included Stores

Elide comes bundled with a number of data stores:

  • Hibernate - Hibernate is a JPA provider that can map operations on a data model to an underlying relational database (ORM) or nosql persistence layer (OGM). Elide supports stores for Hibernate 3 and 5.
  • In Memory Store - Data is persisted in a hash table on the JVM heap.
  • Multiplex Store - A multiplex store delegates persistence to different underlying stores depending on the data model.
  • Noop Store - A store which does nothing allowing business logic in computed attributes and life cycle hooks to entirely implement CRUD operations on the model.
    Stores can be included through the following artifact dependencies:

Hibernate Store

  1. <dependency>
  2. <groupId>com.yahoo.elide</groupId>
  3. <artifactId>elide-datastore-hibernate5</artifactId>
  4. <version>4.0</version>
  5. </dependency>

In Memory Store

  1. <dependency>
  2. <groupId>com.yahoo.elide</groupId>
  3. <artifactId>elide-datastore-inmemorydb</artifactId>
  4. <version>4.0</version>
  5. </dependency>

Multiplex Store

  1. <dependency>
  2. <groupId>com.yahoo.elide</groupId>
  3. <artifactId>elide-datastore-multiplex</artifactId>
  4. <version>4.0</version>
  5. </dependency>

Noop Store

  1. <dependency>
  2. <groupId>com.yahoo.elide</groupId>
  3. <artifactId>elide-datastore-noop</artifactId>
  4. <version>4.0</version>
  5. </dependency>

Overriding the Store

The elide-standalone artifact is the simplest way to get started with Elide. It runs an embedded Jetty container withcommon default settings including the Hibernate 5 data store.

To change the store, the ElideStandaloneSettings interface can be overridden to change the function which builds the ElideSettings object:

  1. /**
  2. * Elide settings to be used for bootstrapping the Elide service. By default, this method constructs an
  3. * ElideSettings object using the application overrides provided in this class. If this method is overridden,
  4. * the returned settings object is used over any additional Elide setting overrides.
  5. *
  6. * That is to say, if you intend to override this method, expect to fully configure the ElideSettings object to
  7. * your needs.
  8. *
  9. * @param injector Service locator for web service for dependency injection.
  10. * @return Configured ElideSettings object.
  11. */
  12. default ElideSettings getElideSettings(ServiceLocator injector) {
  13. DataStore dataStore = new InjectionAwareHibernateStore(
  14. injector, Util.getSessionFactory(getHibernate5ConfigPath(), getModelPackageName()));
  15. EntityDictionary dictionary = new EntityDictionary(getCheckMappings());
  16. return new ElideSettingsBuilder(dataStore)
  17. .withUseFilterExpressions(true)
  18. .withEntityDictionary(dictionary)
  19. .withJoinFilterDialect(new RSQLFilterDialect(dictionary))
  20. .withSubqueryFilterDialect(new RSQLFilterDialect(dictionary))
  21. .build();
  22. }

Custom Stores

Custom stores can be written by implenting the DataStore and DataStoreTransaction interfaces.

原文: http://elide.io/pages/guide/06-datatstores.html