Đang chuẩn bị liên kết để tải về tài liệu:
Beginning Hibernate From Novice to Professional phần 9

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Ngoài ra, bộ lọc Hibernate có thể được tham số, trong đó đặc biệt hữu ích khi bạn đang xây dựng các ứng dụng trên đầu trang của Hibernate rằng vai trò an ninh sử dụng hoặc cá nhân. Ví dụ, hãy xem xét một ứng dụng web quản lý hồ sơ người dùng. | APPENDIX A MORE ADVANCED FEATURES 259 Transaction tx session.beginTransaction Make our bookings. session.save new Booking dave F1 session.save new Booking jeff C3 The confirmation letters should not be sent out until AFTER the commit completes. tx.commit The interceptor that we are applying is going to capture the information from the Booking objects that we are storing in the database. Listing A-26 demonstrates the basic mechanism but it is only a toy example. We will discuss some of its deficiencies in a moment. Listing A-26. An Interceptor Implementation package com.hibernatebook.advanced.events import java.io.Serializable import java.util.Collection import java.util.HashSet import java.util.Iterator import org.hibernate.CallbackException import org.hibernate.EntityMode import org.hibernate.Interceptor import org.hibernate.Transaction import org.hibernate.type.Type public class BookingInterceptor implements Interceptor public BookingInterceptor private ThreadLocal stored new ThreadLocal public void afterTransactionBegin Transaction tx stored.set new HashSet public void afterTransactionCompletion Transaction tx if tx.wasCommitted Iterator i Collection stored.get .iterator 260 APPENDIX A MORE ADVANCED FEATURES while i.hasNext Booking b Booking i.next sendMail b stored.set null public boolean onSave Object entity Serializable id Object state String propertyNames Type types throws CallbackException Collection stored.get .add entity return false private void sendMail Booking b Here we would actually send out the e-mail System.out.print Name b.getName System.out.println Seat b.getSeat public void beforeTransactionCompletion Transaction tx public int findDirty Object entity Serializable id Object currentState Object previousState String propertyNames Type types return null public Object getEntity String entityName Serializable id throws CallbackException return null public String getEntityName Object object throws CallbackException return null public Object instantiate

crossorigin="anonymous">
Đã 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.