Search in sources :

Example 6 with QueryPage

use of org.hibernate.console.QueryPage in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationTest method testHQLListParameters.

@Test
public void testHQLListParameters() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    // fix for https://issues.jboss.org/browse/JBIDE-9392
    // the view calls jdbc connection
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart view = activePage.findView(QueryPageTabView.ID);
    if (view != null) {
        activePage.hideView(view);
        view.dispose();
    }
    consoleCfg.build();
    IConfiguration c = consoleCfg.getConfiguration();
    IPersistentClass rc = service.newRootClass();
    rc.setEntityName("java.awt.Button");
    rc.setClassName("java.awt.Button");
    IColumn column = service.newColumn("label");
    ITable table = service.newTable("faketable");
    IPrimaryKey pk = table.getPrimaryKey();
    pk.addColumn(column);
    rc.setTable(table);
    table.addColumn(column);
    IProperty fakeProp = service.newProperty();
    fakeProp.setName("label");
    IValue sv = service.newSimpleValue();
    sv.addColumn(column);
    sv.setTypeName("string");
    sv.setTable(table);
    fakeProp.setValue(sv);
    rc.setIdentifierProperty(fakeProp);
    rc.setIdentifier(fakeProp.getValue());
    c.addClass(rc);
    consoleCfg.buildSessionFactory();
    ConsoleQueryParameter paramA = new ConsoleQueryParameter(service, "a", typeFactory.getIntegerType(), new Integer[] { new Integer(1), new Integer(2) });
    ConsoleQueryParameter paramB = new ConsoleQueryParameter(service, "b", typeFactory.getIntegerType(), new Integer(3));
    ConsoleQueryParameter paramOrdered = new ConsoleQueryParameter(service, "0", typeFactory.getIntegerType(), new Integer(4));
    QueryInputModel model = new QueryInputModel(service);
    model.addParameter(paramA);
    model.addParameter(paramB);
    model.addParameter(paramOrdered);
    // $NON-NLS-1$
    QueryPage qp = consoleCfg.executeHQLQuery("select count(*) from java.awt.Button where 1 in ( ?, :a, :b )", model);
    Assert.assertNotNull(qp);
    try {
        // execute the query
        qp.getList();
    } catch (Exception e) {
    // ignore - there is fake mapping
    }
}
Also used : ConsoleQueryParameter(org.hibernate.console.ConsoleQueryParameter) IViewPart(org.eclipse.ui.IViewPart) QueryPage(org.hibernate.console.QueryPage) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) QueryInputModel(org.hibernate.console.QueryInputModel) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Test(org.junit.Test)

Example 7 with QueryPage

use of org.hibernate.console.QueryPage in project jbosstools-hibernate by jbosstools.

the class QueryPageTabView method rebuild.

protected void rebuild() {
    QueryPage selection = getSelectedQueryPage();
    for (QueryPage results : getAddedResultSets()) {
        this.pageViewers.add(new QueryPageViewer(this, results));
    }
    for (QueryPage results : getRemovedResultSets()) {
        QueryPageViewer viewer = findViewerFor(results);
        this.pageViewers.remove(viewer);
        viewer.dispose();
    }
    // Handle firing selection changes here to cover for when the model fire changes
    // but the Tab widget doesn't (e.g. the first page).
    QueryPage newSelection = getSelectedQueryPage();
    if (selection != null && newSelection == null) {
        fireSelectionChangedEvent();
    } else if (selection == null && newSelection != null) {
        fireSelectionChangedEvent();
    } else if (selection != null && !selection.equals(newSelection)) {
        fireSelectionChangedEvent();
    }
}
Also used : QueryPage(org.hibernate.console.QueryPage)

Example 8 with QueryPage

use of org.hibernate.console.QueryPage in project jbosstools-hibernate by jbosstools.

the class HibernatePropertySourceProvider method getPropertySource.

public IPropertySource getPropertySource(Object object) {
    if (object == null) {
        return null;
    } else if (object instanceof QueryPage) {
        return new QueryPagePropertySource((QueryPage) object);
    } else if (object instanceof IPropertySource) {
        return (IPropertySource) object;
    } else {
        QueryPage selectedQueryPage = view.getSelectedQueryPage();
        ConsoleExtension consoleExtension = selectedQueryPage.getHibernateExtension().getConsoleExtension();
        return consoleExtension.getPropertySource(object, selectedQueryPage);
    /*return (IPropertySource) selectedQueryPage.getAdapter(IPropertySource.class);
			//			 maybe we should be hooked up with the queryview to get this ?
			Session currentSession = .getSession();
			String consoleConfigName = view.getSelectedQueryPage().getConsoleConfiguration().getName();
			if((currentSession.isOpen() && currentSession.contains(object)) || hasMetaData( object, currentSession) ) {
				return new EntityPropertySource(object, currentSession, consoleConfigName);	
			} else {*/
    // return null;
    // }
    }
}
Also used : IPropertySource(org.eclipse.ui.views.properties.IPropertySource) QueryPage(org.hibernate.console.QueryPage) ConsoleExtension(org.hibernate.eclipse.console.common.ConsoleExtension)

Aggregations

QueryPage (org.hibernate.console.QueryPage)8 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)3 Test (org.junit.Test)3 Command (org.hibernate.console.execution.ExecutionContext.Command)2 ISession (org.jboss.tools.hibernate.runtime.spi.ISession)2 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabFolder2Adapter (org.eclipse.swt.custom.CTabFolder2Adapter)1 CTabFolderEvent (org.eclipse.swt.custom.CTabFolderEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)1 ConsoleQueryParameter (org.hibernate.console.ConsoleQueryParameter)1 QueryInputModel (org.hibernate.console.QueryInputModel)1 ConsoleExtension (org.hibernate.eclipse.console.common.ConsoleExtension)1 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)1 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)1 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)1 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)1