Search in sources :

Example 41 with ServiceRegistry

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();
        }
    }
}
Also used : ScriptSourceInput(org.hibernate.tool.schema.spi.ScriptSourceInput) Formatter(org.hibernate.engine.jdbc.internal.Formatter) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject) ServiceRegistry(org.hibernate.service.ServiceRegistry) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 42 with ServiceRegistry

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;
}
Also used : ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) Dialect(org.hibernate.dialect.Dialect) ServiceRegistry(org.hibernate.service.ServiceRegistry) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 43 with ServiceRegistry

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);
}
Also used : Marshaller(javax.xml.bind.Marshaller) XmlMappingBinderAccess(org.hibernate.boot.spi.XmlMappingBinderAccess) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServiceRegistry(org.hibernate.service.ServiceRegistry)

Example 44 with ServiceRegistry

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);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 45 with ServiceRegistry

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);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

ServiceRegistry (org.hibernate.service.ServiceRegistry)49 Test (org.junit.Test)27 MetadataSources (org.hibernate.boot.MetadataSources)18 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)17 Configuration (org.hibernate.cfg.Configuration)14 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)12 AnnotationException (org.hibernate.AnnotationException)6 MappingException (org.hibernate.MappingException)6 SessionFactory (org.hibernate.SessionFactory)6 Metadata (org.hibernate.boot.Metadata)6 TestForIssue (org.hibernate.testing.TestForIssue)5 Map (java.util.Map)4 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)4 File (java.io.File)3 HibernateException (org.hibernate.HibernateException)3 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)3 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)3 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2