|
1 | 1 | from ThreadPoolExecutorPlus import ThreadPoolExecutor |
2 | | -import cx_Oracle as csor |
| 2 | +import cx_Oracle as cxor |
3 | 3 | import platform |
4 | 4 | import asyncio |
5 | 5 | import os |
|
12 | 12 | DEFAULT_MAXIMUM_WORKER_NUM = (os.cpu_count() or 1) * 32 |
13 | 13 | DEFAULT_MAXIMUM_WORKER_TIMES = 3 |
14 | 14 |
|
| 15 | +makedsn = cxor.makedsn |
| 16 | + |
15 | 17 | class AsyncCursorWrapper: |
16 | 18 |
|
17 | 19 | def __init__(self , loop , thread_pool , cursor): |
@@ -115,10 +117,56 @@ def _test(): |
115 | 117 |
|
116 | 118 | await self._loop.run_in_executor(self._thread_pool , _test) |
117 | 119 |
|
118 | | -async def create_pool(host = 'localhost', port = '1521' , user = 'sys', password = '', db = 'orcl', loop = None, minsize = 2 , maxsize = 4 , encoding = 'UTF-8' , autocommit=False): |
| 120 | +async def create_pool( |
| 121 | + user=None, |
| 122 | + password=None, |
| 123 | + dsn=None, |
| 124 | + min=2, |
| 125 | + max=4, |
| 126 | + increment=1, |
| 127 | + connectiontype=cxor.Connection, |
| 128 | + threaded=True, |
| 129 | + getmode=cxor.SPOOL_ATTRVAL_NOWAIT, |
| 130 | + events=False, |
| 131 | + homogeneous=True, |
| 132 | + externalauth=False, |
| 133 | + encoding='UTF-8', |
| 134 | + edition=None, |
| 135 | + timeout=0, |
| 136 | + waitTimeout=0, |
| 137 | + maxLifetimeSession=0, |
| 138 | + sessionCallback=None, |
| 139 | + maxSessionsPerShard=0, |
| 140 | + host='localhost', |
| 141 | + port='1521', |
| 142 | + service_name='orcl', |
| 143 | + sid=None, |
| 144 | + loop=None |
| 145 | + ): |
119 | 146 | if loop == None: |
120 | 147 | loop = asyncio.get_running_loop() |
121 | | - pool = csor.SessionPool(user , password , f"{host}:{port}/{db}", min = minsize , max = maxsize , increment = 1 , threaded = True , encoding = encoding) |
| 148 | + if dsn == None: |
| 149 | + dsn = makedsn(host = host, port = port, sid = sid , service_name = service_name) |
| 150 | + pool = cxor.SessionPool( |
| 151 | + user=user, |
| 152 | + password=password, |
| 153 | + dsn=dsn, |
| 154 | + min=min, |
| 155 | + max=max, |
| 156 | + increment=increment, |
| 157 | + connectiontype=connectiontype, |
| 158 | + threaded=threaded, |
| 159 | + getmode=getmode, |
| 160 | + events=events, |
| 161 | + homogeneous=homogeneous, |
| 162 | + externalauth=externalauth, |
| 163 | + encoding=encoding, |
| 164 | + edition=edition, |
| 165 | + timeout=timeout, |
| 166 | + waitTimeout=waitTimeout, |
| 167 | + maxLifetimeSession=maxLifetimeSession, |
| 168 | + sessionCallback=sessionCallback, |
| 169 | + maxSessionsPerShard=maxSessionsPerShard) |
122 | 170 | pool = AsyncPoolWrapper(pool) |
123 | 171 | await pool.preexciting() |
124 | 172 | return pool |
|
0 commit comments