Ticket #7732: oracle_pool.2.diff
File oracle_pool.2.diff, 4.1 KB (added by , 16 years ago) |
---|
-
django/db/backends/oracle/base.py
33 33 interprets_empty_strings_as_nulls = True 34 34 date_field_supports_time_value = False 35 35 36 class DatabasePool: 37 def __get__(self): 38 if hasattr(self,'_pool'): 39 return self._pool 40 else: 41 from django.conf import settings 42 if len(settings.DATABASE_HOST.strip()) == 0: 43 settings.DATABASE_HOST = 'localhost' 44 if len(settings.DATABASE_PORT.strip()) != 0: 45 dsn = Database.makedsn(settings.DATABASE_HOST, int(settings.DATABASE_PORT), settings.DATABASE_NAME) 46 # FIXME. make the Pool parameters inside the settings 47 self._pool = cx_Oracle.SessionPool(settings.DATABASE_USER, settings.DATABASE_PASSWORD, dsn, 2, 12, 1) 48 49 else: 50 # FIXME. make the Pool parameters inside the settings 51 self._pool = cx_Oracle.SessionPool(settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME, 2, 12, 1) 52 return self._pool 53 36 54 class DatabaseOperations(BaseDatabaseOperations): 37 55 def autoinc_sql(self, table, column): 38 56 # To simulate auto-incrementing primary keys in Oracle, we have to … … 199 217 'iendswith': "LIKEC UPPER(%s) ESCAPE '\\'", 200 218 } 201 219 oracle_version = None 202 203 def _valid_connection(self): 204 return self.connection is not None 205 206 def _cursor(self, settings): 207 cursor = None 208 if not self._valid_connection(): 220 221 def _get_pool (self): 222 if not hasattr (self.__class__, '_pool'): 223 from django.conf import settings 224 Database.OPT_Threading = 1 209 225 if len(settings.DATABASE_HOST.strip()) == 0: 210 226 settings.DATABASE_HOST = 'localhost' 211 227 if len(settings.DATABASE_PORT.strip()) != 0: 212 228 dsn = Database.makedsn(settings.DATABASE_HOST, int(settings.DATABASE_PORT), settings.DATABASE_NAME) 213 self.connection = Database.connect(settings.DATABASE_USER, settings.DATABASE_PASSWORD, dsn, **self.options) 229 # FIXME. make the Pool parameters inside the settings 230 p = Database.SessionPool(settings.DATABASE_USER, settings.DATABASE_PASSWORD, dsn, 10, 100, 10, threaded = True) 231 214 232 else: 215 conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME) 216 self.connection = Database.connect(conn_string, **self.options) 233 # FIXME. make the Pool parameters inside the settings 234 p = Database.SessionPool(settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME, 10, 100, 10, threaded = True) 235 setattr(self.__class__, '_pool', p) 236 237 return getattr(self.__class__, '_pool') 238 239 240 pool = property (_get_pool) 241 242 def _cursor(self, settings): 243 cursor = None 244 if self.pool is not None: 245 if self.connection is None: 246 self.connection = self.pool.acquire() 247 217 248 cursor = FormatStylePlaceholderCursor(self.connection) 218 249 # Set oracle date to ansi date format. This only needs to execute 219 250 # once when we create a new connection. … … 237 268 # Django docs specify cx_Oracle version 4.3.1 or higher, but 238 269 # stmtcachesize is available only in 4.3.2 and up. 239 270 pass 271 240 272 if not cursor: 241 273 cursor = FormatStylePlaceholderCursor(self.connection) 242 274 # Default arraysize of 1 is highly sub-optimal. 243 275 cursor.arraysize = 100 244 276 return cursor 245 277 278 def close(self): 279 if self.connection is not None: 280 self.pool.release(self.connection) 281 self.connection = None 282 283 246 284 class FormatStylePlaceholderCursor(Database.Cursor): 247 285 """ 248 286 Django uses "format" (e.g. '%s') style placeholders, but Oracle uses ":var"