~rvalyi/openobject-server/trunk-java-jython

« back to all changes in this revision

Viewing changes to bin/sql_db.py

  • Committer: Raphaël Valyi
  • Date: 2009-01-28 02:27:26 UTC
  • Revision ID: rvalyi@gmail.com-20090128022726-h1pgjjnud4rpgvf3
round 2: true Java DataSource pooling this time. Now we properly borrow and give back connections to the pool.
as a result, we are able to answer basic XML/RPC calls properly and a simple_profile database!!
yes, you heard that running sock.execute("jython", 1, "admin", 'res.partner', 'read', [1,2,3])
in a console will just get back the correct result from a Jython backed server!

By the way, it looks like reportlab might actually be loaded, but there is an issue with its padfbase/_fontdata which seems to be too large
to get parsed properly. That's a Jython issue, I'll report them (if I trim that file, it loads reportlab properly).

Some module like CRM won't load either yet cause there is no proper pychart wrapper yet.

An other issue is that the web_service#list method supposed to list the database isn't yet running properly.
Indeed, the database name are returned as bytearrays, but for some strange reason, in Jython str(the stuff) won't make it a string,
might be a Jython issue or some encoding issue. That's the main thing preventing to connect from the GTK client I think.

as for mx.Datatime, conversation with Jythonistas, Fabien Pinckaers and a glance at Tryton let me very optimistic about getting
rid of that dependence.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import netsvc
24
24
#TODO: JYTHON TEMPORARY HACK
25
25
from com.ziclix.python.sql import zxJDBC
 
26
from org.postgresql.ds import PGConnectionPoolDataSource
 
27
from com.ziclix.python.sql import PyConnection
26
28
from com.ziclix.python.sql import PyExtendedCursor
27
 
 
28
29
#monkey patching PyExtendedCursor to fake the psycopg2 API:
29
30
#here we use the code from Django when ported from psycopg2 to zxJDBC
30
31
#that has been suggested on IRC by Jim Baker, many thanks to him
111
112
        @wraps(f)
112
113
        def wrapper(self, *args, **kwargs):
113
114
            if not hasattr(self, '_obj'):
 
115
                #TODO: JYTHON TEMPORARY HACK
114
116
                print "error while looking for _obj in"
115
 
                print "self"
 
117
                print self
 
118
                print dir(self)
116
119
                raise "SGBD driver error!!"
 
120
                import traceback
 
121
                traceback.print_stack()
117
122
                #raise psycopg2.ProgrammingError('Unable to use the cursor after having closing it')
 
123
                #END JYTHON TEMPORARY HACK
118
124
            return f(self, *args, **kwargs)
119
125
        return wrapper
120
126
 
121
127
    def __init__(self, pool):
122
 
        self._pool = pool._pool
 
128
        self._pool = pool
123
129
        #TODO: JYTHON TEMPORARY HACK
124
 
        self._cnx = pool._pool#pool.getconn()
 
130
        java_connection = pool._pool.getPooledConnection().getConnection()
 
131
        java_connection.setAutoCommit(False) 
 
132
        self._cnx = PyConnection(java_connection)
125
133
        self._obj = self._cnx.cursor()#self._cnx.cursor(cursor_factory=psycopg1cursor)
126
134
        #END JYTHON TEMPORARY HACK
127
 
        self.autocommit(False)
128
135
        self.dbname = pool.dbname
129
136
 
130
137
        if tools.config['log_level'] in (netsvc.LOG_DEBUG, netsvc.LOG_DEBUG_RPC):
222
229
        # part because browse records keep a reference to the cursor.
223
230
        del self._obj
224
231
        #TODO: JYTHON TEMPORARY HACK
225
 
        self._pool.close()
 
232
        self._cnx.close()
 
233
        #self._pool.release(self._cnx)
226
234
        #self._pool.putconn(self._cnx)
227
235
        #END JYTHON TEMPORARY HACK
228
236
    
229
237
    @check
230
238
    def autocommit(self, on):
231
 
        #TODO: JYTHON TEMPORARY HACK
232
 
        pass
233
 
        #self._cnx.set_isolation_level([ISOLATION_LEVEL_SERIALIZABLE, ISOLATION_LEVEL_AUTOCOMMIT][bool(on)])
234
 
        #END JYTHON TEMPORARY HACK
 
239
        self._cnx.set_isolation_level([ISOLATION_LEVEL_SERIALIZABLE, ISOLATION_LEVEL_AUTOCOMMIT][bool(on)])
 
240
 
235
241
    
236
242
    @check
237
243
    def commit(self):
287
293
            try:
288
294
                logger.notifyChannel('dbpool', netsvc.LOG_INFO, 'Connecting to %s' % (db_name,))
289
295
                #TODO: JYTHON TEMPORARY HACK
290
 
                cls._pools[db_name] = ConnectionPool(zxJDBC.connectx("org.postgresql.ds.PGConnectionPoolDataSource", serverName=tools.config['db_host'] or 'localhost', databaseName=db_name, portNumber=tools.config['db_port'] or 5432, user=tools.config['db_user'], password=tools.config['db_password']), db_name)
 
296
                pool = PGConnectionPoolDataSource()
 
297
                pool.setServerName(tools.config['db_host'] or 'localhost')
 
298
                pool.setPortNumber(tools.config['db_port'] or 5432)
 
299
                pool.setDatabaseName(db_name)
 
300
                pool.setUser(tools.config['db_user'])
 
301
                pool.setPassword(tools.config['db_password'])
 
302
                cls._pools[db_name] = ConnectionPool(pool, db_name)
291
303
                #cls._pools[db_name] = ConnectionPool(ThreadedConnectionPool(1, cls.maxconn, cls.dsn(db_name)), db_name)
292
304
                #END JYTHON TEMPORARY HACK
293
305
            except Exception, e:
302
314
            logger = netsvc.Logger()
303
315
            logger.notifyChannel('dbpool', netsvc.LOG_INFO, 'Closing all connections to %s' % (db_name,))
304
316
            #TODO: JYTHON TEMPORARY HACK
 
317
            cls._pools[db_name]._pool.close()
305
318
            #cls._pools[db_name].closall()
306
319
            #END JYTHON TEMPORARY HACK
307
320
            del cls._pools[db_name]