Search in sources :

Example 1 with JDBCMetaDataConfiguration

use of org.hibernate.cfg.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 : JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) 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)

Example 2 with JDBCMetaDataConfiguration

use of org.hibernate.cfg.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);
    Iterator<?> iterator = jdbcMdCfg.getClassMappings();
    Assert.assertFalse(iterator.hasNext());
    configurationFacade.readFromJDBC();
    iterator = jdbcMdCfg.getClassMappings();
    PersistentClass persistentClass = (PersistentClass) iterator.next();
    Assert.assertEquals("Foo", persistentClass.getClassName());
    statement.execute("DROP TABLE FOO");
    connection.close();
}
Also used : JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) Statement(java.sql.Statement) Connection(java.sql.Connection) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.Test)

Example 3 with JDBCMetaDataConfiguration

use of org.hibernate.cfg.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 : JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) 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)

Example 4 with JDBCMetaDataConfiguration

use of org.hibernate.cfg.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 false
    Assert.assertTrue(configuration.preferBasicCompositeIds());
    configurationFacade.setPreferBasicCompositeIds(false);
    Assert.assertFalse(configuration.preferBasicCompositeIds());
}
Also used : JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) Test(org.junit.Test)

Example 5 with JDBCMetaDataConfiguration

use of org.hibernate.cfg.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);
    Iterator<?> iterator = jdbcMdCfg.getClassMappings();
    Assert.assertFalse(iterator.hasNext());
    configurationFacade.readFromJDBC();
    iterator = jdbcMdCfg.getClassMappings();
    PersistentClass persistentClass = (PersistentClass) iterator.next();
    Assert.assertEquals("Foo", persistentClass.getClassName());
    statement.execute("DROP TABLE FOO");
}
Also used : JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) Statement(java.sql.Statement) Connection(java.sql.Connection) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.Test)

Aggregations

JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)31 Test (org.junit.Test)31 Connection (java.sql.Connection)14 Statement (java.sql.Statement)14 DefaultReverseEngineeringStrategy (org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy)7 ReverseEngineeringStrategy (org.hibernate.cfg.reveng.ReverseEngineeringStrategy)7 PersistentClass (org.hibernate.mapping.PersistentClass)7 Table (org.hibernate.mapping.Table)7 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)7 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)7 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)7 Metadata (org.hibernate.boot.Metadata)3 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)3 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)3