Search in sources :

Example 11 with IPrimaryKey

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

the class TableFacadeTest method testGetPrimaryKey.

@Test
public void testGetPrimaryKey() {
    Table table = new Table();
    PrimaryKey primaryKey = new PrimaryKey(table);
    ITable tableFacade = FACADE_FACTORY.createTable(table);
    Assert.assertNull(tableFacade.getPrimaryKey());
    table.setPrimaryKey(primaryKey);
    IPrimaryKey primaryKeyFacade = tableFacade.getPrimaryKey();
    Assert.assertSame(primaryKey, ((IFacade) primaryKeyFacade).getTarget());
}
Also used : Table(org.hibernate.mapping.Table) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) PrimaryKey(org.hibernate.mapping.PrimaryKey) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) Test(org.junit.Test)

Example 12 with IPrimaryKey

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

the class TypeMappingView method doAdd.

private void doAdd() {
    ISelection selection = viewer.getSelection();
    if (!selection.isEmpty()) {
        StructuredSelection ss = (StructuredSelection) selection;
        Iterator<?> iterator = ss.iterator();
        while (iterator.hasNext()) {
            Object sel = iterator.next();
            if (sel instanceof IColumn) {
                IColumn col = (IColumn) sel;
                Integer sqlTypeCode = col.getSqlTypeCode();
                createTypeMapping(col, sqlTypeCode);
            } else if (sel instanceof IPrimaryKey) {
                IPrimaryKey pk = (IPrimaryKey) sel;
                Iterator<IColumn> iter = pk.columnIterator();
                while (iter.hasNext()) {
                    IColumn column = (IColumn) iter.next();
                    createTypeMapping(column, column.getSqlTypeCode());
                }
            } else {
                createDefaultSqlTypeMapping();
            }
        }
    } else {
        createDefaultSqlTypeMapping();
    }
}
Also used : IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Iterator(java.util.Iterator) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)

Example 13 with IPrimaryKey

use of org.jboss.tools.hibernate.runtime.spi.IPrimaryKey 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 14 with IPrimaryKey

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

the class TableFacadeTest method testGetPrimaryKey.

@Test
public void testGetPrimaryKey() {
    PrimaryKey primaryKey = new PrimaryKey();
    Table table = new Table();
    ITable tableFacade = FACADE_FACTORY.createTable(table);
    Assert.assertNull(tableFacade.getPrimaryKey());
    table.setPrimaryKey(primaryKey);
    IPrimaryKey primaryKeyFacade = tableFacade.getPrimaryKey();
    Assert.assertSame(primaryKey, ((IFacade) primaryKeyFacade).getTarget());
}
Also used : Table(org.hibernate.mapping.Table) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) PrimaryKey(org.hibernate.mapping.PrimaryKey) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) Test(org.junit.Test)

Example 15 with IPrimaryKey

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

the class FacadeFactoryTest method testCreatePrimaryKey.

@Test
public void testCreatePrimaryKey() {
    PrimaryKey primaryKey = new PrimaryKey();
    IPrimaryKey facade = facadeFactory.createPrimaryKey(primaryKey);
    Assert.assertSame(primaryKey, ((IFacade) facade).getTarget());
}
Also used : PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) Test(org.junit.Test)

Aggregations

IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)20 Test (org.junit.Test)17 PrimaryKey (org.hibernate.mapping.PrimaryKey)16 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)11 Table (org.hibernate.mapping.Table)8 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 ConsoleQueryParameter (org.hibernate.console.ConsoleQueryParameter)1 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)1 QueryInputModel (org.hibernate.console.QueryInputModel)1 QueryPage (org.hibernate.console.QueryPage)1 IRevEngColumn (org.hibernate.eclipse.console.model.IRevEngColumn)1