use of org.hibernate.boot.MetadataBuilder 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.MetadataBuilder in project hibernate-orm by hibernate.
the class IdentityGeneratorExtendsTest method testIdentifierGeneratorExtendsIdentityGenerator.
@Test
public void testIdentifierGeneratorExtendsIdentityGenerator() {
final MetadataSources sources = new MetadataSources(serviceRegistry());
sources.addAnnotatedClass(EntityBean.class);
final MetadataBuilder builder = sources.getMetadataBuilder();
final Metadata metadata = builder.build();
for (final Namespace ns : metadata.getDatabase().getNamespaces()) {
for (final org.hibernate.mapping.Table table : ns.getTables()) {
final KeyValue value = table.getIdentifierValue();
assertNotNull("IdentifierValue was null", value);
assertTrue(value.isIdentityColumn(metadata.getIdentifierGeneratorFactory(), getDialect()));
}
}
Session s = openSession();
s.beginTransaction();
s.save(new EntityBean());
s.getTransaction().commit();
s.close();
}
use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class Tests method testJpaJoinColumnPhysicalNaming.
@Test
@TestForIssue(jiraKey = "HHH-9961")
public void testJpaJoinColumnPhysicalNaming() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings(Environment.getProperties()).build();
try {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(Language.class);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE);
metadataBuilder.applyPhysicalNamingStrategy(PhysicalNamingStrategyImpl.INSTANCE);
final Metadata metadata = metadataBuilder.build();
((MetadataImplementor) metadata).validate();
final PersistentClass languageBinding = metadata.getEntityBinding(Language.class.getName());
final Property property = languageBinding.getProperty("fallBack");
Iterator itr = property.getValue().getColumnIterator();
assertTrue(itr.hasNext());
final Column column = (Column) itr.next();
assertFalse(itr.hasNext());
assertEquals("C_FALLBACK_ID", column.getName().toUpperCase(Locale.ROOT));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class SchemaExport method buildMetadata.
private static MetadataImplementor buildMetadata(CommandLineArgs parsedArgs, StandardServiceRegistry 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();
}
use of org.hibernate.boot.MetadataBuilder 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);
}
Aggregations