Skip to content

Method: AbstractSession(Configuration)

1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.sessions;
19:
20: import cz.cvut.kbss.jopa.model.MetamodelImpl;
21: import cz.cvut.kbss.jopa.query.NamedQueryManager;
22: import cz.cvut.kbss.jopa.query.ResultSetMappingManager;
23: import cz.cvut.kbss.jopa.utils.Configuration;
24: import org.slf4j.Logger;
25: import org.slf4j.LoggerFactory;
26:
27: /**
28: * This is the implementation of the basic Session operations. Other more
29: * specific methods are to be implemented in descendants.
30: */
31: public abstract class AbstractSession implements Session, MetamodelProvider, ConfigurationHolder {
32:
33: protected static final Logger LOG = LoggerFactory.getLogger(AbstractSession.class);
34:
35: protected Configuration configuration;
36:
37: protected AbstractSession(Configuration configuration) {
38: this.configuration = configuration;
39: }
40:
41: @Override
42: public UnitOfWork acquireUnitOfWork() {
43: // TODO UoW acquisition needs to be provided with configuration from EntityManager, because it may override the server session config
44: UnitOfWork uow = new UnitOfWorkImpl(this);
45: LOG.trace("UnitOfWork acquired.");
46: return uow;
47: }
48:
49: @Override
50: public abstract MetamodelImpl getMetamodel();
51:
52: /**
53: * This method just releases the live object cache. Subclasses are free to
54: * make additional cleanup.
55: */
56: @Override
57: public void release() {
58: getLiveObjectCache().evictAll();
59: }
60:
61: @Override
62: public Configuration getConfiguration() {
63: return configuration;
64: }
65:
66: /**
67: * Get the current live object cache.
68: * <p>
69: * This manager represents the second level cache.
70: *
71: * @return Second level cache
72: */
73: public abstract CacheManager getLiveObjectCache();
74:
75: /**
76: * Acquires connection to the underlying ontology storage.
77: *
78: * @return Connection
79: */
80: protected abstract ConnectionWrapper acquireConnection();
81:
82: /**
83: * Gets an object managing named queries in this persistence unit.
84: *
85: * @return {@link NamedQueryManager}
86: */
87: public abstract NamedQueryManager getNamedQueryManager();
88:
89: /**
90: * Gets the manager of SPARQL result set mapping instances.
91: * @return {@link ResultSetMappingManager}
92: */
93: public abstract ResultSetMappingManager getResultSetMappingManager();
94: }