Skip to content

Package: PersistenceUtil

PersistenceUtil

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(s).
22: * <p>
23: * The {@code PersistenceUtil} interface instance obtained from the {@link cz.cvut.kbss.jopa.Persistence} class is used
24: * to determine the load state of an entity or entity attribute regardless of which persistence provider in the
25: * environment created the entity.
26: */
27: public interface PersistenceUtil {
28:
29: /**
30: * Determine the load state of a given persistent attribute.
31: *
32: * @param entity entity containing the attribute
33: * @param attributeName name of attribute whose load state is to be determined
34: * @return {@code false} if entity's state has not been loaded or if the attribute state has not been loaded, else
35: * {@code true}
36: */
37: boolean isLoaded(Object entity, String attributeName);
38:
39: /**
40: * Determine the load state of an entity. This method can be used to determine the load state of an entity passed as
41: * a reference. An entity is considered loaded if all attributes for which {@link
42: * cz.cvut.kbss.jopa.model.annotations.FetchType#EAGER} has been specified have been loaded.
43: * <p>
44: * The {@link #isLoaded(Object, String)} method should be used to determine the load state of an attribute. Not
45: * doing so might lead to unintended loading of state.
46: *
47: * @param entity whose load state is to be determined
48: * @return {@code false} if the entity has not been loaded, else {@code true}
49: */
50: boolean isLoaded(Object entity);
51: }