Skip to contentMethod: acquireUnitOfWork()
1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: * <p>
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.sessions;
16:
17: import cz.cvut.kbss.jopa.model.MetamodelImpl;
18: import cz.cvut.kbss.jopa.query.NamedQueryManager;
19: import org.slf4j.Logger;
20: import org.slf4j.LoggerFactory;
21:
22: /**
23: * This is the implementation of the basic Session operations. Other more
24: * specific methods are to be implemented in descendants.
25: */
26: public abstract class AbstractSession implements Session, MetamodelProvider {
27: protected static final Logger LOG = LoggerFactory.getLogger(AbstractSession.class);
28:
29: public UnitOfWork acquireUnitOfWork() {
30: UnitOfWork uow = new UnitOfWorkImpl(this);
31: LOG.trace("UnitOfWork acquired.");
32: return uow;
33: }
34:
35: @Override
36: public abstract MetamodelImpl getMetamodel();
37:
38: /**
39: * This method just releases the live object cache. Subclasses are free to
40: * make additional cleanup.
41: */
42: public void release() {
43: releaseObjectCache();
44: }
45:
46: /**
47: * Release the current liveObjectCache. This method is called whenever any
48: * attribute of a cached objects changes during a transaction because then
49: * our cache is no more actual.
50: */
51: public void releaseObjectCache() {
52: getLiveObjectCache().evictAll();
53: }
54:
55: /**
56: * Get the current live object cache. </p>
57: * <p>
58: * This manager represents the second level cache.
59: *
60: * @return Second level cache
61: */
62: public abstract CacheManager getLiveObjectCache();
63:
64: /**
65: * Acquires connection to the underlying ontology storage. </p>
66: *
67: * @return Connection
68: */
69: protected abstract ConnectionWrapper acquireConnection();
70:
71: /**
72: * Register the specified entity as managed in the specified
73: * {@code UnitOfWork}. </p>
74: * <p>
75: * Registering loaded entities with their owning {@code UnitOfWork} is
76: * highly recommended, since it speeds up persistence context lookup when
77: * entity attributes are modified.
78: *
79: * @param entity The entity to register
80: * @param uow Persistence context of the specified entity
81: */
82: abstract void registerEntityWithPersistenceContext(Object entity, UnitOfWorkImpl uow);
83:
84: /**
85: * Detaches the specified entity from its persistence context.
86: *
87: * @param entity The entity to deregister
88: * @param uow Persistence context to which the entity belonged
89: */
90: abstract void deregisterEntityFromPersistenceContext(Object entity, UnitOfWork uow);
91:
92: /**
93: * Releases the specified persistence context, detaching any entities associated with it.
94: * @param uow The persistence context to release
95: */
96: abstract void releasePersistenceContext(UnitOfWork uow);
97:
98: /**
99: * Gets an object managing named queries in this persistence unit.
100: *
101: * @return {@link NamedQueryManager}
102: */
103: public abstract NamedQueryManager getNamedQueryManager();
104: }