use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SingleRegisteredProviderTest method testCachingImplicitlyEnabledNoRegistered.
@Test
public void testCachingImplicitlyEnabledNoRegistered() {
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final Collection<Class<? extends RegionFactory>> implementors = bsr.getService(StrategySelector.class).getRegisteredStrategyImplementors(RegionFactory.class);
assertThat(implementors.size(), equalTo(1));
bsr.getService(StrategySelector.class).unRegisterStrategyImplementor(RegionFactory.class, implementors.iterator().next());
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.USE_SECOND_LEVEL_CACHE, "").build();
assertThat(ssr.getService(RegionFactory.class), instanceOf(NoCachingRegionFactory.class));
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SingleRegisteredProviderTest method testCachingImplicitlyEnabledRegistered.
@Test
public void testCachingImplicitlyEnabledRegistered() {
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final Collection<Class<? extends RegionFactory>> implementors = bsr.getService(StrategySelector.class).getRegisteredStrategyImplementors(RegionFactory.class);
assertThat(implementors.size(), equalTo(1));
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.USE_SECOND_LEVEL_CACHE, "").build();
assertThat(ssr.getService(RegionFactory.class), instanceOf(NoCachingRegionFactory.class));
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SingleRegisteredProviderTest method testCachingExplicitlyDisabled.
@Test
public void testCachingExplicitlyDisabled() {
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.USE_SECOND_LEVEL_CACHE, "false").build();
assertThat(registry.getService(RegionFactory.class), instanceOf(NoCachingRegionFactory.class));
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class BasicCdiTest method testIt.
@Test
@SuppressWarnings("unchecked")
public void testIt() {
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(Monitor.class, EventQueue.class, Event.class);
count = 0;
try (final SeContainer cdiContainer = cdiInitializer.initialize()) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).applySetting(AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager()).applySetting(AvailableSettings.DELAY_CDI_ACCESS, "true").applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build();
final SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata().getSessionFactoryBuilder().build();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(ssr);
throw e;
}
try {
inTransaction(sessionFactory, session -> session.persist(new MyEntity(1)));
assertEquals(1, count);
inTransaction(sessionFactory, session -> {
MyEntity it = session.find(MyEntity.class, 1);
assertNotNull(it);
});
} finally {
inTransaction(sessionFactory, session -> {
session.createQuery("delete MyEntity").executeUpdate();
});
sessionFactory.close();
}
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class TransactionsTest method jdbc.
@Test
public void jdbc() {
// tag::transactions-api-jdbc-example[]
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jdbc").build();
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).getMetadataBuilder().build();
SessionFactory sessionFactory = metadata.getSessionFactoryBuilder().build();
Session session = sessionFactory.openSession();
try {
// calls Connection#setAutoCommit( false ) to
// signal start of transaction
session.getTransaction().begin();
session.createQuery("UPDATE customer set NAME = 'Sir. '||NAME").executeUpdate();
// calls Connection#commit(), if an error
// happens we attempt a rollback
session.getTransaction().commit();
} catch (Exception e) {
// where the exception happened
if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE || session.getTransaction().getStatus() == TransactionStatus.MARKED_ROLLBACK) {
session.getTransaction().rollback();
}
// handle the underlying error
} finally {
session.close();
sessionFactory.close();
}
// end::transactions-api-jdbc-example[]
}
Aggregations