Skip to content

Package: ProviderUtil

ProviderUtil

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 implemented by the persistence provider. This interface is invoked by the PersistenceUtil
22: * implementation to determine the load status of an entity or entity attribute.
23: */
24: public interface ProviderUtil {
25:
26: /**
27: * If the provider determines that the entity has been provided by itself and that the state of the specified
28: * attribute has been loaded, this method returns LoadState.LOADED.
29: * <p>
30: * If the provider determines that the entity has been provided by itself and that either entity attributes with
31: * FetchType EAGER have not been loaded or that the state of the specified attribute has not been loaded, this
32: * methods returns LoadState.NOT_LOADED.
33: * <p>
34: * If the provider cannot determine the load state, this method returns LoadState.UNKNOWN.
35: * <p>
36: * The provider's implementation of this method must not obtain a reference to an attribute value, as this could
37: * trigger the loading of entity state if the entity has been provided by a different provider.
38: *
39: * @param entity entity instance
40: * @param attributeName name of attribute whose load status is to be determined
41: * @return load status of the attribute
42: */
43: LoadState isLoadedWithoutReference(Object entity, String attributeName);
44:
45: /**
46: * If the provider determines that the entity has been provided by itself and that the state of the specified
47: * attribute has been loaded, this method returns LoadState.LOADED.
48: * <p>
49: * If the provider determines that the entity has been provided by itself and that either entity attributes with
50: * FetchType EAGER have not been loaded or that the state of the specified attribute has not been loaded, this
51: * methods returns LoadState.NOT_LOADED.
52: * <p>
53: * If the provider cannot determine the load state, this method returns LoadState.UNKNOWN.
54: * <p>
55: * The provider's implementation of this method is permitted to obtain a reference to the attribute value. (This
56: * access is safe, because providers which might trigger the loading of the attribute state will have already been
57: * determined by isLoadedWithoutReference.)
58: *
59: * @param entity entity instance
60: * @param attributeName name of attribute whose load status is to be determined
61: * @return load status of the attribute
62: */
63: LoadState isLoadedWithReference(Object entity, String attributeName);
64:
65: /**
66: * If the provider determines that the entity has been provided by itself and that the state of all attributes for
67: * which {@code FetchType.EAGER} has been specified have been loaded, this method returns {@code LoadState.LOADED}.
68: * If the provider determines that the entity has been provided by itself and that not all attributes with {@code
69: * FetchType.EAGER} have been loaded, this method returns {@code LoadState.NOT_LOADED}.
70: * <p>
71: * If the provider cannot determine if the entity has been provided by itself, this method returns {@code
72: * LoadState.UNKNOWN}.
73: * <p>
74: * The provider's implementation of this method must not obtain a reference to any attribute value, as this could
75: * trigger the loading of entity state if the entity has been provided by a different provider.
76: *
77: * @param entity whose loaded status is to be determined
78: * @return load status of the entity
79: */
80: LoadState isLoaded(Object entity);
81: }