use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SchemaValidator method buildStandardServiceRegistry.
private static StandardServiceRegistry buildStandardServiceRegistry(CommandLineArgs parsedArgs) throws Exception {
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
if (parsedArgs.cfgXmlFile != null) {
ssrBuilder.configure(parsedArgs.cfgXmlFile);
}
if (parsedArgs.propertiesFile != null) {
Properties properties = new Properties();
properties.load(new FileInputStream(parsedArgs.propertiesFile));
ssrBuilder.applySettings(properties);
}
return ssrBuilder.build();
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SchemaValidatorTask method execute.
/**
* Execute the task
*/
@Override
public void execute() throws BuildException {
try {
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
configure(ssrBuilder);
final StandardServiceRegistry ssr = ssrBuilder.build();
try {
final MetadataSources metadataSources = new MetadataSources(ssrBuilder.build());
configure(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
configure(metadataBuilder, ssr);
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
new SchemaValidator().validate(metadata, ssr);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
} catch (HibernateException e) {
throw new BuildException("Schema text failed: " + e.getMessage(), e);
} catch (FileNotFoundException e) {
throw new BuildException("File not found: " + e.getMessage(), e);
} catch (IOException e) {
throw new BuildException("IOException : " + e.getMessage(), e);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project querydsl by querydsl.
the class HibernateTestRunner method start.
private void start() throws Exception {
Configuration cfg = new Configuration();
for (Class<?> cl : Domain.classes) {
cfg.addAnnotatedClass(cl);
}
String mode = Mode.mode.get() + ".properties";
isDerby = mode.contains("derby");
if (isDerby) {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
}
Properties props = new Properties();
InputStream is = HibernateTestRunner.class.getResourceAsStream(mode);
if (is == null) {
throw new IllegalArgumentException("No configuration available at classpath:" + mode);
}
props.load(is);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(props).build();
cfg.setProperties(props);
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
session = sessionFactory.openSession();
session.beginTransaction();
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project dropwizard by dropwizard.
the class SessionFactoryFactory method buildSessionFactory.
private SessionFactory buildSessionFactory(HibernateBundle<?> bundle, PooledDataSourceFactory dbConfig, ConnectionProvider connectionProvider, Map<String, String> properties, List<Class<?>> entities) {
final Configuration configuration = new Configuration();
configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
configuration.setProperty(AvailableSettings.USE_SQL_COMMENTS, Boolean.toString(dbConfig.isAutoCommentsEnabled()));
configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true");
configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, "true");
configuration.setProperty(AvailableSettings.ORDER_UPDATES, "true");
configuration.setProperty(AvailableSettings.ORDER_INSERTS, "true");
configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
configuration.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
for (Map.Entry<String, String> property : properties.entrySet()) {
configuration.setProperty(property.getKey(), property.getValue());
}
addAnnotatedClasses(configuration, entities);
bundle.configure(configuration);
final ServiceRegistry registry = new StandardServiceRegistryBuilder().addService(ConnectionProvider.class, connectionProvider).applySettings(configuration.getProperties()).build();
configure(configuration, registry);
return configuration.buildSessionFactory(registry);
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMissingColumn.
@Test
public void testMissingColumn() throws Exception {
MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(NoNameColumn.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
Map<String, Object> settings = new HashMap<>();
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
connectionProvider.configure(properties());
final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
try {
new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(NameColumn.class);
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: missing column [name] in table [SomeSchema.ColumnEntity]", e.getMessage());
}
} finally {
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
serviceRegistry.destroy();
connectionProvider.stop();
}
}
Aggregations