Beginning Hibernate From Novice to Professional phần 8

Các bộ lọc được không phải một khái niệm bạn mới có thể đạt được nhiều tác dụng tương tự bằng cách sử dụng cơ sở dữ liệu SQL xem nhưng Hibernate cung cấp một hệ thống quản lý tập trung cho họ. Không giống như quan điểm cơ sở dữ liệu, bộ lọc Hibernate có thể được kích hoạt hay vô hiệu hóa trong một phiên Hibernate. | CHAPTER 11 Filtering the Results of Searches Your application will often need to process only a subset of the data in the database tables. In these cases you can create a Hibernate filter to eliminate the unwanted data. Filters provide a way for your application to limit the results of a query to data that passes the filter s criteria. Filters are not a new concept you can achieve much the same effect using SQL database views but Hibernate offers a centralized management system for them. Unlike database views Hibernate filters can be enabled or disabled during a Hibernate session. In addition Hibernate filters can be parameterized which is particularly useful when you are building applications on top of Hibernate that use security roles or personalization. When to Use Filters As an example consider a web application that manages user profiles. Currently your application presents a list of all users through a single web interface but you receive a change request from your end user to manage active users and expired users separately. For this example assume that the status is stored as a column on the user table. One way to solve this problem is to rewrite every HQL SELECT query in your application adding a WHERE clause that restricts the result by the user s status. Depending on how you built your application this could be an easy undertaking or it could be complex but you still end up modifying code that you have already tested thoroughly potentially changing it in many different places. With Hibernate 3 you can create a filter restriction for the user status. When your end user selects the user type active or expired your application activates the user status filter with the proper status for the end user s Hibernate session. Now any SELECT queries will return the correct subset of results and the relevant code for the user status is limited to two locations the Hibernate session and the user status filter. The advantage of using Hibernate filters is that you can

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
27    88    2    03-07-2024
1    102    2    03-07-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.