~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/session.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman, Adam Gandelman, Chuck Short
  • Date: 2012-08-27 15:37:18 UTC
  • mfrom: (1.1.60)
  • Revision ID: package-import@ubuntu.com-20120827153718-lj8er44eqqz1gsrj
Tags: 2012.2~rc1~20120827.15815-0ubuntu1
[ Adam Gandelman ]
* New upstream release.

[ Chuck Short ]
* debian/patches/0001-Update-tools-hacking-for-pep8-1.2-and-
  beyond.patch: Dropped we dont run pep8 tests anymore.
* debian/control: Drop pep8 build depends
* debian/*.upstart.in: Make sure we transition correctly from runlevel
  1 to 2. (LP: #820694)

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    dbapi_conn.execute("PRAGMA synchronous = OFF")
58
58
 
59
59
 
 
60
def add_regexp_listener(dbapi_con, con_record):
 
61
    """Add REGEXP function to sqlite connections."""
 
62
 
 
63
    def regexp(expr, item):
 
64
        reg = re.compile(expr)
 
65
        return reg.search(unicode(item)) is not None
 
66
    dbapi_con.create_function('regexp', 2, regexp)
 
67
 
 
68
 
60
69
def ping_listener(dbapi_conn, connection_rec, connection_proxy):
61
70
    """
62
71
    Ensures that MySQL connections checked out of the
86
95
    return False
87
96
 
88
97
 
89
 
def regexp(expr, item):
90
 
    reg = re.compile(expr)
91
 
    return reg.search(unicode(item)) is not None
92
 
 
93
 
 
94
 
class AddRegexFactory(sqlalchemy.interfaces.PoolListener):
95
 
    def connect(delf, dbapi_con, con_record):
96
 
        dbapi_con.create_function('REGEXP', 2, regexp)
97
 
 
98
 
 
99
98
def get_engine():
100
99
    """Return a SQLAlchemy engine."""
101
100
    global _ENGINE
120
119
            if FLAGS.sql_connection == "sqlite://":
121
120
                engine_args["poolclass"] = StaticPool
122
121
                engine_args["connect_args"] = {'check_same_thread': False}
123
 
                engine_args['listeners'] = [AddRegexFactory()]
124
122
 
125
123
        _ENGINE = sqlalchemy.create_engine(FLAGS.sql_connection, **engine_args)
126
124
 
130
128
            if not FLAGS.sqlite_synchronous:
131
129
                sqlalchemy.event.listen(_ENGINE, 'connect',
132
130
                                        synchronous_switch_listener)
 
131
            sqlalchemy.event.listen(_ENGINE, 'connect', add_regexp_listener)
133
132
 
134
133
        if (FLAGS.sql_connection_trace and
135
134
                _ENGINE.dialect.dbapi.__name__ == 'MySQLdb'):