Skip to content

Package: CloneBuilder

CloneBuilder

Coverage

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