Search in sources :

Example 6 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class IndividuallySchemaValidatorImplTest method testMissingEntityContainsUnqualifiedEntityName.

@Test
public void testMissingEntityContainsUnqualifiedEntityName() throws Exception {
    final MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(UnqualifiedMissingEntity.class);
    final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    try {
        getSchemaValidator(metadata);
        Assert.fail("SchemaManagementException expected");
    } catch (SchemaManagementException e) {
        assertEquals("Schema-validation: missing table [UnqualifiedMissingEntity]", e.getMessage());
    }
}
Also used : SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Test(org.junit.Test)

Example 7 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class SchemaUpdate method buildMetadata.

private static MetadataImplementor buildMetadata(CommandLineArgs parsedArgs, ServiceRegistry serviceRegistry) throws Exception {
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    for (String filename : parsedArgs.hbmXmlFiles) {
        metadataSources.addFile(filename);
    }
    for (String filename : parsedArgs.jarFiles) {
        metadataSources.addJar(new File(filename));
    }
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
    if (parsedArgs.implicitNamingStrategyImplName != null) {
        metadataBuilder.applyImplicitNamingStrategy(strategySelector.resolveStrategy(ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName));
    }
    if (parsedArgs.physicalNamingStrategyImplName != null) {
        metadataBuilder.applyPhysicalNamingStrategy(strategySelector.resolveStrategy(PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName));
    }
    return (MetadataImplementor) metadataBuilder.build();
}
Also used : ImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategy) MetadataBuilder(org.hibernate.boot.MetadataBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) File(java.io.File) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) PhysicalNamingStrategy(org.hibernate.boot.model.naming.PhysicalNamingStrategy)

Example 8 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class SchemaUpdate method main.

public static void main(String[] args) {
    try {
        final CommandLineArgs parsedArgs = CommandLineArgs.parseCommandLineArgs(args);
        final StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry(parsedArgs);
        try {
            final MetadataImplementor metadata = buildMetadata(parsedArgs, serviceRegistry);
            new SchemaUpdate().setOutputFile(parsedArgs.outputFile).setDelimiter(parsedArgs.delimiter).execute(parsedArgs.targetTypes, metadata, serviceRegistry);
        } finally {
            StandardServiceRegistryBuilder.destroy(serviceRegistry);
        }
    } catch (Exception e) {
        LOG.unableToRunSchemaUpdate(e);
        e.printStackTrace();
    }
}
Also used : MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 9 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class SchemaUpdateTask method execute.

/**
	 * Execute the task
	 */
@Override
public void execute() throws BuildException {
    log("Running Hibernate Core SchemaUpdate.");
    log("This is an Ant task supporting only mapping files, if you want to use annotations see http://tools.hibernate.org.");
    try {
        final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder();
        configure(ssrBuilder);
        final StandardServiceRegistry ssr = ssrBuilder.build();
        final MetadataSources metadataSources = new MetadataSources(ssr);
        configure(metadataSources);
        final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
        configure(metadataBuilder, ssr);
        final MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
        new SchemaUpdate().setOutputFile(outputFile.getPath()).setDelimiter(delimiter).setHaltOnError(haltOnError).execute(TargetTypeHelper.parseLegacyCommandLineOptions(!quiet, !text, outputFile.getPath()), metadata);
    } 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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) HibernateException(org.hibernate.HibernateException) MetadataSources(org.hibernate.boot.MetadataSources) FileNotFoundException(java.io.FileNotFoundException) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException) HibernateException(org.hibernate.HibernateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 10 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class SchemaValidator method main.

public static void main(String[] args) {
    try {
        final CommandLineArgs parsedArgs = CommandLineArgs.parseCommandLineArgs(args);
        final StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry(parsedArgs);
        try {
            final MetadataImplementor metadata = buildMetadata(parsedArgs, serviceRegistry);
            new SchemaValidator().validate(metadata, serviceRegistry);
        } finally {
            StandardServiceRegistryBuilder.destroy(serviceRegistry);
        }
    } catch (Exception e) {
        LOG.unableToRunSchemaUpdate(e);
        e.printStackTrace();
    }
}
Also used : MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Aggregations

MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)67 MetadataSources (org.hibernate.boot.MetadataSources)58 Test (org.junit.Test)53 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)33 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)33 TestForIssue (org.hibernate.testing.TestForIssue)25 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)19 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)16 PersistentClass (org.hibernate.mapping.PersistentClass)15 File (java.io.File)13 MetadataBuilder (org.hibernate.boot.MetadataBuilder)7 Property (org.hibernate.mapping.Property)7 SimpleValue (org.hibernate.mapping.SimpleValue)7 Type (org.hibernate.type.Type)7 AbstractStandardBasicType (org.hibernate.type.AbstractStandardBasicType)6 BasicType (org.hibernate.type.BasicType)6 Metadata (org.hibernate.boot.Metadata)4 Namespace (org.hibernate.boot.model.relational.Namespace)4 Sequence (org.hibernate.boot.model.relational.Sequence)4 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)4