Skip to contentMethod: getEntityContext()
1: /**
2: * Copyright (C) 2020 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.change;
16:
17: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18: import cz.cvut.kbss.jopa.sessions.ChangeRecord;
19: import cz.cvut.kbss.jopa.sessions.ObjectChangeSet;
20:
21: import java.net.URI;
22: import java.util.Collections;
23: import java.util.Objects;
24: import java.util.Set;
25:
26: /**
27: * Change set representing object deletion.
28: * <p>
29: * Supports only a subset of the {@link ObjectChangeSet} operations relevant for object removal during merge into parent
30: * session.
31: */
32: public class DeleteObjectChangeSet implements ObjectChangeSet {
33:
34: private final Object object;
35:
36: private final Descriptor descriptor;
37:
38: public DeleteObjectChangeSet(Object object, Descriptor descriptor) {
39: this.object = Objects.requireNonNull(object);
40: this.descriptor = Objects.requireNonNull(descriptor);
41: }
42:
43: /**
44: * @throws UnsupportedOperationException This method is not supported
45: */
46: @Override
47: public void addChangeRecord(ChangeRecord record) {
48: unsupported();
49: }
50:
51: private static void unsupported() {
52: throw new UnsupportedOperationException("Can't invoke on " + DeleteObjectChangeSet.class.getSimpleName());
53: }
54:
55: @Override
56: public Class<?> getObjectClass() {
57: return object.getClass();
58: }
59:
60: @Override
61: public Set<ChangeRecord> getChanges() {
62: return Collections.emptySet();
63: }
64:
65: @Override
66: public boolean hasChanges() {
67: return false;
68: }
69:
70: /**
71: * @throws UnsupportedOperationException This method is not supported
72: */
73: @Override
74: public void setNew(boolean isNew) {
75: unsupported();
76: }
77:
78: @Override
79: public boolean isNew() {
80: return false;
81: }
82:
83: @Override
84: public Object getCloneObject() {
85: return object;
86: }
87:
88: @Override
89: public Object getChangedObject() {
90: return object;
91: }
92:
93: @Override
94: public Descriptor getEntityDescriptor() {
95: return descriptor;
96: }
97:
98: @Override
99: public URI getEntityContext() {
100: return descriptor.getSingleContext().orElse(null);
101: }
102: }