Ticket #7732: oracle_pool.diff
File oracle_pool.diff, 4.3 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 print self.pool 245 if self.pool is not None: 246 if self.connection is None: 247 self.connection = self.pool.acquire() 248 print "DEBUG: acquire session " 249 print self.connection 250 217 251 cursor = FormatStylePlaceholderCursor(self.connection) 218 252 # Set oracle date to ansi date format. This only needs to execute 219 253 # once when we create a new connection. … … 237 271 # Django docs specify cx_Oracle version 4.3.1 or higher, but 238 272 # stmtcachesize is available only in 4.3.2 and up. 239 273 pass 274 else: 275 print "Nonono, David Blain" 276 240 277 if not cursor: 241 278 cursor = FormatStylePlaceholderCursor(self.connection) 242 279 # Default arraysize of 1 is highly sub-optimal. 243 280 cursor.arraysize = 100 244 281 return cursor 245 282 283 def close(self): 284 if self.connection is not None: 285 print "DEBUG: Release session " 286 print self.connection 287 288 self.pool.release(self.connection) 289 self.connection = None 290 291 246 292 class FormatStylePlaceholderCursor(Database.Cursor): 247 293 """ 248 294 Django uses "format" (e.g. '%s') style placeholders, but Oracle uses ":var"