1. Owen Nelson
  2. cloud-studio

Commits

Owen Nelson  committed 466cc0b

modified to use Google SDK dbapi driver instead of jdbc

  • Participants
  • Parent commits 7646c88
  • Branches master

Comments (0)

Files changed (4)

File README.md

View file
  • Ignore whitespace
 Hoping to build a SQL query runner, and perhaps query profiler, for use with Google's Cloud SQL service.
 
-Idea came from reading:
-http://phreakmonkey.com/index.php/archives/255
+Google Python SDK is now required.
 
-PySide will require the Qt development headers to be installed on your system. If on ubuntu, try installing `libqt4-dev`.
-
-Also, make sure your `JAVA_HOME` points to a recent JDK root, and consider adding
+Currently, the project will try to add the SDK root directory to the `sys.path`
+by reading it from the `GAE_SDK` environment variable, but I plan to make this configurable from the front-end of the app later.
 
-    export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib/python2.7/site-packages/PySide
-
-to your virtualenv postactivate script.
+PySide will require the Qt development headers to be installed on your system. If on ubuntu, try installing `libqt4-dev`.

File cloudstudio/__init__.py

View file
  • Ignore whitespace
+import os
+import sys
+
+__all__ = ()
+_path = lambda s: os.path.abspath(os.path.expanduser(os.path.expandvars(s)))
+
+# TODO: user should select this directory through the app
+GAE_SDK = _path(os.environ['GAE_SDK'])  # SDK root dir
+sys.path.insert(0, GAE_SDK)

File cloudstudio/driver.py

View file
  • Ignore whitespace
-import os
-import jaydebeapi
-import jpype
 from PySide import QtSql
-
-
-_path = lambda s: os.path.abspath(os.path.expanduser(os.path.expandvars(s)))
-
-# TODO: get this info from user prefs, etc (make it configurable from the front-end)
-GOOGLE_SQL_PATH = _path('~/bin')
-JAVA_HOME = os.environ['JAVA_HOME']
-
-classpath = ('{}/jre/lib/'
-             ':{}/google_sql.jar:.'.format(JAVA_HOME, GOOGLE_SQL_PATH))
-jvm_path = '{}/jre/lib/amd64/server/libjvm.so'.format(JAVA_HOME)
+from google.storage.speckle.python.api import rdbms_googleapi as dbi
 
 
 class CloudSqlDriver(QtSql.QSqlDriver):
     http://srinikom.github.com/pyside-docs/PySide/QtSql/QSqlDriver.html#PySide.QtSql.QSqlDriver
     for details on expected return values.
     """
-
     _conn = None
-    _jvm = None
-
-    def __init__(self, *args, **kwargs):
-        # unsure if we want to do this here, or in ``open()``
-        self._jvm = jpype.startJVM(jvm_path, '-Djava.class.path=%s' % classpath)
-        super(CloudSqlDriver, self).__init__(*args, **kwargs)
+    _cursor = None
 
     def beginTransaction(self):
         # Python db api does not provide an interface for explicitly
         pass
 
     def close(self):
-        self._conn.close()
-        self._conn = None
+        if self._conn is not None:
+            self._conn.close()
+            self._conn = self._cursor = None
 
     def commitTransaction(self):
         self._conn.commit()
         pass
 
     def isOpen(self):
-        pass
+        return self._cursor and self._cursor._open
+
+    def open(self, db, instance, host="", user="", password=""):
+        if self._conn is None:
+            self._conn = dbi.connect(
+                host, instance, database=db, user=user, password=password)
 
-    def open(self, db, instance, user="", password=""):
-        self._conn = jaydebeapi.connect('com.google.cloud.sql.Driver',
-                                        'jdbc:google:rdbms://{}/{}'.format(
-                                            instance, db),
-                                        user, password)
+            if not self.isOpen():
+                self._cursor = self._conn.cursor()
 
     def primaryIndex(self, tableName):
         pass

File requirements.txt

View file
  • Ignore whitespace
-jaydebeapi
-http://downloads.sourceforge.net/project/jpype/JPype/0.5.4/JPype-0.5.4.2.zip#egg=jpype-0.5.4.2
 pyside