Skip to content

Package: AbstractSession

AbstractSession

nameinstructionbranchcomplexitylinemethod
AbstractSession()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
acquireUnitOfWork()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
release()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
releaseObjectCache()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
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: *
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.query.NamedQueryManager;
18: import org.slf4j.Logger;
19: import org.slf4j.LoggerFactory;
20:
21: /**
22: * This is the implementation of the basic Session operations. Other more
23: * specific methods are to be implemented in descendants.
24: */
25: public abstract class AbstractSession implements Session, MetamodelProvider {
26: protected static final Logger LOG = LoggerFactory.getLogger(AbstractSession.class);
27:
28: public UnitOfWork acquireUnitOfWork() {
29: UnitOfWork uow = new UnitOfWorkImpl(this);
30: LOG.trace("UnitOfWork acquired.");
31: return uow;
32: }
33:
34: /**
35: * This method just releases the live object cache. Subclasses are free to
36: * make additional cleanup.
37: */
38: public void release() {
39: releaseObjectCache();
40: }
41:
42: /**
43: * Release the current liveObjectCache. This method is called whenever any
44: * attribute of a cached objects changes during a transaction because then
45: * our cache is no more actual.
46: */
47: public void releaseObjectCache() {
48: getLiveObjectCache().evictAll();
49: }
50:
51: /**
52: * Get the current live object cache. </p>
53: * <p>
54: * This manager represents the second level cache.
55: *
56: * @return Second level cache
57: */
58: public abstract CacheManager getLiveObjectCache();
59:
60: /**
61: * Acquires connection to the underlying ontology storage. </p>
62: *
63: * @return Connection
64: */
65: protected abstract ConnectionWrapper acquireConnection();
66:
67: /**
68: * Register the specified entity as managed in the specified
69: * {@code UnitOfWork}. </p>
70: * <p>
71: * Registering loaded entities with their owning {@code UnitOfWork} is
72: * highly recommended, since it speeds up persistence context lookup when
73: * entity attributes are modified.
74: *
75: * @param entity The entity to register
76: * @param uow Persistence context of the specified entity
77: */
78: abstract void registerEntityWithPersistenceContext(Object entity, UnitOfWorkImpl uow);
79:
80: /**
81: * Detaches the specified entity from its persistence context.
82: *
83: * @param entity The entity to deregister
84: * @param uow Persistence context to which the entity belonged
85: */
86: abstract void deregisterEntityFromPersistenceContext(Object entity, UnitOfWork uow);
87:
88: /**
89: * Gets an object managing named queries in this persistence unit.
90: *
91: * @return {@link NamedQueryManager}
92: */
93: public abstract NamedQueryManager getNamedQueryManager();
94: }