01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.transaction;
19:
20: /**
21: * This is a "Unit of Work" object (see "Unit of Work" pattern by Martin Fowler,
22: * <a href="http://www.martinfowler.com/eaaCatalog/unitOfWork.html">
23: * http://www.martinfowler.com/eaaCatalog/unitOfWork.html
24: * </a>: the unit of work "maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems".
25: *
26: * <p>In the current design, this interface allows a use case to generate documents, while ensuring that only one instance of a document is created. This access is provided by the DocumentIdentityMap's DocumentFactory.</p>
27: *
28: * <p>This interface may be extended in the future to allow for access to further types of business objects.</p>
29: *
30: * @version $Id: UnitOfWork.java 534530 2007-05-02 16:24:22Z andreas $
31: */
32: public interface UnitOfWork {
33:
34: /**
35: * Registers an object as new.
36: * @param object The object.
37: * @throws TransactionException if an error occurs.
38: */
39: void registerNew(Transactionable object)
40: throws TransactionException;
41:
42: /**
43: * Registers an object as modified.
44: * @param object The object.
45: * @throws TransactionException if an error occurs.
46: */
47: void registerDirty(Transactionable object)
48: throws TransactionException;
49:
50: /**
51: * Registers an object as removed.
52: * @param object The object.
53: * @throws TransactionException if an error occurs.
54: */
55: void registerRemoved(Transactionable object)
56: throws TransactionException;
57:
58: /**
59: * Commits the transaction.
60: * @throws TransactionException if an error occurs.
61: */
62: void commit() throws TransactionException;
63:
64: /**
65: * Rolls the transaction back.
66: * @throws TransactionException if an error occurs.
67: */
68: void rollback() throws TransactionException;
69:
70: /**
71: * @param transactionable A transactionable.
72: * @return If the transactionable is registered as dirty.
73: */
74: boolean isDirty(Transactionable transactionable);
75:
76: /**
77: * Creates a lock.
78: * @param lockable The lockable.
79: * @param version The version.
80: * @return A lock.
81: * @throws TransactionException if a lock is already placed on this transactionable.
82: */
83: Lock createLock(Lockable lockable, int version)
84: throws TransactionException;
85:
86: /**
87: * Removes a lock.
88: * @param lockable The lockable.
89: * @throws TransactionException if no lock is placed on this transactionable.
90: */
91: void removeLock(Lockable lockable) throws TransactionException;
92:
93: }
|