Revision b7647a99
Added by Andreas Kohlbecker about 5 years ago
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPresenter.java | ||
---|---|---|
3 | 3 |
import java.io.Serializable; |
4 | 4 |
|
5 | 5 |
import org.apache.log4j.Logger; |
6 |
import org.hibernate.Session; |
|
7 |
import org.hibernate.engine.internal.StatefulPersistenceContext; |
|
8 |
import org.hibernate.engine.spi.SessionImplementor; |
|
9 | 6 |
import org.springframework.beans.factory.DisposableBean; |
10 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 8 |
import org.springframework.beans.factory.annotation.Qualifier; |
... | ... | |
103 | 100 |
return SecurityContextHolder.getContext(); |
104 | 101 |
} |
105 | 102 |
|
106 |
/** |
|
107 |
* @return |
|
108 |
*/ |
|
109 |
protected Session getSession() { |
|
110 |
Session session = getRepo().getSession(); |
|
111 |
if(logger.isTraceEnabled()){ |
|
112 |
if(session.isOpen()){ |
|
113 |
logger.trace(this._toString() + ".getSession() - session:" + session.hashCode() +", persistenceContext: " + ((SessionImplementor)session).getPersistenceContext() + " - " + session.toString()); |
|
114 |
} else { |
|
115 |
logger.trace(this._toString() + ".getSession() - session:" + session.hashCode() +" is closed "); |
|
116 |
} |
|
117 |
} |
|
118 |
return session; |
|
119 |
} |
|
120 | 103 |
|
121 | 104 |
protected String _toString(){ |
122 | 105 |
return this.getClass().getSimpleName() + "@" + this.hashCode(); |
... | ... | |
146 | 129 |
logger.trace(String.format("Presenter %s ready", _toString())); |
147 | 130 |
} |
148 | 131 |
|
149 |
/** |
|
150 |
* @return |
|
151 |
*/ |
|
152 |
private StatefulPersistenceContext getPersitenceContext() { |
|
153 |
return (StatefulPersistenceContext)((SessionImplementor)getSession()).getPersistenceContext(); |
|
154 |
} |
|
155 |
|
|
156 | 132 |
public final void onViewEnter() { |
157 | 133 |
logger.trace(String.format("%s onViewEnter()", _toString())); |
158 | 134 |
handleViewEntered(); |
... | ... | |
174 | 150 |
// fist of all clear the session to wipe out any left overs from previous usage of the session |
175 | 151 |
// this can happen if not all operations within a session are cleaned up correctly in |
176 | 152 |
// turn of an exception |
177 |
getSession().clear();
|
|
153 |
getRepo().clearSession();
|
|
178 | 154 |
} |
179 | 155 |
|
180 | 156 |
/** |
Also available in: Unified diff
ref #7106 using new CdmRepository.clearSession() method