Merge "Fixed for bug 1197"
[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
9 package org.opendaylight.controller.cluster.datastore.modification;
10
11 import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
12 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
13 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15
16 /**
17  * DeleteModification store all the parameters required to delete a path from the data tree
18  */
19 public class DeleteModification extends AbstractModification {
20   public DeleteModification(YangInstanceIdentifier path) {
21     super(path);
22   }
23
24   @Override
25   public void apply(DOMStoreWriteTransaction transaction) {
26     transaction.delete(path);
27   }
28
29     @Override public Object toSerializable() {
30         return PersistentMessages.Modification.newBuilder()
31             .setType(this.getClass().toString())
32             .setPath(InstanceIdentifierUtils.toSerializable(this.path))
33             .build();
34     }
35
36     public static DeleteModification fromSerializable(Object serializable){
37         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
38         return new DeleteModification(InstanceIdentifierUtils.fromSerializable(o.getPath()));
39     }
40 }