Merge pull request #135 from khangp0000/patch-1

Update to support jpype 0.7.2+
master
baztian 2020-05-22 20:56:18 +02:00 committed by GitHub
commit d9dc88872d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -151,10 +151,17 @@ def _handle_sql_exception_jpype():
import jpype import jpype
SQLException = jpype.java.sql.SQLException SQLException = jpype.java.sql.SQLException
exc_info = sys.exc_info() exc_info = sys.exc_info()
if issubclass(exc_info[1].__javaclass__, SQLException): if old_jpype:
clazz = exc_info[1].__javaclass__
db_err = issubclass(clazz, SQLException)
else:
db_err = isinstance(exc_info[1], SQLException)
if db_err:
exc_type = DatabaseError exc_type = DatabaseError
else: else:
exc_type = InterfaceError exc_type = InterfaceError
reraise(exc_type, exc_info[1], exc_info[2]) reraise(exc_type, exc_info[1], exc_info[2])
def _jdbc_connect_jpype(jclassname, url, driver_args, jars, libs): def _jdbc_connect_jpype(jclassname, url, driver_args, jars, libs):
@ -195,12 +202,15 @@ def _jdbc_connect_jpype(jclassname, url, driver_args, jars, libs):
if _jdbc_name_to_const is None: if _jdbc_name_to_const is None:
types = jpype.java.sql.Types types = jpype.java.sql.Types
types_map = {} types_map = {}
for i in types.__javaclass__.getClassFields(): if old_jpype:
if old_jpype: for i in types.__javaclass__.getClassFields():
const = i.getStaticAttribute() const = i.getStaticAttribute()
else:
const = i.__get__(i)
types_map[i.getName()] = const types_map[i.getName()] = const
else:
for i in types.class_.getFields():
if jpype.java.lang.reflect.Modifier.isStatic(i.getModifiers()):
const = i.get(None)
types_map[i.getName()] = const
_init_types(types_map) _init_types(types_map)
global _java_array_byte global _java_array_byte
if _java_array_byte is None: if _java_array_byte is None: