Skip to content

Commit df4ec92

Browse files
committed
refactor(db): ⚡ add stateless sessions (not used at the moment)
1 parent 180f09f commit df4ec92

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/main/java/net/netshot/netshot/database/Database.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
import org.hibernate.HibernateException;
9999
import org.hibernate.Session;
100100
import org.hibernate.SessionFactory;
101+
import org.hibernate.StatelessSession;
101102
import org.hibernate.boot.Metadata;
102103
import org.hibernate.boot.MetadataSources;
103104
import org.hibernate.boot.SessionFactoryBuilder;
@@ -416,14 +417,31 @@ public static Session getSession() throws HibernateException {
416417
}
417418

418419
/**
419-
* Gets the session.
420+
* Gets a database session.
420421
*
422+
* @param readOnly = true when requesting a read-only session
421423
* @return the session
422424
* @throws HibernateException the hibernate exception
423425
*/
424426
public static Session getSession(boolean readOnly) throws HibernateException {
425-
return sessionFactory.withOptions().tenantIdentifier(
426-
readOnly ? TenantIdentifier.READ_ONLY : TenantIdentifier.READ_WRITE).openSession();
427+
return sessionFactory
428+
.withOptions()
429+
.tenantIdentifier(
430+
readOnly ? TenantIdentifier.READ_ONLY : TenantIdentifier.READ_WRITE)
431+
.openSession();
432+
}
433+
434+
/**
435+
* Gets a stateless database session.
436+
*
437+
* @return the session
438+
* @throws HibernateException the hibernate exception
439+
*/
440+
public static StatelessSession getStalessSession() throws HibernateException {
441+
return sessionFactory
442+
.withStatelessOptions()
443+
.tenantIdentifier(TenantIdentifier.READ_ONLY)
444+
.openStatelessSession();
427445
}
428446

429447
/**

0 commit comments

Comments
 (0)