001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.gps.device.jdo;
018:
019: import javax.jdo.PersistenceManager;
020: import javax.jdo.Transaction;
021:
022: import org.compass.core.CompassHits;
023: import org.compass.core.CompassSession;
024: import org.compass.core.CompassTransaction;
025:
026: public class Jdo2GpsDeviceTests extends AbstractJdoGpsDeviceTests {
027:
028: protected void setUpGpsDevice() {
029: Jdo2GpsDevice jdoGpsDevice = new Jdo2GpsDevice();
030: jdoGpsDevice.setName("jdoDevice");
031: jdoGpsDevice.setMirrorDataChanges(true);
032: jdoGpsDevice
033: .setPersistenceManagerFactory(persistenceManagerFactory);
034: compassGps.addGpsDevice(jdoGpsDevice);
035: }
036:
037: public void testMirrorWithIndex() {
038: compassGps.index();
039:
040: CompassSession sess = compassGps.getMirrorCompass()
041: .openSession();
042: CompassTransaction tr = sess.beginTransaction();
043:
044: CompassHits hits = sess.find("sony");
045: assertEquals(1, hits.getLength());
046:
047: tr.commit();
048:
049: PersistenceManager pm = persistenceManagerFactory
050: .getPersistenceManager();
051: Transaction tx = pm.currentTransaction();
052: Product product = new Product("Apple",
053: "A standard ipod from Apple", 49.99);
054: try {
055: tx.begin();
056: pm.makePersistent(product);
057: tx.commit();
058: } finally {
059: if (tx.isActive()) {
060: tx.rollback();
061: }
062: pm.close();
063: }
064:
065: tr = sess.beginTransaction();
066:
067: hits = sess.find("Apple");
068: assertEquals(1, hits.getLength());
069:
070: tr.commit();
071:
072: Object id = null;
073: pm = persistenceManagerFactory.getPersistenceManager();
074: tx = pm.currentTransaction();
075: try {
076: tx.begin();
077: product.setDescription("applex");
078: pm.makePersistent(product);
079: id = pm.getObjectId(product);
080: tx.commit();
081: } finally {
082: if (tx.isActive()) {
083: tx.rollback();
084: }
085: pm.close();
086: }
087:
088: tr = sess.beginTransaction();
089:
090: hits = sess.find("applex");
091: assertEquals(1, hits.getLength());
092:
093: tr.commit();
094:
095: pm = persistenceManagerFactory.getPersistenceManager();
096: tx = pm.currentTransaction();
097: try {
098: tx.begin();
099: Object obj = pm.getObjectById(id);
100: pm.deletePersistent(obj);
101: tx.commit();
102: } finally {
103: if (tx.isActive()) {
104: tx.rollback();
105: }
106: pm.close();
107: }
108:
109: tr = sess.beginTransaction();
110:
111: hits = sess.find("applex");
112: assertEquals(0, hits.getLength());
113:
114: tr.commit();
115:
116: }
117: }
|