|
a/Allura/allura/model/session.py |
|
b/Allura/allura/model/session.py |
1 |
import logging
|
1 |
import logging
|
2 |
|
2 |
|
3 |
from pylons import c
|
|
|
4 |
|
|
|
5 |
from ming import Session
|
3 |
from ming import Session
|
6 |
from ming.datastore import ShardedDataStore
|
|
|
7 |
from ming.orm.base import state, session
|
4 |
from ming.orm.base import state
|
8 |
from ming.orm.ormsession import ThreadLocalORMSession, SessionExtension
|
5 |
from ming.orm.ormsession import ThreadLocalORMSession, SessionExtension
|
9 |
|
6 |
|
10 |
log = logging.getLogger(__name__)
|
7 |
log = logging.getLogger(__name__)
|
11 |
|
|
|
12 |
class ProjectSession(Session):
|
|
|
13 |
|
|
|
14 |
def __init__(self, main_session):
|
|
|
15 |
self.main_session = main_session
|
|
|
16 |
|
|
|
17 |
@property
|
|
|
18 |
def db(self):
|
|
|
19 |
try:
|
|
|
20 |
assert c.project.database_uri
|
|
|
21 |
scheme, rest = c.project.database_uri.split('://')
|
|
|
22 |
host, database = rest.split('/', 1)
|
|
|
23 |
return ShardedDataStore.get(scheme + '://' + host, database).db
|
|
|
24 |
except (KeyError, AttributeError, TypeError), ex:
|
|
|
25 |
return None
|
|
|
26 |
|
|
|
27 |
def _impl(self, cls):
|
|
|
28 |
db = self.db
|
|
|
29 |
if db:
|
|
|
30 |
return db[cls.__mongometa__.name]
|
|
|
31 |
else: # pragma no cover
|
|
|
32 |
return None
|
|
|
33 |
|
8 |
|
34 |
class ArtifactSessionExtension(SessionExtension):
|
9 |
class ArtifactSessionExtension(SessionExtension):
|
35 |
|
10 |
|
36 |
def __init__(self, session):
|
11 |
def __init__(self, session):
|
37 |
SessionExtension.__init__(self, session)
|
12 |
SessionExtension.__init__(self, session)
|
|
... |
|
... |
83 |
self.objects_added = []
|
58 |
self.objects_added = []
|
84 |
self.objects_modified = []
|
59 |
self.objects_modified = []
|
85 |
self.objects_deleted = []
|
60 |
self.objects_deleted = []
|
86 |
|
61 |
|
87 |
main_doc_session = Session.by_name('main')
|
62 |
main_doc_session = Session.by_name('main')
|
88 |
project_doc_session = ProjectSession(main_doc_session)
|
63 |
project_doc_session = Session.by_name('project')
|
89 |
main_orm_session = ThreadLocalORMSession(main_doc_session)
|
64 |
main_orm_session = ThreadLocalORMSession(main_doc_session)
|
90 |
project_orm_session = ThreadLocalORMSession(project_doc_session)
|
65 |
project_orm_session = ThreadLocalORMSession(project_doc_session)
|
91 |
artifact_orm_session = ThreadLocalORMSession(
|
66 |
artifact_orm_session = ThreadLocalORMSession(
|
92 |
doc_session=project_doc_session,
|
67 |
doc_session=project_doc_session,
|
93 |
extensions = [ ArtifactSessionExtension ])
|
68 |
extensions = [ ArtifactSessionExtension ])
|