atomic-storage: remove type dependency at segment level I/O
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / DeleteModification.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.modification;
9
10 import java.io.IOException;
11 import java.io.ObjectInput;
12 import java.io.ObjectOutput;
13 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
14 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
15 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
18 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
19 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
20
21 /**
22  * DeleteModification store all the parameters required to delete a path from the data tree.
23  */
24 public class DeleteModification extends AbstractModification {
25     private static final long serialVersionUID = 1L;
26
27     public DeleteModification() {
28         this(DataStoreVersions.CURRENT_VERSION);
29     }
30
31     public DeleteModification(final short version) {
32         super(version);
33     }
34
35     public DeleteModification(final YangInstanceIdentifier path) {
36         super(path);
37     }
38
39     DeleteModification(final short version, final YangInstanceIdentifier path) {
40         super(version, path);
41     }
42
43     @Override
44     public void apply(final DOMStoreWriteTransaction transaction) {
45         transaction.delete(getPath());
46     }
47
48     @Override
49     public void apply(final DataTreeModification transaction) {
50         transaction.delete(getPath());
51     }
52
53     @Override
54     public byte getType() {
55         return DELETE;
56     }
57
58     @Override
59     public void readExternal(final ObjectInput in) throws IOException {
60         setPath(SerializationUtils.readPath(in));
61     }
62
63     @Override
64     public void writeExternal(final ObjectOutput out) throws IOException {
65         SerializationUtils.writePath(out, getPath());
66     }
67
68     @Override
69     public void writeTo(final NormalizedNodeDataOutput out) throws IOException {
70         out.writeYangInstanceIdentifier(getPath());
71     }
72
73     public static DeleteModification fromStream(final NormalizedNodeDataInput in, final short version)
74             throws IOException {
75         return new DeleteModification(version, in.readYangInstanceIdentifier());
76     }
77 }