KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > ObjectImageTest


1 package org.apache.ojb.odmg;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import java.io.Serializable JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Date JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import org.apache.commons.lang.SerializationUtils;
26 import org.apache.commons.lang.SystemUtils;
27 import org.apache.commons.lang.builder.EqualsBuilder;
28 import org.apache.ojb.broker.Identity;
29 import org.apache.ojb.broker.query.Criteria;
30 import org.apache.ojb.broker.query.Query;
31 import org.apache.ojb.broker.query.QueryFactory;
32 import org.apache.ojb.broker.core.proxy.CollectionProxy;
33 import org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl;
34 import org.apache.ojb.broker.core.proxy.CollectionProxyListener;
35 import org.apache.ojb.broker.core.proxy.IndirectionHandler;
36 import org.apache.ojb.broker.core.proxy.MaterializationListener;
37 import org.apache.ojb.broker.core.proxy.ProxyHelper;
38 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
39 import org.apache.ojb.junit.ODMGTestCase;
40 import org.odmg.OQLQuery;
41 import org.odmg.Transaction;
42
43 /**
44  * Check the quality of object image comparison:
45  * - new referenced objects
46  * - deleted referenced objects
47  * - deleted referenced objects
48  * ...etc.
49  *
50  * Test cases for refactored odmg-api implementation. These tests asserts previously outstanding
51  * ODMG-issues and proxy object handling in the ODMG API.
52  *
53  * @author <a HREF="mailto:arminw@apache.org">Armin Waibel</a>
54  * @version $Id: ObjectImageTest.java,v 1.1.2.8 2005/12/13 18:18:25 arminw Exp $
55  */

56 public class ObjectImageTest extends ODMGTestCase
57 {
58     static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE;
59     static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK;
60     static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT;
61     static final String JavaDoc EOL = SystemUtils.LINE_SEPARATOR;
62
63     public static void main(String JavaDoc[] args)
64     {
65         junit.textui.TestRunner.main(new String JavaDoc[]{ObjectImageTest.class.getName()});
66     }
67
68     public void testReplaceOneToOneReference() throws Exception JavaDoc
69     {
70         String JavaDoc prefix = "testReplaceOneToOneReference_" + System.currentTimeMillis();
71         ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, false);
72
73         TransactionExt tx = (TransactionExt) odmg.newTransaction();
74         tx.begin();
75         Book book = new Book(prefix, null, null);
76         Publisher p_1 = new PublisherImpl(prefix);
77         Publisher p_2 = new PublisherImpl(prefix + "_replaced");
78         book.setPublisher(p_1);
79         database.makePersistent(book);
80         database.makePersistent(p_1);
81         database.makePersistent(p_2);
82         tx.commit();
83
84         Integer JavaDoc book_version = book.getVersion();
85         Integer JavaDoc p1_version = p_1.getVersion();
86         Integer JavaDoc p2_version = p_2.getVersion();
87
88         tx.begin();
89         tx.lock(book, Transaction.WRITE);
90         tx.lock(book.getPublisher(), Transaction.READ);
91         tx.lock(p_2, Transaction.READ);
92         book.setPublisher(p_2);
93         tx.commit();
94
95         assertEquals(book_version.intValue() + 1, book.getVersion().intValue());
96         assertEquals(p1_version, p_1.getVersion());
97         assertEquals(p2_version, p_2.getVersion());
98     }
99
100     public void testAddCollectionObjectToExistingObject() throws Exception JavaDoc
101     {
102         String JavaDoc prefix = "testAddCollectionObjectToExistingObject_" + System.currentTimeMillis();
103         ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, false);
104
105         TransactionExt tx = (TransactionExt) odmg.newTransaction();
106         tx.begin();
107         Book book = new Book(prefix, null, null);
108         Review r1 = new Review(prefix + "_1");
109         database.makePersistent(book);
110         database.makePersistent(r1);
111         tx.commit();
112
113         Integer JavaDoc book_version = book.getVersion();
114         Integer JavaDoc r_1_version = r1.getVersion();
115
116         Review r2 = new Review(prefix + "_2");
117         tx.begin();
118         tx.lock(r1, Transaction.WRITE);
119         tx.lock(book, Transaction.READ);
120         book.addReview(r1);
121         book.addReview(r2);
122         database.makePersistent(r2);
123         tx.commit();
124
125         assertEquals(book_version, book.getVersion());
126         assertTrue(book.getId() != null);
127
128         Integer JavaDoc r_2_version = r2.getVersion();
129
130         tx.begin();
131         tx.getBroker().clearCache();
132         Book loadedCopy = (Book) tx.getBroker().getObjectByIdentity(
133                 tx.getBroker().serviceIdentity().buildIdentity(Book.class, book.getId()));
134         assertNotNull(loadedCopy);
135         assertNotNull(loadedCopy.getReviews());
136         assertEquals(2, loadedCopy.getReviews().size());
137         assertEquals(book_version, loadedCopy.getVersion());
138         Review new_r1 = (Review) loadedCopy.getReviews().get(0);
139         Review new_r2 = (Review) loadedCopy.getReviews().get(1);
140         assertEquals(r_1_version.intValue() + 1, new_r1.getVersion().intValue());
141         assertEquals(r_2_version, new_r2.getVersion());
142
143         tx.getBroker().clearCache();
144         Criteria criteria = new Criteria();
145         criteria.addLike("title", prefix);
146         Query q = QueryFactory.newQuery(Book.class, criteria);
147         Collection JavaDoc books = tx.getBroker().getCollectionByQuery(q);
148         assertNotNull(books);
149         assertEquals(1, books.size());
150         Book new_book = (Book) books.iterator().next();
151         tx.commit();
152         assertEquals(book_version, new_book.getVersion());
153
154         tx.begin();
155         tx.lock(loadedCopy, Transaction.WRITE);
156         Review removed = (Review) loadedCopy.getReviews().remove(0);
157         Review stayed = (Review) loadedCopy.getReviews().get(0);
158         tx.commit();
159         // expect same version, nothing should be changed
160
assertEquals(r_2_version, stayed.getVersion());
161         //
162
//assertEquals(r_1_version, removed.getVersion());
163

164         tx.begin();
165         OQLQuery query = odmg.newOQLQuery();
166         query.create("select books from " + Book.class.getName() + " where title like $1");
167         query.bind(prefix);
168         Collection JavaDoc result = (Collection JavaDoc) query.execute();
169         assertEquals(1, result.size());
170         Book b = (Book) result.iterator().next();
171         tx.commit();
172
173         assertEquals(1, b.getReviews().size());
174         Review r = (Review) b.getReviews().get(0);
175         if(!r.equals(r1) && !r.equals(r2))
176         {
177             fail("Wrong object or wrong object version returned. Returned obj was "
178                     + EOL + r + " expected object was " + EOL + r1 + " or " + EOL + r2);
179         }
180     }
181
182     /**
183      * test persistence by reachability of collection reference objects
184      */

185     public void testPersistenceByReachability_1() throws Exception JavaDoc
186     {
187         String JavaDoc name = "testPersistenceByReachability_1_" + System.currentTimeMillis();
188         ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
189
190         Date JavaDoc date = new Date JavaDoc();
191         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
192         Book book = new Book(name, date, cover);
193         Review r1 = new Review(name);
194         Review r2 = new Review(name);
195         Review r3 = new Review(name + "_not_persistent");
196         ArrayList JavaDoc reviews = new ArrayList JavaDoc();
197         reviews.add(r1);
198         reviews.add(r2);
199         reviews.add(r3);
200         book.setReviews(reviews);
201
202         TransactionExt tx = (TransactionExt) odmg.newTransaction();
203         tx.begin();
204         database.makePersistent(book);
205         Review r4 = new Review(name + "_new_added");
206         // add a new review after make persistent main object
207
book.addReview(r4);
208         tx.setCascadingDelete(Book.class, true);
209         // remove object after make persistent main object
210
book.removeReview(r3);
211         tx.commit();
212         // System.err.println("## Insert main object with 3 referecnes");
213

214         tx.begin();
215         tx.getBroker().clearCache();
216
217         OQLQuery query = odmg.newOQLQuery();
218         query.create("select books from " + Book.class.getName() + " where title like $1");
219         query.bind(name);
220         Collection JavaDoc result = (Collection JavaDoc) query.execute();
221         assertEquals(1, result.size());
222         Book b = (Book) result.iterator().next();
223         assertNotNull(b.getReviews());
224         assertEquals(3, b.getReviews().size());
225
226         query = odmg.newOQLQuery();
227         query.create("select reviews from " + Review.class.getName() + " where summary like $1");
228         query.bind(name + "_new_added");
229         result = (Collection JavaDoc) query.execute();
230         // we expect the delayed added Review object
231
assertEquals(1, result.size());
232
233         query = odmg.newOQLQuery();
234         query.create("select reviews from " + Review.class.getName() + " where summary like $1");
235         query.bind(name + "_not_persistent");
236         result = (Collection JavaDoc) query.execute();
237         // we expect the removed Review object wasn't persistet
238
assertEquals(0, result.size());
239         tx.commit();
240     }
241
242     /**
243      * test persistence by reachability of collection reference objects
244      */

245     public void testPersistenceByReachability_2() throws Exception JavaDoc
246     {
247         String JavaDoc name = "testPersistenceByReachability_2_" + System.currentTimeMillis();
248         ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
249
250         Date JavaDoc date = new Date JavaDoc();
251         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
252         Book book = new Book(name, date, cover);
253         Review r1 = new Review(name);
254         Review r2 = new Review(name);
255         Review r3 = new Review(name + "_not_persistent");
256         ArrayList JavaDoc reviews = new ArrayList JavaDoc();
257         reviews.add(r1);
258         reviews.add(r2);
259         reviews.add(r3);
260         book.setReviews(reviews);
261
262         TransactionExt tx = (TransactionExt) odmg.newTransaction();
263         tx.begin();
264         database.makePersistent(book);
265         Review r4 = new Review(name + "_new_added");
266         // add a new review after make persistent main object
267
book.addReview(r4);
268         tx.setCascadingDelete(Book.class, true);
269         // remove object after make persistent main object
270
book.removeReview(r3);
271         tx.checkpoint();
272
273         //tx.begin();
274
tx.getBroker().clearCache();
275
276         OQLQuery query = odmg.newOQLQuery();
277         query.create("select books from " + Book.class.getName() + " where title like $1");
278         query.bind(name);
279         Collection JavaDoc result = (Collection JavaDoc) query.execute();
280         assertEquals(1, result.size());
281         Book b = (Book) result.iterator().next();
282         assertNotNull(b.getReviews());
283         assertEquals(3, b.getReviews().size());
284
285         query = odmg.newOQLQuery();
286         query.create("select reviews from " + Review.class.getName() + " where summary like $1");
287         query.bind(name + "_new_added%");
288         result = (Collection JavaDoc) query.execute();
289         // we expect the delayed added Review object
290
assertEquals(1, result.size());
291
292         query = odmg.newOQLQuery();
293         query.create("select reviews from " + Review.class.getName() + " where summary like $1");
294         query.bind(name + "_not_persistent");
295         result = (Collection JavaDoc) query.execute();
296         // we expect the removed Review object wasn't persistet
297
assertEquals(0, result.size());
298
299         b.setTitle(name + "_updated");
300         tx.commit();
301
302         query = odmg.newOQLQuery();
303         query.create("select books from " + Book.class.getName() + " where title like $1");
304         query.bind(name + "_updated");
305         result = (Collection JavaDoc) query.execute();
306         assertEquals(1, result.size());
307         Book b_updated = (Book) result.iterator().next();
308         assertNotNull(b_updated.getReviews());
309         assertEquals(3, b_updated.getReviews().size());
310         assertEquals(name+"_updated", b_updated.getTitle());
311     }
312
313     public void testAddPersistentObjectTo1toN() throws Exception JavaDoc
314     {
315         String JavaDoc name = "testAddPersistentObjectTo1toN_" + System.currentTimeMillis();
316         Review review = new Review(name);
317         TransactionExt tx = (TransactionExt) odmg.newTransaction();
318         tx.begin();
319         database.makePersistent(review);
320         tx.commit();
321
322         Integer JavaDoc versionReview = review.getVersion();
323
324         Date JavaDoc date = new Date JavaDoc();
325         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
326         Book book = new Book(name, date, cover);
327         tx = (TransactionExt) odmg.newTransaction();
328         tx.begin();
329         // tx.lock(review, Transaction.WRITE);
330
database.makePersistent(book);
331         book.addReview(review);
332         tx.commit();
333
334         // the Review object has to be linked
335
assertEquals("expect that this object was updated", versionReview.intValue() + 1, review.getVersion().intValue());
336
337         tx.begin();
338         tx.getBroker().clearCache();
339         OQLQuery query = odmg.newOQLQuery();
340         query.create("select books from " + Book.class.getName() + " where title like $1");
341         query.bind(name);
342         Collection JavaDoc result = (Collection JavaDoc) query.execute();
343         assertEquals(1, result.size());
344         Book b = (Book) result.iterator().next();
345         assertNotNull(b.getReviews());
346         assertEquals(1, b.getReviews().size());
347         tx.commit();
348     }
349
350     public void testAddPersistentObjectToMtoN() throws Exception JavaDoc
351     {
352         String JavaDoc name = "testAddPersistentObjectToMtoN_" + System.currentTimeMillis();
353         Author author = new Author(name, null);
354         TransactionExt tx = (TransactionExt) odmg.newTransaction();
355         tx.begin();
356         database.makePersistent(author);
357         tx.commit();
358
359         Integer JavaDoc versionReview = author.getVersion();
360
361         Date JavaDoc date = new Date JavaDoc();
362         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
363         Book book = new Book(name, date, cover);
364         tx = (TransactionExt) odmg.newTransaction();
365         tx.begin();
366         database.makePersistent(book);
367         book.addAuthor(author);
368         author.addBook(book);
369         tx.commit();
370
371         // the Review object has to be linked
372
assertEquals("expect that this object wasn't updated", versionReview.intValue(), author.getVersion().intValue());
373
374         tx.begin();
375         tx.getBroker().clearCache();
376         OQLQuery query = odmg.newOQLQuery();
377         query.create("select books from " + Book.class.getName() + " where title like $1");
378         query.bind(name);
379         Collection JavaDoc result = (Collection JavaDoc) query.execute();
380         assertEquals(1, result.size());
381         Book b = (Book) result.iterator().next();
382         assertNotNull(b.getAuthors());
383         assertEquals(1, b.getAuthors().size());
384         tx.commit();
385     }
386
387     /**
388      * only lock object, no changes made
389      */

390     public void testChangeMainFields() throws Exception JavaDoc
391     {
392         String JavaDoc name = "testChangeMainFields_" + System.currentTimeMillis();
393         Date JavaDoc date = new Date JavaDoc();
394         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
395         Book book = new Book(name, date, cover);
396
397         TransactionExt tx = (TransactionExt) odmg.newTransaction();
398         tx.begin();
399         database.makePersistent(book);
400         tx.commit();
401
402         Integer JavaDoc version = book.getVersion();
403         // System.err.println("### 1. commit, insert new object");
404

405         tx.begin();
406         tx.lock(book, Transaction.WRITE);
407         tx.commit();
408
409         // System.err.println("### 2. commit, no changes");
410
assertEquals(version, book.getVersion());
411
412         tx.begin();
413         tx.lock(book, Transaction.WRITE);
414         // we set the same date, so no reason to update
415
book.setPublicationDate(new Date JavaDoc(date.getTime()));
416         tx.commit();
417
418         // System.err.println("### 3. commit, replace with same date");
419
assertEquals(version, book.getVersion());
420
421         tx.begin();
422         tx.lock(book, Transaction.WRITE);
423         // now we change the date
424
Date JavaDoc d = new Date JavaDoc(1111);
425         book.setPublicationDate(d);
426         tx.commit();
427         // System.err.println("### 4. commit, changed date");
428
assertFalse(date.equals(book.getPublicationDate()));
429         assertFalse(version.equals(book.getVersion()));
430     }
431
432     /**
433      * modify field of main object
434      */

435     public void testChangeMainFields_2() throws Exception JavaDoc
436     {
437         String JavaDoc name = "testChangeMainFields_2_" + System.currentTimeMillis();
438         Date JavaDoc date = new Date JavaDoc();
439         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
440         Book book = new Book(name, date, cover);
441
442         TransactionExt tx = (TransactionExt) odmg.newTransaction();
443         tx.begin();
444         database.makePersistent(book);
445         tx.commit();
446
447         Integer JavaDoc version = book.getVersion();
448
449         tx.begin();
450         tx.lock(book, Transaction.WRITE);
451         book.setCover(new byte[]{2,3,4,5,6,7,8,8});
452         tx.commit();
453
454         assertFalse(version.equals(book.getVersion()));
455         tx.begin();
456         tx.getBroker().clearCache();
457         OQLQuery query = odmg.newOQLQuery();
458         query.create("select books from " + Book.class.getName() + " where title like $1");
459         query.bind(name);
460         Collection JavaDoc result = (Collection JavaDoc) query.execute();
461         assertEquals(1, result.size());
462         Book b = (Book) result.iterator().next();
463         assertFalse(version.equals(b.getVersion()));
464         tx.commit();
465     }
466
467     /**
468      * lock object and lock serialized unmodified version again
469      */

470     public void testChangeMainFields_3() throws Exception JavaDoc
471     {
472         String JavaDoc name = "testChangeMainFields_3_" + System.currentTimeMillis();
473         Date JavaDoc date = new Date JavaDoc();
474         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
475         Book book = new Book(name, date, cover);
476
477         TransactionExt tx = (TransactionExt) odmg.newTransaction();
478         tx.begin();
479         database.makePersistent(book);
480         tx.commit();
481
482         Integer JavaDoc version = book.getVersion();
483
484         tx.begin();
485         tx.lock(book, Transaction.WRITE);
486         book = (Book) SerializationUtils.clone(book);
487         tx.lock(book, Transaction.WRITE);
488         tx.commit();
489
490         assertEquals(version, book.getVersion());
491     }
492
493     /**
494      * Double lock object with reference
495      */

496     public void testChangeOneToOneReference_1() throws Exception JavaDoc
497     {
498         String JavaDoc name = "testChangeOneToOneReference_1_" + System.currentTimeMillis();
499         Date JavaDoc date = new Date JavaDoc();
500         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
501         Book book = new Book(name, date, cover);
502         Publisher publisher = new PublisherImpl(name);
503         book.setPublisher(publisher);
504
505         TransactionExt tx = (TransactionExt) odmg.newTransaction();
506         tx.begin();
507         database.makePersistent(book);
508         tx.commit();
509         // System.err.println("### 1. commit, insert new object");
510

511         Integer JavaDoc versionBook = book.getVersion();
512         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
513
514         tx.begin();
515         tx.lock(book, Transaction.WRITE);
516         tx.lock(book, Transaction.WRITE);
517         tx.commit();
518         // System.err.println("### 2. commit, double lock call, no changes");
519

520         assertEquals(versionBook, book.getVersion());
521         assertEquals(versionPublisher, book.getVersion());
522     }
523
524     /**
525      * Double lock object with reference and proxy reference
526      */

527     public void testChangeOneToOneReference_1b() throws Exception JavaDoc
528     {
529         String JavaDoc name = "testChangeOneToOneReference_1b_" + System.currentTimeMillis();
530         ojbChangeReferenceSetting(Book.class, "publisher", true, NONE, NONE, true);
531
532         Date JavaDoc date = new Date JavaDoc();
533         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
534         Book book = new Book(name, date, cover);
535         Publisher publisher = new PublisherImpl(name);
536         book.setPublisher(publisher);
537
538         TransactionExt tx = (TransactionExt) odmg.newTransaction();
539         tx.begin();
540         database.makePersistent(book);
541         tx.commit();
542         // System.err.println("### 1. commit, insert new object");
543

544         Integer JavaDoc versionBook = book.getVersion();
545         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
546
547         tx.begin();
548         tx.lock(book, Transaction.WRITE);
549         tx.lock(book, Transaction.WRITE);
550         tx.commit();
551         // System.err.println("### 2. commit, double lock call, no changes");
552

553         assertEquals(versionBook, book.getVersion());
554         assertEquals(versionPublisher, book.getVersion());
555     }
556
557     /**
558      * lock object with reference and lock serialized version again
559      */

560     public void testChangeOneToOneReference_2() throws Exception JavaDoc
561     {
562         String JavaDoc name = "testChangeOneToOneReference_2_" + System.currentTimeMillis();
563         Date JavaDoc date = new Date JavaDoc();
564         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
565         Book book = new Book(name, date, cover);
566         Publisher publisher = new PublisherImpl(name);
567         book.setPublisher(publisher);
568
569         TransactionExt tx = (TransactionExt) odmg.newTransaction();
570         tx.begin();
571         database.makePersistent(book);
572         tx.commit();
573         // System.err.println("### 1. commit, insert new object");
574

575         Integer JavaDoc versionBook = book.getVersion();
576         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
577
578         tx.begin();
579         tx.lock(book, Transaction.WRITE);
580         // nothing changed, so no need to update objects
581
book = (Book) SerializationUtils.clone(book);
582         tx.lock(book, Transaction.WRITE);
583         tx.commit();
584
585         assertEquals(versionBook, book.getVersion());
586         assertEquals(versionPublisher, book.getVersion());
587     }
588
589     /**
590      * lock object with reference, change reference only
591      */

592     public void testChangeOneToOneReference_3() throws Exception JavaDoc
593     {
594         String JavaDoc name = "testChangeOneToOneReference_2_" + System.currentTimeMillis();
595         Date JavaDoc date = new Date JavaDoc();
596         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
597         Book book = new Book(name, date, cover);
598         Publisher publisher = new PublisherImpl(name);
599         book.setPublisher(publisher);
600
601         TransactionExt tx = (TransactionExt) odmg.newTransaction();
602         tx.begin();
603         database.makePersistent(book);
604         tx.commit();
605         // System.err.println("### 1. commit, insert new object");
606

607         Integer JavaDoc versionBook = book.getVersion();
608         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
609
610         tx.begin();
611         tx.lock(book, Transaction.WRITE);
612         // nothing changed, so no need to update objects
613
book = (Book) SerializationUtils.clone(book);
614         Publisher p = book.getPublisher();
615         p.setName(name + "_updated");
616         // not needed to re-lock, because nothing changed, but
617
// if we lock Book no update should be done, because nothing changed
618
tx.lock(book, Transaction.WRITE);
619         // we have to re-lock the changed objects, because it was serialized
620
tx.lock(p, Transaction.WRITE);
621         tx.commit();
622
623         // no changes made in Book
624
assertEquals(versionBook, book.getVersion());
625         // publisher should be updated
626
assertEquals(new Integer JavaDoc(versionPublisher.intValue() + 1), p.getVersion());
627     }
628
629     /**
630      * lock object with reference, replace reference only
631      */

632     public void testReplaceOneToOneReference_1() throws Exception JavaDoc
633     {
634         String JavaDoc name = "testChangeOneToOneReference_2_" + System.currentTimeMillis();
635         Date JavaDoc date = new Date JavaDoc();
636         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
637         Book book = new Book(name, date, cover);
638         Publisher publisher = new PublisherImpl(name);
639         book.setPublisher(publisher);
640
641         TransactionExt tx = (TransactionExt) odmg.newTransaction();
642         tx.begin();
643         database.makePersistent(book);
644         tx.commit();
645         // System.err.println("### 1. commit, insert new object");
646

647         Integer JavaDoc versionBook = book.getVersion();
648         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
649
650         tx.begin();
651         tx.lock(book, Transaction.WRITE);
652         Publisher p = new PublisherImpl(name + "_new");
653         // set new Publisher instance
654
book.setPublisher(p);
655         tx.lock(p, Transaction.WRITE);
656         tx.commit();
657
658         // changes made in Book
659
assertEquals(new Integer JavaDoc(versionBook.intValue() + 1), book.getVersion());
660         // publisher should not be updated, because it was replaced
661
assertEquals(versionPublisher, p.getVersion());
662     }
663
664     /**
665      * lock object with reference, replace reference only
666      */

667     public void testReplaceOneToOneReference_2() throws Exception JavaDoc
668     {
669         String JavaDoc name = "testChangeOneToOneReference_2_" + System.currentTimeMillis();
670         Date JavaDoc date = new Date JavaDoc();
671         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
672         Book book = new Book(name, date, cover);
673         Publisher publisher = new PublisherImpl(name);
674         book.setPublisher(publisher);
675
676         TransactionExt tx = (TransactionExt) odmg.newTransaction();
677         tx.begin();
678         database.makePersistent(book);
679         tx.commit();
680         // System.err.println("### 1. commit, insert new object");
681

682         Integer JavaDoc versionBook = book.getVersion();
683         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
684
685         tx.begin();
686         tx.lock(book, Transaction.WRITE);
687         book = (Book) SerializationUtils.clone(book);
688         Publisher p = new PublisherImpl(name + "_new");
689         // set new Publisher instance
690
book.setPublisher(p);
691         // not needed to re-lock, because nothing changed, but
692
// if we lock Book no update should be done, because nothing changed
693
tx.lock(book, Transaction.WRITE);
694         // we have to re-lock the changed objects, because it was serialized
695
tx.lock(p, Transaction.WRITE);
696         tx.commit();
697
698         // changes made in Book
699
assertEquals(new Integer JavaDoc(versionBook.intValue() + 1), book.getVersion());
700         // publisher should not be updated, because it was replaced
701
assertEquals(versionPublisher, p.getVersion());
702     }
703
704     /**
705      * check materialization of proxy object
706      */

707     public void testChangeOneToOneReference_4() throws Exception JavaDoc
708     {
709         ojbChangeReferenceSetting(Book.class, "publisher", true, NONE, NONE, true);
710         String JavaDoc name = "testChangeOneToOneReference_4_" + System.currentTimeMillis();
711         Date JavaDoc date = new Date JavaDoc();
712         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
713         Book book = new Book(name, date, cover);
714         Publisher publisher = new PublisherImpl(name);
715         book.setPublisher(publisher);
716
717         TransactionExt tx = (TransactionExt) odmg.newTransaction();
718         tx.begin();
719         database.makePersistent(book);
720         tx.commit();
721
722         Integer JavaDoc versionBook = book.getVersion();
723
724         tx.begin();
725         tx.getBroker().clearCache();
726         OQLQuery query = odmg.newOQLQuery();
727         query.create("select books from " + Book.class.getName() + " where title like $1");
728         query.bind(name);
729         Collection JavaDoc result = (Collection JavaDoc) query.execute();
730         assertEquals(1, result.size());
731         Book b = (Book) result.iterator().next();
732         IndirectionHandler handler = ProxyHelper.getIndirectionHandler(b.getPublisher());
733         assertNotNull(handler);
734         assertFalse(handler.alreadyMaterialized());
735         handler.addListener(
736                 new MaterializationListener()
737                 {
738                     public void beforeMaterialization(IndirectionHandler handler, Identity oid)
739                     {
740                         fail("Reference shall not materialize while locking");
741                     }
742
743                     public void afterMaterialization(IndirectionHandler handler, Object JavaDoc materializedObject)
744                     {
745                     }
746                 }
747         );
748         tx.lock(b, Transaction.WRITE);
749         tx.commit();
750
751         assertEquals(versionBook, b.getVersion());
752     }
753
754     /**
755      * replace proxy reference by new reference object
756      */

757     public void testChangeOneToOneReference_5() throws Exception JavaDoc
758     {
759         ojbChangeReferenceSetting(Book.class, "publisher", true, NONE, NONE, true);
760         String JavaDoc name = "testChangeOneToOneReference_5_" + System.currentTimeMillis();
761         Date JavaDoc date = new Date JavaDoc();
762         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
763         Book book = new Book(name, date, cover);
764         Publisher publisher = new PublisherImpl(name);
765         book.setPublisher(publisher);
766
767         TransactionExt tx = (TransactionExt) odmg.newTransaction();
768         tx.begin();
769         database.makePersistent(book);
770         tx.commit();
771         // System.err.println("### 1. commit, insert new object");
772

773
774         Integer JavaDoc versionBook = book.getVersion();
775
776         tx.begin();
777         tx.getBroker().clearCache();
778         OQLQuery query = odmg.newOQLQuery();
779         query.create("select books from " + Book.class.getName() + " where title like $1");
780         query.bind(name);
781         Collection JavaDoc result = (Collection JavaDoc) query.execute();
782         assertEquals(1, result.size());
783         Book b = (Book) result.iterator().next();
784         IndirectionHandler handler = ProxyHelper.getIndirectionHandler(b.getPublisher());
785         assertNotNull(handler);
786         assertFalse(handler.alreadyMaterialized());
787         handler.addListener(
788                 new MaterializationListener()
789                 {
790                     public void beforeMaterialization(IndirectionHandler handler, Identity oid)
791                     {
792                         fail("Reference shall not materialize while locking");
793                     }
794
795                     public void afterMaterialization(IndirectionHandler handler, Object JavaDoc materializedObject)
796                     {
797                     }
798                 }
799         );
800         // no need to lock with default settings, because lock is done when query object
801
tx.lock(b, Transaction.WRITE);
802         // replace 1:1 reference
803
Publisher p = new PublisherImpl(name+"_new");
804         b.setPublisher(p);
805         //tx.lock(p, Transaction.WRITE);
806
tx.commit();
807
808         // we expect increased version, because Book object needs update - changed FK
809
assertEquals(new Integer JavaDoc(versionBook.intValue() + 1), b.getVersion());
810         // should should differ, because new reference should be stored
811
assertFalse(publisher.getName().equals(p.getName()));
812         assertNotNull(p.getVersion());
813
814         tx.begin();
815         tx.getBroker().clearCache();
816         query = odmg.newOQLQuery();
817         query.create("select books from " + Book.class.getName() + " where title like $1");
818         query.bind(name);
819         result = (Collection JavaDoc) query.execute();
820         tx.commit();
821         assertEquals(1, result.size());
822         b = (Book) result.iterator().next();
823         Publisher newP = b.getPublisher();
824         assertNotNull(newP);
825         assertEquals(name+"_new", newP.getName());
826     }
827
828     /**
829      * update referenced object
830      */

831     public void testChangeOneToOneReference_6() throws Exception JavaDoc
832     {
833         String JavaDoc name = "testChangeOneToOneReference_6_" + System.currentTimeMillis();
834         Date JavaDoc date = new Date JavaDoc();
835         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
836         Book book = new Book(name, date, cover);
837         Publisher publisher = new PublisherImpl(name);
838         book.setPublisher(publisher);
839
840         TransactionExt tx = (TransactionExt) odmg.newTransaction();
841         tx.begin();
842         database.makePersistent(book);
843         tx.commit();
844
845         Integer JavaDoc versionBook = book.getVersion();
846         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
847
848         tx.begin();
849         tx.getBroker().clearCache();
850         OQLQuery query = odmg.newOQLQuery();
851         query.create("select books from " + Book.class.getName() + " where title like $1");
852         query.bind(name);
853         Collection JavaDoc result = (Collection JavaDoc) query.execute();
854         assertEquals(1, result.size());
855         Book b = (Book) result.iterator().next();
856         tx.lock(b, Transaction.WRITE);
857         b.getPublisher().setName("updated_" + b.getPublisher().getName());
858         tx.commit();
859
860         // nothing changed
861
assertEquals(versionBook, b.getVersion());
862         // version should should differ, because reference should be updated
863
assertFalse(versionPublisher.equals(b.getPublisher().getVersion()));
864         assertEquals("updated_" + name, b.getPublisher().getName());
865     }
866
867     /**
868      * add new reference
869      */

870     public void testChangeOneToOneReference_7() throws Exception JavaDoc
871     {
872         String JavaDoc name = "testChangeOneToOneReference_7_" + System.currentTimeMillis();
873         Date JavaDoc date = new Date JavaDoc();
874         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
875         Book book = new Book(name, date, cover);
876
877         TransactionExt tx = (TransactionExt) odmg.newTransaction();
878         tx.begin();
879         database.makePersistent(book);
880         tx.commit();
881
882         Integer JavaDoc versionBook = book.getVersion();
883
884         tx.begin();
885         tx.getBroker().clearCache();
886         OQLQuery query = odmg.newOQLQuery();
887         query.create("select books from " + Book.class.getName() + " where title like $1");
888         query.bind(name);
889         Collection JavaDoc result = (Collection JavaDoc) query.execute();
890         assertEquals(1, result.size());
891         Book b = (Book) result.iterator().next();
892
893         tx.lock(b, Transaction.WRITE);
894         assertNull(b.getPublisher());
895         Publisher publisher = new PublisherImpl(name);
896         b.setPublisher(publisher);
897         // tx.lock(publisher, Transaction.WRITE);
898
tx.commit();
899
900         tx.begin();
901         tx.getBroker().clearCache();
902         query = odmg.newOQLQuery();
903         query.create("select books from " + Book.class.getName() + " where title like $1");
904         query.bind(name);
905         result = (Collection JavaDoc) query.execute();
906         assertEquals(1, result.size());
907         b = (Book) result.iterator().next();
908         tx.commit();
909
910         // we expect increased version, because Book object needs update
911
assertEquals(new Integer JavaDoc(versionBook.intValue() + 1), b.getVersion());
912         // version should differ from null, because new reference should be stored
913
assertNotNull(b.getPublisher());
914         assertNotNull(b.getPublisher().getVersion());
915         assertEquals(name, b.getPublisher().getName());
916     }
917
918     /**
919      * remove reference
920      */

921     public void testChangeOneToOneReference_8() throws Exception JavaDoc
922     {
923         String JavaDoc name = "testChangeOneToOneReference_8_" + System.currentTimeMillis();
924         Date JavaDoc date = new Date JavaDoc();
925         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
926         Book book = new Book(name, date, cover);
927         Publisher publisher = new PublisherImpl(name);
928         book.setPublisher(publisher);
929
930         TransactionExt tx = (TransactionExt) odmg.newTransaction();
931         tx.begin();
932         database.makePersistent(book);
933         tx.commit();
934
935         Integer JavaDoc versionBook = book.getVersion();
936         Integer JavaDoc versionPublisher = book.getPublisher().getVersion();
937
938         tx.begin();
939         tx.getBroker().clearCache();
940         OQLQuery query = odmg.newOQLQuery();
941         query.create("select books from " + Book.class.getName() + " where title like $1");
942         query.bind(name);
943         Collection JavaDoc result = (Collection JavaDoc) query.execute();
944         assertEquals(1, result.size());
945         Book b = (Book) result.iterator().next();
946
947         tx.lock(b, Transaction.WRITE);
948         b.setPublisher(null);
949         tx.commit();
950
951         tx.begin();
952         tx.getBroker().clearCache();
953         query = odmg.newOQLQuery();
954         query.create("select books from " + Book.class.getName() + " where title like $1");
955         query.bind(name);
956         result = (Collection JavaDoc) query.execute();
957         assertEquals(1, result.size());
958         b = (Book) result.iterator().next();
959         tx.commit();
960
961         // we expect increased version, because Book object needs update
962
assertEquals(new Integer JavaDoc(versionBook.intValue() + 1), b.getVersion());
963         assertNull(b.getPublisher());
964
965         tx.begin();
966         tx.getBroker().clearCache();
967         query = odmg.newOQLQuery();
968         query.create("select publishers from " + Publisher.class.getName() + " where name like $1");
969         query.bind(name);
970         result = (Collection JavaDoc) query.execute();
971         // we don't remove the reference object
972
assertEquals(1, result.size());
973         Publisher p = (Publisher) result.iterator().next();
974         assertEquals(name, p.getName());
975         // removed 1:1 reference, expect unchanged version
976
assertEquals(versionPublisher, p.getVersion());
977         tx.commit();
978     }
979
980     /**
981      * delete reference
982      */

983     public void testChangeOneToOneReference_8b() throws Exception JavaDoc
984     {
985         String JavaDoc name = "testChangeOneToOneReference_8b_" + System.currentTimeMillis();
986         Date JavaDoc date = new Date JavaDoc();
987         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
988         Book book = new Book(name, date, cover);
989         Publisher publisher = new PublisherImpl(name);
990         book.setPublisher(publisher);
991
992         TransactionExt tx = (TransactionExt) odmg.newTransaction();
993         tx.begin();
994         database.makePersistent(book);
995         tx.commit();
996
997         Integer JavaDoc versionBook = book.getVersion();
998
999         tx.begin();
1000        tx.getBroker().clearCache();
1001        OQLQuery query = odmg.newOQLQuery();
1002        query.create("select books from " + Book.class.getName() + " where title like $1");
1003        query.bind(name);
1004        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1005        assertEquals(1, result.size());
1006        Book b = (Book) result.iterator().next();
1007
1008        tx.lock(b, Transaction.WRITE);
1009        database.deletePersistent(b.getPublisher());
1010        b.setPublisher(null);
1011        tx.commit();
1012
1013        tx.begin();
1014        tx.getBroker().clearCache();
1015        query = odmg.newOQLQuery();
1016        query.create("select books from " + Book.class.getName() + " where title like $1");
1017        query.bind(name);
1018        result = (Collection JavaDoc) query.execute();
1019        assertEquals(1, result.size());
1020        b = (Book) result.iterator().next();
1021        tx.commit();
1022
1023        // we expect increased version, because Book object needs update
1024
assertEquals(new Integer JavaDoc(versionBook.intValue() + 1), b.getVersion());
1025        assertNull(b.getPublisher());
1026
1027        tx.begin();
1028        tx.getBroker().clearCache();
1029        query = odmg.newOQLQuery();
1030        query.create("select publishers from " + Publisher.class.getName() + " where name like $1");
1031        query.bind(name);
1032        result = (Collection JavaDoc) query.execute();
1033        // we don't remove the reference object
1034
assertEquals(0, result.size());
1035        tx.commit();
1036    }
1037
1038    /**
1039     * check materialzation of collection reference
1040     */

1041    public void testCollectionReference_1() throws Exception JavaDoc
1042    {
1043        String JavaDoc name = "testCollectionReference_1_" + System.currentTimeMillis();
1044        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
1045
1046        Date JavaDoc date = new Date JavaDoc();
1047        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1048        Book book = new Book(name, date, cover);
1049        Review r1 = new Review(name);
1050        Review r2 = new Review(name);
1051        Review r3 = new Review(name);
1052        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1053        reviews.add(r1);
1054        reviews.add(r2);
1055        reviews.add(r3);
1056        book.setReviews(reviews);
1057
1058        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1059        tx.begin();
1060        database.makePersistent(book);
1061        tx.commit();
1062        // System.err.println("## Insert main object with 3 referecnes");
1063

1064        tx.begin();
1065        tx.getBroker().clearCache();
1066        OQLQuery query = odmg.newOQLQuery();
1067        query.create("select books from " + Book.class.getName() + " where title like $1");
1068        query.bind(name);
1069        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1070        assertEquals(1, result.size());
1071        Book b = (Book) result.iterator().next();
1072        CollectionProxy handler = ProxyHelper.getCollectionProxy(b.getReviews());
1073        assertFalse("Don't expect an materialized collection proxy", handler.isLoaded());
1074        handler.addListener(new CollectionProxyListener()
1075        {
1076            public void beforeLoading(CollectionProxyDefaultImpl colProxy)
1077            {
1078                fail("Collection proxy shouldn't be materialized");
1079            }
1080
1081            public void afterLoading(CollectionProxyDefaultImpl colProxy)
1082            {
1083            }
1084        });
1085        assertNotNull(b.getReviews());
1086        assertEquals(3, b.getReviews().size());
1087
1088        tx.lock(b, Transaction.WRITE);
1089        tx.commit();
1090    }
1091
1092    /**
1093     * update collection reference object
1094     */

1095    public void testCollectionReference_2a() throws Exception JavaDoc
1096    {
1097        String JavaDoc name = "testCollectionReference_2a_" + System.currentTimeMillis();
1098        Date JavaDoc date = new Date JavaDoc();
1099        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1100        Book book = new Book(name, date, cover);
1101        Review r1 = new Review(name);
1102        Review r2 = new Review(name);
1103        Review r3 = new Review(name);
1104        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1105        reviews.add(r1);
1106        reviews.add(r2);
1107        reviews.add(r3);
1108        book.setReviews(reviews);
1109
1110        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1111        tx.begin();
1112        database.makePersistent(book);
1113        tx.commit();
1114        // System.err.println("## Insert main object with 3 referecnes");
1115

1116        Integer JavaDoc versionBook = book.getVersion();
1117        Integer JavaDoc versionR1 = ((Review) book.getReviews().get(0)).getVersion();
1118
1119        tx.begin();
1120        tx.getBroker().clearCache();
1121        OQLQuery query = odmg.newOQLQuery();
1122        query.create("select books from " + Book.class.getName() + " where title like $1");
1123        query.bind(name);
1124        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1125        assertEquals(1, result.size());
1126        Book b = (Book) result.iterator().next();
1127        assertEquals(versionBook, b.getVersion());
1128        assertNotNull(b.getReviews());
1129        assertEquals(3, b.getReviews().size());
1130
1131        tx.lock(b, Transaction.WRITE);
1132        Review newR2 = (Review) b.getReviews().get(1);
1133        newR2.setSummary("updated" + name);
1134        final int newR2id = newR2.getId().intValue();
1135        tx.commit();
1136
1137        assertEquals(versionBook, b.getVersion());
1138        // this referenced object was not updated
1139
Integer JavaDoc versionR1New = ((Review) b.getReviews().get(0)).getVersion();
1140        assertEquals(versionR1, versionR1New);
1141
1142        tx.begin();
1143        tx.getBroker().clearCache();
1144        query = odmg.newOQLQuery();
1145        query.create("select books from " + Book.class.getName() + " where title like $1");
1146        query.bind(name);
1147        result = (Collection JavaDoc) query.execute();
1148        assertEquals(1, result.size());
1149        b = (Book) result.iterator().next();
1150        assertNotNull(b.getReviews());
1151        assertEquals(3, b.getReviews().size());
1152
1153        // Search for the updated R2:
1154
final List JavaDoc updatedReviews = b.getReviews();
1155        for (int i = 0; i < updatedReviews.size(); i++)
1156        {
1157            newR2 = (Review) updatedReviews.get(i);
1158            if (newR2id == newR2.getId().intValue()) {
1159                break;
1160            }
1161        }
1162        assertEquals("Could not find the updated review in the returned results",
1163                newR2id, newR2.getId().intValue());
1164        assertEquals("updated" + name, newR2.getSummary());
1165        assertEquals(versionBook, b.getVersion());
1166        // this referenced object was not updated
1167
versionR1New = ((Review) b.getReviews().get(0)).getVersion();
1168        assertEquals(versionR1, versionR1New);
1169    }
1170
1171    /**
1172     * update proxy collection reference object
1173     */

1174    public void testCollectionReference_2b() throws Exception JavaDoc
1175    {
1176        String JavaDoc name = "testCollectionReference_2b_" + System.currentTimeMillis();
1177
1178        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
1179
1180        Date JavaDoc date = new Date JavaDoc();
1181        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1182        Book book = new Book(name, date, cover);
1183        Review r1 = new Review(name);
1184        Review r2 = new Review(name);
1185        Review r3 = new Review(name);
1186        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1187        reviews.add(r1);
1188        reviews.add(r2);
1189        reviews.add(r3);
1190        book.setReviews(reviews);
1191
1192        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1193        tx.begin();
1194        database.makePersistent(book);
1195        tx.commit();
1196        // System.err.println("## Insert main object with 3 referecnes");
1197

1198        Integer JavaDoc versionBook = book.getVersion();
1199        Integer JavaDoc versionR0 = ((Review) book.getReviews().get(0)).getVersion();
1200        Integer JavaDoc versionR1 = ((Review) book.getReviews().get(1)).getVersion();
1201
1202        tx.begin();
1203        tx.getBroker().clearCache();
1204        // System.err.println("## Started new tx");
1205
OQLQuery query = odmg.newOQLQuery();
1206        query.create("select books from " + Book.class.getName() + " where title like $1");
1207        query.bind(name);
1208        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1209        assertEquals(1, result.size());
1210        Book b = (Book) result.iterator().next();
1211        assertEquals(versionBook, b.getVersion());
1212        assertNotNull(b.getReviews());
1213        assertEquals(3, b.getReviews().size());
1214        assertEquals(versionR0, ((Review) b.getReviews().get(0)).getVersion());
1215        assertEquals(versionR1, ((Review) b.getReviews().get(1)).getVersion());
1216
1217        // System.err.println("## Query done");
1218
tx.lock(b, Transaction.WRITE);
1219        // System.err.println("## Lock object again");
1220
Review newR1 = (Review) b.getReviews().get(1);
1221        newR1.setSummary("updated" + name);
1222        // System.err.println("## Before commit");
1223
tx.commit();
1224        // System.err.println("## Commit Book with updated Review");
1225

1226        assertEquals(versionBook, b.getVersion());
1227        assertEquals(3, b.getReviews().size());
1228
1229        // the updated one
1230
Integer JavaDoc versionR1New = ((Review) b.getReviews().get(1)).getVersion();
1231        assertEquals(new Integer JavaDoc(versionR1.intValue() + 1), versionR1New);
1232        // this referenced object was not updated
1233
Integer JavaDoc versionR0New = ((Review) b.getReviews().get(0)).getVersion();
1234        assertEquals(versionR0, versionR0New);
1235
1236        tx.begin();
1237        tx.getBroker().clearCache();
1238        query = odmg.newOQLQuery();
1239        query.create("select books from " + Book.class.getName() + " where title like $1");
1240        query.bind(name);
1241        result = (Collection JavaDoc) query.execute();
1242        assertEquals(1, result.size());
1243        b = (Book) result.iterator().next();
1244        assertNotNull(b.getReviews());
1245        assertEquals(3, b.getReviews().size());
1246        tx.commit();
1247
1248        // query for updated Review
1249
tx.begin();
1250        tx.getBroker().clearCache();
1251        query = odmg.newOQLQuery();
1252        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
1253        query.bind("updated" + name);
1254        result = (Collection JavaDoc) query.execute();
1255        tx.commit();
1256        // the update Review object
1257
assertEquals(1, result.size());
1258        // query for unchanged Review objects
1259
tx.begin();
1260        tx.getBroker().clearCache();
1261        query = odmg.newOQLQuery();
1262        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
1263        query.bind(name);
1264        result = (Collection JavaDoc) query.execute();
1265        tx.commit();
1266
1267        assertEquals(2, result.size());
1268        assertEquals(versionR0, ((Review) new ArrayList JavaDoc(result).get(0)).getVersion());
1269
1270    }
1271
1272    /**
1273     * remove collection reference object
1274     * this test expects that removed 1:n referenced objects only
1275     * be "unlinked" instead of deleted.
1276     */

1277    public void testCollectionReference_3() throws Exception JavaDoc
1278    {
1279        String JavaDoc name = "testCollectionReference_3_" + System.currentTimeMillis();
1280        Date JavaDoc date = new Date JavaDoc();
1281        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1282        Book book = new Book(name, date, cover);
1283        Review r1 = new Review(name);
1284        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1285        reviews.add(r1);
1286        book.setReviews(reviews);
1287
1288        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1289        tx.begin();
1290        database.makePersistent(book);
1291        tx.commit();
1292
1293        Integer JavaDoc versionBook = book.getVersion();
1294        Integer JavaDoc versionR1 = ((Review) book.getReviews().get(0)).getVersion();
1295
1296        tx.begin();
1297        tx.getBroker().clearCache();
1298        OQLQuery query = odmg.newOQLQuery();
1299        query.create("select books from " + Book.class.getName() + " where title like $1");
1300        query.bind(name);
1301        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1302        assertEquals(1, result.size());
1303        Book b = (Book) result.iterator().next();
1304        assertEquals(versionBook, b.getVersion());
1305        assertNotNull(b.getReviews());
1306        assertEquals(1, b.getReviews().size());
1307
1308        //***********************************
1309
tx.lock(b, Transaction.WRITE);
1310        // remove from collection, but do not explicit delete
1311
tx.setCascadingDelete(Book.class, "reviews", false);
1312        Review newR1 = (Review) b.getReviews().remove(0);
1313        tx.commit();
1314        //***********************************
1315

1316        // only the removed reference has changed
1317
assertEquals(versionBook, b.getVersion());
1318        // expect an "unlinked" new version
1319
assertEquals(new Integer JavaDoc(versionR1.intValue() + 1), newR1.getVersion());
1320
1321        tx.begin();
1322        tx.getBroker().clearCache();
1323        query = odmg.newOQLQuery();
1324        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
1325        query.bind(name);
1326        result = (Collection JavaDoc) query.execute();
1327        tx.commit();
1328
1329        // we don't delete the Review object, only remove from reference collection
1330
assertEquals(1, result.size());
1331        Review r = (Review) result.iterator().next();
1332        // expect new object version, because the FK to main object was set null
1333
assertEquals(new Integer JavaDoc(versionR1.intValue() + 1), r.getVersion());
1334
1335        tx.begin();
1336        query = odmg.newOQLQuery();
1337        query.create("select books from " + Book.class.getName() + " where title like $1");
1338        query.bind(name);
1339        result = (Collection JavaDoc) query.execute();
1340        tx.commit();
1341
1342        assertEquals(1, result.size());
1343        b = (Book) result.iterator().next();
1344        assertEquals(versionBook, b.getVersion());
1345        // we have removed the Review object
1346
assertEquals(0, b.getReviews().size());
1347    }
1348
1349    /**
1350     * remove collection reference object and explicit delete it
1351     */

1352    public void testCollectionReference_3b() throws Exception JavaDoc
1353    {
1354        String JavaDoc name = "testCollectionReference_3b_" + System.currentTimeMillis();
1355        Date JavaDoc date = new Date JavaDoc();
1356        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1357        Book book = new Book(name, date, cover);
1358        Review r1 = new Review(name);
1359        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1360        reviews.add(r1);
1361        book.setReviews(reviews);
1362
1363        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1364        tx.begin();
1365        database.makePersistent(book);
1366        tx.commit();
1367
1368        Integer JavaDoc versionBook = book.getVersion();
1369
1370        tx.begin();
1371        tx.getBroker().clearCache();
1372        OQLQuery query = odmg.newOQLQuery();
1373        query.create("select books from " + Book.class.getName() + " where title like $1");
1374        query.bind(name);
1375        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1376        assertEquals(1, result.size());
1377        Book b = (Book) result.iterator().next();
1378        assertEquals(versionBook, b.getVersion());
1379        assertNotNull(b.getReviews());
1380        assertEquals(1, b.getReviews().size());
1381
1382        tx.lock(b, Transaction.WRITE);
1383        // remove from collection and delete
1384
Review newR1 = (Review) b.getReviews().remove(0);
1385        database.deletePersistent(newR1);
1386        tx.commit();
1387
1388        // only the removed reference has changed
1389
assertEquals(versionBook, b.getVersion());
1390
1391        tx.begin();
1392        query = odmg.newOQLQuery();
1393        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
1394        query.bind(name);
1395        result = (Collection JavaDoc) query.execute();
1396        tx.commit();
1397
1398        assertEquals(0, result.size());
1399
1400        tx.begin();
1401        query = odmg.newOQLQuery();
1402        query.create("select books from " + Book.class.getName() + " where title like $1");
1403        query.bind(name);
1404        result = (Collection JavaDoc) query.execute();
1405        tx.commit();
1406
1407        assertEquals(1, result.size());
1408        b = (Book) result.iterator().next();
1409        assertEquals(versionBook, b.getVersion());
1410        assertEquals(0, b.getReviews().size());
1411    }
1412
1413    /**
1414     * remove collection reference object with enabled auto-delete
1415     */

1416    public void testCollectionReference_3c() throws Exception JavaDoc
1417    {
1418        String JavaDoc name = "testCollectionReference_3c_" + System.currentTimeMillis();
1419        Date JavaDoc date = new Date JavaDoc();
1420        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1421        Book book = new Book(name, date, cover);
1422        Review r1 = new Review(name);
1423        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1424        reviews.add(r1);
1425        book.setReviews(reviews);
1426
1427        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1428        tx.begin();
1429        database.makePersistent(book);
1430        tx.commit();
1431
1432        Integer JavaDoc versionBook = book.getVersion();
1433
1434        tx.begin();
1435        tx.getBroker().clearCache();
1436        OQLQuery query = odmg.newOQLQuery();
1437        query.create("select books from " + Book.class.getName() + " where title like $1");
1438        query.bind(name);
1439        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1440        assertEquals(1, result.size());
1441        Book b = (Book) result.iterator().next();
1442        assertEquals(versionBook, b.getVersion());
1443        assertNotNull(b.getReviews());
1444        assertEquals(1, b.getReviews().size());
1445
1446        tx.lock(b, Transaction.WRITE);
1447        tx.setCascadingDelete(Book.class, "reviews", true);
1448        // remove from collection with cascading delete
1449
b.getReviews().remove(0);
1450        tx.commit();
1451
1452        // only the removed reference has changed
1453
assertEquals(versionBook, b.getVersion());
1454
1455        tx.begin();
1456        tx.getBroker().clearCache();
1457        query = odmg.newOQLQuery();
1458        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
1459        query.bind(name);
1460        result = (Collection JavaDoc) query.execute();
1461        tx.commit();
1462
1463        // cascading delete was used, so we don't expect an unlinked
1464
// version of the Review class
1465
assertEquals(0, result.size());
1466
1467
1468        tx.begin();
1469        query = odmg.newOQLQuery();
1470        query.create("select books from " + Book.class.getName() + " where title like $1");
1471        query.bind(name);
1472        result = (Collection JavaDoc) query.execute();
1473        tx.commit();
1474
1475        assertEquals(1, result.size());
1476        b = (Book) result.iterator().next();
1477        assertEquals(versionBook, b.getVersion());
1478        // we have removed the Review object
1479
assertEquals(0, b.getReviews().size());
1480    }
1481
1482    /**
1483     * delete Book object with existing references
1484     */

1485    public void testCollectionReference_4a() throws Exception JavaDoc
1486    {
1487        String JavaDoc name = "testCollectionReference_4_" + System.currentTimeMillis();
1488        Date JavaDoc date = new Date JavaDoc();
1489        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1490        Book book = new Book(name, date, cover);
1491        Review r1 = new Review(name);
1492        Review r2 = new Review(name);
1493        Review r3 = new Review(name);
1494        Author a1 = new Author(name, null);
1495        Author a2 = new Author(name, null);
1496        r1.setAuthor(a1);
1497        r2.setAuthor(a1);
1498        r3.setAuthor(a2);
1499        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1500        reviews.add(r1);
1501        reviews.add(r2);
1502        reviews.add(r3);
1503        book.setReviews(reviews);
1504
1505        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1506        tx.begin();
1507        database.makePersistent(book);
1508        tx.commit();
1509
1510        Integer JavaDoc versionBook = book.getVersion();
1511
1512        tx.begin();
1513        tx.getBroker().clearCache();
1514        OQLQuery query = odmg.newOQLQuery();
1515        query.create("select books from " + Book.class.getName() + " where title like $1");
1516        query.bind(name);
1517        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1518        assertEquals(1, result.size());
1519        Book b = (Book) result.iterator().next();
1520        assertEquals(versionBook, b.getVersion());
1521        assertNotNull(b.getReviews());
1522        assertEquals(3, b.getReviews().size());
1523        assertNotNull(((Review) b.getReviews().get(0)).getAuthor());
1524        assertNotNull(((Review) b.getReviews().get(1)).getAuthor());
1525        assertNotNull(((Review) b.getReviews().get(2)).getAuthor());
1526
1527        // Book instance should be already locked
1528
// now mark Book for delete and disable cascading delete
1529
// for the 1:n relation to Review class
1530
tx.setCascadingDelete(Book.class, "reviews", false);
1531        database.deletePersistent(b);
1532        tx.commit();
1533        // System.out.println("## After commit");
1534

1535        tx.begin();
1536        tx.getBroker().clearCache();
1537        query = odmg.newOQLQuery();
1538        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
1539        query.bind(name);
1540        result = (Collection JavaDoc) query.execute();
1541        tx.commit();
1542        // we auto-delete the Review object, only remove from reference collection
1543
assertEquals(3, result.size());
1544        List JavaDoc list = new ArrayList JavaDoc(result);
1545        assertNotNull(((Review) list.get(0)).getAuthor());
1546        assertNotNull(((Review) list.get(1)).getAuthor());
1547        assertNotNull(((Review) list.get(2)).getAuthor());
1548        Review newR1 = (Review) list.get(0);
1549        // book was deleted so we expect unlink of FK
1550
assertNull(newR1.getFkBook());
1551
1552
1553        tx.begin();
1554        query = odmg.newOQLQuery();
1555        query.create("select books from " + Book.class.getName() + " where title like $1");
1556        query.bind(name);
1557        result = (Collection JavaDoc) query.execute();
1558        tx.commit();
1559        assertEquals(0, result.size());
1560    }
1561
1562    /**
1563     * delete Book object with existing references and circular referencing objects
1564     */

1565    public void testCollectionReference_4b() throws Exception JavaDoc
1566    {
1567        String JavaDoc name = "testCollectionReference_4_" + System.currentTimeMillis();
1568        Date JavaDoc date = new Date JavaDoc();
1569        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
1570        Book book = new Book(name, date, cover);
1571        Review r1 = new Review(name);
1572        Review r2 = new Review(name);
1573        Review r3 = new Review(name);
1574        Author a1 = new Author(name, null);
1575        Author a2 = new Author(name, null);
1576        r1.setAuthor(a1);
1577        r2.setAuthor(a1);
1578        r3.setAuthor(a2);
1579        ArrayList JavaDoc reviews = new ArrayList JavaDoc();
1580        reviews.add(r1);
1581        reviews.add(r2);
1582        reviews.add(r3);
1583        book.setReviews(reviews);
1584        ArrayList JavaDoc authors = new ArrayList JavaDoc();
1585        authors.add(a1);
1586        authors.add(a2);
1587        book.setAuthors(authors);
1588
1589        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1590        tx.begin();
1591        database.makePersistent(book);
1592        tx.commit();
1593
1594        Integer JavaDoc versionBook = book.getVersion();
1595
1596        tx.begin();
1597        tx.getBroker().clearCache();
1598        OQLQuery query = odmg.newOQLQuery();
1599        query.create("select books from " + Book.class.getName() + " where title like $1");
1600        query.bind(name);
1601        Collection JavaDoc result = (Collection JavaDoc) query.execute();
1602        assertEquals(1, result.size());
1603        Book b = (Book) result.iterator().next();
1604        assertEquals(versionBook, b.getVersion());
1605        assertNotNull(b.getReviews());
1606        assertEquals(3, b.getReviews().size());
1607        assertNotNull(((Review) b.getReviews().get(0)).getAuthor());
1608        assertNotNull(((Review) b.getReviews().get(1)).getAuthor());
1609        assertNotNull(((Review) b.getReviews().get(2)).getAuthor());
1610        assertNotNull(b.getAuthors());
1611        assertEquals(2, b.getAuthors().size());
1612        Author newA = (Author) b.getAuthors().get(0);
1613        boolean failed = true;
1614        for(Iterator JavaDoc iterator = b.getReviews().iterator(); iterator.hasNext();)
1615        {
1616            Review review = (Review) iterator.next();
1617            if(newA.equals(review.getAuthor()))
1618            {
1619                // as we have circular references we expect the same object instance
1620
assertSame(newA, review.getAuthor());
1621                failed = false;
1622            }
1623        }
1624        if(failed) fail("Expect the same object instance, but not found for " + newA);
1625
1626        // Book instance should be already locked
1627
// now mark Book for delete and disable cascading delete
1628
// for the 1:n relation to Review class
1629
tx.setCascadingDelete(Book.class, "reviews", false);
1630        database.deletePersistent(b);
1631        tx.commit();
1632
1633        tx.begin();
1634        tx.getBroker().clearCache();
1635        query = odmg.newOQLQuery();
1636        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
1637        query.bind(name);
1638        result = (Collection JavaDoc) query.execute();
1639        tx.commit();
1640        // we auto-delete the Review object, only remove from reference collection
1641
assertEquals(3, result.size());
1642        List JavaDoc list = new ArrayList JavaDoc(result);
1643        assertNotNull(((Review) list.get(0)).getAuthor());
1644        assertNotNull(((Review) list.get(1)).getAuthor());
1645        assertNotNull(((Review) list.get(2)).getAuthor());
1646        Review newR1 = (Review) list.get(0);
1647        // book was deleted so we expect unlink of FK
1648
assertNull(newR1.getFkBook());
1649        newA = ((Review) list.get(0)).getAuthor();
1650        assertEquals(0, newA.getBooks().size());
1651
1652
1653        tx.begin();
1654        query = odmg.newOQLQuery();
1655        query.create("select books from " + Book.class.getName() + " where title like $1");
1656        query.bind(name);
1657        result = (Collection JavaDoc) query.execute();
1658        tx.commit();
1659        assertEquals(0, result.size());
1660    }
1661
1662    //=======================================================
1663
// inner test classes
1664
//=======================================================
1665
public static final class Book implements Serializable JavaDoc
1666    {
1667        private Integer JavaDoc id;
1668        private String JavaDoc title;
1669        private Date JavaDoc publicationDate;
1670        private byte[] cover;
1671        private Integer JavaDoc version;
1672
1673        private List JavaDoc authors;
1674        private List JavaDoc reviews;
1675        private Publisher publisher;
1676
1677        public Book()
1678        {
1679        }
1680
1681        public Book(String JavaDoc title, Date JavaDoc publicationDate, byte[] cover)
1682        {
1683            this.title = title;
1684            this.publicationDate = publicationDate;
1685            this.cover = cover;
1686        }
1687
1688        public void addAuthor(Author author)
1689        {
1690            if(authors == null)
1691            {
1692                authors = new ArrayList JavaDoc();
1693            }
1694            authors.add(author);
1695        }
1696
1697        public void addReview(Review review)
1698        {
1699            if(reviews == null)
1700            {
1701                reviews = new ArrayList JavaDoc();
1702            }
1703            reviews.add(review);
1704        }
1705
1706        public boolean removeReview(Review review)
1707        {
1708            if(reviews != null) return reviews.remove(review);
1709            else return false;
1710        }
1711
1712        public Integer JavaDoc getId()
1713        {
1714            return id;
1715        }
1716
1717        public void setId(Integer JavaDoc id)
1718        {
1719            this.id = id;
1720        }
1721
1722        public String JavaDoc getTitle()
1723        {
1724            return title;
1725        }
1726
1727        public void setTitle(String JavaDoc title)
1728        {
1729            this.title = title;
1730        }
1731
1732        public Date JavaDoc getPublicationDate()
1733        {
1734            return publicationDate;
1735        }
1736
1737        public void setPublicationDate(Date JavaDoc publicationDate)
1738        {
1739            this.publicationDate = publicationDate;
1740        }
1741
1742        public byte[] getCover()
1743        {
1744            return cover;
1745        }
1746
1747        public void setCover(byte[] cover)
1748        {
1749            this.cover = cover;
1750        }
1751
1752        public Integer JavaDoc getVersion()
1753        {
1754            return version;
1755        }
1756
1757        public void setVersion(Integer JavaDoc version)
1758        {
1759            this.version = version;
1760        }
1761
1762        public List JavaDoc getAuthors()
1763        {
1764            return authors;
1765        }
1766
1767        public void setAuthors(List JavaDoc authors)
1768        {
1769            this.authors = authors;
1770        }
1771
1772        public List JavaDoc getReviews()
1773        {
1774            return reviews;
1775        }
1776
1777        public void setReviews(List JavaDoc reviews)
1778        {
1779            this.reviews = reviews;
1780        }
1781
1782        public Publisher getPublisher()
1783        {
1784            return publisher;
1785        }
1786
1787        public void setPublisher(Publisher publisher)
1788        {
1789            this.publisher = publisher;
1790        }
1791    }
1792
1793    public static final class Author implements Serializable JavaDoc
1794    {
1795        private Integer JavaDoc id;
1796        private String JavaDoc name;
1797        private List JavaDoc books;
1798        private Integer JavaDoc version;
1799
1800        public Author()
1801        {
1802        }
1803
1804        public Author(String JavaDoc name, List JavaDoc books)
1805        {
1806            this.name = name;
1807            this.books = books;
1808        }
1809
1810        public void addBook(Book book)
1811        {
1812            if(books == null)
1813            {
1814                books = new ArrayList JavaDoc();
1815            }
1816            books.add(book);
1817        }
1818
1819        public Integer JavaDoc getId()
1820        {
1821            return id;
1822        }
1823
1824        public void setId(Integer JavaDoc id)
1825        {
1826            this.id = id;
1827        }
1828
1829        public String JavaDoc getName()
1830        {
1831            return name;
1832        }
1833
1834        public void setName(String JavaDoc name)
1835        {
1836            this.name = name;
1837        }
1838
1839        public List JavaDoc getBooks()
1840        {
1841            return books;
1842        }
1843
1844        public void setBooks(List JavaDoc books)
1845        {
1846            this.books = books;
1847        }
1848
1849        public Integer JavaDoc getVersion()
1850        {
1851            return version;
1852        }
1853
1854        public void setVersion(Integer JavaDoc version)
1855        {
1856            this.version = version;
1857        }
1858    }
1859
1860    public static interface Publisher extends Serializable JavaDoc
1861    {
1862        public Integer JavaDoc getId();
1863        public void setId(Integer JavaDoc id);
1864        public String JavaDoc getName();
1865        public void setName(String JavaDoc name);
1866        public Integer JavaDoc getVersion();
1867        public void setVersion(Integer JavaDoc version);
1868    }
1869
1870    public static final class PublisherImpl implements Publisher
1871    {
1872        private Integer JavaDoc id;
1873        private String JavaDoc name;
1874        private Integer JavaDoc version;
1875
1876        public PublisherImpl()
1877        {
1878        }
1879
1880        public PublisherImpl(String JavaDoc name)
1881        {
1882            this.name = name;
1883        }
1884
1885        public Integer JavaDoc getId()
1886        {
1887            return id;
1888        }
1889
1890        public void setId(Integer JavaDoc id)
1891        {
1892            this.id = id;
1893        }
1894
1895        public String JavaDoc getName()
1896        {
1897            return name;
1898        }
1899
1900        public void setName(String JavaDoc name)
1901        {
1902            this.name = name;
1903        }
1904
1905        public Integer JavaDoc getVersion()
1906        {
1907            return version;
1908        }
1909
1910        public void setVersion(Integer JavaDoc version)
1911        {
1912            this.version = version;
1913        }
1914    }
1915
1916    public static final class Review implements Serializable JavaDoc
1917    {
1918        private Integer JavaDoc id;
1919        private String JavaDoc summary;
1920        private Integer JavaDoc fkBook;
1921        private Integer JavaDoc version;
1922        private Author author;
1923
1924        public Review()
1925        {
1926        }
1927
1928        public Review(String JavaDoc summary)
1929        {
1930            this.summary = summary;
1931        }
1932
1933        public Integer JavaDoc getId()
1934        {
1935            return id;
1936        }
1937
1938        public void setId(Integer JavaDoc id)
1939        {
1940            this.id = id;
1941        }
1942
1943        public Integer JavaDoc getFkBook()
1944        {
1945            return fkBook;
1946        }
1947
1948        public void setFkBook(Integer JavaDoc fkBook)
1949        {
1950            this.fkBook = fkBook;
1951        }
1952
1953        public String JavaDoc getSummary()
1954        {
1955            return summary;
1956        }
1957
1958        public void setSummary(String JavaDoc summary)
1959        {
1960            this.summary = summary;
1961        }
1962
1963        public Integer JavaDoc getVersion()
1964        {
1965            return version;
1966        }
1967
1968        public void setVersion(Integer JavaDoc version)
1969        {
1970            this.version = version;
1971        }
1972
1973        public Author getAuthor()
1974        {
1975            return author;
1976        }
1977
1978        public void setAuthor(Author author)
1979        {
1980            this.author = author;
1981        }
1982
1983        public boolean equals(Object JavaDoc obj)
1984        {
1985            boolean result = false;
1986            if(obj instanceof Review)
1987            {
1988                Review other = (Review) obj;
1989                result = new EqualsBuilder()
1990                        .append(id, other.id)
1991                        .append(summary, other.summary)
1992                        .append(version, other.version)
1993                        .append(fkBook, other.fkBook)
1994                        .append(author, other.author)
1995                        .isEquals();
1996            }
1997            return result;
1998        }
1999    }
2000
2001}
2002
Popular Tags