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 DeleteUpdateTestCase extends Db4oClientServerTestCase {
029:
030: public static void main(String[] args) {
031: new DeleteUpdateTestCase().runClientServer();
032: }
033:
034: protected void store() {
035: store(new SimpleObject("hello", 1));
036: }
037:
038: /*
039: * delete - set - commit delete - commit set
040: */
041: public void _testDS() {
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: o2.setS("o2");
053: oc2.set(o2);
054:
055: oc1.commit();
056: oc2.commit();
057:
058: o1 = (SimpleObject) retrieveOnlyInstance(oc1,
059: SimpleObject.class);
060: oc1.refresh(o1, Integer.MAX_VALUE);
061: Assert.areEqual("o2", o1.getS());
062:
063: o2 = (SimpleObject) retrieveOnlyInstance(oc2,
064: SimpleObject.class);
065: oc2.refresh(o2, Integer.MAX_VALUE);
066: Assert.areEqual("o2", o2.getS());
067:
068: SimpleObject o3 = (SimpleObject) retrieveOnlyInstance(oc3,
069: SimpleObject.class);
070: oc1.refresh(o1, Integer.MAX_VALUE);
071: Assert.areEqual("o2", o3.getS());
072:
073: } finally {
074: oc1.close();
075: oc2.close();
076: oc3.close();
077: }
078:
079: }
080:
081: /*
082: * delete - set - commit set - commit delete
083: */
084: public void testSD() {
085: ExtObjectContainer oc1 = openNewClient();
086: ExtObjectContainer oc2 = openNewClient();
087: ExtObjectContainer oc3 = openNewClient();
088: try {
089: SimpleObject o1 = (SimpleObject) retrieveOnlyInstance(oc1,
090: SimpleObject.class);
091: oc1.delete(o1);
092: SimpleObject o2 = (SimpleObject) retrieveOnlyInstance(oc2,
093: SimpleObject.class);
094: Assert.areEqual("hello", o2.getS());
095: o2.setS("o2");
096: oc2.set(o2);
097:
098: oc2.commit();
099: oc1.commit();
100:
101: assertOccurrences(oc1, SimpleObject.class, 0);
102: assertOccurrences(oc2, SimpleObject.class, 0);
103: assertOccurrences(oc3, SimpleObject.class, 0);
104:
105: } finally {
106: oc1.close();
107: oc2.close();
108: oc3.close();
109: }
110:
111: }
112:
113: }
|