コード例 #1
0
    def test_update(self):
        p1 = self.create_person_one()
        objectstore.flush()
        objectstore.clear()
        
        person = Person.select()[0]
        person.gender = 'F'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 2)

        person = Person.select()[0]
        person.gender = 'M'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 3)

        #TODO: check that a concurrent modification raises exception
        p1 = Person.select()[0]
        s1 = objectstore.session
        s2 = create_session()
        objectstore.context.current = s2
        p2 = Person.select()[0]
        p1.first_name = "jack"
        p2.first_name = "ed"
        objectstore.flush()
        try:
            objectstore.context.current = s1
            objectstore.flush()
            # Only dialects with a sane rowcount can detect the ConcurrentModificationError
            if testbase.db.dialect.supports_sane_rowcount():
                assert False
        except exceptions.ConcurrentModificationError:
            pass
コード例 #2
0
ファイル: activemapper.py プロジェクト: zeus911/vpnease-l2tp
    def test_update(self):
        p1 = self.create_person_one()
        objectstore.flush()
        objectstore.clear()

        person = Person.select()[0]
        person.gender = 'F'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 2)

        person = Person.select()[0]
        person.gender = 'M'
        objectstore.flush()
        objectstore.clear()
        self.assertEquals(person.row_version, 3)

        #TODO: check that a concurrent modification raises exception
        p1 = Person.select()[0]
        s1 = objectstore.session
        s2 = create_session()
        objectstore.context.current = s2
        p2 = Person.select()[0]
        p1.first_name = "jack"
        p2.first_name = "ed"
        objectstore.flush()
        try:
            objectstore.context.current = s1
            objectstore.flush()
            # Only dialects with a sane rowcount can detect the ConcurrentModificationError
            if testbase.db.dialect.supports_sane_rowcount():
                assert False
        except exceptions.ConcurrentModificationError:
            pass
コード例 #3
0
 def getCohIds(self):
     """
     Returns the list of commands_on_host linked to this command
     """
     session = sqlalchemy.create_session()
     myCommandOnHosts = session.query(CommandsOnHost).filter(CommandsOnHost.fk_commands == self.getId())
     session.close()
     return myCommandOnHosts.all()
コード例 #4
0
ファイル: commands.py プロジェクト: tekmans/mmc
 def getCohIds(self):
     """
     Returns the list of commands_on_host linked to this command
     """
     session = sqlalchemy.create_session()
     myCommandOnHosts = session.query(CommandsOnHost).filter(CommandsOnHost.fk_commands == self.getId())
     session.close()
     return myCommandOnHosts.all()
コード例 #5
0
ファイル: notebook.py プロジェクト: minrk/ipython-svn-archive
 def __init__(self, engine=None, session=None):
     if session is None:
         session = sqla.create_session()
     self.session = session
     self.engine = engine
     self.userQuery = session.query(models.User)
     self.nodeQuery = session.query(models.Node)
     self.nbQuery = session.query(models.Notebook)
     self.users = []
コード例 #6
0
 def __init__(self):
     self._db = create_engine(os.getenv('DB_DRIVER'))
     self._metadata = BoundMetaData(self.__db)
     self.__user = mapper(
         User, Table(os.getenv('USER_TABLE'), self._metadata,
                     autoload=True))
     self.__event = mapper(
         Event,
         Table(os.getenv('EVENT_TABLE'), self._metadata, autoload=True))
     self.__payment = mapper(
         Payment,
         Table(os.getenv('PAYMENT_TABLE'), self._metadata, autoload=True))
     self._session = create_session()
コード例 #7
0
ファイル: commands.py プロジェクト: sebastiendu/mmc
def stopCommand(c_id):
    """
    Stop a command, by stopping all its related commands_on_host.
    @returns: the list of all related commands_on_host
    @rtype: list
    """
    session = sqlalchemy.create_session()
    myCommand = session.query(Commands).get(c_id)
    ret = []
    for cmd in myCommand.getCohIds():
        ret.append(cmd)
        stopCommandOnHost(cmd.id)
    session.close()
    return ret
コード例 #8
0
def stopCommand(c_id):
    """
    Stop a command, by stopping all its related commands_on_host.
    @returns: the list of all related commands_on_host
    @rtype: list
    """
    session = sqlalchemy.create_session()
    myCommand = session.query(Commands).get(c_id)
    ret = []
    for cmd in myCommand.getCohIds():
        ret.append(cmd)
        stopCommandOnHost(cmd.id)
    session.close()
    return ret
コード例 #9
0
def dumpDBtoXML(session=None, fname=None):
    """Build an XML String"""
    if session is None:
        session = sqla.create_session()
    users = session.query(models.User).select()
    s = "<XMLBackup>\n"
    for u in users:
        s += models.indent(u.xmlize(justme=False),2)
    s += "</XMLBackup>\n"
    
    if fname is not None:
        f = open(fname, 'w')
        f.write(s)
        f.close()
    # else:
    return s
コード例 #10
0
    def _setUp(self, scriptfile="implicit_chaining_1.xml"):
        self.job_script = file(self.database + "data/job_scripts/%s" % scriptfile).read()
        
        self.job_schedule = "now"
        
        self.job_input_uri_list = "<input><uri>/workspaces/1/hosts/resources/1/</uri>\n<uri>/workspaces/1/hosts/resources/2/</uri></input>"
        
        self.job_xml = '%s%s\n<when>%s</when>\n%s\n</JobDefinition>' % (
                     '<?xml version="1.0"?>\n<JobDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" href="/workspaces/1/jobs/234/">',
                     re.sub(r'^<\?[^\?]+\?>', '', self.job_script),
                     re.sub(r'^<\?[^\?]+\?>', '', self.job_schedule),
                     re.sub(r'^<\?[^\?]+\?>', '', self.job_input_uri_list),
                     )
        
        self.script_runner = sr.ScriptRunner(indexer=False, mbus=self.mbus, testing=True)
        self.script_runner.indexer = testindexer.ACTestIndexer()
        self.session = sa.create_session()

        self.t_job = models.Job("ScriptRunner TestJob #1", schedule=self.job_schedule, input=self.job_input_uri_list, script=self.job_script, workspace_id=1)
        self.session.save(self.t_job)
        self.session.update(self.t_job)
        self.t_res = models.ResultSet(name="%s Results Container @ %s" % (self.t_job.name, mir_datetime.strISO_now()), job=self.t_job, workspace_id=self.t_job.workspace_id)
        self.session.save(self.t_res)
        self.session.update(self.t_res)
        self.t_job.results.append(self.t_res)
        self.t_res.status = models.Status("Status for ResultSet %s" % self.t_res.id, activity='Starting', state='pending', status=None, id=self.t_res.id)
        self.session.flush()
        self.session.update(self.t_job)
        self.session.save(self.t_job)
        self.session.flush()
        self.session.clear()
        
        job_rec = {
           'job_obj': self.t_job, 
           'result': self.t_res,
           'job_identity': self.t_job.href,
           'job_script': self.t_job.script,
           'job_url': str(identity.identity_from_string(self.t_job.href)),
           'script_dom': minidom.parseString(self.job_script),
           'workspace_id': 1,
           'input': self.t_job.input,
           'job_elem': minidom.parseString('<?xml version="1.0" encoding="utf-8"?>%s' % self.t_job.dump_job_manifest()),
           'executionMetaData': minidom.parseString('<?xml version="1.0" encoding="utf-8"?>%s' % self.t_res.dump_execution_manifest()),
        }
        
        self.job_rec = job_rec
コード例 #11
0
ファイル: database.py プロジェクト: adrianpike/wwscc
    def make_session(uri=None, echo=None, session_kwargs=None, **kwargs):
        """Returns a SQLAlchemy session for the specified database uri from
        the the engine cache (returned from ``get_engines``)``. Uses the
        configuration values from ``get_engine_conf`` for uri and echo when
        None are specified.

        ``session_kwargs`` are passed to SQLAlchemy's ``create_session``
        function as keyword arguments.
        
        If the uri's engine does not exist, it will be created and added to
        the engine cache.
        """
        if session_kwargs is None:
            session_kwargs = {}
        engine = create_engine(uri, echo=echo, **kwargs)
        log.debug("Created engine for session context")
        return sqlalchemy.create_session(bind_to=engine, **session_kwargs)
コード例 #12
0
    def make_session(uri=None, echo=None, session_kwargs=None, **kwargs):
        """Returns a SQLAlchemy session for the specified database uri from
        the the engine cache (returned from ``get_engines``)``. Uses the
        configuration values from ``get_engine_conf`` for uri and echo when
        None are specified.

        ``session_kwargs`` are passed to SQLAlchemy's ``create_session``
        function as keyword arguments.
        
        If the uri's engine does not exist, it will be created and added to
        the engine cache.
        """
        if session_kwargs is None:
            session_kwargs = {}
        engine = create_engine(uri, echo=echo, **kwargs)
        log.debug("Created engine for session context")
        return sqlalchemy.create_session(bind_to=engine, **session_kwargs)
コード例 #13
0
    def __init__(self, object_path, options, connection=None, **kw):
        from sqlalchemy import BoundMetaData, create_engine
        from sqlalchemy.ext.sessioncontext import SessionContext

        self.connection = connection
        super(SQLAlchemyHandler, self).__init__(object_path, options, **kw)
        if not self.connection:
            if self.options.dsn:
                self.meta = BoundMetaData(self.options.dsn)
            else:
                raise MisconfiguredHandler("--dsn option is required by %s" %
                                           self.__class__)
            self.connection = self.meta.engine.connect()

        self.session_context = SessionContext(
            lambda: sqlalchemy.create_session(bind_to=self.connection))

        self.env = TableEnv(*[self.obj.__module__] + self.options.env)
コード例 #14
0
def mergeDB(*dburis):
    """merge databases through XML
    *this should go in dbutil, but cannot until it can be done without xml*
    """
    dblist = []
    for name in dburis:
        if '://' not in name:# guess it is just a filename, use sqlite
            name = 'sqlite:///'+name
        dblist.append(name)
    targetURI = dblist.pop(0)
    if targetURI == 'sqlite://':
        dbutil.initDB(targetURI)
    while dblist:
        engine = sqla.create_engine(dblist.pop(0))
        models.metadata.connect(engine)
        s = dumpDBtoXML()
        
        session = sqla.create_session()
        engine = sqla.create_engine(targetURI)
        models.metadata.connect(engine)

        loadDBfromXML(session, s)
コード例 #15
0
ファイル: oldupdate.py プロジェクト: kdar/cwc3
 def __init__(self):
   self.metadata = sa.BoundMetaData('sqlite:///cwc3.db')
   self.session = sa.create_session()
   self.InitTables()
コード例 #16
0
ファイル: target.py プロジェクト: allgi/mmc
 def flush(self):
     """ Handle SQL flushing """
     session = sqlalchemy.create_session()
     session.add(self)
     session.flush()
     session.close()
コード例 #17
0
ファイル: target.py プロジェクト: gnumaniac/pulse
 def flush(self):
     """ Handle SQL flushing """
     session = sqlalchemy.create_session()
     session.add(self)
     session.flush()
     session.close()
コード例 #18
0
ファイル: search_sqlalch.py プロジェクト: Schevo/kiwi
    SQLAColumn('category_id', Integer, ForeignKey('category.id')),
    SQLAColumn('date', Date),
)

class Task(object):
    """A task"""

mapper(Task, task_table, properties=dict(
    category = relation(Category, backref='tasks'),
))

engine = create_engine('sqlite:///')
meta.connect(engine)
meta.create_all()

session = create_session(bind_to=engine)



for category in ['Work',
                 'Home',
                 'School']:
    c = Category()
    c.name=category
    session.save(c)
session.flush()

work = session.query(Category).select_by(name='Work')[0]
home = session.query(Category).select_by(name='Home')[0]
school = session.query(Category).select_by(name='School')[0]
コード例 #19
0
ファイル: oldupdate.py プロジェクト: ternence-li/cwc3
 def __init__(self):
     self.metadata = sa.BoundMetaData('sqlite:///cwc3.db')
     self.session = sa.create_session()
     self.InitTables()
コード例 #20
0
ファイル: database.py プロジェクト: thraxil/gtreed
 def create_session():
     "Creates a session with the appropriate engine"
     return sqlalchemy.create_session(bind_to=get_engine())
コード例 #21
0
    def _setUp(self, scriptfile="implicit_chaining_1.xml"):
        self.job_script = file(self.database +
                               "data/job_scripts/%s" % scriptfile).read()

        self.job_schedule = "now"

        self.job_input_uri_list = "<input><uri>/workspaces/1/hosts/resources/1/</uri>\n<uri>/workspaces/1/hosts/resources/2/</uri></input>"

        self.job_xml = '%s%s\n<when>%s</when>\n%s\n</JobDefinition>' % (
            '<?xml version="1.0"?>\n<JobDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" href="/workspaces/1/jobs/234/">',
            re.sub(r'^<\?[^\?]+\?>', '', self.job_script),
            re.sub(r'^<\?[^\?]+\?>', '', self.job_schedule),
            re.sub(r'^<\?[^\?]+\?>', '', self.job_input_uri_list),
        )

        self.script_runner = sr.ScriptRunner(indexer=False,
                                             mbus=self.mbus,
                                             testing=True)
        self.script_runner.indexer = testindexer.ACTestIndexer()
        self.session = sa.create_session()

        self.t_job = models.Job("ScriptRunner TestJob #1",
                                schedule=self.job_schedule,
                                input=self.job_input_uri_list,
                                script=self.job_script,
                                workspace_id=1)
        self.session.save(self.t_job)
        self.session.update(self.t_job)
        self.t_res = models.ResultSet(
            name="%s Results Container @ %s" %
            (self.t_job.name, mir_datetime.strISO_now()),
            job=self.t_job,
            workspace_id=self.t_job.workspace_id)
        self.session.save(self.t_res)
        self.session.update(self.t_res)
        self.t_job.results.append(self.t_res)
        self.t_res.status = models.Status("Status for ResultSet %s" %
                                          self.t_res.id,
                                          activity='Starting',
                                          state='pending',
                                          status=None,
                                          id=self.t_res.id)
        self.session.flush()
        self.session.update(self.t_job)
        self.session.save(self.t_job)
        self.session.flush()
        self.session.clear()

        job_rec = {
            'job_obj':
            self.t_job,
            'result':
            self.t_res,
            'job_identity':
            self.t_job.href,
            'job_script':
            self.t_job.script,
            'job_url':
            str(identity.identity_from_string(self.t_job.href)),
            'script_dom':
            minidom.parseString(self.job_script),
            'workspace_id':
            1,
            'input':
            self.t_job.input,
            'job_elem':
            minidom.parseString('<?xml version="1.0" encoding="utf-8"?>%s' %
                                self.t_job.dump_job_manifest()),
            'executionMetaData':
            minidom.parseString('<?xml version="1.0" encoding="utf-8"?>%s' %
                                self.t_res.dump_execution_manifest()),
        }

        self.job_rec = job_rec
コード例 #22
0
"""sqlalchemy table and ORM definitions for Agora."""

from sqlalchemy import create_engine, create_session, BoundMetaData, \
                       Table, mapper, relation, func

DATABASE_URL = 'postgres://agora@localhost/agora'

engine = create_engine(DATABASE_URL)
session = create_session(bind_to=engine)
metadata = BoundMetaData(engine)

_entity = Table('entity', metadata, autoload=True)
_player = Table('player', metadata, autoload=True)

class DbObject(object):
    def __repr__(self):
        return '(%s: %s)' % (type(self),
                             ', '.join('%s=%s' % (x, getattr(self, x)) \
                                       for x in self.c.keys()))

class Entity(DbObject):
    pass

class Player(DbObject):
    def get_name(self):
        return self.entity.name
    def set_name(self, name):
        self.entity.name = name
    name = property(get_name, set_name)

    def get_short(self):