use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class SchemaExportTask method doExecution.
private void doExecution() throws Exception {
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
final MetadataSources metadataSources = new MetadataSources(bsr);
if (configurationFile != null) {
ssrBuilder.configure(configurationFile);
}
if (propertiesFile != null) {
ssrBuilder.loadProperties(propertiesFile);
}
ssrBuilder.applySettings(getProject().getProperties());
for (String fileName : getFiles()) {
if (fileName.endsWith(".jar")) {
metadataSources.addJar(new File(fileName));
} else {
metadataSources.addFile(fileName);
}
}
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DELIMITER, delimiter);
ExportType exportType = ExportType.interpret(drop, create);
Target output = Target.interpret(!quiet, !text);
if (output.doScript()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_ACTION, exportType.getAction());
final Object scriptTarget;
if (outputFile == null) {
scriptTarget = new OutputStreamWriter(System.out);
} else {
scriptTarget = outputFile;
}
if (exportType.doCreate()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET, scriptTarget);
}
if (exportType.doDrop()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_SCRIPTS_DROP_TARGET, scriptTarget);
}
}
if (output.doExport()) {
ssrBuilder.applySetting(AvailableSettings.HBM2DDL_DATABASE_ACTION, exportType.getAction());
}
final StandardServiceRegistryImpl ssr = (StandardServiceRegistryImpl) ssrBuilder.build();
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(ssr);
ClassLoaderService classLoaderService = bsr.getService(ClassLoaderService.class);
if (implicitNamingStrategy != null) {
metadataBuilder.applyImplicitNamingStrategy((ImplicitNamingStrategy) classLoaderService.classForName(implicitNamingStrategy).newInstance());
}
if (physicalNamingStrategy != null) {
metadataBuilder.applyPhysicalNamingStrategy((PhysicalNamingStrategy) classLoaderService.classForName(physicalNamingStrategy).newInstance());
}
final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
metadata.validate();
SchemaManagementToolCoordinator.process(metadata, ssr, ssr.getService(ConfigurationService.class).getSettings(), DelayedDropRegistryNotAvailableImpl.INSTANCE);
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingLegacyHbmStrategy.
@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingLegacyHbmStrategy() {
final MetadataSources metadataSources = new MetadataSources();
try {
metadataSources.addAnnotatedClass(Input.class);
metadataSources.addAnnotatedClass(Ptx.class);
final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyHbmImpl.INSTANCE).build();
Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
assertEquals("ptx_inputs1", inputs1Mapping.getCollectionTable().getName());
Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
assertEquals("ptx_inputs2", inputs2Mapping.getCollectionTable().getName());
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingBase.
@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingBase() {
// really the same as the JPA compliant tests; here we just pick up the default ImplicitNamingStrategy
final MetadataSources metadataSources = new MetadataSources();
try {
metadataSources.addAnnotatedClass(Input.class);
metadataSources.addAnnotatedClass(Ptx.class);
final Metadata metadata = metadataSources.getMetadataBuilder().build();
assertSameTableUsed(metadata);
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class BootstrapTest method test_bootstrap_bootstrap_native_registry_MetadataSources_example.
@Test
public void test_bootstrap_bootstrap_native_registry_MetadataSources_example() {
try {
//tag::bootstrap-bootstrap-native-registry-MetadataSources-example[]
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
MetadataSources sources = new MetadataSources(standardRegistry);
// alternatively, we can build the MetadataSources without passing
// a service registry, in which case it will build a default
// BootstrapServiceRegistry to use. But the approach shown
// above is preferred
// MetadataSources sources = new MetadataSources();
// add a class using JPA/Hibernate annotations for mapping
sources.addAnnotatedClass(MyEntity.class);
// add the name of a class using JPA/Hibernate annotations for mapping.
// differs from above in that accessing the Class is deferred which is
// important if using runtime bytecode-enhancement
sources.addAnnotatedClassName("org.hibernate.example.Customer");
// Read package-level metadata.
sources.addPackage("hibernate.example");
// Read package-level metadata.
sources.addPackage(MyEntity.class.getPackage());
// Adds the named hbm.xml resource as a source: which performs the
// classpath lookup and parses the XML
sources.addResource("org/hibernate/example/Order.hbm.xml");
// Adds the named JPA orm.xml resource as a source: which performs the
// classpath lookup and parses the XML
sources.addResource("org/hibernate/example/Product.orm.xml");
// Read all mapping documents from a directory tree.
// Assumes that any file named *.hbm.xml is a mapping document.
sources.addDirectory(new File("."));
// Read mappings from a particular XML file
sources.addFile(new File("./mapping.xml"));
// Read all mappings from a jar file.
// Assumes that any file named *.hbm.xml is a mapping document.
sources.addJar(new File("./entities.jar"));
// Read a mapping as an application resource using the convention that a class named foo.bar.MyEntity is
// mapped by a file named foo/bar/MyEntity.hbm.xml which can be resolved as a classpath resource.
sources.addClass(MyEntity.class);
//end::bootstrap-bootstrap-native-registry-MetadataSources-example[]
} catch (Exception ignore) {
}
}
use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.
the class BootstrapTest method test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2.
@Test
public void test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2() {
//tag::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
// An example using an explicitly built BootstrapServiceRegistry
BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder().build();
StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapRegistry);
//end::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[]
}
Aggregations