001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.common.assorted;
022:
023: import com.db4o.*;
024: import com.db4o.config.*;
025: import com.db4o.ext.*;
026:
027: import db4ounit.extensions.*;
028:
029: public class DualDeleteTestCase extends Db4oClientServerTestCase {
030:
031: public static void main(String[] args) {
032: new DualDeleteTestCase().runClientServer();
033: }
034:
035: public Atom atom;
036:
037: protected void configure(Configuration config) {
038: config.objectClass(this ).cascadeOnDelete(true);
039: config.objectClass(this ).cascadeOnUpdate(true);
040: }
041:
042: protected void store() {
043: DualDeleteTestCase dd1 = new DualDeleteTestCase();
044: dd1.atom = new Atom("justone");
045: store(dd1);
046: DualDeleteTestCase dd2 = new DualDeleteTestCase();
047: dd2.atom = dd1.atom;
048: store(dd2);
049: }
050:
051: public void test() {
052: ExtObjectContainer oc1 = openNewClient();
053: ExtObjectContainer oc2 = openNewClient();
054: try {
055: ObjectSet os1 = oc1.query(DualDeleteTestCase.class);
056: ObjectSet os2 = oc2.query(DualDeleteTestCase.class);
057: deleteObjectSet(oc1, os1);
058: assertOccurrences(oc1, Atom.class, 0);
059: assertOccurrences(oc2, Atom.class, 1);
060: deleteObjectSet(oc2, os2);
061: assertOccurrences(oc1, Atom.class, 0);
062: assertOccurrences(oc2, Atom.class, 0);
063: oc1.rollback();
064: assertOccurrences(oc1, Atom.class, 1);
065: assertOccurrences(oc2, Atom.class, 0);
066: oc1.commit();
067: assertOccurrences(oc1, Atom.class, 1);
068: assertOccurrences(oc2, Atom.class, 0);
069: deleteAll(oc2, DualDeleteTestCase.class);
070: oc2.commit();
071: assertOccurrences(oc1, Atom.class, 0);
072: assertOccurrences(oc2, Atom.class, 0);
073: } finally {
074: oc1.close();
075: oc2.close();
076: }
077: }
078:
079: public void conc1(ExtObjectContainer oc) throws Exception {
080: ObjectSet os = oc.query(DualDeleteTestCase.class);
081: Thread.sleep(500);
082: deleteObjectSet(oc, os);
083: oc.rollback();
084: }
085:
086: public void check1(ExtObjectContainer oc) throws Exception {
087: assertOccurrences(oc, Atom.class, 1);
088: }
089:
090: public void conc2(ExtObjectContainer oc) throws Exception {
091: ObjectSet os = oc.query(DualDeleteTestCase.class);
092: Thread.sleep(500);
093: deleteObjectSet(oc, os);
094: assertOccurrences(oc, Atom.class, 0);
095: }
096:
097: public void check2(ExtObjectContainer oc) throws Exception {
098: assertOccurrences(oc, Atom.class, 0);
099: }
100:
101: }
|