OmniSciDB  04ee39c94c
OmniSciDriver.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.omnisci.jdbc;
18 
19 import org.slf4j.LoggerFactory;
20 
21 import java.sql.Connection;
22 import java.sql.DriverManager;
23 import java.sql.DriverPropertyInfo;
24 import java.sql.SQLException;
25 import java.sql.SQLFeatureNotSupportedException;
26 import java.util.Properties;
27 import java.util.logging.Logger;
28 
33 public class OmniSciDriver implements java.sql.Driver {
34  static final int DriverMajorVersion = 2;
35  static final int DriverMinorVersion = 1;
36 
37  final static org.slf4j.Logger logger = LoggerFactory.getLogger(OmniSciDriver.class);
38  public static final String OMNISCI_PREFIX = "jdbc:omnisci:";
39  public static final String MAPD_PREFIX = "jdbc:mapd:";
40 
41  static {
42  try {
43  DriverManager.registerDriver(new OmniSciDriver());
44  } catch (SQLException e) {
45  e.printStackTrace();
46  }
47  }
48 
49  @Override
50  public Connection connect(String url, Properties info)
51  throws SQLException { // logger.debug("Entered");
52  if (!isValidURL(url)) {
53  return null;
54  }
55 
56  url = url.trim();
57  return new OmniSciConnection(url, info);
58  }
59 
60  @Override
61  public boolean acceptsURL(String url) throws SQLException { // logger.debug("Entered");
62  return isValidURL(url);
63  }
64 
71  private static boolean isValidURL(String url) {
72  return url != null
73  && (url.toLowerCase().startsWith(OMNISCI_PREFIX)
74  || url.toLowerCase().startsWith(MAPD_PREFIX));
75  }
76 
77  @Override
78  public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
79  throws SQLException { // logger.debug("Entered");
80  return null;
81  }
82 
83  @Override
84  public int getMajorVersion() {
85  return DriverMajorVersion;
86  }
87 
88  @Override
89  public int getMinorVersion() {
90  return DriverMinorVersion;
91  }
92 
93  @Override
94  public boolean jdbcCompliant() {
95  return false;
96  }
97 
98  @Override
99  public Logger getParentLogger() throws SQLFeatureNotSupportedException {
100  return null;
101  }
102 }
static final int DriverMajorVersion
boolean acceptsURL(String url)
static final String OMNISCI_PREFIX
auto sql(const std::string &sql_stmts)
static final int DriverMinorVersion
static boolean isValidURL(String url)
static final String MAPD_PREFIX
DriverPropertyInfo [] getPropertyInfo(String url, Properties info)
Connection connect(String url, Properties info)