Here are the examples of the java api org.hibernate.SessionFactory.openStatelessSession() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
12 Examples
19
Source : AbstractObjectDao.java
with Mozilla Public License 2.0
from secdec
with Mozilla Public License 2.0
from secdec
public void insert(T object) {
sessionFactory.openStatelessSession().insert(object);
}
19
Source : DefaultStreamerTest.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
@Test
public void testUnsuccessfulExecutionWithSessionNull() {
when(factory.openStatelessSession()).thenThrow(RuntimeException.clreplaced);
DefaultStreamer<Person> defaultStreamer = DefaultStreamer.<Person>builder().query(QUERY).type(Person.clreplaced).sessionFactory(factory).fetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE).build();
Flux<Person> flux = Flux.create(defaultStreamer::stream);
StepVerifier.create(flux).expectError(RuntimeException.clreplaced).verify();
}
19
Source : DefaultStreamerTest.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
@Test
public void testUnsuccessfulExecutionWithScrollNull() {
when(factory.openStatelessSession()).thenReturn(session);
when(session.createQuery(QUERY, Person.clreplaced)).thenThrow(RuntimeException.clreplaced);
DefaultStreamer<Person> defaultStreamer = DefaultStreamer.<Person>builder().query(QUERY).type(Person.clreplaced).sessionFactory(factory).fetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE).build();
Flux<Person> flux = Flux.create(defaultStreamer::stream);
StepVerifier.create(flux).expectError(RuntimeException.clreplaced).verify();
}
19
Source : DefaultStreamer.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
private StatelessSession openSession() {
return sessionFactory.openStatelessSession();
}
18
Source : HibernateChannelVulnerabilityDao.java
with Mozilla Public License 2.0
from secdec
with Mozilla Public License 2.0
from secdec
@Override
public void saveOrUpdateStateless(ChannelVulnerability channelVulnerability) {
StatelessSession statelessSession = sessionFactory.openStatelessSession();
statelessSession.insert(channelVulnerability);
statelessSession.close();
}
18
Source : DefaultStreamerTest.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
@Test
public void testUnsuccessfulExecution() {
when(factory.openStatelessSession()).thenReturn(session);
when(session.createQuery(QUERY, Person.clreplaced)).thenReturn(query);
when(query.setFetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE)).thenReturn(query);
when(query.setReadOnly(true)).thenReturn(query);
when(query.scroll(ScrollMode.FORWARD_ONLY)).thenReturn(results);
when(results.next()).thenThrow(new RuntimeException());
DefaultStreamer<Person> defaultStreamer = DefaultStreamer.<Person>builder().query(QUERY).type(Person.clreplaced).sessionFactory(factory).fetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE).build();
Flux<Person> flux = Flux.create(defaultStreamer::stream);
StepVerifier.create(flux).expectError(RuntimeException.clreplaced).verify();
}
18
Source : DefaultStreamerTest.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
@Test
public void testUnsuccessfulTransactionalExecution() throws SQLException {
when(factory.openStatelessSession()).thenReturn(session);
when(session.createQuery(QUERY, Person.clreplaced)).thenReturn(query);
when(query.setFetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE)).thenReturn(query);
when(query.setReadOnly(true)).thenReturn(query);
when(query.scroll(ScrollMode.FORWARD_ONLY)).thenReturn(results);
when(results.next()).thenThrow(new RuntimeException());
when(session.getTransaction()).thenReturn(transaction);
when(session.connection()).thenReturn(connection);
when(transaction.isActive()).thenReturn(true);
when(connection.getTransactionIsolation()).thenReturn(Connection.TRANSACTION_NONE);
doThrow(PersistenceException.clreplaced).when(transaction).rollback();
DefaultStreamer<Person> defaultStreamer = DefaultStreamer.<Person>builder().query(QUERY).type(Person.clreplaced).sessionFactory(factory).isolationLevel(IsolationLevel.READ_COMMITTED).fetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE).build();
Flux<Person> flux = Flux.create(defaultStreamer::stream);
StepVerifier.create(flux).expectError(RuntimeException.clreplaced).verify();
Mockito.reset(transaction);
when(transaction.isActive()).thenReturn(true);
flux = Flux.create(defaultStreamer::stream);
StepVerifier.create(flux).verifyError(RuntimeException.clreplaced);
}
18
Source : DefaultStreamerTest.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
private void setupTransactionMocks(IsolationLevel level) throws SQLException {
when(factory.openStatelessSession()).thenReturn(session);
when(session.createQuery(QUERY, Person.clreplaced)).thenReturn(query);
when(query.setFetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE)).thenReturn(query);
when(query.setReadOnly(true)).thenReturn(query);
when(query.scroll(ScrollMode.FORWARD_ONLY)).thenReturn(results);
when(results.next()).thenReturn(true).thenReturn(false);
when(results.get(0)).thenReturn(PERSON);
if (level != null) {
when(session.getTransaction()).thenReturn(transaction);
when(session.connection()).thenReturn(connection);
if (level != IsolationLevel.DEFAULT) {
when(connection.getTransactionIsolation()).thenReturn(Connection.TRANSACTION_NONE);
}
}
}
17
Source : HibernateChannelSeverityDao.java
with Mozilla Public License 2.0
from secdec
with Mozilla Public License 2.0
from secdec
@Override
public void insert(List<ChannelSeverity> channelSeverities) {
StatelessSession statelessSession = sessionFactory.openStatelessSession();
try {
for (ChannelSeverity channelSeverity : channelSeverities) {
statelessSession.insert(channelSeverity);
}
} finally {
statelessSession.close();
}
}
17
Source : DatabaseTest.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
private void setupStreamTransactionMocks(IsolationLevel level) throws SQLException {
when(sessionFactory.openStatelessSession()).thenReturn(statelessSession);
when(statelessSession.createQuery(DefaultStreamerTest.QUERY, Person.clreplaced)).thenReturn(query);
when(query.setFetchSize(DefaultStreamer.DEFAULT_FETCH_SIZE)).thenReturn(query);
when(query.setReadOnly(true)).thenReturn(query);
when(query.scroll(ScrollMode.FORWARD_ONLY)).thenReturn(results);
when(results.next()).thenReturn(true).thenReturn(false);
when(results.get(0)).thenReturn(DefaultStreamerTest.PERSON);
if (level != null) {
when(statelessSession.getTransaction()).thenReturn(transaction);
when(statelessSession.connection()).thenReturn(connection);
if (level != IsolationLevel.DEFAULT) {
when(connection.getTransactionIsolation()).thenReturn(Connection.TRANSACTION_NONE);
}
}
}
17
Source : PeriodServiceTest.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
private void removeTestPeriod(String period) {
StatelessSession session = sessionFactory.openStatelessSession();
session.beginTransaction();
try {
session.delete(periodService.getPeriod(period));
session.getTransaction().commit();
} catch (Exception ex) {
session.getTransaction().rollback();
} finally {
session.close();
}
}
10
Source : PeriodTypePopulator.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
// -------------------------------------------------------------------------
// Execute
// -------------------------------------------------------------------------
@Override
public void executeInTransaction() {
List<PeriodType> types = PeriodType.getAvailablePeriodTypes();
Collection<PeriodType> storedTypes = periodStore.getAllPeriodTypes();
types.removeAll(storedTypes);
// ---------------------------------------------------------------------
// Populate missing
// ---------------------------------------------------------------------
StatelessSession session = sessionFactory.openStatelessSession();
session.beginTransaction();
try {
types.forEach(type -> {
session.insert(type);
log.debug("Added PeriodType: " + type.getName());
});
} catch (Exception exception) {
exception.printStackTrace();
} finally {
DbmsUtils.closeStatelessSession(session);
}
types.forEach(type -> periodStore.reloadPeriodType(type));
}