Skip to content

Package: EntityTransaction

EntityTransaction

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.transactions;
16:
17: import cz.cvut.kbss.jopa.model.EntityManager;
18:
19: /**
20: * Interface used to control transactions on resource-local entity managers.
21: * <p>
22: * The {@link EntityManager#getTransaction()} method returns the {@code EntityTransaction} interface.
23: */
24: public interface EntityTransaction {
25:
26: /**
27: * Start a resource transaction.
28: *
29: * @throws IllegalStateException if {@code isActive()} is true
30: */
31: void begin();
32:
33: /**
34: * Commit the current resource transaction, writing any unflushed changes to the database.
35: *
36: * @throws IllegalStateException if {@code isActive()} is false
37: * @throws cz.cvut.kbss.jopa.exceptions.RollbackException if the commit fails
38: */
39: void commit();
40:
41: /**
42: * Roll back the current resource transaction.
43: *
44: * @throws IllegalStateException if {@code isActive()} is false
45: * @throws cz.cvut.kbss.jopa.exceptions.OWLPersistenceException if an unexpected error condition is encountered
46: */
47: void rollback();
48:
49: /**
50: * Mark the current resource transaction so that the only possible outcome of the transaction is for the transaction
51: * to be rolled back.
52: *
53: * @throws IllegalStateException if {@code isActive()} is false
54: */
55: void setRollbackOnly();
56:
57: /**
58: * Determine whether the current resource transaction has been marked for rollback.
59: *
60: * @return boolean indicating whether the transaction has been marked for rollback
61: * @throws IllegalStateException if {@code isActive()} is false
62: */
63: boolean isRollbackOnly();
64:
65: /**
66: * Indicate whether a resource transaction is in progress.
67: *
68: * @return boolean indicating whether transaction is in progress
69: * @throws cz.cvut.kbss.jopa.exceptions.OWLPersistenceException if an unexpected error condition is encountered
70: */
71: boolean isActive();
72: }