Search in sources :

Example 16 with IDatabaseCollector

use of org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateDatabaseCollector.

@Test
public void testCreateDatabaseCollector() {
    DatabaseCollector databaseCollector = (DatabaseCollector) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { DatabaseCollector.class }, new TestInvocationHandler());
    IDatabaseCollector facade = facadeFactory.createDatabaseCollector(databaseCollector);
    Assert.assertSame(databaseCollector, ((IFacade) facade).getTarget());
}
Also used : PersistentClass(org.hibernate.mapping.PersistentClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector) DatabaseCollector(org.hibernate.cfg.reveng.DatabaseCollector) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector) Test(org.junit.Test)

Example 17 with IDatabaseCollector

use of org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewDatabaseCollector.

@Test
public void testNewDatabaseCollector() {
    IJDBCReader jdbcReader = FACADE_FACTORY.createJDBCReader(JDBCReaderFactory.newJDBCReader(new Configuration().getProperties(), new DefaultReverseEngineeringStrategy(), new StandardServiceRegistryBuilder().build()));
    IDatabaseCollector databaseCollectorFacade = service.newDatabaseCollector(jdbcReader);
    Assert.assertNotNull(databaseCollectorFacade);
    DatabaseCollector databaseCollector = (DatabaseCollector) ((IFacade) databaseCollectorFacade).getTarget();
    Assert.assertNotNull(databaseCollector);
}
Also used : JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector) IJDBCReader(org.jboss.tools.hibernate.runtime.spi.IJDBCReader) DatabaseCollector(org.hibernate.cfg.reveng.DatabaseCollector) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector) Test(org.junit.Test)

Example 18 with IDatabaseCollector

use of org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector in project jbosstools-hibernate by jbosstools.

the class LazyDatabaseSchemaWorkbenchAdapter method getChildren.

public Object[] getChildren(Object o, final IProgressMonitor monitor) {
    LazyDatabaseSchema dbs = getLazyDatabaseSchema(o);
    dbs.setConnected(false);
    dbs.setErrorFlag(false);
    ConsoleConfiguration consoleConfiguration = dbs.getConsoleConfiguration();
    Object[] res;
    try {
        IDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration, dbs.getReverseEngineeringStrategy());
        List<TableContainer> result = new ArrayList<TableContainer>();
        Iterator<Map.Entry<String, List<ITable>>> qualifierEntries = db.getQualifierEntries();
        while (qualifierEntries.hasNext()) {
            Map.Entry<String, List<ITable>> entry = qualifierEntries.next();
            result.add(new TableContainer(entry.getKey(), entry.getValue()));
        }
        res = toArray(result.iterator(), Object.class, new Comparator<Object>() {

            public int compare(Object arg0, Object arg1) {
                return getName(arg0).compareTo(getName(arg1));
            }

            private String getName(Object o) {
                String result = null;
                try {
                    // $NON-NLS-1$
                    Method m = o.getClass().getMethod("getName", new Class[] {});
                    result = (String) m.invoke(o, new Object[] {});
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                return result;
            }
        });
        dbs.setConnected(true);
    } catch (Exception e) {
        HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_problems_while_reading_database_schema, e);
        String out = NLS.bind(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_reading_schema_error, e.getMessage());
        res = new Object[] { out };
        dbs.setErrorFlag(true);
    }
    return res;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) Comparator(java.util.Comparator) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector)

Aggregations

IDatabaseCollector (org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector)18 DatabaseCollector (org.hibernate.cfg.reveng.DatabaseCollector)16 Test (org.junit.Test)16 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)9 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)9 Configuration (org.hibernate.cfg.Configuration)8 DefaultReverseEngineeringStrategy (org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy)8 PersistentClass (org.hibernate.mapping.PersistentClass)8 RootClass (org.hibernate.mapping.RootClass)8 POJOClass (org.hibernate.tool.hbm2x.pojo.POJOClass)8 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)8 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)8 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)3 HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1