Search in sources :

Example 16 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 17 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(null);
    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)

Example 18 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 19 with IPrimaryKey

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

the class TableWorkbenchAdapter method getChildren.

public Object[] getChildren(Object o) {
    ITable t = getTable(o);
    List<Object> items = new ArrayList<Object>();
    IPrimaryKey primaryKey = t.getPrimaryKey();
    if (primaryKey != null) {
        items.add(primaryKey);
    }
    Iterator<?> columnIterator = t.getColumnIterator();
    while (columnIterator.hasNext()) {
        IColumn col = (IColumn) columnIterator.next();
        if (primaryKey == null || !primaryKey.containsColumn(col)) {
            // only add non-pk columns here
            items.add(col);
        }
    }
    return items.toArray(new Object[items.size()]);
}
Also used : IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ArrayList(java.util.ArrayList) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)

Example 20 with IPrimaryKey

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

the class TablePropertiesBlock method doAdd.

protected void doAdd() {
    CheckedTreeSelectionDialog dialog = createTreeSelectionDialog();
    LazyDatabaseSchema lds = editor.getLazyDatabaseSchema();
    List<ITable> tables = new ArrayList<ITable>();
    Map<ITable, List<IColumn>> columns = new HashMap<ITable, List<IColumn>>();
    if (lds == null) {
        // $NON-NLS-1$  //$NON-NLS-2$
        String tableName = "", namePrefix = "TABLE_";
        IRevEngTable retable = editor.getReverseEngineeringDefinition().createTable();
        // $NON-NLS-1$
        retable.setCatalog("");
        // $NON-NLS-1$
        retable.setSchema("");
        TreeSet<String> ts = new TreeSet<String>();
        IRevEngTable[] retables = editor.getReverseEngineeringDefinition().getTables();
        char separartor = '%';
        for (int i = 0; i < retables.length; i++) {
            ts.add(retables[i].getCatalog() + separartor + retables[i].getSchema() + separartor + retables[i].getName());
        }
        String strCatalogSchema = retable.getCatalog() + separartor + retable.getSchema() + separartor;
        int i = 0;
        do {
            tableName = namePrefix + (i++);
        } while (ts.contains(strCatalogSchema + tableName));
        retable.setName(tableName);
        editor.getReverseEngineeringDefinition().addTable(retable);
    } else {
        dialog.setTitle(MapperMessages.TablePropertiesBlock_add_tables_columns);
        dialog.setMessage(MapperMessages.TablePropertiesBlock_select_tables_columns);
        dialog.setInput(lds);
        dialog.setContainerMode(true);
        dialog.open();
        Object[] result = dialog.getResult();
        ITable lastTable = null;
        if (result != null) {
            for (int i = 0; i < result.length; i++) {
                Object object = result[i];
                if (object instanceof ITable) {
                    ITable table = (ITable) object;
                    tables.add(table);
                    lastTable = table;
                } else if (object instanceof IColumn) {
                    IColumn column = (IColumn) object;
                    List<IColumn> existing = columns.get(lastTable);
                    if (existing == null) {
                        existing = new ArrayList<IColumn>();
                        columns.put(lastTable, existing);
                    }
                    existing.add(column);
                } else if (object instanceof IPrimaryKey) {
                    List<IColumn> existing = columns.get(lastTable);
                    if (existing == null) {
                        existing = new ArrayList<IColumn>();
                        columns.put(lastTable, existing);
                    }
                    existing.addAll(((IPrimaryKey) object).getColumns());
                }
            }
        }
        Iterator<ITable> iterator = tables.iterator();
        while (iterator.hasNext()) {
            ITable table = iterator.next();
            IRevEngTable retable = null;
            // editor.getReverseEngineeringDefinition().findTable(TableIdentifier.create(table));
            if (retable == null) {
                retable = editor.getReverseEngineeringDefinition().createTable();
                retable.setCatalog(table.getCatalog());
                retable.setSchema(table.getSchema());
                retable.setName(table.getName());
                editor.getReverseEngineeringDefinition().addTable(retable);
            }
            List<IColumn> columnList = columns.get(table);
            if (columnList != null) {
                Iterator<IColumn> colIterator = columnList.iterator();
                while (colIterator.hasNext()) {
                    IColumn column = colIterator.next();
                    IRevEngColumn revCol = editor.getReverseEngineeringDefinition().createColumn();
                    revCol.setName(column.getName());
                    if (column.getSqlType() != null) {
                        // TODO: should not be required
                        revCol.setJDBCType(column.getSqlType());
                    }
                    retable.addColumn(revCol);
                }
            }
        }
    // editor.getReverseEngineeringDefinition();
    }
}
Also used : CheckedTreeSelectionDialog(org.hibernate.eclipse.mapper.editors.reveng.xpl.CheckedTreeSelectionDialog) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IRevEngColumn(org.hibernate.eclipse.console.model.IRevEngColumn) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) TreeSet(java.util.TreeSet) IRevEngTable(org.hibernate.eclipse.console.model.IRevEngTable) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) List(java.util.List) ArrayList(java.util.ArrayList)

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