Merge "BUG 2799: SPI for EventSources"
[controller.git] / opendaylight / md-sal / sal-dom-xsql / src / main / java / org / odl / xsql / JDBCDriver.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.odl.xsql;
9
10 import java.sql.Connection;
11 import java.sql.Driver;
12 import java.sql.DriverManager;
13 import java.sql.DriverPropertyInfo;
14 import java.sql.SQLException;
15 import java.sql.SQLFeatureNotSupportedException;
16 import java.util.Properties;
17 import java.util.logging.Logger;
18
19 import org.opendaylight.controller.md.sal.dom.xsql.jdbc.JDBCConnection;
20 /**
21  * @author Sharon Aicler(saichler@gmail.com)
22  **/
23 public class JDBCDriver implements Driver {
24
25     public static JDBCDriver drv = new JDBCDriver();
26
27     public JDBCDriver() {
28         try {
29             DriverManager.registerDriver(this);
30         } catch (SQLException e) {
31             // TODO Auto-generated catch block
32             e.printStackTrace();
33         }
34     }
35
36     @Override
37     public boolean acceptsURL(String arg0) throws SQLException {
38         return true;
39     }
40
41     @Override
42     public Connection connect(String url, Properties arg1) throws SQLException {
43         System.err.println("JDBC Connection");
44         try {
45             if (url.equals("svr")) {
46                 return new JDBCConnection(true);
47             } else {
48                 return new JDBCConnection(url).getProxy();
49             }
50         } catch (Exception err) {
51             err.printStackTrace();
52         }
53         System.err.println("Error JDBC Connection");
54         return null;
55     }
56
57     @Override
58     public int getMajorVersion() {
59         return 1;
60     }
61
62     @Override
63     public int getMinorVersion() {
64         return 0;
65     }
66
67     @Override
68     public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1)
69         throws SQLException {
70         DriverPropertyInfo i = new DriverPropertyInfo("OpenDayLight", "OpenDayLight");
71         return new DriverPropertyInfo[] {i};
72     }
73
74     @Override
75     public boolean jdbcCompliant() {
76         return false;
77     }
78
79     @Override
80     public Logger getParentLogger() throws SQLFeatureNotSupportedException {
81         // TODO Auto-generated method stub
82         return null;
83     }
84
85 }