Context
The client requires a list of items from the service for presentation. The number of
items in the list is unknown and can be quite large in many instances.
Problem
Most Java 2 Platform, Enterprise Edition (J2EE) applications have a search and query
requirement to search and list certain data. In some cases, such a search and query operation
could yield results that can be quite large. It is impractical to return the full result set when
the client's requirements are to traverse the results, rather than process the complete set.
Typically, a client uses the results of a query for read-only purposes, such as displaying the
result list. Often, the client views only the first few matching records, and then may discard
the remaining records and attempt a new query. The search activity often does not involve
an immediate transaction on the matching objects. The practice of getting a list of values
represented in entity beans by calling an ejbFind() method, which returns a collection of
remote objects, and then calling each entity bean to get the value, is very network expensive
and is considered a bad practice.
There are consequences associated with using Enterprise JavaBeans (EJB) finder
methods that result in large results sets. Every container implementation has a certain
amount of finder method overhead for creating a collection of EJBObject references. Finder
method behavior performance varies, depending on a vendor's container implementation.
According to the EJB specification, a container may invoke ejbActivate() methods on
entities found by a finder method. At a minimum, a finder method returns the primary keys
of the matching entities, which the container returns to the client as a collection of
EJBObject references. This behavior applies for all container implementations. Some
container implementations may introduce additional finder method overhead by associating
the entity bean instances to these EJBObject instances to give the client access to those
entity beans. However, this is a poor use of resources if the client is not interested in
accessing the bean or invoking its methods. This overhead can significantly impede
application performance if the application includes queries that produce many matching
results.
Forces
The application client needs an efficient query facility to avoid having to call the
entity bean's ejbFind() method and invoking each remote object returned.
A server-tier caching mechanism is needed to serve clients that cannot receive and
process the entire results set.
A query that is repeatedly executed on reasonably static data can be optimized to
provide faster results. This depends on the application and on the implementation of this
pattern.
EJB finder methods are not suitable for browsing entire tables in the database or for
searching large result sets from a table.
Finder methods may have considerable overhead when used to find large numbers of
result objects. The container may create a large number of infrastructure objects to facilitate
the finders.
EJB finder methods are not suitable for caching results. The client may not be able to
handle the entire result set in a single call. If so, the client may need server-side caching and
navigation functions to traverse the result set.
EJB finder methods have predetermined query constructs and offer minimum
flexibility. The EJB specification 2.0 allows a query language, EJB QL, for
container-managed entity beans. EJB QL makes it easier to write portable finders and offers
greater flexibility for querying.
Client wants to scroll forward and backward within a result set.
Solution
Use a Value List Handler to control the search, cache the results, and provide the
results to the client in a result set whose size and traversal meets the client's requirements.
This pattern creates a ValueListHandler to control query execution functionality and
results caching. The ValueListHandler directly accesses a DAO that can execute the
required query. The ValueListHandler stores the results obtained from the DAO as a
collection of Transfer Objects. The client requests the ValueListHandler to provide the
query results as needed. The ValueListHandler implements an Iterator pattern [GoF] to
provide the solution.
- 浏览: 15368 次
- 性别:
- 来自: 北京
文章分类
最新评论
发表评论
-
集成层模式:Service Activator—服务激发器模式
2014-04-09 20:31 1107ContextEnterprise beans and o ... -
集成层模式:Data Access Object—数据访问对象模式
2014-04-09 20:31 533ContextAccess to data varies ... -
业务层模式:Service Locator—服务定位器模式
2014-04-09 20:31 1167ContextService lookup and cre ... -
表示层模式:Transfer Object Assembler—传输对象组装器模式
2014-04-10 22:48 757ContextIn a Java 2 Platform, ... -
业务层模式:Composite Entity—复合实体模式
2014-04-08 21:38 497ContextEntity beans are not i ... -
业务层模式:Session Facade—会话门面模式
2014-04-08 21:38 423ContextEnterprise beans encap ... -
业务层模式:Transfer Object—传输对象模式
2014-04-08 21:37 434ContextApplication clients ne ... -
业务层模式:Business Delegate—业务委托模式
2014-04-08 21:37 983ContextA multi-tiered, distri ... -
表示层模式:Dispatcher View—分发者视图模式
2014-04-08 21:37 543ContextSystem controls flow o ... -
表示层模式:Service to Worker—工作者服务模式
2014-04-07 10:48 988ContextThe system controls flow ... -
表示层模式:Front Controller—前端控制器模式
2014-04-07 10:45 377ContextThe presentation-tier re ... -
表示层模式:Composite View—复合视图模式
2014-04-07 10:41 490ContextSophisticated Web page ... -
表示层模式:View Helper—视图助手模式
2014-04-07 10:37 1028ContextThe system creates pre ... -
表示层模式:Intercepting Filter—拦截过滤器模式
2014-04-07 10:29 627Context The presentati ...
相关推荐
- **值列表处理器**(Value List Handler):处理值列表的逻辑。 #### 集成层模式 集成层模式关注于如何将J2EE应用与其他系统或服务进行有效集成,包括消息传递、事务管理和持久化策略等。 J2EE模式的引入,极大...
3. **事件处理器层(Event Handler Layer)**: - 负责处理来自核心层的事件,并将这些事件转换为应用程序可以理解的形式。 - 比如,`evdev`事件处理器就是将输入事件转化为用户空间程序可以通过标准读写操作访问...
- **typeHandlers**:自定义类型处理器,处理Java类型和数据库类型的转换。 - **示例**:`<typeHandler handler="com.example.handler.MyTypeHandler"/>` - **objectFactory**:用于创建POJO实例的工厂,可以定制...
- **定义**:MyBatis是一款优秀的支持自定义SQL、存储过程以及高级映射的持久层框架。它极大地简化了JDBC代码的编写,几乎消除了所有JDBC相关的编码工作,如设置参数、获取结果集等,并提供了基于XML配置文件或注解...
MyBatis ...-- 返回list 的select 语句,注意 resultMap 的值是指向前面定义好的 --> select * from user where userName like #{userName} 在 IUserOperation 接口中增加方法:public List...
<param-value>true</param-value> <filter-name>hibernateFilter *.do ``` 这里`singleSession`参数默认为`true`,表示在整个请求生命周期内只使用一个Session。如果设置为`false`,则每个请求都会创建新...
3. **HandlerMapping 映射处理器**:`DispatcherServlet` 将请求转发给 `HandlerMapping` 接口的实现类,根据 URL 映射规则找到合适的控制器方法(Handler)来处理请求。 4. **HandlerAdapter 处理请求**:`...
- **定义**:Spring MVC 是一种基于 Java 的轻量级 Web 框架,它实现了 MVC(Model-View-Controller)设计模式。该框架通过将 Web 层进行职责解耦,帮助开发者简化 Web 应用程序的开发过程。 - **工作原理**:...
8. **dart_list.cc**:这个文件实现了Dart列表在C++中的表示,使得C++能够处理Dart数组。 9. **dart_library_natives.cc**:DartLibraryNatives包含了对Dart原生函数的注册和调用逻辑,使得C++可以直接调用Dart的...
<param-value>true</param-value> <filter-name>hibernateFilter *.do ``` 在`web.xml`中定义`OpenSessionInViewFilter`,并将其映射到所有以`.do`结尾的请求路径上。这里特别需要注意`singleSession`...