01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.transaction;
18:
19: import org.compass.core.CompassException;
20: import org.compass.core.engine.SearchEngine;
21: import org.compass.core.spi.InternalCompassSession;
22:
23: public abstract class AbstractTransaction implements
24: InternalCompassTransaction {
25:
26: private boolean begun;
27:
28: protected TransactionFactory transactionFactory;
29:
30: protected AbstractTransaction(TransactionFactory transactionFactory) {
31: this .transactionFactory = transactionFactory;
32: }
33:
34: public void setBegun(boolean begun) {
35: this .begun = begun;
36: }
37:
38: public boolean isBegun() {
39: return begun;
40: }
41:
42: public void commit() throws CompassException {
43: if (!begun) {
44: throw new TransactionException(
45: "Transaction not successfully started");
46: }
47:
48: doCommit();
49: }
50:
51: public void rollback() throws CompassException {
52: if (!begun) {
53: throw new TransactionException(
54: "Transaction not successfully started");
55: }
56:
57: doRollback();
58: }
59:
60: public SearchEngine getSearchEngine() {
61: return ((InternalCompassSession) getSession())
62: .getSearchEngine();
63: }
64:
65: protected abstract void doCommit() throws CompassException;
66:
67: protected abstract void doRollback() throws CompassException;
68:
69: }
|