Search in sources :

Example 1 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ConfigurationMetadataDescriptor method patch.

private Metadata patch(Metadata metadata) {
    try {
        if (metadata instanceof MetadataImpl) {
            MetadataImpl metadataImpl = (MetadataImpl) metadata;
            Field entityBindingMapField = metadataImpl.getClass().getDeclaredField("entityBindingMap");
            if (entityBindingMapField != null) {
                entityBindingMapField.setAccessible(true);
                Object object = entityBindingMapField.get(metadataImpl);
                if (object instanceof HashMap<?, ?>) {
                    @SuppressWarnings("unchecked") HashMap<String, PersistentClass> map = (HashMap<String, PersistentClass>) object;
                    for (IPersistentClass ipc : ((ConfigurationFacadeImpl) this.configurationFacade).getAddedClasses()) {
                        PersistentClass pc = (PersistentClass) ((IFacade) ipc).getTarget();
                        map.put(pc.getEntityName(), pc);
                    }
                }
            }
        }
        return metadata;
    } catch (Throwable t) {
        throw new RuntimeException("Problem while creating metadata", t);
    }
}
Also used : Field(java.lang.reflect.Field) MetadataImpl(org.hibernate.boot.internal.MetadataImpl) HashMap(java.util.HashMap) ConfigurationFacadeImpl(org.jboss.tools.hibernate.runtime.v_5_5.internal.ConfigurationFacadeImpl) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 2 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetEntityResolver.

@Test
public void testSetEntityResolver() {
    EntityResolver testResolver = new DefaultHandler();
    ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
    assertNull(facade.entityResolver);
    configurationFacade.setEntityResolver(testResolver);
    assertSame(testResolver, facade.entityResolver);
}
Also used : EntityResolver(org.xml.sax.EntityResolver) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 3 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testAddClass.

@Test
public void testAddClass() {
    PersistentClass persistentClass = new RootClass(DummyMetadataBuildingContext.INSTANCE);
    persistentClass.setEntityName("Foo");
    IPersistentClass persistentClassFacade = FACADE_FACTORY.createPersistentClass(persistentClass);
    assertFalse(((ConfigurationFacadeImpl) configurationFacade).addedClasses.contains(persistentClassFacade));
    configurationFacade.addClass(persistentClassFacade);
    assertTrue(((ConfigurationFacadeImpl) configurationFacade).addedClasses.contains(persistentClassFacade));
}
Also used : RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 4 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testGetClassMapping.

@Test
public void testGetClassMapping() {
    PersistentClass persistentClass = new RootClass(DummyMetadataBuildingContext.INSTANCE);
    persistentClass.setEntityName("Foo");
    IPersistentClass persistentClassFacade = FACADE_FACTORY.createPersistentClass(persistentClass);
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    assertNull(configurationFacade.getClassMapping("Foo"));
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    ((ConfigurationFacadeImpl) configurationFacade).addedClasses.add(persistentClassFacade);
    assertSame(configurationFacade.getClassMapping("Foo"), persistentClassFacade);
}
Also used : RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 5 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl 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 = new ConfigurationFacadeImpl(FACADE_FACTORY, jdbcMdCfg);
    Metadata metadata = jdbcMdCfg.getMetadata();
    assertNull(metadata);
    jdbcMdCfg = new JdbcMetadataConfiguration();
    jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, jdbcMdCfg);
    configurationFacade.readFromJDBC();
    metadata = jdbcMdCfg.getMetadata();
    Iterator<PersistentClass> iterator = metadata.getEntityBindings().iterator();
    PersistentClass persistentClass = iterator.next();
    assertEquals("Foo", persistentClass.getClassName());
    statement.execute("DROP TABLE FOO");
    statement.close();
    connection.close();
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration) Metadata(org.hibernate.boot.Metadata) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Aggregations

Test (org.junit.jupiter.api.Test)20 Configuration (org.hibernate.cfg.Configuration)13 PersistentClass (org.hibernate.mapping.PersistentClass)13 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)13 MetadataHelperTest (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)12 Metadata (org.hibernate.boot.Metadata)8 RootClass (org.hibernate.mapping.RootClass)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Field (java.lang.reflect.Field)5 MetadataSources (org.hibernate.boot.MetadataSources)5 JdbcMetadataConfiguration (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration)5 HashMap (java.util.HashMap)4 MetadataImpl (org.hibernate.boot.internal.MetadataImpl)4 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_3.internal.ConfigurationFacadeImpl)3 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_4.internal.ConfigurationFacadeImpl)3 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_5.internal.ConfigurationFacadeImpl)3 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_6.internal.ConfigurationFacadeImpl)3 MockConnectionProvider (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MockConnectionProvider)3 MockDialect (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MockDialect)3