Search in sources :

Example 56 with PersistentClass

use of org.hibernate.mapping.PersistentClass 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)

Example 57 with PersistentClass

use of org.hibernate.mapping.PersistentClass 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();
    Iterator<?> iterator = metadata.getEntityBindings().iterator();
    jdbcMdCfg = new JDBCMetaDataConfiguration();
    jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
    configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
    Assert.assertFalse(iterator.hasNext());
    configurationFacade.readFromJDBC();
    metadata = jdbcMdCfg.getMetadata();
    iterator = metadata.getEntityBindings().iterator();
    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) Metadata(org.hibernate.boot.Metadata) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.Test)

Example 58 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreatePersistentClass.

@Test
public void testCreatePersistentClass() {
    PersistentClass persistentClass = new RootClass(null);
    IPersistentClass facade = facadeFactory.createPersistentClass(persistentClass);
    Assert.assertSame(persistentClass, ((IFacade) facade).getTarget());
}
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.Test)

Example 59 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project jbosstools-hibernate by jbosstools.

the class Cfg2HbmToolFacadeTest method testGetPersistentClassTag.

@Test
public void testGetPersistentClassTag() {
    PersistentClass target = new RootClass(null);
    IPersistentClass persistentClass = new AbstractPersistentClassFacade(FACADE_FACTORY, target) {
    };
    Assert.assertEquals("class", cfg2HbmToolFacade.getTag(persistentClass));
}
Also used : RootClass(org.hibernate.mapping.RootClass) AbstractPersistentClassFacade(org.jboss.tools.hibernate.runtime.common.AbstractPersistentClassFacade) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 60 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testAddClass.

@Test
public void testAddClass() {
    PersistentClass persistentClass = new RootClass(null);
    persistentClass.setEntityName("Foo");
    IPersistentClass persistentClassFacade = FACADE_FACTORY.createPersistentClass(persistentClass);
    Assert.assertNull(configurationFacade.getClassMapping("Foo"));
    configurationFacade = FACADE_FACTORY.createConfiguration(configuration);
    configurationFacade.addClass(persistentClassFacade);
    Assert.assertEquals(persistentClassFacade, configurationFacade.getClassMapping("Foo"));
}
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.Test)

Aggregations

PersistentClass (org.hibernate.mapping.PersistentClass)229 Test (org.junit.Test)121 Property (org.hibernate.mapping.Property)65 MetadataSources (org.hibernate.boot.MetadataSources)53 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)52 RootClass (org.hibernate.mapping.RootClass)50 Metadata (org.hibernate.boot.Metadata)45 Column (org.hibernate.mapping.Column)43 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)42 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)38 Iterator (java.util.Iterator)30 SimpleValue (org.hibernate.mapping.SimpleValue)24 HashMap (java.util.HashMap)22 Collection (org.hibernate.mapping.Collection)21 MappingException (org.hibernate.MappingException)20 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)20 Table (org.hibernate.mapping.Table)20 Map (java.util.Map)19 ArrayList (java.util.ArrayList)18 TestForIssue (org.hibernate.testing.TestForIssue)18