use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class DefaultMergeEventListener method createEntityCopyObserver.
private EntityCopyObserver createEntityCopyObserver(SessionFactoryImplementor sessionFactory) {
final ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
if (entityCopyObserverStrategy == null) {
final ConfigurationService configurationService = serviceRegistry.getService(ConfigurationService.class);
entityCopyObserverStrategy = configurationService.getSetting(AvailableSettings.MERGE_ENTITY_COPY_OBSERVER, new ConfigurationService.Converter<String>() {
@Override
public String convert(Object value) {
return value.toString();
}
}, EntityCopyNotAllowedObserver.SHORT_NAME);
LOG.debugf("EntityCopyObserver strategy: %s", entityCopyObserverStrategy);
}
final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
return strategySelector.resolveStrategy(EntityCopyObserver.class, entityCopyObserverStrategy);
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SchemaCreatorImpl method generateCreationCommands.
/**
* For testing...
*
* @param metadata The metadata for which to generate the creation commands.
*
* @return The generation commands
*/
public List<String> generateCreationCommands(Metadata metadata, final boolean manageNamespaces) {
final JournalingGenerationTarget target = new JournalingGenerationTarget();
final ServiceRegistry serviceRegistry = ((MetadataImplementor) metadata).getMetadataBuildingOptions().getServiceRegistry();
final Dialect dialect = serviceRegistry.getService(JdbcEnvironment.class).getDialect();
final ExecutionOptions options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return manageNamespaces;
}
@Override
public Map getConfigurationValues() {
return Collections.emptyMap();
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerHaltImpl.INSTANCE;
}
};
createFromMetadata(metadata, options, dialect, FormatStyle.NONE.getFormatter(), target);
return target.commands;
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SchemaDropperImpl method doDrop.
/**
* For tests
*/
public void doDrop(Metadata metadata, boolean manageNamespaces, GenerationTarget... targets) {
final ServiceRegistry serviceRegistry = ((MetadataImplementor) metadata).getMetadataBuildingOptions().getServiceRegistry();
doDrop(metadata, serviceRegistry, serviceRegistry.getService(ConfigurationService.class).getSettings(), manageNamespaces, targets);
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class JdbcCoordinatorTest method testConnectionClose.
@Test
public void testConnectionClose() throws NoSuchFieldException, IllegalAccessException, SQLException {
Connection connection = Mockito.mock(Connection.class);
JdbcSessionOwner sessionOwner = Mockito.mock(JdbcSessionOwner.class);
JdbcConnectionAccess jdbcConnectionAccess = Mockito.mock(JdbcConnectionAccess.class);
when(jdbcConnectionAccess.obtainConnection()).thenReturn(connection);
when(jdbcConnectionAccess.supportsAggressiveRelease()).thenReturn(false);
JdbcSessionContext sessionContext = Mockito.mock(JdbcSessionContext.class);
when(sessionOwner.getJdbcSessionContext()).thenReturn(sessionContext);
when(sessionOwner.getJdbcConnectionAccess()).thenReturn(jdbcConnectionAccess);
ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
when(sessionContext.getServiceRegistry()).thenReturn(serviceRegistry);
when(sessionContext.getPhysicalConnectionHandlingMode()).thenReturn(PhysicalConnectionHandlingMode.IMMEDIATE_ACQUISITION_AND_HOLD);
JdbcObserver jdbcObserver = Mockito.mock(JdbcObserver.class);
when(sessionContext.getObserver()).thenReturn(jdbcObserver);
JdbcServices jdbcServices = Mockito.mock(JdbcServices.class);
when(serviceRegistry.getService(eq(JdbcServices.class))).thenReturn(jdbcServices);
SqlExceptionHelper sqlExceptionHelper = Mockito.mock(SqlExceptionHelper.class);
when(jdbcServices.getSqlExceptionHelper()).thenReturn(sqlExceptionHelper);
JdbcCoordinatorImpl jdbcCoordinator = new JdbcCoordinatorImpl(null, sessionOwner);
Batch currentBatch = Mockito.mock(Batch.class);
Field currentBatchField = JdbcCoordinatorImpl.class.getDeclaredField("currentBatch");
currentBatchField.setAccessible(true);
currentBatchField.set(jdbcCoordinator, currentBatch);
doThrow(IllegalStateException.class).when(currentBatch).release();
try {
jdbcCoordinator.close();
fail("Should throw IllegalStateException");
} catch (Exception expected) {
assertEquals(IllegalStateException.class, expected.getClass());
}
verify(jdbcConnectionAccess, times(1)).releaseConnection(same(connection));
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SubclassProxyInterfaceTest method testSubclassProxyInterfaces.
@Test
public void testSubclassProxyInterfaces() {
final Configuration cfg = new Configuration().setProperty(Environment.DIALECT, H2Dialect.class.getName()).addClass(Person.class);
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(cfg.getProperties());
cfg.buildSessionFactory(serviceRegistry).close();
ServiceRegistryBuilder.destroy(serviceRegistry);
}
Aggregations