def __init__(self, jdbcconn, stmtcachesize=20): """Create a ConnectionWrapper around the given JDBC connection. If no default ConnectionWrapper already exists, the new ConnectionWrapper is set to be the default ConnectionWrapper. Arguments: - jdbcconn: An open JDBC Connection (not a PEP249 Connection) - stmtcachesize: The maximum number of PreparedStatements kept open. Default: 20. """ if not isinstance(jdbcconn, jdbc.Connection): raise TypeError('1st argument must implement java.sql.Connection') if jdbcconn.isClosed(): raise ValueError('1st argument must be an open Connection') self.__jdbcconn = jdbcconn # Add a finalizer to __prepstmts to close PreparedStatements when # they are pushed out self.__prepstmts = FIFODict(stmtcachesize, lambda k, v: v[0].close()) self.__resultmeta = FIFODict(stmtcachesize) self.__resultset = None self.__resultnames = None self.__resulttypes = None self.nametranslator = lambda s: s self.__jdbcconn.setAutoCommit(False) if pygrametl._defaulttargetconnection is None: pygrametl._defaulttargetconnection = self
def __init__(self, jdbcconn, stmtcachesize=20): """Create a ConnectionWrapper around the given JDBC connection """ self.__jdbcconn = jdbcconn # Add a finalizer to __prepstmts to close PreparedStatements when # they are pushed out self.__prepstmts = FIFODict(stmtcachesize, lambda k, v: v[0].close()) self.__resultmeta = FIFODict(stmtcachesize) self.__resultset = None self.__resultnames = None self.__resulttypes = None self.nametranslator = lambda s: s self.__jdbcconn.setAutoCommit(False) self.__queue = Queue(5000) t = Thread(target=self.__worker) t.setDaemon(True) # NB: "t.daemon = True" does NOT work... t.start()
def __init__(self, connection, stmtcachesize=1000, paramstyle=None): self.__connection = connection self.__cursor = connection.cursor() self.nametranslator = lambda s: s self.__underlyingmodule = None # will be updated next self.getunderlyingmodule() # updates self.__underlyingmodule if paramstyle is None: paramstyle = self.__underlyingmodule.paramstyle if not paramstyle == 'pyformat': self.__translations = FIFODict(stmtcachesize) try: self.__translate = getattr(self, '_translate2' + paramstyle) except AttributeError: raise InterfaceError("The paramstyle '%s' is not supported" % paramstyle) else: self.__translate = None # Thread-stuff self.__cursor = connection.cursor() self.__queue = Queue(5000) t = Thread(target=self.__worker) t.daemon = True t.start()
def __init__(self, jdbcconn, stmtcachesize=20): """Create a ConnectionWrapper around the given JDBC connection. If no default ConnectionWrapper already exists, the new ConnectionWrapper is set to be the default ConnectionWrapper. """ self.__jdbcconn = jdbcconn # Add a finalizer to __prepstmts to close PreparedStatements when # they are pushed out self.__prepstmts = FIFODict(stmtcachesize, lambda k, v: v[0].close()) self.__resultmeta = FIFODict(stmtcachesize) self.__resultset = None self.__resultnames = None self.__resulttypes = None self.nametranslator = lambda s: s self.__jdbcconn.setAutoCommit(False) if pygrametl._defaulttargetconnection is None: pygrametl._defaulttargetconnection = self
def __init__(self, connection, stmtcachesize=1000, paramstyle=None): """Create a ConnectionWrapper around the given PEP 249 connection If no default ConnectionWrapper already exists, the new ConnectionWrapper is set as the default. Arguments: - connection: An open PEP 249 connection to the database - stmtcachesize: A number deciding how many translated statements to cache. A statement needs to be translated when the connection does not use 'pyformat' to specify parameters. When 'pyformat' is used, stmtcachesize is ignored as no statements need to be translated. - paramstyle: A string holding the name of the PEP 249 connection's paramstyle. If None, pygrametl will try to find the paramstyle automatically (an AttributeError can be raised if that fails). """ self.__connection = connection self.__cursor = connection.cursor() self.nametranslator = lambda s: s if paramstyle is None: try: paramstyle = \ modules[self.__connection.__class__.__module__].paramstyle except AttributeError: # Note: This is probably a better way to do this, but to avoid # to break anything that worked before this fix, we only do it # this way if the first approach didn't work try: paramstyle = \ modules[self.__connection.__class__.__module__. split('.')[0]].paramstyle except AttributeError: # To support, e.g., mysql.connector connections paramstyle = \ modules[self.__connection.__class__.__module__. rsplit('.', 1)[0]].paramstyle if not paramstyle == 'pyformat': self.__translations = FIFODict(stmtcachesize) try: self.__translate = getattr(self, '_translate2' + paramstyle) except AttributeError: raise InterfaceError("The paramstyle '%s' is not supported" % paramstyle) else: self.__translate = None global _defaulttargetconnection if _defaulttargetconnection is None: _defaulttargetconnection = self
def __init__(self, jdbcconn, stmtcachesize=20): """Create a ConnectionWrapper around the given JDBC connection Arguments: - jdbcconn: An open JDBC Connection (not a PEP249 Connection) - stmtcachesize: The maximum number of PreparedStatements kept open. Default: 20. """ self.__jdbcconn = jdbcconn # Add a finalizer to __prepstmts to close PreparedStatements when # they are pushed out self.__prepstmts = FIFODict(stmtcachesize, lambda k, v: v[0].close()) self.__resultmeta = FIFODict(stmtcachesize) self.__resultset = None self.__resultnames = None self.__resulttypes = None self.nametranslator = lambda s: s self.__jdbcconn.setAutoCommit(False) self.__queue = Queue(5000) t = Thread(target=self.__worker) t.setDaemon(True) # NB: "t.daemon = True" does NOT work... t.setName('BackgroundJDBCConnectionWrapper') t.start()
def __init__(self, connection, stmtcachesize=1000, paramstyle=None, \ copyintonew=False): """Create a ConnectionWrapper around the given PEP 249 connection If no default ConnectionWrapper already exists, the new ConnectionWrapper is set as the default. Arguments: - connection: An open PEP 249 connection to the database - stmtcachesize: A number deciding how many translated statements to cache. A statement needs to be translated when the connection does not use 'pyformat' to specify parameters. When 'pyformat' is used and copyintonew == False, stmtcachesize is ignored as no statements need to be translated. - paramstyle: A string holding the name of the PEP 249 connection's paramstyle. If None, pygrametl will try to find the paramstyle automatically (an AttributeError can be raised if that fails). - copyintonew: A boolean deciding if a new mapping only holding the needed arguments should be created when a statement is executed. Some drivers require this. """ self.__connection = connection self.__cursor = connection.cursor() self.nametranslator = lambda s: s self.__underlyingmodule = None # will be updated next self.getunderlyingmodule() # updates self.__underlyingmodule if paramstyle is None: paramstyle = self.__underlyingmodule.paramstyle if copyintonew or not paramstyle == 'pyformat': self.__translations = FIFODict(stmtcachesize) try: self.__translate = getattr(self, '_translate2' + paramstyle) except AttributeError: raise InterfaceError("The paramstyle '%s' is not supported" % paramstyle) else: # Since paramstyle == 'pyformat' and copyintonew == False, # no translations are needed self.__translate = None self.__paramstyle = paramstyle self.__copyintonew = copyintonew global _defaulttargetconnection if _defaulttargetconnection is None: _defaulttargetconnection = self
def __init__(self, connection, stmtcachesize=1000, paramstyle=None): self.__connection = connection self.__cursor = connection.cursor() self.nametranslator = lambda s: s if paramstyle is None: try: paramstyle = \ modules[self.__connection.__class__.__module__].paramstyle except AttributeError: # Note: This is probably a better way to do this, but to avoid # to break anything that worked before this fix, we only do it # this way if the first approach didn't work try: paramstyle = \ modules[self.__connection.__class__.__module__. split('.')[0]].paramstyle except AttributeError: # To support, e.g., mysql.connector connections paramstyle = \ modules[self.__connection.__class__.__module__. rsplit('.', 1)[0]].paramstyle if not paramstyle == 'pyformat': self.__translations = FIFODict(stmtcachesize) try: self.__translate = getattr(self, '_translate2' + paramstyle) except AttributeError: raise InterfaceError("The paramstyle '%s' is not supported" % paramstyle) else: self.__translate = None # Thread-stuff self.__cursor = connection.cursor() self.__queue = Queue(5000) t = Thread(target=self.__worker) t.daemon = True t.start()