Search in sources :

Example 1 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_5_6.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_5_6.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class SchemaExportFacadeTest method testSetConfiguration.

@Test
public void testSetConfiguration() throws Exception {
    Field metadataField = SchemaExportFacadeImpl.class.getDeclaredField("metadata");
    metadataField.setAccessible(true);
    Configuration configurationTarget = new Configuration();
    configurationTarget.setProperty(AvailableSettings.DIALECT, MockDialect.class.getName());
    configurationTarget.setProperty(AvailableSettings.CONNECTION_PROVIDER, MockConnectionProvider.class.getName());
    ConfigurationFacadeImpl configuration = new ConfigurationFacadeImpl(FACADE_FACTORY, configurationTarget);
    Metadata metadata = configuration.getMetadata();
    assertNull(metadataField.get(schemaExportFacade));
    schemaExportFacade.setConfiguration(configuration);
    assertSame(metadata, metadataField.get(schemaExportFacade));
}
Also used : MockConnectionProvider(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.MockConnectionProvider) Field(java.lang.reflect.Field) Configuration(org.hibernate.cfg.Configuration) MockDialect(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.MockDialect) Metadata(org.hibernate.boot.Metadata) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationFacadeImpl

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

the class ConfigurationMetadataDescriptorTest method beforeEach.

@BeforeEach
public void beforeEach() {
    configurationTarget = new Configuration();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configurationTarget);
    configurationMetadataDescriptor = new ConfigurationMetadataDescriptor(configurationFacade);
}
Also used : Configuration(org.hibernate.cfg.Configuration) ConfigurationFacadeImpl(org.jboss.tools.hibernate.runtime.v_5_6.internal.ConfigurationFacadeImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ConfigurationFacadeImpl

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

the class ConfigurationMetadataDescriptorTest method beforeEach.

@BeforeEach
public void beforeEach() {
    configurationTarget = new Configuration();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configurationTarget);
    configurationMetadataDescriptor = new ConfigurationMetadataDescriptor(configurationFacade);
}
Also used : Configuration(org.hibernate.cfg.Configuration) ConfigurationFacadeImpl(org.jboss.tools.hibernate.runtime.v_5_3.internal.ConfigurationFacadeImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ConfigurationFacadeImpl

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

the class ConfigurationFacadeTest method testGetClassMappings.

@Test
public void testGetClassMappings() throws Exception {
    Field addedClassesField = ConfigurationFacadeImpl.class.getDeclaredField("addedClasses");
    addedClassesField.setAccessible(true);
    configuration.setProperty("hibernate.dialect", TestDialect.class.getName());
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    assertFalse(configurationFacade.getClassMappings().hasNext());
    PersistentClass persistentClass = new RootClass(null);
    persistentClass.setEntityName("Foo");
    IPersistentClass persistentClassFacade = FACADE_FACTORY.createPersistentClass(persistentClass);
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    @SuppressWarnings("unchecked") List<IPersistentClass> addedClasses = (List<IPersistentClass>) addedClassesField.get(configurationFacade);
    addedClasses.add(persistentClassFacade);
    Iterator<IPersistentClass> iterator = configurationFacade.getClassMappings();
    assertTrue(iterator.hasNext());
    assertSame(iterator.next(), persistentClassFacade);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) List(java.util.List) ArrayList(java.util.ArrayList) TestDialect(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.ConfigurationMetadataDescriptorTest.TestDialect) 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)

Aggregations

Test (org.junit.jupiter.api.Test)14 Configuration (org.hibernate.cfg.Configuration)13 PersistentClass (org.hibernate.mapping.PersistentClass)12 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)12 Field (java.lang.reflect.Field)8 Metadata (org.hibernate.boot.Metadata)7 RootClass (org.hibernate.mapping.RootClass)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 MetadataSources (org.hibernate.boot.MetadataSources)5 JdbcMetadataConfiguration (org.jboss.tools.hibernate.runtime.v_5_6.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_5_6.internal.util.MockConnectionProvider)3 MockDialect (org.jboss.tools.hibernate.runtime.v_5_6.internal.util.MockDialect)3 Connection (java.sql.Connection)2