use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicConverterDisableApplication.
@Test
public void testBasicConverterDisableApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester2.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
PersistentClass tester = metadata.getEntityBinding(Tester2.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter applied (should not have been)");
}
AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicConverterApplication.
@Test
public void testBasicConverterApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
assertTyping(BasicType.class, type);
if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter not applied");
}
AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class AttributeConverterTest method testNonAutoApplyHandling.
@Test
public void testNonAutoApplyHandling() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).getMetadataBuilder().applyAttributeConverter(NotAutoAppliedConverter.class, false).build();
PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter with autoApply=false was auto applied");
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor 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.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class SchemaExport method execute.
public static void execute(CommandLineArgs commandLineArgs) throws Exception {
StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry(commandLineArgs);
try {
final MetadataImplementor metadata = buildMetadata(commandLineArgs, serviceRegistry);
new SchemaExport().setHaltOnError(commandLineArgs.halt).setOutputFile(commandLineArgs.outputFile).setDelimiter(commandLineArgs.delimiter).setFormat(commandLineArgs.format).setManageNamespaces(commandLineArgs.manageNamespaces).setImportFiles(commandLineArgs.importFile).execute(commandLineArgs.targetTypes, commandLineArgs.action, metadata, serviceRegistry);
} finally {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
Aggregations