Skip to content

Package: PersistenceUnitUtil

PersistenceUnitUtil

Coverage

1: /**
2: * Copyright (C) 2020 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.model;
16:
17: /**
18: * Utility interface between the application and the persistence provider managing the persistence unit.
19: * <p>
20: * The methods of this interface should only be invoked on entity instances obtained from or managed by entity managers
21: * for this persistence unit or on new entity instances.
22: */
23: public interface PersistenceUnitUtil {
24:
25: /**
26: * Determine the load state of a given persistent attribute of an entity belonging to the persistence unit.
27: *
28: * @param entity entity instance containing the attribute
29: * @param attributeName name of attribute whose load state is to be determined
30: * @return false if entity's state has not been loaded or if the attribute state has not been loaded, else true
31: */
32: boolean isLoaded(Object entity, String attributeName);
33:
34: /**
35: * Determine the load state of an entity belonging to the persistence unit.
36: * <p>
37: * This method can be used to determine the load state of an entity passed as a reference. An entity is considered
38: * loaded if all attributes for which {@code FetchType.EAGER} has been specified have been loaded.
39: * <p>
40: * The {@link #isLoaded(Object, String)} method should be used to determine the load state of an attribute. Not
41: * doing so might lead to unintended loading of state.
42: *
43: * @param entity entity instance whose load state is to be determined
44: * @return false if the entity has not been loaded, else true
45: */
46: boolean isLoaded(Object entity);
47:
48: /**
49: * Return the id of the entity. A generated id is not guaranteed to be available until after the database insert has
50: * occurred. Returns null if the entity does not yet have an id.
51: *
52: * @param entity entity instance
53: * @return id of the entity
54: * @throws IllegalArgumentException if the object is found not to be an entity
55: */
56: Object getIdentifier(Object entity);
57: }