Search in sources :

Example 41 with IColumn

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

the class TableFilterView method toggle.

protected void toggle(boolean exclude) {
    ConsoleConfiguration cc = getConsoleConfiguration();
    if (cc == null)
        return;
    ISelection selection = viewer.getSelection();
    if (!selection.isEmpty()) {
        StructuredSelection ss = (StructuredSelection) selection;
        Iterator<?> iterator = ss.iterator();
        while (iterator.hasNext()) {
            Object sel = iterator.next();
            ITableFilter filter = null;
            if (sel instanceof ITable) {
                ITable table = (ITable) sel;
                filter = revEngDef.createTableFilter(cc);
                if (StringHelper.isNotEmpty(table.getName())) {
                    filter.setMatchName(table.getName());
                }
                if (StringHelper.isNotEmpty(table.getCatalog())) {
                    filter.setMatchCatalog(table.getCatalog());
                }
                if (StringHelper.isNotEmpty(table.getSchema())) {
                    filter.setMatchSchema(table.getSchema());
                }
                filter.setExclude(Boolean.valueOf(exclude));
            } else if (sel instanceof TableContainer) {
                // assume its a
                // schema!
                TableContainer tc = (TableContainer) sel;
                filter = revEngDef.createTableFilter(cc);
                String schema = tc.getName();
                if (schema == null || "".equals(schema)) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$
                    filter.setMatchCatalog(".*");
                    // $NON-NLS-1$
                    filter.setMatchSchema(".*");
                } else {
                    // fake catalog handling
                    String catalog = StringHelper.qualifier(schema);
                    schema = StringHelper.unqualify(schema);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    filter.setMatchCatalog("".equals(catalog) ? ".*" : catalog);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    filter.setMatchSchema("".equals(schema) ? ".*" : schema);
                }
                // $NON-NLS-1$
                filter.setMatchName(".*");
                filter.setExclude(Boolean.valueOf(exclude));
            } else if (sel instanceof IColumn) {
                // we ignore column since at the moment we dont know which table is there.
                return;
            } else {
                filter = revEngDef.createTableFilter(cc);
                filter.setExclude(Boolean.valueOf(exclude));
            }
            if (filter != null)
                revEngDef.addTableFilter(filter);
        }
    } else {
        ITableFilter filter = revEngDef.createTableFilter(cc);
        // $NON-NLS-1$
        filter.setMatchName(".*");
        filter.setExclude(Boolean.valueOf(exclude));
        revEngDef.addTableFilter(filter);
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ITableFilter(org.hibernate.eclipse.console.model.ITableFilter) TableContainer(org.hibernate.eclipse.console.workbench.TableContainer) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Example 42 with IColumn

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

the class TableViewAdapter method getColumns.

public List<ColumnViewAdapter> getColumns() {
    List<ColumnViewAdapter> result = new ArrayList<ColumnViewAdapter>();
    Iterator<IColumn> columnIterator = table.getColumnIterator();
    while (columnIterator.hasNext()) {
        IColumn element = columnIterator.next();
        result.add(new ColumnViewAdapter(this, element));
    }
    return result;
}
Also used : IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ArrayList(java.util.ArrayList)

Example 43 with IColumn

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

the class TypeVisitor method visit.

@Override
public boolean visit(SimpleType type) {
    ITypeBinding tb = type.resolveBinding();
    // Unresolved binding. Omit the property.
    if (tb == null)
        return false;
    ITypeBinding[] interfaces = Utils.getAllInterfaces(tb);
    IValue value = buildCollectionValue(interfaces);
    if (value != null) {
        // $NON-NLS-1$
        IValue element = buildSimpleValue("string");
        value.setElement(element);
        // TODO what to set?
        value.setCollectionTable(rootClass.getTable());
        buildProperty(value);
        if (value.isList()) {
            value.setIndex(service.newSimpleValue());
        } else if (value.isMap()) {
            IValue map_key = service.newSimpleValue();
            // FIXME: how to detect key-type here
            // $NON-NLS-1$
            map_key.setTypeName("string");
            value.setIndex(map_key);
        }
        // $NON-NLS-1$
        prop.setCascade("none");
    } else if (tb.isEnum()) {
        // $NON-NLS-1$
        value = buildSimpleValue("org.hibernate.type.EnumType");
        Properties typeParameters = new Properties();
        // $NON-NLS-1$
        typeParameters.put("enumClass", tb.getBinaryName());
        // $NON-NLS-1$
        typeParameters.put("type", java.sql.Types.VARCHAR);
        value.setTypeParameters(typeParameters);
        buildProperty(value);
    } else if (ref != null) /*&& ref.fullyQualifiedName.indexOf('$') < 0*/
    {
        IValue sValue = null;
        if (ref.refType == RefType.MANY2ONE) {
            sValue = service.newManyToOne(rootClass.getTable());
        } else if (ref.refType == RefType.ONE2ONE) {
            sValue = service.newOneToOne(rootClass);
        } else if (ref.refType == RefType.UNDEF) {
            sValue = service.newOneToOne(rootClass);
        } else {
            // OneToMany and ManyToMany must be a collection
            throw new IllegalStateException(ref.refType.toString());
        }
        IColumn column = service.newColumn(varName.toUpperCase());
        sValue.addColumn(column);
        sValue.setTypeName(tb.getBinaryName());
        sValue.setFetchModeJoin();
        sValue.setReferencedEntityName(ref.fullyQualifiedName);
        buildProperty(sValue);
        // $NON-NLS-1$
        prop.setCascade("none");
    } else {
        value = buildSimpleValue(tb.getBinaryName());
        buildProperty(value);
    }
    return super.visit(type);
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Properties(java.util.Properties)

Example 44 with IColumn

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

the class ColumnNameHandler method attributeCompletionProposals.

public ICompletionProposal[] attributeCompletionProposals(IJavaProject javaProject, Node node, String attributeName, String start, int offset) {
    List columns = new ArrayList();
    HibernateNature nature = HibernateNature.getHibernateNature(javaProject);
    if (nature != null) {
        String nearestTableName = extractor.getNearestTableName(node);
        if (nearestTableName != null) {
            ITable table = nature.getTable(nearestTableName);
            if (table != null) {
                Iterator tableMappings = table.getColumnIterator();
                while (tableMappings.hasNext()) {
                    IColumn column = (IColumn) tableMappings.next();
                    if (column.getName().toUpperCase().startsWith(start.toUpperCase())) {
                        columns.add(column);
                    }
                }
            }
        }
    }
    List proposals = new ArrayList();
    for (Iterator iter = columns.iterator(); iter.hasNext(); ) {
        IColumn element = (IColumn) iter.next();
        proposals.add(new CompletionProposal(element.getName(), offset, start.length(), element.getName().length(), null, null, null, null));
    }
    return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) HibernateNature(org.hibernate.eclipse.nature.HibernateNature)

Example 45 with IColumn

use of org.jboss.tools.hibernate.runtime.spi.IColumn 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)

Aggregations

IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)86 Test (org.junit.Test)69 Column (org.hibernate.mapping.Column)68 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)26 SimpleValue (org.hibernate.mapping.SimpleValue)16 Table (org.hibernate.mapping.Table)16 ArrayList (java.util.ArrayList)12 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)9 AbstractForeignKeyFacade (org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade)7 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)7 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)7 Iterator (java.util.Iterator)5 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)3 Shape (org.jboss.tools.hibernate.ui.diagram.editors.model.Shape)3 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 List (java.util.List)2