1 # -------------------------------------------------------------------------
2 # Copyright (c) 2015-2017 AT&T Intellectual Property
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # -------------------------------------------------------------------------
20 import sqlalchemy.pool as pool
22 from jaydebeapi import _DEFAULT_CONVERTERS, _java_to_py
23 from osdf.utils.programming_utils import MetaSingleton
24 from osdf.config.base import osdf_config
26 _DEFAULT_CONVERTERS.update({'BIGINT': _java_to_py('longValue')})
29 class VerticaDB(metaclass=MetaSingleton):
30 connection_pool = None
32 def get_connection(self):
33 p = self.get_config_params()
34 c = jaydebeapi.connect(
35 'com.vertica.jdbc.Driver',
36 'jdbc:vertica://{}:{}/{}'.format(p['host'], p['port'], p['db']),
37 {'user': p['user'], 'password': p['passwd'], 'CHARSET': 'UTF8'},
42 def get_config_params(self):
43 config = osdf_config["deployment"]
44 host, port, db = config["verticaHost"], config["verticaPort"], config.get("verticaDB")
45 user, passwd = config["verticaUsername"], config["verticaPassword"]
46 jar_path = osdf_config['core']['osdf_system']['vertica_jar']
47 params = dict(host=host, db=db, user=user, passwd=passwd, port=port, db_driver=jar_path)
51 if self.connection_pool is None:
52 self.connection_pool = pool.QueuePool(self.get_connection, max_overflow=10, pool_size=5, recycle=600)
53 conn = self.connection_pool.connect()
54 cursor = conn.cursor()