Search in sources :

Example 11 with ConfigurationFacadeImpl

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

the class ConfigurationFacadeTest method testSetPreferBasicCompositeIds.

@Test
public void testSetPreferBasicCompositeIds() {
    JdbcMetadataConfiguration configuration = new JdbcMetadataConfiguration();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    // the default is true
    assertTrue(configuration.preferBasicCompositeIds());
    configurationFacade.setPreferBasicCompositeIds(false);
    assertFalse(configuration.preferBasicCompositeIds());
}
Also used : JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.JdbcMetadataConfiguration) Test(org.junit.jupiter.api.Test)

Example 12 with ConfigurationFacadeImpl

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

the class ExporterFacadeTest method testSetConfiguration.

@Test
public void testSetConfiguration() throws Exception {
    exporterTarget = new HibernateConfigurationExporter();
    exporterFacade = new ExporterFacadeImpl(FACADE_FACTORY, exporterTarget);
    Properties properties = new Properties();
    Configuration configurationTarget = new Configuration();
    configurationTarget.setProperties(properties);
    ConfigurationFacadeImpl configurationFacade1 = new ConfigurationFacadeImpl(FACADE_FACTORY, configurationTarget);
    exporterFacade.setConfiguration(configurationFacade1);
    assertSame(properties, ((HibernateConfigurationExporter) exporterTarget).getCustomProperties());
    Field metadataDescriptorField = AbstractExporter.class.getDeclaredField("metadataDescriptor");
    metadataDescriptorField.setAccessible(true);
    ConfigurationMetadataDescriptor configurationMetadataDescriptor = (ConfigurationMetadataDescriptor) metadataDescriptorField.get(exporterTarget);
    assertNotNull(configurationMetadataDescriptor);
    Field configurationFacadeField = ConfigurationMetadataDescriptor.class.getDeclaredField("configurationFacade");
    configurationFacadeField.setAccessible(true);
    ConfigurationFacadeImpl configurationFacade2 = (ConfigurationFacadeImpl) configurationFacadeField.get(configurationMetadataDescriptor);
    assertNotNull(configurationFacade2);
    assertSame(configurationFacade1, configurationFacade2);
}
Also used : Field(java.lang.reflect.Field) ConfigurationMetadataDescriptor(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.ConfigurationMetadataDescriptor) HibernateConfigurationExporter(org.hibernate.tool.hbm2x.HibernateConfigurationExporter) Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 13 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_5_6.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_5_6.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)

Example 14 with ConfigurationFacadeImpl

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

the class ConfigurationFacadeTest method testSetReverseEngineeringStrategy.

@Test
public void testSetReverseEngineeringStrategy() {
    JdbcMetadataConfiguration configuration = new JdbcMetadataConfiguration();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    ReverseEngineeringStrategy reverseEngineeringStrategy = new DefaultReverseEngineeringStrategy();
    IReverseEngineeringStrategy strategyFacade = FACADE_FACTORY.createReverseEngineeringStrategy(reverseEngineeringStrategy);
    assertNotSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
    configurationFacade.setReverseEngineeringStrategy(strategyFacade);
    assertSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
}
Also used : IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.JdbcMetadataConfiguration) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) ReverseEngineeringStrategy(org.hibernate.cfg.reveng.ReverseEngineeringStrategy) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) Test(org.junit.jupiter.api.Test)

Example 15 with ConfigurationFacadeImpl

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

the class ConfigurationFacadeTest method testGetTableMappings.

@Test
public void testGetTableMappings() 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);
    Iterator<ITable> iterator = configurationFacade.getTableMappings();
    assertFalse(iterator.hasNext());
    jdbcMdCfg.readFromJDBC();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, jdbcMdCfg);
    iterator = configurationFacade.getTableMappings();
    IFacade facade = (IFacade) iterator.next();
    Table table = (Table) facade.getTarget();
    assertEquals("FOO", table.getName());
    statement.execute("DROP TABLE FOO");
    connection.close();
}
Also used : ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.JdbcMetadataConfiguration) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) 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