Skip to contentMethod: acquireUnitOfWork()
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.model.MetamodelImpl;
18: import cz.cvut.kbss.jopa.query.NamedQueryManager;
19: import cz.cvut.kbss.jopa.query.ResultSetMappingManager;
20: import cz.cvut.kbss.jopa.utils.Configuration;
21: import org.slf4j.Logger;
22: import org.slf4j.LoggerFactory;
23:
24: /**
25: * This is the implementation of the basic Session operations. Other more
26: * specific methods are to be implemented in descendants.
27: */
28: public abstract class AbstractSession implements Session, MetamodelProvider, ConfigurationHolder {
29:
30: protected static final Logger LOG = LoggerFactory.getLogger(AbstractSession.class);
31:
32:
33: private final Configuration configuration;
34:
35: protected AbstractSession(Configuration configuration) {
36: this.configuration = configuration;
37: }
38:
39: @Override
40: public UnitOfWork acquireUnitOfWork() {
41: UnitOfWork uow = new UnitOfWorkImpl(this);
42: LOG.trace("UnitOfWork acquired.");
43: return uow;
44: }
45:
46: @Override
47: public abstract MetamodelImpl getMetamodel();
48:
49: /**
50: * This method just releases the live object cache. Subclasses are free to
51: * make additional cleanup.
52: */
53: @Override
54: public void release() {
55: getLiveObjectCache().evictAll();
56: }
57:
58: @Override
59: public Configuration getConfiguration() {
60: return configuration;
61: }
62:
63: /**
64: * Get the current live object cache.
65: * <p>
66: * This manager represents the second level cache.
67: *
68: * @return Second level cache
69: */
70: public abstract CacheManager getLiveObjectCache();
71:
72: /**
73: * Acquires connection to the underlying ontology storage.
74: *
75: * @return Connection
76: */
77: protected abstract ConnectionWrapper acquireConnection();
78:
79: /**
80: * Gets an object managing named queries in this persistence unit.
81: *
82: * @return {@link NamedQueryManager}
83: */
84: public abstract NamedQueryManager getNamedQueryManager();
85:
86: /**
87: * Gets the manager of SPARQL result set mapping instances.
88: * @return {@link ResultSetMappingManager}
89: */
90: public abstract ResultSetMappingManager getResultSetMappingManager();
91: }