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

Vaadin JPAContainer

* to explicitly detach them. */

setEntitiesDetached(false);

}

}

If you have more than one EJB provider, you might want to create an abstract super class of the above and only define the entity type in implementations. You can implement an entity provider as a managed bean in Spring Framefork the same way.

21.6. Filtering JPAContainer

Normally, a JPAContainer contains all instances of a particular entity type in the persistence context. Hence, it is equivalent to a database table or query. Just like with database queries, you often want to narrow the results down. JPAContainer implements the Filterable interface in Vaadin containers, described in Section 9.5.7, “Filterable Containers”. All filtering is done at the database level with queries, not in the container.

For example, let us filter all the people older than 117:

Filter filter = new Compare.Greater("age", 117); persons.addContainerFilter(filter);

This would create a JPQL query somewhat as follows:

SELECT id FROM Person WHERE (AGE > 117)

The filtering implementation uses the JPA 2.0 Criteria API transparently. As the filtering is done at the database-level, custom filters that use the Filterable API do not work.

When using Hibernate, note that it does not support implicit joins. See Section 21.9.3, “Joins in Hibernate vs EclipseLink” for more details.

21.7. Querying with the Criteria API

When the Filterable API is not enough and you need to have more control, you can make queries directly with the JPA Criteria API. You may also need to customize sorting or joins, or otherwise modify the query in some way. To do so, you need to implement a QueryModifierDelegate that the JPAContainer entity provider calls when making a query. The easiest way to do this is to extend DefaultQueryModifierDelegate, which has empty implementations of all the methods so that you can only override the ones you need.

The entity provider calls specific QueryModifierDelegate methods at different stages while making a query. The stages are:

1.Start building a query

2.Add "ORDER BY" expression

3.Add "WHERE" expression (filter)

4.Finish building a query

Filtering JPAContainer

469

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