Skip to content

Commit

Permalink
jdbc: add JdbcDialectMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
altairbow committed Sep 16, 2024
1 parent 316fed1 commit 7f0d1d8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
9 changes: 9 additions & 0 deletions dj_db_conn_pool/backends/jdbc/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import jpype.dbapi2


class JdbcDialectMixin:
def do_ping(self, dbapi_connection):
try:
return super().do_ping(dbapi_connection)
except jpype.dbapi2.DatabaseError:
return False
10 changes: 3 additions & 7 deletions dj_db_conn_pool/backends/jdbc/oceanbase/mysql/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import jpype.dbapi2
from django.db.backends.mysql import base
from sqlalchemy.dialects.mysql.base import MySQLDialect

from dj_db_conn_pool.backends.jdbc.mixins import JdbcDialectMixin
from dj_db_conn_pool.backends.jdbc.oceanbase.mixins import JDBCOceanBaseDatabaseWrapperMixin


class DatabaseWrapper(JDBCOceanBaseDatabaseWrapperMixin, base.DatabaseWrapper):
class SQLAlchemyDialect(MySQLDialect):
def do_ping(self, dbapi_connection):
try:
return super().do_ping(dbapi_connection)
except jpype.dbapi2.DatabaseError:
return False
class SQLAlchemyDialect(JdbcDialectMixin, MySQLDialect):
pass
10 changes: 3 additions & 7 deletions dj_db_conn_pool/backends/jdbc/oceanbase/oracle/base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import jpype.dbapi2
from django.db.backends.oracle import base
from sqlalchemy.dialects.oracle.base import OracleDialect

from dj_db_conn_pool.backends.jdbc.mixins import JdbcDialectMixin
from dj_db_conn_pool.backends.jdbc.oceanbase.mixins import JDBCOceanBaseDatabaseWrapperMixin


class DatabaseWrapper(JDBCOceanBaseDatabaseWrapperMixin, base.DatabaseWrapper):
class SQLAlchemyDialect(OracleDialect):
def do_ping(self, dbapi_connection):
try:
return super().do_ping(dbapi_connection)
except jpype.dbapi2.DatabaseError:
return False
class SQLAlchemyDialect(JdbcDialectMixin, OracleDialect):
pass

def init_connection_state(self):
# TODO: custom OceanBase (Oracle mode) connection initialization
Expand Down
10 changes: 3 additions & 7 deletions dj_db_conn_pool/backends/jdbc/oracle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import socket
from multiprocessing import current_process

import jpype.dbapi2
from django.db.backends.oracle import base
from sqlalchemy.dialects.oracle.base import OracleDialect

from dj_db_conn_pool.backends.jdbc import JDBCDatabaseWrapperMixin
from dj_db_conn_pool.backends.jdbc.mixins import JdbcDialectMixin

logger = logging.getLogger(__name__)

Expand All @@ -21,12 +21,8 @@


class DatabaseWrapper(JDBCDatabaseWrapperMixin, base.DatabaseWrapper):
class SQLAlchemyDialect(OracleDialect):
def do_ping(self, dbapi_connection):
try:
return super().do_ping(dbapi_connection)
except jpype.dbapi2.DatabaseError:
return False
class SQLAlchemyDialect(JdbcDialectMixin, OracleDialect):
pass

jdbc_driver = 'oracle.jdbc.OracleDriver'

Expand Down

0 comments on commit 7f0d1d8

Please sign in to comment.