use of org.jboss.tools.hibernate.runtime.v_5_3.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);
}
}
use of org.jboss.tools.hibernate.runtime.v_5_3.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("configuration");
configurationFacadeField.setAccessible(true);
ConfigurationFacadeImpl configurationFacade2 = (ConfigurationFacadeImpl) configurationFacadeField.get(configurationMetadataDescriptor);
assertNotNull(configurationFacade2);
assertSame(configurationFacade1, configurationFacade2);
}
use of org.jboss.tools.hibernate.runtime.v_5_3.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();
}
use of org.jboss.tools.hibernate.runtime.v_5_3.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method beforeEach.
@BeforeEach
public void beforeEach() {
configuration = new Configuration();
configuration.setProperty(AvailableSettings.DIALECT, MockDialect.class.getName());
configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
}
use of org.jboss.tools.hibernate.runtime.v_5_3.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();
}
Aggregations