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.fieldindex;
022:
023: import com.db4o.internal.Transaction;
024: import com.db4o.query.Query;
025:
026: import db4ounit.Assert;
027: import db4ounit.extensions.fixtures.OptOutCS;
028:
029: /**
030: * @exclude
031: */
032: public class StringIndexTestCase extends StringIndexTestCaseBase
033: implements OptOutCS {
034:
035: public static void main(String[] args) {
036: new StringIndexTestCase().runSolo();
037: }
038:
039: public void testNotEquals() {
040: add("foo");
041: add("bar");
042: add("baz");
043: add(null);
044:
045: final Query query = newQuery(Item.class);
046: query.descend("name").constrain("bar").not();
047: assertItems(new String[] { "foo", "baz", null }, query
048: .execute());
049: }
050:
051: public void testCancelRemovalRollback() throws Exception {
052:
053: prepareCancelRemoval(trans(), "original");
054: rename("original", "updated");
055: db().rollback();
056: grafittiFreeSpace();
057: reopen();
058:
059: assertExists("original");
060: }
061:
062: public void testCancelRemovalRollbackForMultipleTransactions()
063: throws Exception {
064: final Transaction trans1 = newTransaction();
065: final Transaction trans2 = newTransaction();
066:
067: prepareCancelRemoval(trans1, "original");
068: assertExists(trans2, "original");
069:
070: trans1.rollback();
071: assertExists(trans2, "original");
072:
073: add(trans2, "second");
074: assertExists(trans2, "original");
075:
076: trans2.commit();
077: assertExists(trans2, "original");
078:
079: grafittiFreeSpace();
080: reopen();
081: assertExists("original");
082: }
083:
084: public void testCancelRemoval() throws Exception {
085: prepareCancelRemoval(trans(), "original");
086: db().commit();
087: grafittiFreeSpace();
088: reopen();
089:
090: assertExists("original");
091: }
092:
093: private void prepareCancelRemoval(Transaction transaction,
094: String itemName) {
095: add(itemName);
096: db().commit();
097:
098: rename(transaction, itemName, "updated");
099: assertExists(transaction, "updated");
100:
101: rename(transaction, "updated", itemName);
102: assertExists(transaction, itemName);
103: }
104:
105: public void testCancelRemovalForMultipleTransactions()
106: throws Exception {
107: final Transaction trans1 = newTransaction();
108: final Transaction trans2 = newTransaction();
109:
110: prepareCancelRemoval(trans1, "original");
111: rename(trans2, "original", "updated");
112: trans1.commit();
113: grafittiFreeSpace();
114: reopen();
115:
116: assertExists("original");
117: }
118:
119: public void testDeletingAndReaddingMember() throws Exception {
120: add("original");
121: assertExists("original");
122: rename("original", "updated");
123: assertExists("updated");
124: Assert.isNull(query("original"));
125: reopen();
126: assertExists("updated");
127: Assert.isNull(query("original"));
128: }
129: }
|