Search in sources :

Example 1 with JdbcMetadataConfiguration

use of org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewJDBCMetaDataConfiguration.

@Test
public void testNewJDBCMetaDataConfiguration() {
    IConfiguration configuration = service.newJDBCMetaDataConfiguration();
    Assert.assertNotNull(configuration);
    Object target = ((IFacade) configuration).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof JdbcMetadataConfiguration);
}
Also used : JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 2 with JdbcMetadataConfiguration

use of org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration 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();
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration) Metadata(org.hibernate.boot.Metadata) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.Test)

Example 3 with JdbcMetadataConfiguration

use of org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration 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 = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
    Iterator<ITable> iterator = configurationFacade.getTableMappings();
    Assert.assertFalse(iterator.hasNext());
    jdbcMdCfg.readFromJDBC();
    configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
    iterator = configurationFacade.getTableMappings();
    Table table = (Table) ((IFacade) iterator.next()).getTarget();
    Assert.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_3.internal.util.JdbcMetadataConfiguration) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Test(org.junit.Test)

Example 4 with JdbcMetadataConfiguration

use of org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetPreferBasicCompositeIds.

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

Example 5 with JdbcMetadataConfiguration

use of org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetReverseEngineeringStrategy.

@Test
public void testSetReverseEngineeringStrategy() {
    JdbcMetadataConfiguration configuration = new JdbcMetadataConfiguration();
    configurationFacade = FACADE_FACTORY.createConfiguration(configuration);
    ReverseEngineeringStrategy reverseEngineeringStrategy = new DefaultReverseEngineeringStrategy();
    IReverseEngineeringStrategy strategyFacade = FACADE_FACTORY.createReverseEngineeringStrategy(reverseEngineeringStrategy);
    Assert.assertNotSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
    configurationFacade.setReverseEngineeringStrategy(strategyFacade);
    Assert.assertSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
}
Also used : IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_3.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.Test)

Aggregations

JdbcMetadataConfiguration (org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration)5 Test (org.junit.Test)5 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 Metadata (org.hibernate.boot.Metadata)1 DefaultReverseEngineeringStrategy (org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy)1 ReverseEngineeringStrategy (org.hibernate.cfg.reveng.ReverseEngineeringStrategy)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Table (org.hibernate.mapping.Table)1 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)1 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)1 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)1 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)1 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)1