use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class ManagedProviderConnectionHelper method createServiceRegistry.
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties(properties);
ConfigurationHelper.resolvePlaceHolders(properties);
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings(properties).build();
}
use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class ConnectionCreatorTest method testBadUrl.
@Test
@TestForIssue(jiraKey = "HHH-8621")
public void testBadUrl() throws Exception {
DriverConnectionCreator connectionCreator = new DriverConnectionCreator((Driver) Class.forName("org.h2.Driver").newInstance(), new StandardServiceRegistryImpl(true, new BootstrapServiceRegistryImpl(), Collections.<StandardServiceInitiator>emptyList(), Collections.<ProvidedService>emptyList(), Collections.emptyMap()) {
@Override
@SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if (JdbcServices.class.equals(serviceRole)) {
// return a new, not fully initialized JdbcServicesImpl
return (R) new JdbcServicesImpl();
}
return super.getService(serviceRole);
}
}, "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", new Properties(), false, null);
try {
Connection conn = connectionCreator.createConnection();
conn.close();
fail("Expecting the bad Connection URL to cause an exception");
} catch (JDBCConnectionException expected) {
}
}
use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project zhcet-web by zhcet-amu.
the class Hibernate5DDLExporter method schemaExport.
private Hibernate5DDLExporter schemaExport(String fileName, String targetDirectory) throws Exception {
if (entityPackages == null && entityPackages.length == 0) {
System.out.println("Not packages selected");
System.exit(0);
}
File exportFile = createExportFileAndMakeDirectory(fileName, targetDirectory);
PhysicalNamingStrategy physicalNamingStrategy;
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, dialect).applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy").build();
MetadataImplementor metadata = (MetadataImplementor) mapAnnotatedClasses(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.setOutputFile(exportFile.getAbsolutePath());
schemaExport.setDelimiter(";");
schemaExport.setFormat(true);
schemaExport.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata, serviceRegistry);
((StandardServiceRegistryImpl) serviceRegistry).destroy();
System.out.println(exportFile.getAbsolutePath());
return this;
}
use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class InterceptorTest method testConfiguredSessionInterceptorWithSessionFactory.
@Test
public void testConfiguredSessionInterceptorWithSessionFactory() {
StandardServiceRegistryImpl standardRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
SessionFactory sessionFactory = null;
try {
MetadataSources metadataSources = new MetadataSources(standardRegistry);
for (Class annotatedClass : getAnnotatedClasses()) {
metadataSources.addAnnotatedClass(annotatedClass);
}
Metadata metadata = metadataSources.getMetadataBuilder().build();
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
sessionFactoryBuilder.applyStatelessInterceptor(LocalExceptionInterceptor.class);
sessionFactory = sessionFactoryBuilder.build();
final SessionFactory sessionFactoryInstance = sessionFactory;
Supplier<SessionFactory> sessionFactorySupplier = () -> sessionFactoryInstance;
Item i = new Item();
i.setName("Laptop");
try {
doInHibernate(sessionFactorySupplier, session -> {
session.persist(i);
fail("No interceptor");
return null;
});
} catch (IllegalStateException e) {
assertEquals(LocalExceptionInterceptor.LOCAL_EXCEPTION_MESSAGE, e.getMessage());
}
} finally {
if (sessionFactory != null) {
sessionFactory.close();
}
standardRegistry.destroy();
}
}
use of org.hibernate.boot.registry.internal.StandardServiceRegistryImpl in project hibernate-orm by hibernate.
the class SchemaToolTransactionHandlingTest method testValidateInExistingJtaTransaction.
@Test
public void testValidateInExistingJtaTransaction() {
// start a JTA transaction...
try {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
} catch (Exception e) {
throw new RuntimeException("Unable to being JTA transaction prior to starting test", e);
}
// hold reference to Transaction object
final Transaction jtaTransaction;
try {
jtaTransaction = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().getTransaction();
} catch (SystemException e) {
throw new RuntimeException("Unable to access JTA Transaction prior to starting test", e);
}
final StandardServiceRegistry registry = buildJtaStandardServiceRegistry();
// perform the test...
try {
final SchemaManagementTool smt = registry.getService(SchemaManagementTool.class);
final Metadata mappings = buildMappings(registry);
// first make the schema exist...
try {
smt.getSchemaCreator(Collections.emptyMap()).doCreation(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
} catch (Exception e) {
throw new RuntimeException("Unable to create schema to validation tests", e);
}
try {
smt.getSchemaValidator(Collections.emptyMap()).doValidation(mappings, ExecutionOptionsTestImpl.INSTANCE);
} finally {
try {
smt.getSchemaDropper(Collections.emptyMap()).doDrop(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
} catch (Exception ignore) {
// ignore
}
}
} finally {
try {
jtaTransaction.commit();
((StandardServiceRegistryImpl) registry).destroy();
} catch (Exception e) {
// not much we can do...
}
}
}
Aggregations