Skip to contentPackage: CloneBuilder
CloneBuilder
Coverage
1: /**
2: * Copyright (C) 2022 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.sessions;
16:
17: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18:
19: import java.lang.reflect.Field;
20:
21: /**
22: * Objects of this interface are responsible for building clones for UnitOfWork
23: * transactions.
24: */
25: public interface CloneBuilder {
26:
27: /**
28: * Builds clone of the given object.
29: *
30: * @param original Object
31: * @param cloneConfiguration Configuration for the cloning process
32: * @return Object The clone
33: * @throws NullPointerException If {@code original} or {@code repository} is {@code null}
34: */
35: Object buildClone(Object original, CloneConfiguration cloneConfiguration);
36:
37: /**
38: * Builds clone of the given object.
39: * <p>
40: * This method differs from {@link #buildClone(Object, CloneConfiguration)} in that it
41: * accepts another argument which represents the owner of the built clone.
42: * This is useful in situations when we are cloning attributes directly, e. g. when lazily loading a field value.
43: *
44: * @param cloneOwner The owner of the created clone
45: * @param clonedField The field whose value is being cloned
46: * @param original The original to clone
47: * @param descriptor Entity descriptor
48: * @return The clone
49: * @throws NullPointerException If {@code cloneOwner}, {@code original} or {@code contextUri} is {@code null}
50: */
51: Object buildClone(Object cloneOwner, Field clonedField, Object original, Descriptor descriptor);
52:
53: /**
54: * Resets the clone builder.
55: * <p>
56: * Especially resets the visited objects cache to make sure all the clones are built from scratch and are not
57: * affected by the previously built ones.
58: */
59: void reset();
60:
61: /**
62: * Removes the specified instance from the clone builder's visited entities cache.
63: *
64: * @param instance The instance to remove (original object).
65: * @param descriptor Instance descriptor
66: */
67: void removeVisited(Object instance, Descriptor descriptor);
68:
69: /**
70: * Merges the changes on clone into the original object.
71: *
72: * @param changeSet Contains changes to merge
73: */
74: void mergeChanges(ObjectChangeSet changeSet);
75: }