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.ext.ExtObjectContainer;
024:
025: import db4ounit.Assert;
026: import db4ounit.extensions.Db4oClientServerTestCase;
027:
028: public class RollbackDeleteTestCase extends Db4oClientServerTestCase {
029:
030: public static void main(String[] args) {
031: new RollbackDeleteTestCase().runClientServer();
032: }
033:
034: protected void store() {
035: store(new SimpleObject("hello", 1));
036: }
037:
038: /*
039: * delete - rollback - delete - commit
040: */
041: public void testDRDC() {
042: ExtObjectContainer oc1 = openNewClient();
043: ExtObjectContainer oc2 = openNewClient();
044: ExtObjectContainer oc3 = openNewClient();
045: try {
046: SimpleObject o1 = (SimpleObject) retrieveOnlyInstance(oc1,
047: SimpleObject.class);
048: oc1.delete(o1);
049: SimpleObject o2 = (SimpleObject) retrieveOnlyInstance(oc2,
050: SimpleObject.class);
051: Assert.areEqual("hello", o2.getS());
052:
053: oc1.rollback();
054:
055: o2 = (SimpleObject) retrieveOnlyInstance(oc2,
056: SimpleObject.class);
057: oc2.refresh(o2, Integer.MAX_VALUE);
058: Assert.areEqual("hello", o2.getS());
059:
060: oc1.commit();
061: o2 = (SimpleObject) retrieveOnlyInstance(oc2,
062: SimpleObject.class);
063: oc2.refresh(o2, Integer.MAX_VALUE);
064: Assert.areEqual("hello", o2.getS());
065:
066: oc1.delete(o1);
067: oc1.commit();
068:
069: assertOccurrences(oc3, SimpleObject.class, 0);
070: assertOccurrences(oc2, SimpleObject.class, 0);
071:
072: } finally {
073: oc1.close();
074: oc2.close();
075: oc3.close();
076: }
077: }
078:
079: /*
080: * set - rollback - delete - commit
081: */
082: public void testSRDC() {
083: ExtObjectContainer oc1 = openNewClient();
084: ExtObjectContainer oc2 = openNewClient();
085: ExtObjectContainer oc3 = openNewClient();
086: try {
087: SimpleObject o1 = (SimpleObject) retrieveOnlyInstance(oc1,
088: SimpleObject.class);
089: oc1.set(o1);
090: SimpleObject o2 = (SimpleObject) retrieveOnlyInstance(oc2,
091: SimpleObject.class);
092: Assert.areEqual("hello", o2.getS());
093:
094: oc1.rollback();
095:
096: o2 = (SimpleObject) retrieveOnlyInstance(oc2,
097: SimpleObject.class);
098: oc2.refresh(o2, Integer.MAX_VALUE);
099: Assert.areEqual("hello", o2.getS());
100:
101: oc1.commit();
102: o2 = (SimpleObject) retrieveOnlyInstance(oc2,
103: SimpleObject.class);
104: oc2.refresh(o2, Integer.MAX_VALUE);
105: Assert.areEqual("hello", o2.getS());
106:
107: oc1.delete(o1);
108: oc1.commit();
109:
110: assertOccurrences(oc3, SimpleObject.class, 0);
111: assertOccurrences(oc2, SimpleObject.class, 0);
112:
113: } finally {
114: oc1.close();
115: oc2.close();
116: oc3.close();
117: }
118: }
119:
120: }
|