• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 8583110103

06 Apr 2024 06:40PM CUT coverage: 64.691%. Remained the same
8583110103

push

github

web-flow
maven(deps): bump org.apache.maven.plugins:maven-source-plugin (#4612)

Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.3.0 to 3.3.1.
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.3.0...maven-source-plugin-3.3.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-source-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

22762 of 35186 relevant lines covered (64.69%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/api/src/main/java/org/openmrs/api/db/hibernate/DbSession.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.api.db.hibernate;
11

12
import java.io.Serializable;
13
import java.sql.Connection;
14

15
import org.hibernate.CacheMode;
16
import org.hibernate.Criteria;
17
import org.hibernate.Filter;
18
import org.hibernate.FlushMode;
19
import org.hibernate.HibernateException;
20
import org.hibernate.IdentifierLoadAccess;
21
import org.hibernate.LobHelper;
22
import org.hibernate.LockMode;
23
import org.hibernate.LockOptions;
24
import org.hibernate.NaturalIdLoadAccess;
25
import org.hibernate.Query;
26
import org.hibernate.ReplicationMode;
27
import org.hibernate.SQLQuery;
28
import org.hibernate.Session;
29
import org.hibernate.Session.LockRequest;
30
import org.hibernate.SessionEventListener;
31
import org.hibernate.SessionFactory;
32
import org.hibernate.SharedSessionBuilder;
33
import org.hibernate.SimpleNaturalIdLoadAccess;
34
import org.hibernate.Transaction;
35
import org.hibernate.TransientObjectException;
36
import org.hibernate.TypeHelper;
37
import org.hibernate.UnknownProfileException;
38
import org.hibernate.jdbc.ReturningWork;
39
import org.hibernate.jdbc.Work;
40
import org.hibernate.procedure.ProcedureCall;
41
import org.hibernate.stat.SessionStatistics;
42

43
/**
44
 * This class has been created to provide backwards compatibility for modules, which need to support
45
 * OpenMRS 1.12 and before. It is because org.hibernate.classic.Session has been removed in
46
 * Hibernate 4 (used in OpenMRS 1.12) and sessionFactory.getCurrentSession() has been changed to
47
 * return org.hibernate.Session. It wraps SessionFactory so that any calls to getCurrentSession()
48
 * are directed to the correct Session class.
49
 * 
50
 * @since 1.12, 1.11.3, 1.10.2, 1.9.9
51
 */
52
public class DbSession {
53
        
54
        private SessionFactory sessionFactory;
55
        
56
        public DbSession(SessionFactory sessionFactory) {
×
57
                this.sessionFactory = sessionFactory;
×
58
        }
×
59
        
60
        private Session getSession() {
61
                return sessionFactory.getCurrentSession();
×
62
        }
63
        
64
        /**
65
         * Obtain the tenant identifier associated with this session.
66
         *
67
         * @return The tenant identifier associated with this session, or {@code null}
68
         */
69
        public String getTenantIdentifier() {
70
                return getSession().getTenantIdentifier();
×
71
        }
72
        
73
        /**
74
         * Begin a unit of work and return the associated {@link Transaction} object. If a new
75
         * underlying transaction is required, begin the transaction. Otherwise continue the new work in
76
         * the context of the existing underlying transaction.
77
         *
78
         * @return a Transaction instance
79
         * @see #getTransaction
80
         */
81
        public Transaction beginTransaction() {
82
                return getSession().beginTransaction();
×
83
        }
84
        
85
        /**
86
         * Get the {@link Transaction} instance associated with this session. The concrete type of the
87
         * returned {@link Transaction} object is determined by the
88
         * {@code hibernate.transaction_factory} property.
89
         *
90
         * @return a Transaction instance
91
         */
92
        public Transaction getTransaction() {
93
                return getSession().getTransaction();
×
94
        }
95
        
96
        /**
97
         * Create a {@link Query} instance for the named query string defined in the metadata.
98
         *
99
         * @param queryName the name of a query defined externally
100
         * @return The query instance for manipulation and execution
101
         */
102
        public Query getNamedQuery(String queryName) {
103
                return getSession().getNamedQuery(queryName);
×
104
        }
105
        
106
        /**
107
         * Create a {@link Query} instance for the given HQL query string.
108
         *
109
         * @param queryString The HQL query
110
         * @return The query instance for manipulation and execution
111
         */
112
        public Query createQuery(String queryString) {
113
                return getSession().createQuery(queryString);
×
114
        }
115
        
116
        /**
117
         * Create a {@link SQLQuery} instance for the given SQL query string.
118
         *
119
         * @param queryString The SQL query
120
         * @return The query instance for manipulation and execution
121
         */
122
        public SQLQuery createSQLQuery(String queryString) {
123
                return getSession().createSQLQuery(queryString);
×
124
        }
125
        
126
        /**
127
         * Gets a ProcedureCall based on a named template
128
         *
129
         * @param name The name given to the template
130
         * @return The ProcedureCall
131
         * @see javax.persistence.NamedStoredProcedureQuery
132
         */
133
        public ProcedureCall getNamedProcedureCall(String name) {
134
                return getSession().getNamedProcedureCall(name);
×
135
        }
136
        
137
        /**
138
         * Creates a call to a stored procedure.
139
         *
140
         * @param procedureName The name of the procedure.
141
         * @return The representation of the procedure call.
142
         */
143
        public ProcedureCall createStoredProcedureCall(String procedureName) {
144
                return getSession().createStoredProcedureCall(procedureName);
×
145
        }
146
        
147
        /**
148
         * Creates a call to a stored procedure with specific result set entity mappings. Each class
149
         * named is considered a "root return".
150
         *
151
         * @param procedureName The name of the procedure.
152
         * @param resultClasses The entity(s) to map the result on to.
153
         * @return The representation of the procedure call.
154
         */
155
        public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
156
                return getSession().createStoredProcedureCall(procedureName, resultClasses);
×
157
        }
158
        
159
        /**
160
         * Creates a call to a stored procedure with specific result set entity mappings.
161
         *
162
         * @param procedureName The name of the procedure.
163
         * @param resultSetMappings The explicit result set mapping(s) to use for mapping the results
164
         * @return The representation of the procedure call.
165
         */
166
        public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
167
                return getSession().createStoredProcedureCall(procedureName, resultSetMappings);
×
168
        }
169
        
170
        /**
171
         * Create {@link Criteria} instance for the given class (entity or subclasses/implementors).
172
         *
173
         * @param persistentClass The class, which is an entity, or has entity subclasses/implementors
174
         * @return The criteria instance for manipulation and execution
175
         */
176
        public Criteria createCriteria(Class persistentClass) {
177
                return getSession().createCriteria(persistentClass);
×
178
        }
179
        
180
        /**
181
         * Create {@link Criteria} instance for the given class (entity or subclasses/implementors),
182
         * using a specific alias.
183
         *
184
         * @param persistentClass The class, which is an entity, or has entity subclasses/implementors
185
         * @param alias The alias to use
186
         * @return The criteria instance for manipulation and execution
187
         */
188
        public Criteria createCriteria(Class persistentClass, String alias) {
189
                return getSession().createCriteria(persistentClass, alias);
×
190
        }
191
        
192
        /**
193
         * Create {@link Criteria} instance for the given entity name.
194
         *
195
         * @param entityName The entity name @return The criteria instance for manipulation and
196
         *            execution
197
         */
198
        public Criteria createCriteria(String entityName) {
199
                return getSession().createCriteria(entityName);
×
200
        }
201
        
202
        /**
203
         * Create {@link Criteria} instance for the given entity name, using a specific alias.
204
         *
205
         * @param entityName The entity name
206
         * @param alias The alias to use
207
         * @return The criteria instance for manipulation and execution
208
         */
209
        public Criteria createCriteria(String entityName, String alias) {
210
                return getSession().createCriteria(entityName, alias);
×
211
        }
212
        
213
        /**
214
         * Obtain a {@link Session} builder with the ability to grab certain information from this
215
         * session.
216
         *
217
         * @return The session builder
218
         */
219
        public SharedSessionBuilder sessionWithOptions() {
220
                return getSession().sessionWithOptions();
×
221
        }
222
        
223
        /**
224
         * Force this session to flush. Must be called at the end of a unit of work, before committing
225
         * the transaction and closing the session (depending on {@link #setFlushMode(FlushMode)},
226
         * {@link Transaction#commit()} calls this method).
227
         * <p>
228
         * <i>Flushing</i> is the process of synchronizing the underlying persistent store with
229
         * persistable state held in memory.
230
         *
231
         * @throws HibernateException Indicates problems flushing the session or talking to the
232
         *             database.
233
         */
234
        public void flush() throws HibernateException {
235
                getSession().flush();
×
236
        }
×
237
        
238
        /**
239
         * Set the flush mode for this session.
240
         * <p>
241
         * The flush mode determines the points at which the session is flushed. <i>Flushing</i> is the
242
         * process of synchronizing the underlying persistent store with persistable state held in
243
         * memory.
244
         * <p>
245
         * For a logically "read only" session, it is reasonable to set the session's flush mode to
246
         * {@link FlushMode#MANUAL} at the start of the session (in order to achieve some extra
247
         * performance).
248
         *
249
         * @param flushMode the new flush mode
250
         * @see FlushMode
251
         */
252
        public void setFlushMode(FlushMode flushMode) {
253
                getSession().setHibernateFlushMode(flushMode);
×
254
        }
×
255
        
256
        /**
257
         * Get the current flush mode for this session.
258
         *
259
         * @return The flush mode
260
         */
261
        public FlushMode getFlushMode() {
262
                return getSession().getHibernateFlushMode();
×
263
        }
264
        
265
        /**
266
         * Set the cache mode.
267
         * <p>
268
         * Cache mode determines the manner in which this session can interact with the second level
269
         * cache.
270
         *
271
         * @param cacheMode The new cache mode.
272
         */
273
        public void setCacheMode(CacheMode cacheMode) {
274
                getSession().setCacheMode(cacheMode);
×
275
        }
×
276
        
277
        /**
278
         * Get the current cache mode.
279
         *
280
         * @return The current cache mode.
281
         */
282
        public CacheMode getCacheMode() {
283
                return getSession().getCacheMode();
×
284
        }
285
        
286
        /**
287
         * Get the session factory which created this session.
288
         *
289
         * @return The session factory.
290
         * @see SessionFactory
291
         */
292
        public SessionFactory getSessionFactory() {
293
                return getSession().getSessionFactory();
×
294
        }
295
        
296
        /**
297
         * End the session by releasing the JDBC connection and cleaning up. It is not strictly
298
         * necessary to close the session but you must at least {@link #disconnect()} it.
299
         *
300
         * @return the connection provided by the application or null.
301
         * @throws HibernateException Indicates problems cleaning up.
302
         */
303
        public Connection close() throws HibernateException {
304
                getSession().close();
×
305
                return null;
×
306
        }
307
        
308
        /**
309
         * Cancel the execution of the current query.
310
         * <p>
311
         * This is the sole method on session which may be safely called from another thread.
312
         *
313
         * @throws HibernateException There was a problem canceling the query
314
         */
315
        public void cancelQuery() throws HibernateException {
316
                getSession().cancelQuery();
×
317
        }
×
318
        
319
        /**
320
         * Check if the session is still open.
321
         *
322
         * @return boolean
323
         */
324
        public boolean isOpen() {
325
                return getSession().isOpen();
×
326
        }
327
        
328
        /**
329
         * Check if the session is currently connected.
330
         *
331
         * @return boolean
332
         */
333
        public boolean isConnected() {
334
                return getSession().isConnected();
×
335
        }
336
        
337
        /**
338
         * Does this session contain any changes which must be synchronized with the database? In other
339
         * words, would any DML operations be executed if we flushed this session?
340
         *
341
         * @return True if the session contains pending changes; false otherwise.
342
         * @throws HibernateException could not perform dirtying checking
343
         */
344
        public boolean isDirty() throws HibernateException {
345
                return getSession().isDirty();
×
346
        }
347
        
348
        /**
349
         * Will entities and proxies that are loaded into this session be made read-only by default? To
350
         * determine the read-only/modifiable setting for a particular entity or proxy:
351
         * 
352
         * @see Session#isReadOnly(Object)
353
         * @return true, loaded entities/proxies will be made read-only by default; false, loaded
354
         *         entities/proxies will be made modifiable by default.
355
         */
356
        public boolean isDefaultReadOnly() {
357
                return getSession().isDefaultReadOnly();
×
358
        }
359
        
360
        /**
361
         * Change the default for entities and proxies loaded into this session from modifiable to
362
         * read-only mode, or from modifiable to read-only mode. Read-only entities are not
363
         * dirty-checked and snapshots of persistent state are not maintained. Read-only entities can be
364
         * modified, but changes are not persisted. When a proxy is initialized, the loaded entity will
365
         * have the same read-only/modifiable setting as the uninitialized proxy has, regardless of the
366
         * session's current setting. To change the read-only/modifiable setting for a particular entity
367
         * or proxy that is already in this session:
368
         * 
369
         * @see Session#setReadOnly(Object,boolean) To override this session's read-only/modifiable
370
         *      setting for entities and proxies loaded by a Query:
371
         * @see Query#setReadOnly(boolean)
372
         * @param readOnly true, the default for loaded entities/proxies is read-only; false, the
373
         *            default for loaded entities/proxies is modifiable
374
         */
375
        public void setDefaultReadOnly(boolean readOnly) {
376
                getSession().setDefaultReadOnly(readOnly);
×
377
        }
×
378
        
379
        /**
380
         * Return the identifier value of the given entity as associated with this session. An exception
381
         * is thrown if the given entity instance is transient or detached in relation to this session.
382
         *
383
         * @param object a persistent instance
384
         * @return the identifier
385
         * @throws TransientObjectException if the instance is transient or associated with a different
386
         *             session
387
         */
388
        public Serializable getIdentifier(Object object) {
389
                return getSession().getIdentifier(object);
×
390
        }
391
        
392
        /**
393
         * Check if this instance is associated with this <tt>Session</tt>.
394
         *
395
         * @param object an instance of a persistent class
396
         * @return true if the given instance is associated with this <tt>Session</tt>
397
         */
398
        public boolean contains(Object object) {
399
                return getSession().contains(object);
×
400
        }
401
        
402
        /**
403
         * Remove this instance from the session cache. Changes to the instance will not be synchronized
404
         * with the database. This operation cascades to associated instances if the association is
405
         * mapped with <tt>cascade="evict"</tt>.
406
         *
407
         * @param object The entity to evict
408
         * @throws NullPointerException if the passed object is {@code null}
409
         * @throws IllegalArgumentException if the passed object is not defined as an entity
410
         */
411
        public void evict(Object object) {
412
                getSession().evict(object);
×
413
        }
×
414
        
415
        /**
416
         * Return the persistent instance of the given entity class with the given identifier, obtaining
417
         * the specified lock mode, assuming the instance exists.
418
         *
419
         * @param theClass a persistent class
420
         * @param id a valid identifier of an existing persistent instance of the class
421
         * @param lockOptions contains the lock level
422
         * @return the persistent instance or proxy
423
         */
424
        public Object load(Class theClass, Serializable id, LockOptions lockOptions) {
425
                return getSession().load(theClass, id, lockOptions);
×
426
        }
427
        
428
        /**
429
         * Return the persistent instance of the given entity class with the given identifier, obtaining
430
         * the specified lock mode, assuming the instance exists.
431
         *
432
         * @param entityName a persistent class
433
         * @param id a valid identifier of an existing persistent instance of the class
434
         * @param lockOptions contains the lock level
435
         * @return the persistent instance or proxy
436
         */
437
        public Object load(String entityName, Serializable id, LockOptions lockOptions) {
438
                return getSession().load(entityName, id, lockOptions);
×
439
        }
440
        
441
        /**
442
         * Return the persistent instance of the given entity class with the given identifier, assuming
443
         * that the instance exists. This method might return a proxied instance that is initialized
444
         * on-demand, when a non-identifier method is accessed. <br>
445
         * <br>
446
         * You should not use this method to determine if an instance exists (use <tt>get()</tt>
447
         * instead). Use this only to retrieve an instance that you assume exists, where non-existence
448
         * would be an actual error.
449
         *
450
         * @param theClass a persistent class
451
         * @param id a valid identifier of an existing persistent instance of the class
452
         * @return the persistent instance or proxy
453
         */
454
        public Object load(Class theClass, Serializable id) {
455
                return getSession().load(theClass, id);
×
456
        }
457
        
458
        /**
459
         * Return the persistent instance of the given entity class with the given identifier, assuming
460
         * that the instance exists. This method might return a proxied instance that is initialized
461
         * on-demand, when a non-identifier method is accessed. <br>
462
         * <br>
463
         * You should not use this method to determine if an instance exists (use <tt>get()</tt>
464
         * instead). Use this only to retrieve an instance that you assume exists, where non-existence
465
         * would be an actual error.
466
         *
467
         * @param entityName a persistent class
468
         * @param id a valid identifier of an existing persistent instance of the class
469
         * @return the persistent instance or proxy
470
         */
471
        public Object load(String entityName, Serializable id) {
472
                return getSession().load(entityName, id);
×
473
        }
474
        
475
        /**
476
         * Read the persistent state associated with the given identifier into the given transient
477
         * instance.
478
         *
479
         * @param object an "empty" instance of the persistent class
480
         * @param id a valid identifier of an existing persistent instance of the class
481
         */
482
        public void load(Object object, Serializable id) {
483
                getSession().load(object, id);
×
484
        }
×
485
        
486
        /**
487
         * Persist the state of the given detached instance, reusing the current identifier value. This
488
         * operation cascades to associated instances if the association is mapped with
489
         * {@code cascade="replicate"}
490
         *
491
         * @param object a detached instance of a persistent class
492
         * @param replicationMode The replication mode to use
493
         */
494
        public void replicate(Object object, ReplicationMode replicationMode) {
495
                getSession().replicate(object, replicationMode);
×
496
        }
×
497
        
498
        /**
499
         * Persist the state of the given detached instance, reusing the current identifier value. This
500
         * operation cascades to associated instances if the association is mapped with
501
         * {@code cascade="replicate"}
502
         *
503
         * @param entityName The entity name
504
         * @param object a detached instance of a persistent class
505
         * @param replicationMode The replication mode to use
506
         */
507
        public void replicate(String entityName, Object object, ReplicationMode replicationMode) {
508
                getSession().replicate(entityName, object, replicationMode);
×
509
        }
×
510
        
511
        /**
512
         * Persist the given transient instance, first assigning a generated identifier. (Or using the
513
         * current value of the identifier property if the <tt>assigned</tt> generator is used.) This
514
         * operation cascades to associated instances if the association is mapped with
515
         * {@code cascade="save-update"}
516
         *
517
         * @param object a transient instance of a persistent class
518
         * @return the generated identifier
519
         */
520
        public Serializable save(Object object) {
521
                return getSession().save(object);
×
522
        }
523
        
524
        /**
525
         * Persist the given transient instance, first assigning a generated identifier. (Or using the
526
         * current value of the identifier property if the <tt>assigned</tt> generator is used.) This
527
         * operation cascades to associated instances if the association is mapped with
528
         * {@code cascade="save-update"}
529
         *
530
         * @param entityName The entity name
531
         * @param object a transient instance of a persistent class
532
         * @return the generated identifier
533
         */
534
        public Serializable save(String entityName, Object object) {
535
                return getSession().save(entityName, object);
×
536
        }
537
        
538
        /**
539
         * Either {@link #save(Object)} or {@link #update(Object)} the given instance, depending upon
540
         * resolution of the unsaved-value checks (see the manual for discussion of unsaved-value
541
         * checking).
542
         * <p>
543
         * This operation cascades to associated instances if the association is mapped with
544
         * {@code cascade="save-update"}
545
         *
546
         * @param object a transient or detached instance containing new or updated state
547
         * @see Session#save(java.lang.Object)
548
         * @see Session#update(Object object)
549
         */
550
        public void saveOrUpdate(Object object) {
551
                getSession().saveOrUpdate(object);
×
552
        }
×
553
        
554
        /**
555
         * Either {@link #save(String, Object)} or {@link #update(String, Object)} the given instance,
556
         * depending upon resolution of the unsaved-value checks (see the manual for discussion of
557
         * unsaved-value checking).
558
         * <p>
559
         * This operation cascades to associated instances if the association is mapped with
560
         * {@code cascade="save-update"}
561
         *
562
         * @param entityName The entity name
563
         * @param object a transient or detached instance containing new or updated state
564
         * @see Session#save(String,Object)
565
         * @see Session#update(String,Object)
566
         */
567
        public void saveOrUpdate(String entityName, Object object) {
568
                getSession().saveOrUpdate(entityName, object);
×
569
        }
×
570
        
571
        /**
572
         * Update the persistent instance with the identifier of the given detached instance. If there
573
         * is a persistent instance with the same identifier, an exception is thrown. This operation
574
         * cascades to associated instances if the association is mapped with
575
         * {@code cascade="save-update"}
576
         *
577
         * @param object a detached instance containing updated state
578
         */
579
        public void update(Object object) {
580
                getSession().update(object);
×
581
        }
×
582
        
583
        /**
584
         * Update the persistent instance with the identifier of the given detached instance. If there
585
         * is a persistent instance with the same identifier, an exception is thrown. This operation
586
         * cascades to associated instances if the association is mapped with
587
         * {@code cascade="save-update"}
588
         *
589
         * @param entityName The entity name
590
         * @param object a detached instance containing updated state
591
         */
592
        public void update(String entityName, Object object) {
593
                getSession().update(entityName, object);
×
594
        }
×
595
        
596
        /**
597
         * Copy the state of the given object onto the persistent object with the same identifier. If
598
         * there is no persistent instance currently associated with the session, it will be loaded.
599
         * Return the persistent instance. If the given instance is unsaved, save a copy of and return
600
         * it as a newly persistent instance. The given instance does not become associated with the
601
         * session. This operation cascades to associated instances if the association is mapped with
602
         * {@code cascade="merge"}
603
         * <p>
604
         * The semantics of this method are defined by JSR-220.
605
         *
606
         * @param object a detached instance with state to be copied
607
         * @return an updated persistent instance
608
         */
609
        public Object merge(Object object) {
610
                return getSession().merge(object);
×
611
        }
612
        
613
        /**
614
         * Copy the state of the given object onto the persistent object with the same identifier. If
615
         * there is no persistent instance currently associated with the session, it will be loaded.
616
         * Return the persistent instance. If the given instance is unsaved, save a copy of and return
617
         * it as a newly persistent instance. The given instance does not become associated with the
618
         * session. This operation cascades to associated instances if the association is mapped with
619
         * {@code cascade="merge"}
620
         * <p>
621
         * The semantics of this method are defined by JSR-220.
622
         *
623
         * @param entityName The entity name
624
         * @param object a detached instance with state to be copied
625
         * @return an updated persistent instance
626
         */
627
        public Object merge(String entityName, Object object) {
628
                return getSession().merge(entityName, object);
×
629
        }
630
        
631
        /**
632
         * Make a transient instance persistent. This operation cascades to associated instances if the
633
         * association is mapped with {@code cascade="persist"}
634
         * <p>
635
         * The semantics of this method are defined by JSR-220.
636
         *
637
         * @param object a transient instance to be made persistent
638
         */
639
        public void persist(Object object) {
640
                getSession().persist(object);
×
641
        }
×
642
        
643
        /**
644
         * Make a transient instance persistent. This operation cascades to associated instances if the
645
         * association is mapped with {@code cascade="persist"}
646
         * <p>
647
         * The semantics of this method are defined by JSR-220.
648
         *
649
         * @param entityName The entity name
650
         * @param object a transient instance to be made persistent
651
         */
652
        public void persist(String entityName, Object object) {
653
                getSession().persist(entityName, object);
×
654
        }
×
655
        
656
        /**
657
         * Remove a persistent instance from the datastore. The argument may be an instance associated
658
         * with the receiving <tt>Session</tt> or a transient instance with an identifier associated
659
         * with existing persistent state. This operation cascades to associated instances if the
660
         * association is mapped with {@code cascade="delete"}
661
         *
662
         * @param object the instance to be removed
663
         */
664
        public void delete(Object object) {
665
                getSession().delete(object);
×
666
        }
×
667
        
668
        /**
669
         * Remove a persistent instance from the datastore. The <b>object</b> argument may be an
670
         * instance associated with the receiving <tt>Session</tt> or a transient instance with an
671
         * identifier associated with existing persistent state. This operation cascades to associated
672
         * instances if the association is mapped with {@code cascade="delete"}
673
         *
674
         * @param entityName The entity name for the instance to be removed.
675
         * @param object the instance to be removed
676
         */
677
        public void delete(String entityName, Object object) {
678
                getSession().delete(entityName, object);
×
679
        }
×
680
        
681
        /**
682
         * Build a LockRequest that specifies the LockMode, pessimistic lock timeout and lock scope.
683
         * timeout and scope is ignored for optimistic locking. After building the LockRequest, call
684
         * LockRequest.lock to perform the requested locking.
685
         * <p>
686
         * Example usage:
687
         * {@code session.buildLockRequest().setLockMode(LockMode.PESSIMISTIC_WRITE).setTimeOut(60000).lock(entity);}
688
         *
689
         * @param lockOptions contains the lock level
690
         * @return a lockRequest that can be used to lock the passed object.
691
         */
692
        public LockRequest buildLockRequest(LockOptions lockOptions) {
693
                return getSession().buildLockRequest(lockOptions);
×
694
        }
695
        
696
        /**
697
         * Re-read the state of the given instance from the underlying database. It is inadvisable to
698
         * use this to implement long-running sessions that span many business tasks. This method is,
699
         * however, useful in certain special circumstances. For example
700
         * <ul>
701
         * <li>where a database trigger alters the object state upon insert or update
702
         * <li>after executing direct SQL (eg. a mass update) in the same session
703
         * <li>after inserting a <tt>Blob</tt> or <tt>Clob</tt>
704
         * </ul>
705
         *
706
         * @param object a persistent or detached instance
707
         */
708
        public void refresh(Object object) {
709
                getSession().refresh(object);
×
710
        }
×
711
        
712
        /**
713
         * Re-read the state of the given instance from the underlying database. It is inadvisable to
714
         * use this to implement long-running sessions that span many business tasks. This method is,
715
         * however, useful in certain special circumstances. For example
716
         * <ul>
717
         * <li>where a database trigger alters the object state upon insert or update
718
         * <li>after executing direct SQL (eg. a mass update) in the same session
719
         * <li>after inserting a <tt>Blob</tt> or <tt>Clob</tt>
720
         * </ul>
721
         *
722
         * @param entityName a persistent class
723
         * @param object a persistent or detached instance
724
         */
725
        public void refresh(String entityName, Object object) {
726
                getSession().refresh(entityName, object);
×
727
        }
×
728
        
729
        /**
730
         * Re-read the state of the given instance from the underlying database, with the given
731
         * <tt>LockMode</tt>. It is inadvisable to use this to implement long-running sessions that span
732
         * many business tasks. This method is, however, useful in certain special circumstances.
733
         *
734
         * @param object a persistent or detached instance
735
         * @param lockOptions contains the lock mode to use
736
         */
737
        public void refresh(Object object, LockOptions lockOptions) {
738
                getSession().refresh(object, lockOptions);
×
739
        }
×
740
        
741
        /**
742
         * Re-read the state of the given instance from the underlying database, with the given
743
         * <tt>LockMode</tt>. It is inadvisable to use this to implement long-running sessions that span
744
         * many business tasks. This method is, however, useful in certain special circumstances.
745
         *
746
         * @param entityName a persistent class
747
         * @param object a persistent or detached instance
748
         * @param lockOptions contains the lock mode to use
749
         */
750
        public void refresh(String entityName, Object object, LockOptions lockOptions) {
751
                getSession().refresh(entityName, object, lockOptions);
×
752
        }
×
753
        
754
        /**
755
         * Determine the current lock mode of the given object.
756
         *
757
         * @param object a persistent instance
758
         * @return the current lock mode
759
         */
760
        public LockMode getCurrentLockMode(Object object) {
761
                return getSession().getCurrentLockMode(object);
×
762
        }
763
        
764
        /**
765
         * Create a {@link Query} instance for the given collection and filter string. Contains an
766
         * implicit {@code FROM} element named {@code this} which refers to the defined table for the
767
         * collection elements, as well as an implicit {@code WHERE} restriction for this particular
768
         * collection instance's key value.
769
         *
770
         * @param collection a persistent collection
771
         * @param queryString a Hibernate query fragment.
772
         * @return The query instance for manipulation and execution
773
         */
774
        public Query createFilter(Object collection, String queryString) {
775
                return getSession().createFilter(collection, queryString);
×
776
        }
777
        
778
        /**
779
         * Completely clear the session. Evict all loaded instances and cancel all pending saves,
780
         * updates and deletions. Do not close open iterators or instances of <tt>ScrollableResults</tt>
781
         * .
782
         */
783
        public void clear() {
784
                getSession().clear();
×
785
        }
×
786
        
787
        /**
788
         * Return the persistent instance of the given entity class with the given identifier, or null
789
         * if there is no such persistent instance. (If the instance is already associated with the
790
         * session, return that instance. This method never returns an uninitialized instance.)
791
         *
792
         * @param clazz a persistent class
793
         * @param id an identifier
794
         * @return a persistent instance or null
795
         */
796
        public Object get(Class clazz, Serializable id) {
797
                return getSession().get(clazz, id);
×
798
        }
799
        
800
        /**
801
         * Return the persistent instance of the given entity class with the given identifier, or null
802
         * if there is no such persistent instance. (If the instance is already associated with the
803
         * session, return that instance. This method never returns an uninitialized instance.) Obtain
804
         * the specified lock mode if the instance exists.
805
         *
806
         * @param clazz a persistent class
807
         * @param id an identifier
808
         * @param lockOptions the lock mode
809
         * @return a persistent instance or null
810
         */
811
        public Object get(Class clazz, Serializable id, LockOptions lockOptions) {
812
                return getSession().get(clazz, id, lockOptions);
×
813
        }
814
        
815
        /**
816
         * Return the persistent instance of the given named entity with the given identifier, or null
817
         * if there is no such persistent instance. (If the instance is already associated with the
818
         * session, return that instance. This method never returns an uninitialized instance.)
819
         *
820
         * @param entityName the entity name
821
         * @param id an identifier
822
         * @return a persistent instance or null
823
         */
824
        public Object get(String entityName, Serializable id) {
825
                return getSession().get(entityName, id);
×
826
        }
827
        
828
        /**
829
         * Return the persistent instance of the given entity class with the given identifier, or null
830
         * if there is no such persistent instance. (If the instance is already associated with the
831
         * session, return that instance. This method never returns an uninitialized instance.) Obtain
832
         * the specified lock mode if the instance exists.
833
         *
834
         * @param entityName the entity name
835
         * @param id an identifier
836
         * @param lockOptions contains the lock mode
837
         * @return a persistent instance or null
838
         */
839
        public Object get(String entityName, Serializable id, LockOptions lockOptions) {
840
                return getSession().get(entityName, id, lockOptions);
×
841
        }
842
        
843
        /**
844
         * Return the entity name for a persistent entity.
845
         * 
846
         * @param object a persistent entity
847
         * @return the entity name
848
         */
849
        public String getEntityName(Object object) {
850
                return getSession().getEntityName(object);
×
851
        }
852
        
853
        /**
854
         * Create an {@link IdentifierLoadAccess} instance to retrieve the specified entity type by
855
         * primary key.
856
         * 
857
         * @param entityName The entity name of the entity type to be retrieved
858
         * @return load delegate for loading the specified entity type by primary key
859
         * @throws HibernateException If the specified entity name cannot be resolved as an entity name
860
         */
861
        public IdentifierLoadAccess byId(String entityName) {
862
                return getSession().byId(entityName);
×
863
        }
864
        
865
        /**
866
         * Create an {@link IdentifierLoadAccess} instance to retrieve the specified entity by primary
867
         * key.
868
         *
869
         * @param entityClass The entity type to be retrieved
870
         * @return load delegate for loading the specified entity type by primary key
871
         * @throws HibernateException If the specified Class cannot be resolved as a mapped entity
872
         */
873
        public IdentifierLoadAccess byId(Class entityClass) {
874
                return getSession().byId(entityClass);
×
875
        }
876
        
877
        /**
878
         * Create an {@link NaturalIdLoadAccess} instance to retrieve the specified entity by its
879
         * natural id.
880
         * 
881
         * @param entityName The entity name of the entity type to be retrieved
882
         * @return load delegate for loading the specified entity type by natural id
883
         * @throws HibernateException If the specified entity name cannot be resolved as an entity name
884
         */
885
        public NaturalIdLoadAccess byNaturalId(String entityName) {
886
                return getSession().byNaturalId(entityName);
×
887
        }
888
        
889
        /**
890
         * Create an {@link NaturalIdLoadAccess} instance to retrieve the specified entity by its
891
         * natural id.
892
         * 
893
         * @param entityClass The entity type to be retrieved
894
         * @return load delegate for loading the specified entity type by natural id
895
         * @throws HibernateException If the specified Class cannot be resolved as a mapped entity
896
         */
897
        public NaturalIdLoadAccess byNaturalId(Class entityClass) {
898
                return getSession().byNaturalId(entityClass);
×
899
        }
900
        
901
        /**
902
         * Create an {@link SimpleNaturalIdLoadAccess} instance to retrieve the specified entity by its
903
         * natural id.
904
         *
905
         * @param entityName The entity name of the entity type to be retrieved
906
         * @return load delegate for loading the specified entity type by natural id
907
         * @throws HibernateException If the specified entityClass cannot be resolved as a mapped
908
         *             entity, or if the entity does not define a natural-id or if its natural-id is
909
         *             made up of multiple attributes.
910
         */
911
        public SimpleNaturalIdLoadAccess bySimpleNaturalId(String entityName) {
912
                return getSession().bySimpleNaturalId(entityName);
×
913
        }
914
        
915
        /**
916
         * Create an {@link SimpleNaturalIdLoadAccess} instance to retrieve the specified entity by its
917
         * simple (single attribute) natural id.
918
         *
919
         * @param entityClass The entity type to be retrieved
920
         * @return load delegate for loading the specified entity type by natural id
921
         * @throws HibernateException If the specified entityClass cannot be resolved as a mapped
922
         *             entity, or if the entity does not define a natural-id or if its natural-id is
923
         *             made up of multiple attributes.
924
         */
925
        public SimpleNaturalIdLoadAccess bySimpleNaturalId(Class entityClass) {
926
                return getSession().bySimpleNaturalId(entityClass);
×
927
        }
928
        
929
        /**
930
         * Enable the named filter for this current session.
931
         *
932
         * @param filterName The name of the filter to be enabled.
933
         * @return The Filter instance representing the enabled filter.
934
         */
935
        public Filter enableFilter(String filterName) {
936
                return getSession().enableFilter(filterName);
×
937
        }
938
        
939
        /**
940
         * Retrieve a currently enabled filter by name.
941
         *
942
         * @param filterName The name of the filter to be retrieved.
943
         * @return The Filter instance representing the enabled filter.
944
         */
945
        public Filter getEnabledFilter(String filterName) {
946
                return getSession().getEnabledFilter(filterName);
×
947
        }
948
        
949
        /**
950
         * Disable the named filter for the current session.
951
         *
952
         * @param filterName The name of the filter to be disabled.
953
         */
954
        public void disableFilter(String filterName) {
955
                getSession().disableFilter(filterName);
×
956
        }
×
957
        
958
        /**
959
         * Get the statistics for this session.
960
         *
961
         * @return The session statistics being collected for this session
962
         */
963
        public SessionStatistics getStatistics() {
964
                return getSession().getStatistics();
×
965
        }
966
        
967
        /**
968
         * Is the specified entity or proxy read-only? To get the default read-only/modifiable setting
969
         * used for entities and proxies that are loaded into the session:
970
         * 
971
         * @see org.hibernate.Session#isDefaultReadOnly()
972
         * @param entityOrProxy an entity or HibernateProxy
973
         * @return {@code true} if the entity or proxy is read-only, {@code false} if the entity or
974
         *         proxy is modifiable.
975
         */
976
        public boolean isReadOnly(Object entityOrProxy) {
977
                return getSession().isReadOnly(entityOrProxy);
×
978
        }
979
        
980
        /**
981
         * Set an unmodified persistent object to read-only mode, or a read-only object to modifiable
982
         * mode. In read-only mode, no snapshot is maintained, the instance is never dirty checked, and
983
         * changes are not persisted. If the entity or proxy already has the specified
984
         * read-only/modifiable setting, then this method does nothing. To set the default
985
         * read-only/modifiable setting used for entities and proxies that are loaded into the session:
986
         * 
987
         * @see org.hibernate.Session#setDefaultReadOnly(boolean) To override this session's
988
         *      read-only/modifiable setting for entities and proxies loaded by a Query:
989
         * @see Query#setReadOnly(boolean)
990
         * @param entityOrProxy an entity or HibernateProxy
991
         * @param readOnly {@code true} if the entity or proxy should be made read-only; {@code false}
992
         *            if the entity or proxy should be made modifiable
993
         */
994
        public void setReadOnly(Object entityOrProxy, boolean readOnly) {
995
                getSession().setReadOnly(entityOrProxy, readOnly);
×
996
        }
×
997
        
998
        /**
999
         * Controller for allowing users to perform JDBC related work using the Connection managed by
1000
         * this Session.
1001
         *
1002
         * @param work The work to be performed.
1003
         * @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException}
1004
         */
1005
        public void doWork(Work work) throws HibernateException {
1006
                getSession().doWork(work);
×
1007
        }
×
1008
        
1009
        /**
1010
         * Controller for allowing users to perform JDBC related work using the Connection managed by
1011
         * this Session. After execution returns the result of the {@link ReturningWork#execute} call.
1012
         *
1013
         * @param work The work to be performed.
1014
         * @param <T> The type of the result returned from the work
1015
         * @return the result from calling {@link ReturningWork#execute}.
1016
         * @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException}
1017
         */
1018
        public <T> T doReturningWork(ReturningWork<T> work) throws HibernateException {
1019
                return getSession().doReturningWork(work);
×
1020
        }
1021
        
1022
        /**
1023
         * Disconnect the session from its underlying JDBC connection. This is intended for use in cases
1024
         * where the application has supplied the JDBC connection to the session and which require
1025
         * long-sessions (aka, conversations).
1026
         * <p>
1027
         * It is considered an error to call this method on a session which was not opened by supplying
1028
         * the JDBC connection and an exception will be thrown.
1029
         * <p>
1030
         * For non-user-supplied scenarios, normal transaction management already handles disconnection
1031
         * and reconnection automatically.
1032
         *
1033
         * @return the application-supplied connection or {@code null}
1034
         * @see #reconnect(Connection)
1035
         */
1036
        Connection disconnect() {
1037
                return getSession().disconnect();
×
1038
        }
1039
        
1040
        /**
1041
         * Reconnect to the given JDBC connection.
1042
         *
1043
         * @param connection a JDBC connection
1044
         * @see #disconnect()
1045
         */
1046
        void reconnect(Connection connection) {
1047
                getSession().reconnect(connection);
×
1048
        }
×
1049
        
1050
        /**
1051
         * Is a particular fetch profile enabled on this session?
1052
         *
1053
         * @param name The name of the profile to be checked.
1054
         * @return True if fetch profile is enabled; false if not.
1055
         * @throws UnknownProfileException Indicates that the given name does not match any known
1056
         *             profile names
1057
         * @see org.hibernate.engine.profile.FetchProfile for discussion of this feature
1058
         */
1059
        public boolean isFetchProfileEnabled(String name) throws UnknownProfileException {
1060
                return getSession().isFetchProfileEnabled(name);
×
1061
        }
1062
        
1063
        /**
1064
         * Enable a particular fetch profile on this session. No-op if requested profile is already
1065
         * enabled.
1066
         *
1067
         * @param name The name of the fetch profile to be enabled.
1068
         * @throws UnknownProfileException Indicates that the given name does not match any known
1069
         *             profile names
1070
         * @see org.hibernate.engine.profile.FetchProfile for discussion of this feature
1071
         */
1072
        public void enableFetchProfile(String name) throws UnknownProfileException {
1073
                getSession().enableFetchProfile(name);
×
1074
        }
×
1075
        
1076
        /**
1077
         * Disable a particular fetch profile on this session. No-op if requested profile is already
1078
         * disabled.
1079
         *
1080
         * @param name The name of the fetch profile to be disabled.
1081
         * @throws UnknownProfileException Indicates that the given name does not match any known
1082
         *             profile names
1083
         * @see org.hibernate.engine.profile.FetchProfile for discussion of this feature
1084
         */
1085
        public void disableFetchProfile(String name) throws UnknownProfileException {
1086
                getSession().disableFetchProfile(name);
×
1087
        }
×
1088
        
1089
        /**
1090
         * Convenience access to the {@link TypeHelper} associated with this session's
1091
         * {@link SessionFactory}.
1092
         * <p>
1093
         * Equivalent to calling {@link #getSessionFactory()}.{@link SessionFactory#getTypeHelper
1094
         * getTypeHelper()}
1095
         *
1096
         * @return The {@link TypeHelper} associated with this session's {@link SessionFactory}
1097
         */
1098
        public TypeHelper getTypeHelper() {
1099
                return getSession().getTypeHelper();
×
1100
        }
1101
        
1102
        /**
1103
         * Retrieve this session's helper/delegate for creating LOB instances.
1104
         *
1105
         * @return This session's LOB helper
1106
         */
1107
        public LobHelper getLobHelper() {
1108
                return getSession().getLobHelper();
×
1109
        }
1110
        
1111
        /**
1112
         * Add one or more listeners to the Session
1113
         *
1114
         * @param listeners The listener(s) to add
1115
         */
1116
        public void addEventListeners(SessionEventListener... listeners) {
1117
                getSession().addEventListeners(listeners);
×
1118
        }
×
1119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc