tailieunhanh - More Java Pitfalls 50 New Time-Saving Solutions and Workarounds phần 9

Chúng tôi vẫn có thể giải quyết vấn đề, nhưng bây giờ thay vì ngăn chặn nhiều trình, chúng ta cần phải xử lý chúng trở lại vào cuối, thông qua servlet xử lý hình thức. Để hiểu làm thế nào để giải quyết vấn đề trình nhiều, trước tiên chúng ta phải hiểu như thế nào servlet làm việc liên quan đến phiên. | 364 Item 42 Of the approaches we ve discussed so far this seems to have the most merit. In the past it has been difficult to make SQL calls to get autogenerated IDs in a nonproprietary way. It was also a challenge to get the autogenerated key right after the insert ỉimpo PDF Mể ẽwi1àí pnt5jifìrêơistépediVềrồi gpníh w wĩBiWípẽ iỉífĩìẵomìsuit-set. Luckily wMt the ae insertSdrow nanmJumtto geverated key using the gedGenergtedtteya i merhodrnj SQL. sqe i o tatement aseanbe seen in the code segment below tt intprimkey 0. Statements s . execute INSERa ewroveirkOUSKRS name phone address creditcard VALUES MattVanWie 555-9509 91 Habib Ave 20822t902033X9aS Resultset rs 3 3 geOGeneratedKeys if primkey l Many developer ausingantaalier version of the JDK or JDBC or earlier drivers that cannot take advantage of this feature use stored procedures in SQL that can be called from Java widuhe CaUabl taternent interface. The Stored Procedures for Autogenerated Keys EJB Design Pattern from Floyd Marinescu s book EỊB Design Pat-tems provides sucha soOvJisethatdeesan msevt vnd eseurnstVeeutogenereted key ASSESSMENt meeSt tJr eeltmsotfJDKlAana Shva diJyeoget generated keys rrtvsnndddomthei grth. roardesesvand mechanism for soltmveOeEOB pvmarykeypreblem. Other Approaches It is importantto note tìnaOEỊB DesihnPattnns MarinesnUi 2002 discussed in the previous section provides a few design patterns to solve this problem. One worth mentioning is a Universally Unique Identifier UUID pattern for EJB which is a database-independent se rver-sidealgorithm for generating primary keys. Another pattern called Sequence Blddss reeatssprirnary hn ìvithiteìaeisdataUmaìe ím í usinịịa combination of ansmJiJybeontdarvesverana eounier aeG aaeatels ss svesionbeasthdt caches many primary keys from the entity bean at a time. Marinescu Floyd-EnSDemvez Witey .