Merge "Small fix to xsql dependencies"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardWriteTransaction.java
1 /*
2  *
3  *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  *  This program and the accompanying materials are made available under the
6  *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  */
10
11 package org.opendaylight.controller.cluster.datastore;
12
13 import akka.actor.ActorRef;
14
15 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
16 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
17 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
18 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22
23 /**
24  * @author: syedbahm
25  * Date: 8/6/14
26  */
27 public class ShardWriteTransaction extends ShardTransaction {
28     private final DOMStoreWriteTransaction transaction;
29
30     public ShardWriteTransaction(DOMStoreWriteTransaction transaction, ActorRef shardActor,
31             SchemaContext schemaContext) {
32         super(shardActor, schemaContext);
33         this.transaction = transaction;
34     }
35
36     @Override
37     public void handleReceive(Object message) throws Exception {
38         if(WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
39             writeData(transaction, WriteData.fromSerializable(message, schemaContext));
40         } else if(MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
41             mergeData(transaction, MergeData.fromSerializable(message, schemaContext));
42         } else if(DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
43             deleteData(transaction, DeleteData.fromSerializable(message));
44         } else if(ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
45             readyTransaction(transaction, new ReadyTransaction());
46         } else {
47             super.handleReceive(message);
48         }
49     }
50
51     @Override
52     protected DOMStoreTransaction getDOMStoreTransaction() {
53         return transaction;
54     }
55 }