fa85cf4530f362f45a5b3878c7398547f3d152a4
[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 /**
22  * To be removed in Nitrogen
23  */
24 @Deprecated
25 public class XSQLProvider implements AutoCloseable {
26
27     public static final InstanceIdentifier<XSQL> ID = InstanceIdentifier.builder(XSQL.class).build();
28     //public static final InstanceIdentifier<SalTest> ID2 = InstanceIdentifier.builder(SalTest.class).build();
29
30     public void close() {
31     }
32
33     public XSQL buildXSQL(DataBroker dps) {
34             XSQLAdapter.log("Building XSL...");
35             XSQLBuilder builder = new XSQLBuilder();
36             builder.setPort("34343");
37             XSQL xsql = builder.build();
38             try {
39                 if (dps != null) {
40                     XSQLAdapter.log("Starting TRansaction...");
41                     WriteTransaction t = dps.newReadWriteTransaction();
42                     t.delete(LogicalDatastoreType.OPERATIONAL, ID);
43                     t.put(LogicalDatastoreType.OPERATIONAL,ID,xsql);
44                     XSQLAdapter.log("Submitting...");
45                     t.submit();
46                 }
47             } catch (Exception e) {
48                 XSQLAdapter.log(e);
49             }
50         return xsql;
51     }
52 }