Merge "BUG 2799: SPI for EventSources"
[controller.git] / opendaylight / md-sal / sal-dom-xsql / src / main / java / org / opendaylight / xsql / XSQLProvider.java
1 /*
2  * Copyright (c) 2015 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.xsql;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.dom.xsql.XSQLAdapter;
14 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.xsql.rev140626.XSQL;
15 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.xsql.rev140626.XSQLBuilder;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17
18 /**
19  * @author Sharon Aicler(saichler@gmail.com)
20  **/
21 public class XSQLProvider implements AutoCloseable {
22
23     public static final InstanceIdentifier<XSQL> ID = InstanceIdentifier.builder(XSQL.class).build();
24     //public static final InstanceIdentifier<SalTest> ID2 = InstanceIdentifier.builder(SalTest.class).build();
25
26     public void close() {
27     }
28
29     public XSQL buildXSQL(DataBroker dps) {
30             XSQLAdapter.log("Building XSL...");
31             XSQLBuilder builder = new XSQLBuilder();
32             builder.setPort("34343");
33             XSQL xsql = builder.build();
34             try {
35                 if (dps != null) {
36                     XSQLAdapter.log("Starting TRansaction...");
37                     WriteTransaction t = dps.newReadWriteTransaction();
38                     t.delete(LogicalDatastoreType.OPERATIONAL, ID);
39                     t.put(LogicalDatastoreType.OPERATIONAL,ID,xsql);
40                     XSQLAdapter.log("Submitting...");
41                     t.submit();
42                 }
43             } catch (Exception e) {
44                 XSQLAdapter.log(e);
45             }
46         return xsql;
47     }
48 }