2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore.modification;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
16 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
17 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 * DeleteModification store all the parameters required to delete a path from the data tree
24 public class DeleteModification extends AbstractModification {
25 private static final long serialVersionUID = 1L;
27 public DeleteModification() {
28 this(DataStoreVersions.CURRENT_VERSION);
31 public DeleteModification(short version) {
35 public DeleteModification(YangInstanceIdentifier path) {
40 public void apply(DOMStoreWriteTransaction transaction) {
41 transaction.delete(getPath());
45 public byte getType() {
50 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
51 setPath(SerializationUtils.deserializePath(in));
55 public void writeExternal(ObjectOutput out) throws IOException {
56 SerializationUtils.serializePath(getPath(), out);
61 public Object toSerializable() {
62 return PersistentMessages.Modification.newBuilder().setType(this.getClass().toString())
63 .setPath(InstanceIdentifierUtils.toSerializable(getPath())).build();
67 public static DeleteModification fromSerializable(Object serializable) {
68 PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
69 return new DeleteModification(InstanceIdentifierUtils.fromSerializable(o.getPath()));
72 public static DeleteModification fromStream(ObjectInput in, short version)
73 throws ClassNotFoundException, IOException {
74 DeleteModification mod = new DeleteModification(version);