[pypy-svn] r69651 - in pypy/trunk/pypy/module/oracle: . test
afa at codespeak.net
afa at codespeak.net
Thu Nov 26 11:59:40 CET 2009
Author: afa
Date: Thu Nov 26 11:59:39 2009
New Revision: 69651
Added:
pypy/trunk/pypy/module/oracle/interp_pool.py
Modified:
pypy/trunk/pypy/module/oracle/__init__.py
pypy/trunk/pypy/module/oracle/interp_connect.py
pypy/trunk/pypy/module/oracle/roci.py
pypy/trunk/pypy/module/oracle/test/test_connect.py
Log:
Start implementing oracle.SessionPool
Modified: pypy/trunk/pypy/module/oracle/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/__init__.py (original)
+++ pypy/trunk/pypy/module/oracle/__init__.py Thu Nov 26 11:59:39 2009
@@ -23,6 +23,7 @@
'Variable': 'interp_variable.W_Variable',
'Timestamp': 'interp_error.get(space).w_DateTimeType',
'Date': 'interp_error.get(space).w_DateType',
+ 'SessionPool': 'interp_pool.W_SessionPool',
}
appleveldefs = {
Modified: pypy/trunk/pypy/module/oracle/interp_connect.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/interp_connect.py (original)
+++ pypy/trunk/pypy/module/oracle/interp_connect.py Thu Nov 26 11:59:39 2009
@@ -12,7 +12,7 @@
from pypy.module.oracle.config import string_w, StringBuffer, MAX_STRING_CHARS
from pypy.module.oracle.interp_environ import Environment
from pypy.module.oracle.interp_cursor import W_Cursor
-#from pypy.module.oracle.interp_pool import W_Pool
+from pypy.module.oracle.interp_pool import W_Pool
from pypy.module.oracle.interp_variable import VT_String
class W_Connection(Wrappable):
@@ -43,7 +43,7 @@
W_Connection.__init__(self)
# set up the environment
- if 0 and w_pool: # XXX
+ if w_pool:
pool = space.instance_w(W_Pool, w_pool)
self.environment = pool.environment.clone()
else:
Added: pypy/trunk/pypy/module/oracle/interp_pool.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/module/oracle/interp_pool.py Thu Nov 26 11:59:39 2009
@@ -0,0 +1,144 @@
+from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped
+from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.typedef import interp_attrproperty, interp_attrproperty_w
+from pypy.rpython.lltypesystem import rffi, lltype
+
+Null = NoneNotWrapped
+
+from pypy.module.oracle import roci, config, interp_error, interp_environ
+
+
+class W_SessionPool(Wrappable):
+ def __init__(self):
+ self.environment = None
+
+ def descr_new(space, w_subtype,
+ w_user, w_password, w_dsn,
+ min, max, increment,
+ w_connectiontype=Null,
+ threaded=False,
+ getmode=roci.OCI_SPOOL_ATTRVAL_NOWAIT,
+ events=False,
+ homogeneous=True):
+ self = space.allocate_instance(W_SessionPool, w_subtype)
+ W_SessionPool.__init__(self)
+
+ if w_connectiontype is not None:
+ if not space.is_true(space.issubtype(w_value,
+ interp_connect.W_Connection)):
+ raise OperationError(
+ interp_error.get(space).w_ProgrammingError,
+ space.wrap(
+ "connectiontype must be a subclass of Connection"))
+ self.w_username = w_user
+ self.w_password = w_password
+ self.w_tnsentry = w_dsn
+
+ self.w_connectionType = w_connectiontype
+ self.minSessions = min
+ self.maxSessions = max
+ self.sessionIncrement = increment
+ self.homogeneous = homogeneous
+
+ # set up the environment
+ self.environment = interp_environ.Environment(space, threaded, events)
+
+ # create the session pool handle
+ handleptr = lltype.malloc(rffi.CArrayPtr(roci.OCIServer).TO,
+ 1, flavor='raw')
+ try:
+ status = roci.OCIHandleAlloc(
+ self.environment.handle,
+ handleptr, roci.OCI_HTYPE_SPOOL, 0,
+ lltype.nullptr(rffi.CArray(roci.dvoidp)))
+ self.environment.checkForError(
+ status, "SessionPool_New(): allocate handle")
+ self.handle = handleptr[0]
+ finally:
+ lltype.free(handleptr, flavor='raw')
+
+ # prepare pool mode
+ poolMode = roci.OCI_SPC_STMTCACHE
+ if self.homogeneous:
+ poolMode |= roci.OCI_SPC_HOMOGENEOUS
+
+ # create the session pool
+ user_buf = config.StringBuffer()
+ user_buf.fill(space, self.w_username)
+ password_buf = config.StringBuffer()
+ password_buf.fill(space, self.w_password)
+ dsn_buf = config.StringBuffer()
+ dsn_buf.fill(space, self.w_tnsentry)
+ poolnameptr = lltype.malloc(rffi.CArrayPtr(roci.oratext).TO, 1,
+ flavor='raw')
+ poolnamelenptr = lltype.malloc(rffi.CArrayPtr(roci.ub4).TO, 1,
+ flavor='raw')
+
+ try:
+ status = roci.OCISessionPoolCreate(
+ self.environment.handle,
+ self.environment.errorHandle,
+ self.handle,
+ poolnameptr, poolnamelenptr,
+ dsn_buf.ptr, dsn_buf.size,
+ min, max, increment,
+ user_buf.ptr, user_buf.size,
+ password_buf.ptr, password_buf.size,
+ poolMode)
+ self.environment.checkForError(
+ status, "SessionPool_New(): create pool")
+
+ self.w_name = config.w_string(space, poolnameptr[0],
+ poolnamelenptr[0])
+ finally:
+ user_buf.clear()
+ password_buf.clear()
+ dsn_buf.clear()
+
+ return space.wrap(self)
+ descr_new.unwrap_spec = [ObjSpace, W_Root,
+ W_Root, W_Root, W_Root,
+ int, int, int,
+ W_Root,
+ bool, int, bool, bool]
+
+ def checkConnected(self, space):
+ if not self.handle:
+ raise OperationError(
+ get(space).w_InterfaceError,
+ space.wrap("not connected"))
+
+def computedProperty(oci_attr_code, oci_value_type):
+ def fget(space, self):
+ self.checkConnected(space)
+
+ valueptr = lltype.malloc(rffi.CArrayPtr(oci_value_type).TO,
+ 1, flavor='raw')
+ try:
+ status = roci.OCIAttrGet(
+ self.handle, roci.OCI_HTYPE_SPOOL,
+ rffi.cast(roci.dvoidp, valueptr),
+ lltype.nullptr(roci.Ptr(roci.ub4).TO),
+ oci_attr_code,
+ self.environment.errorHandle)
+ return space.wrap(valueptr[0])
+ finally:
+ lltype.free(valueptr, flavor='raw')
+ return GetSetProperty(fget)
+
+W_SessionPool.typedef = TypeDef(
+ "SessionPool",
+ __new__ = interp2app(W_SessionPool.descr_new.im_func),
+ username = interp_attrproperty_w('w_username', W_SessionPool),
+ password = interp_attrproperty_w('w_password', W_SessionPool),
+ tnsentry = interp_attrproperty_w('w_tnsentry', W_SessionPool),
+ min = interp_attrproperty('minSessions', W_SessionPool),
+ max = interp_attrproperty('maxSessions', W_SessionPool),
+ increment = interp_attrproperty('sessionIncrement', W_SessionPool),
+ opened = computedProperty(roci.OCI_ATTR_SPOOL_OPEN_COUNT, roci.ub4),
+ busy = computedProperty(roci.OCI_ATTR_SPOOL_BUSY_COUNT, roci.ub4),
+ timeout = computedProperty(roci.OCI_ATTR_SPOOL_TIMEOUT, roci.ub4),
+ getmode = computedProperty(roci.OCI_ATTR_SPOOL_GETMODE, roci.ub1),
+ )
Modified: pypy/trunk/pypy/module/oracle/roci.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/roci.py (original)
+++ pypy/trunk/pypy/module/oracle/roci.py Thu Nov 26 11:59:39 2009
@@ -55,7 +55,7 @@
OCI_DEFAULT OCI_OBJECT OCI_THREADED OCI_EVENTS
OCI_SUCCESS OCI_SUCCESS_WITH_INFO OCI_INVALID_HANDLE OCI_NO_DATA
OCI_HTYPE_ERROR OCI_HTYPE_SVCCTX OCI_HTYPE_SERVER OCI_HTYPE_SESSION
- OCI_HTYPE_STMT OCI_HTYPE_DESCRIBE OCI_HTYPE_ENV
+ OCI_HTYPE_STMT OCI_HTYPE_DESCRIBE OCI_HTYPE_ENV OCI_HTYPE_SPOOL
OCI_DTYPE_PARAM OCI_DTYPE_TIMESTAMP OCI_DTYPE_INTERVAL_DS OCI_DTYPE_LOB
OCI_CRED_RDBMS OCI_CRED_EXT OCI_SPOOL_ATTRVAL_NOWAIT
OCI_ATTR_SERVER OCI_ATTR_SESSION OCI_ATTR_USERNAME OCI_ATTR_PASSWORD
@@ -67,6 +67,8 @@
OCI_ATTR_COLLECTION_ELEMENT
OCI_ATTR_CHARSET_FORM OCI_ATTR_ENV_CHARSET_ID
OCI_ATTR_PARSE_ERROR_OFFSET
+ OCI_ATTR_SPOOL_OPEN_COUNT OCI_ATTR_SPOOL_BUSY_COUNT OCI_ATTR_SPOOL_TIMEOUT
+ OCI_ATTR_SPOOL_GETMODE
OCI_NTV_SYNTAX OCI_COMMIT_ON_SUCCESS
OCI_FETCH_NEXT
OCI_IND_NULL OCI_IND_NOTNULL
@@ -86,6 +88,7 @@
OCI_TYPECODE_NUMBER OCI_TYPECODE_DATE OCI_TYPECODE_TIMESTAMP
OCI_TYPECODE_NAMEDCOLLECTION OCI_TYPECODE_OBJECT
OCI_NLS_MAXBUFSZ OCI_NLS_CS_ORA_TO_IANA
+ OCI_SPC_STMTCACHE OCI_SPC_HOMOGENEOUS
'''.split()
for c in constants:
@@ -102,6 +105,7 @@
OCIError = rffi.VOIDP
OCIServer = rffi.VOIDP
OCISession = rffi.VOIDP
+OCISPool = rffi.VOIDP
OCIStmt = rffi.VOIDP
OCIParam = rffi.VOIDP
OCIBind = rffi.VOIDP
@@ -169,6 +173,25 @@
ub4], # mode
sword)
+OCISessionPoolCreate = external(
+ 'OCISessionPoolCreate',
+ [OCISvcCtx, # svchp
+ OCIError, # errhp
+ OCISPool, # spoolhp
+ Ptr(oratext), # poolName
+ Ptr(ub4), # poolNameLen
+ oratext, # connStr
+ ub4, # connStrLen
+ ub4, # sessMin
+ ub4, # sessMax
+ ub4, # sessIncr
+ oratext, # userid
+ ub4, # useridLen
+ oratext, # password
+ ub4, # passwordLen
+ ub4], # mode
+ sword)
+
# Handle and Descriptor Functions
OCIAttrGet = external(
Modified: pypy/trunk/pypy/module/oracle/test/test_connect.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/test/test_connect.py (original)
+++ pypy/trunk/pypy/module/oracle/test/test_connect.py Thu Nov 26 11:59:39 2009
@@ -116,3 +116,16 @@
assert encoding != ""
+class AppTestPool(OracleNotConnectedTestBase):
+ def test_pool(self):
+ pool = oracle.SessionPool(self.username, self.password,
+ self.tnsentry,
+ 2, 8, 3)
+ assert pool.username == self.username
+ assert pool.password == self.password
+ assert pool.tnsentry == self.tnsentry
+ assert pool.max == 8
+ assert pool.min == 2
+ assert pool.increment == 3
+ assert pool.opened == 2
+ assert pool.busy == 0
More information about the Pypy-commit
mailing list