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);
}
}
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();
}
}
use of org.hibernate.boot.spi.MetadataImplementor 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.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMissingEntityContainsQualifiedEntityName.
@Test
public void testMissingEntityContainsQualifiedEntityName() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(MissingEntity.class);
final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: missing table [SomeCatalog.SomeSchema.MissingEntity]", e.getMessage());
}
}
use of org.hibernate.boot.spi.MetadataImplementor 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