use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SchemaCreatorImpl method applyImportSources.
private void applyImportSources(ExecutionOptions options, ImportSqlCommandExtractor commandExtractor, boolean format, GenerationTarget... targets) {
final ServiceRegistry serviceRegistry = tool.getServiceRegistry();
final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
// I have had problems applying the formatter to these imported statements.
// and legacy SchemaExport did not format them, so doing same here
//final Formatter formatter = format ? DDLFormatterImpl.INSTANCE : FormatStyle.NONE.getFormatter();
final Formatter formatter = FormatStyle.NONE.getFormatter();
final Object importScriptSetting = options.getConfigurationValues().get(HBM2DDL_LOAD_SCRIPT_SOURCE);
String charsetName = (String) options.getConfigurationValues().get(HBM2DDL_CHARSET_NAME);
if (importScriptSetting != null) {
final ScriptSourceInput importScriptInput = interpretScriptSourceSetting(importScriptSetting, classLoaderService, charsetName);
log.executingImportScript(importScriptInput.toString());
importScriptInput.prepare();
try {
for (String command : importScriptInput.read(commandExtractor)) {
applySqlString(command, formatter, options, targets);
}
} finally {
importScriptInput.release();
}
}
final String importFiles = ConfigurationHelper.getString(AvailableSettings.HBM2DDL_IMPORT_FILES, options.getConfigurationValues(), DEFAULT_IMPORT_FILE);
for (String currentFile : importFiles.split(",")) {
final String resourceName = currentFile.trim();
final ScriptSourceInput importScriptInput = interpretLegacyImportScriptSetting(resourceName, classLoaderService, charsetName);
importScriptInput.prepare();
try {
log.executingImportScript(importScriptInput.toString());
for (String command : importScriptInput.read(commandExtractor)) {
applySqlString(command, formatter, options, targets);
}
} finally {
importScriptInput.release();
}
}
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class SchemaDropperImpl method generateDropCommands.
/**
* For testing...
*
* @param metadata The metadata for which to generate the creation commands.
*
* @return The generation commands
*/
public List<String> generateDropCommands(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;
}
};
dropFromMetadata(metadata, options, dialect, FormatStyle.NONE.getFormatter(), target);
return target.commands;
}
use of org.hibernate.service.ServiceRegistry in project hibernate-orm by hibernate.
the class XmlBindingChecker method checkValidGeneration.
public static void checkValidGeneration(JaxbHbmHibernateMapping hbmMapping) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(JaxbHbmHibernateMapping.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
jaxbMarshaller.marshal(hbmMapping, bos);
ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
ServiceRegistry sr = new StandardServiceRegistryBuilder().build();
new XmlMappingBinderAccess(sr).bind(is);
}
use of org.hibernate.service.ServiceRegistry 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.service.ServiceRegistry 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);
}
}
}
Aggregations