Skip to content

Package: EntityTransaction

EntityTransaction

Coverage

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