Skip to content

Package: CloneBuilder

CloneBuilder

Coverage

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