use of org.hibernate.boot.Metadata in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testReadFromJDBC.
@Test
public void testReadFromJDBC() throws Exception {
Connection connection = DriverManager.getConnection("jdbc:h2:mem:test");
Statement statement = connection.createStatement();
statement.execute("CREATE TABLE FOO(id int primary key, bar varchar(255))");
JdbcMetadataConfiguration jdbcMdCfg = new JdbcMetadataConfiguration();
jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
Metadata metadata = jdbcMdCfg.getMetadata();
Assert.assertNull(metadata);
jdbcMdCfg = new JdbcMetadataConfiguration();
jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
configurationFacade.readFromJDBC();
metadata = jdbcMdCfg.getMetadata();
Iterator<PersistentClass> iterator = metadata.getEntityBindings().iterator();
PersistentClass persistentClass = (PersistentClass) iterator.next();
Assert.assertEquals("Foo", persistentClass.getClassName());
statement.execute("DROP TABLE FOO");
connection.close();
}
use of org.hibernate.boot.Metadata in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testConfigure.
@Test
public void testConfigure() {
String fooClassName = "org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo";
Metadata metadata = MetadataHelper.getMetadata(configuration);
Assert.assertNull(metadata.getEntityBinding(fooClassName));
configurationFacade.configure();
metadata = MetadataHelper.getMetadata(configuration);
Assert.assertNotNull(metadata.getEntityBinding(fooClassName));
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class InterceptorTest method testConfiguredSessionInterceptorWithSessionFactory.
@Test
public void testConfiguredSessionInterceptorWithSessionFactory() {
StandardServiceRegistryImpl standardRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
SessionFactory sessionFactory = null;
try {
MetadataSources metadataSources = new MetadataSources(standardRegistry);
for (Class annotatedClass : getAnnotatedClasses()) {
metadataSources.addAnnotatedClass(annotatedClass);
}
Metadata metadata = metadataSources.getMetadataBuilder().build();
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
sessionFactoryBuilder.applyStatelessInterceptor(LocalExceptionInterceptor.class);
sessionFactory = sessionFactoryBuilder.build();
final SessionFactory sessionFactoryInstance = sessionFactory;
Supplier<SessionFactory> sessionFactorySupplier = () -> sessionFactoryInstance;
Item i = new Item();
i.setName("Laptop");
try {
doInHibernate(sessionFactorySupplier, session -> {
session.persist(i);
fail("No interceptor");
return null;
});
} catch (IllegalStateException e) {
assertEquals(LocalExceptionInterceptor.LOCAL_EXCEPTION_MESSAGE, e.getMessage());
}
} finally {
if (sessionFactory != null) {
sessionFactory.close();
}
standardRegistry.destroy();
}
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class SimpleXmlOverriddenTest method baseline.
/**
* A baseline test, with an explicit @Convert annotation that should be in effect
*/
@Test
public void baseline() {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
PersistentClass pc = metadata.getEntityBinding(TheEntity.class.getName());
Type type = pc.getProperty("it").getType();
AttributeConverterTypeAdapter adapter = assertTyping(AttributeConverterTypeAdapter.class, type);
assertTrue(SillyStringConverter.class.isAssignableFrom(adapter.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class SimpleXmlOverriddenTest method testDefinitionAtAttributeLevel.
/**
* Test outcome of applying overrides via orm.xml, specifically at the attribute level
*/
@Test
public void testDefinitionAtAttributeLevel() {
// NOTE : simple-override.xml applied disable-conversion="true" at the attribute-level
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).addResource("org/hibernate/test/converter/simple-override.xml").buildMetadata();
PersistentClass pc = metadata.getEntityBinding(TheEntity.class.getName());
Type type = pc.getProperty("it").getType();
assertTyping(StringType.class, type);
}
Aggregations