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