Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Vaadin JPAContainer

//Customize JPAContainer to define the logic for

//displaying the node expansion indicator JPAContainer<CelestialBody> bodies =

new JPAContainer<CelestialBody>(CelestialBody.class) { @Override

public boolean areChildrenAllowed(Object itemId) {

// Some simple logic

return getChildren(itemId).size() > 0;

}

};

bodies.setEntityProvider(

new CachingLocalEntityProvider<CelestialBody>( CelestialBody.class, em));

21.5. Entity Providers

Entity providers provide access to entities persisted in a data store.They are essentially wrappers over a JPA entity manager with optimizations and other features important when binding persistent data to a user interface.

The choice and use of entity providers is largely invisible if you create your JPAContainer instances with the JPAContainerFactory, which hides such details.

JPAContainer entity providers can be customized, which is necessary for some purposes. Entity providers can be Enterprise JavaBeans (EJBs), which is useful when you use them in a Java EE application server.

21.5.1. Built-In Entity Providers

JPAContainer includes various kinds of built-in entity providers: caching and non-caching, readwrite and read-only, and batchable.

Caching is useful for performance, but takes some memory for the cache and makes the provider stateful. Batching, that is, running updates in larger batches, can also enhance performance and be used together with caching. It is stateless, but doing updates is a bit more complex than otherwise.

Using a read-only container is preferable if read-write capability is not needed.

All built-in providers are local in the sense that they provide access to entities using a local JPA entity manager.

The CachingMutableLocalEntityProvider is usually recommended as the first choise for readwrite access and CachingLocalEntityProvider for read-only access.

LocalEntityProvider

A read-only, lazy loading entity provider that does not perform caching and reads its data directly from an entity manager.

You can create the provider with makeNonCachedReadOnly() method in JPAContainerFactory.

MutableLocalEntityProvider

Extends LocalEntityProvider with write support. All changes are directly sent to the entity manager.

466

Entity Providers

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]