Skip to content

Package: PersistenceUnitUtil

PersistenceUnitUtil

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