OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.io.IOException;
22 import java.io.InputStream;
23 import java.sql.Connection;
24 import java.sql.DriverManager;
25 import java.sql.DriverPropertyInfo;
26 import java.sql.SQLException;
27 import java.util.Properties;
28 import java.util.logging.Logger;
29 
34 public class OmniSciDriver implements java.sql.Driver {
35  static int DriverMajorVersion = -1;
36  static int DriverMinorVersion = -1;
37  static String DriverVersion = "UNKNOWN";
38  final static String VERSION_FILE = "version.properties";
39  final static org.slf4j.Logger logger = LoggerFactory.getLogger(OmniSciDriver.class);
40  public static final String OMNISCI_PREFIX = "jdbc:omnisci:";
41  public static final String MAPD_PREFIX = "jdbc:mapd:";
42 
43  static {
44  try {
45  DriverManager.registerDriver(new OmniSciDriver());
46  } catch (SQLException e) {
47  e.printStackTrace();
48  }
49 
50  try (InputStream input = OmniSciDriver.class.getClassLoader().getResourceAsStream(
51  VERSION_FILE)) {
52  Properties prop = new Properties();
53  if (input == null) {
54  logger.error("Cannot read " + VERSION_FILE + " file");
55  } else {
56  prop.load(input);
57  DriverVersion = prop.getProperty("version");
58  String[] version = DriverVersion.split("\\.");
59  try {
60  DriverMajorVersion = Integer.parseInt(version[0]);
61  DriverMinorVersion = Integer.parseInt(version[1]);
62  } catch (NumberFormatException ex) {
63  logger.error("Unexpected driver version format in " + VERSION_FILE);
64  DriverVersion = "UNKNOWN";
65  }
66  }
67  } catch (IOException e) {
68  e.printStackTrace();
69  }
70  }
71 
72  @Override
73  public Connection connect(String url, Properties info)
74  throws SQLException { // logger.debug("Entered");
75  if (!isValidURL(url)) {
76  return null;
77  }
78 
79  url = url.trim();
80  return new OmniSciConnection(url, info);
81  }
82 
83  @Override
84  public boolean acceptsURL(String url) throws SQLException { // logger.debug("Entered");
85  return isValidURL(url);
86  }
87 
94  private static boolean isValidURL(String url) {
95  return url != null
96  && (url.toLowerCase().startsWith(OMNISCI_PREFIX)
97  || url.toLowerCase().startsWith(MAPD_PREFIX));
98  }
99 
100  @Override
101  public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
102  throws SQLException { // logger.debug("Entered");
103  return null;
104  }
105 
106  @Override
107  public int getMajorVersion() {
108  return DriverMajorVersion;
109  }
110 
111  @Override
112  public int getMinorVersion() {
113  return DriverMinorVersion;
114  }
115 
116  @Override
117  public boolean jdbcCompliant() {
118  return false;
119  }
120 
121  @Override
122  public Logger getParentLogger() {
123  return null;
124  }
125 }
boolean acceptsURL(String url)
static final String OMNISCI_PREFIX
static boolean isValidURL(String url)
static final String VERSION_FILE
static final String MAPD_PREFIX
string url
Definition: setup.py:48
DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
static final org.slf4j.Logger logger
string version
Definition: setup.in.py:73
Connection connect(String url, Properties info)