Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d062be837d19ad883d92e6ea745b127aada131b0 (plain) (blame)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/**
 * <copyright>
 *
 * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Martin Taal
 * </copyright>
 *
 * $Id: HbBaseSessionDataStore.java,v 1.11 2010/11/11 10:28:18 mtaal Exp $
 */

package org.eclipse.emf.teneo.hibernate;

import java.io.Serializable;
import java.sql.Connection;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.naming.NamingException;
import javax.naming.Reference;

import org.hibernate.Cache;
import org.hibernate.CustomEntityDirtinessStrategy;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.StatelessSession;
import org.hibernate.StatelessSessionBuilder;
import org.hibernate.TypeHelper;
import org.hibernate.cache.spi.QueryCache;
import org.hibernate.cache.spi.Region;
import org.hibernate.cache.spi.UpdateTimestampsCache;
import org.hibernate.cfg.Settings;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunctionRegistry;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.profile.FetchProfile;
import org.hibernate.engine.query.spi.QueryPlanCache;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.NamedQueryDefinition;
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.exception.spi.SQLExceptionConverter;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.stat.Statistics;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.Type;
import org.hibernate.type.TypeResolver;

/**
 * Holds the sessionfactory related methods, makes the HbSessionDataStore better readable.
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.11 $
 */
public abstract class HbBaseSessionDataStore extends HbDataStore implements SessionFactory,
		SessionFactoryImplementor {

	private static final long serialVersionUID = 1L;

	/** The persistency manager factory */
	private SessionFactory sessionFactory;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.teneo.hibernate.HbDataStore#close()
	 */
	@Override
	public void close() {
		if (isInitialized()) {
			closeSessionFactory();
			// this will call the close method again but because the
			// datastore
			// is not initialized anymore it won't get here
			HbHelper.INSTANCE.deRegisterDataStore(this);
		}
	}

	/**
	 * @return the sessionFactory
	 */
	@Override
	public SessionFactory getSessionFactory() {
		if (!isInitialized()) {
			initialize();
		}
		return sessionFactory;
	}

	// close session factory if set
	protected void closeSessionFactory() {
		if (sessionFactory != null && !sessionFactory.isClosed()) {
			sessionFactory.close();
			sessionFactory = null;
		}
		// do set initialized false after closing it
		setInitialized(false);
	}

	/**
	 * @param sessionFactory
	 *          the sessionFactory to set
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@SuppressWarnings({ "rawtypes", "deprecation" })
	public void evict(Class persistentClass, Serializable id) throws HibernateException {
		getSessionFactory().evict(persistentClass, id);
	}

	@SuppressWarnings({ "rawtypes", "deprecation" })
	public void evict(Class persistentClass) throws HibernateException {
		getSessionFactory().evict(persistentClass);
	}

	@SuppressWarnings({ "deprecation" })
	public void evictCollection(String roleName, Serializable id) throws HibernateException {
		getSessionFactory().evictCollection(roleName, id);
	}

	@SuppressWarnings({ "deprecation" })
	public void evictCollection(String roleName) throws HibernateException {
		getSessionFactory().evictCollection(roleName);
	}

	@SuppressWarnings({ "deprecation" })
	public void evictEntity(String entityName, Serializable id) throws HibernateException {
		getSessionFactory().evictEntity(entityName, id);
	}

	@SuppressWarnings({ "deprecation" })
	public void evictEntity(String entityName) throws HibernateException {
		getSessionFactory().evictEntity(entityName);
	}

	@SuppressWarnings({ "deprecation" })
	public void evictQueries() throws HibernateException {
		getSessionFactory().evictQueries();
	}

	@SuppressWarnings({ "deprecation" })
	public void evictQueries(String cacheRegion) throws HibernateException {
		getSessionFactory().evictQueries(cacheRegion);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Map getAllClassMetadata() throws HibernateException {
		return getSessionFactory().getAllClassMetadata();
	}

	@SuppressWarnings({ "rawtypes" })
	public Map getAllCollectionMetadata() throws HibernateException {
		return getSessionFactory().getAllCollectionMetadata();
	}

	@SuppressWarnings({ "rawtypes" })
	public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {
		return getSessionFactory().getClassMetadata(persistentClass);
	}

	public ClassMetadata getClassMetadata(String entityName) throws HibernateException {
		return getSessionFactory().getClassMetadata(entityName);
	}

	public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {
		return getSessionFactory().getCollectionMetadata(roleName);
	}

	public Session getCurrentSession() throws HibernateException {
		return getSessionFactory().getCurrentSession();
	}

	@SuppressWarnings("rawtypes")
	public Set getDefinedFilterNames() {
		return getSessionFactory().getDefinedFilterNames();
	}

	public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
		return getSessionFactory().getFilterDefinition(filterName);
	}

	public Reference getReference() throws NamingException {
		return getSessionFactory().getReference();
	}

	public Statistics getStatistics() {
		return getSessionFactory().getStatistics();
	}

	public boolean isClosed() {
		return getSessionFactory().isClosed();
	}

	public Session openSession() throws HibernateException {
		return getSessionFactory().openSession();
	}

	public Session openSession(Connection connection, Interceptor interceptor) {
		return ((SessionFactoryImpl) getSessionFactory()).withOptions().interceptor(interceptor)
				.connection(connection).openSession();
	}

	public Session openSession(Connection connection) {
		return ((SessionFactoryImpl) getSessionFactory()).withOptions().connection(connection)
				.openSession();
	}

	public Session openSession(Interceptor interceptor) throws HibernateException {
		return ((SessionFactoryImpl) getSessionFactory()).withOptions().interceptor(interceptor)
				.openSession();
	}

	public StatelessSession openStatelessSession() {
		return getSessionFactory().openStatelessSession();
	}

	public StatelessSession openStatelessSession(Connection connection) {
		return getSessionFactory().openStatelessSession(connection);
	}

	protected SessionFactoryImplementor getSessionFactoryImplementor() {
		return (SessionFactoryImplementor) getSessionFactory();
	}

	public void addObserver(SessionFactoryObserver arg0) {
		getSessionFactoryImplementor().addObserver(arg0);
	}

	public boolean containsFetchProfileDefinition(String arg0) {
		return getSessionFactoryImplementor().containsFetchProfileDefinition(arg0);
	}

	@SuppressWarnings("rawtypes")
	public Map getAllSecondLevelCacheRegions() {
		return getSessionFactoryImplementor().getAllSecondLevelCacheRegions();
	}

	public Cache getCache() {
		return getSessionFactoryImplementor().getCache();
	}

	public CollectionPersister getCollectionPersister(String arg0) throws MappingException {
		return getSessionFactoryImplementor().getCollectionPersister(arg0);
	}

	public Set<String> getCollectionRolesByEntityParticipant(String arg0) {
		return getSessionFactoryImplementor().getCollectionRolesByEntityParticipant(arg0);
	}

	public ConnectionProvider getConnectionProvider() {
		return getSessionFactoryImplementor().getConnectionProvider();
	}

	public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
		return getSessionFactoryImplementor().getCurrentTenantIdentifierResolver();
	}

	public CustomEntityDirtinessStrategy getCustomEntityDirtinessStrategy() {
		return getSessionFactoryImplementor().getCustomEntityDirtinessStrategy();
	}

	public Dialect getDialect() {
		return getSessionFactoryImplementor().getDialect();
	}

	public EntityNotFoundDelegate getEntityNotFoundDelegate() {
		return getSessionFactoryImplementor().getEntityNotFoundDelegate();
	}

	public EntityPersister getEntityPersister(String arg0) throws MappingException {
		return getSessionFactoryImplementor().getEntityPersister(arg0);
	}

	public FetchProfile getFetchProfile(String arg0) {
		return getSessionFactoryImplementor().getFetchProfile(arg0);
	}

	public IdentifierGenerator getIdentifierGenerator(String arg0) {
		return getSessionFactoryImplementor().getIdentifierGenerator(arg0);
	}

	@Deprecated
	public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
		return getSessionFactoryImplementor().getIdentifierGeneratorFactory();
	}

	public String getIdentifierPropertyName(String arg0) throws MappingException {
		return getSessionFactoryImplementor().getIdentifierPropertyName(arg0);
	}

	public Type getIdentifierType(String arg0) throws MappingException {
		return getSessionFactoryImplementor().getIdentifierType(arg0);
	}

	public String[] getImplementors(String arg0) throws MappingException {
		return getSessionFactoryImplementor().getImplementors(arg0);
	}

	public String getImportedClassName(String arg0) {
		return getSessionFactoryImplementor().getImportedClassName(arg0);
	}

	public Interceptor getInterceptor() {
		return getSessionFactoryImplementor().getInterceptor();
	}

	public JdbcServices getJdbcServices() {
		return getSessionFactoryImplementor().getJdbcServices();
	}

	public NamedQueryDefinition getNamedQuery(String arg0) {
		return getSessionFactoryImplementor().getNamedQuery(arg0);
	}

	public NamedSQLQueryDefinition getNamedSQLQuery(String arg0) {
		return getSessionFactoryImplementor().getNamedSQLQuery(arg0);
	}

	public Region getNaturalIdCacheRegion(String arg0) {
		return getSessionFactoryImplementor().getNaturalIdCacheRegion(arg0);
	}

	public Properties getProperties() {
		return getSessionFactoryImplementor().getProperties();
	}

	public QueryCache getQueryCache() {
		return getSessionFactoryImplementor().getQueryCache();
	}

	public QueryCache getQueryCache(String arg0) throws HibernateException {
		return getSessionFactoryImplementor().getQueryCache(arg0);
	}

	public QueryPlanCache getQueryPlanCache() {
		return getSessionFactoryImplementor().getQueryPlanCache();
	}

	public Type getReferencedPropertyType(String arg0, String arg1) throws MappingException {
		return getSessionFactoryImplementor().getReferencedPropertyType(arg0, arg1);
	}

	public ResultSetMappingDefinition getResultSetMapping(String arg0) {
		return getSessionFactoryImplementor().getResultSetMapping(arg0);
	}

	public String[] getReturnAliases(String arg0) throws HibernateException {
		return getSessionFactoryImplementor().getReturnAliases(arg0);
	}

	public Type[] getReturnTypes(String arg0) throws HibernateException {
		return getSessionFactoryImplementor().getReturnTypes(arg0);
	}

	public SQLExceptionConverter getSQLExceptionConverter() {
		return getSessionFactoryImplementor().getSQLExceptionConverter();
	}

	public SqlExceptionHelper getSQLExceptionHelper() {
		return getSessionFactoryImplementor().getSQLExceptionHelper();
	}

	public Region getSecondLevelCacheRegion(String arg0) {
		return getSessionFactoryImplementor().getSecondLevelCacheRegion(arg0);
	}

	public ServiceRegistryImplementor getServiceRegistry() {
		return getSessionFactoryImplementor().getServiceRegistry();
	}

	public SessionFactoryOptions getSessionFactoryOptions() {
		return getSessionFactoryImplementor().getSessionFactoryOptions();
	}

	public Settings getSettings() {
		return getSessionFactoryImplementor().getSettings();
	}

	public SQLFunctionRegistry getSqlFunctionRegistry() {
		return getSessionFactoryImplementor().getSqlFunctionRegistry();
	}

	public StatisticsImplementor getStatisticsImplementor() {
		return getSessionFactoryImplementor().getStatisticsImplementor();
	}

	public TypeHelper getTypeHelper() {
		return getSessionFactoryImplementor().getTypeHelper();
	}

	public TypeResolver getTypeResolver() {
		return getSessionFactoryImplementor().getTypeResolver();
	}

	public UpdateTimestampsCache getUpdateTimestampsCache() {
		return getSessionFactoryImplementor().getUpdateTimestampsCache();
	}

	public Session openTemporarySession() throws HibernateException {
		return getSessionFactoryImplementor().openTemporarySession();
	}

	public SessionBuilder withOptions() {
		return getSessionFactoryImplementor().withOptions();
	}

	public StatelessSessionBuilder withStatelessOptions() {
		return getSessionFactoryImplementor().withStatelessOptions();
	}
}

Back to the top