TAILIEUCHUNG - The j2eetm tutorial - phần 8

Các mã nguồn cho ví dụ sau đây là các ví dụ / src / ejb / thư mục rút tiền. Để biên dịch mã, ví dụ / thư mục src và rút tiền kiến loại. Để tạo ra các bảng cơ sở dữ liệu, kiểu kiến tạo-ngân hàng-rút tiền. | 246 Transactions The source code for the following example is in the examples src ejb teller directory. To compile the code go to the examples src directory and type ant teller. To create the database tables type ant create-bank-teller. To demarcate a JTA transaction you invoke the begin commit and rollback methods of the UserTransaction interface. The following code taken from the TellerEJB example program demonstrates the UserTransaction methods. The begin and commit invocations delimit the updates to the database. If the updates fail the code invokes the rollback method and throws an EJBException. public void withdrawCash double amount UserTransaction ut try updateChecking amount machineBalance - amount insertMachine machineBalance catch Exception ex try catch SystemException syex throw new EJBException Rollback failed throw new EJBException Transaction failed Returning Without Committing In a stateless session bean with bean-managed transactions a business method must commit or roll back a transaction before returning. However a stateful session bean does not have this restriction. In a stateful session bean with a JTA transaction the association between the bean instance and the transaction is retained across multiple client calls. Even if each business method called by the client opens and closes the database connection the association is retained until the instance completes the transaction. Summary of Transaction Options 247 In a stateful session bean with a JDBC transaction the JDBC connection retains the association between the bean instance and the transaction across multiple calls. If the connection is closed the association is not retained. Methods Not Allowed in Bean-Managed Transactions Do not invoke the getRoIIbackOnly and setRoIIbackOnly methods of the EJBContext interface. These methods should be used only in container-managed transactions. For bean-managed .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.