Search in sources :

Example 1 with LazyDatabaseSchema

use of org.hibernate.eclipse.console.workbench.LazyDatabaseSchema in project jbosstools-hibernate by jbosstools.

the class ReverseEngineeringEditor method getLazyDatabaseSchema.

public LazyDatabaseSchema getLazyDatabaseSchema() {
    try {
        ConsoleConfiguration configuration = KnownConfigurations.getInstance().find(getConsoleConfigurationName());
        if (configuration == null) {
            configuration = askForConsoleConfiguration();
            if (configuration == null) {
                return null;
            } else {
                setConsoleConfigurationName(configuration.getName());
            }
        }
        org.hibernate.eclipse.console.model.ITableFilter[] tableFilters = getReverseEngineeringDefinition().getTableFilters();
        IService service = configuration.getHibernateExtension().getHibernateService();
        IOverrideRepository repository = service.newOverrideRepository();
        boolean hasIncludes = false;
        for (int i = 0; i < tableFilters.length; i++) {
            org.hibernate.eclipse.console.model.ITableFilter filter = tableFilters[i];
            ITableFilter tf = service.newTableFilter();
            tf.setExclude(filter.getExclude());
            if (filter.getExclude() != null && !filter.getExclude().booleanValue()) {
                hasIncludes = true;
            }
            tf.setMatchCatalog(filter.getMatchCatalog());
            tf.setMatchName(filter.getMatchName());
            tf.setMatchSchema(filter.getMatchSchema());
            repository.addTableFilter(tf);
        }
        ITableFilter tf = service.newTableFilter();
        tf.setExclude(Boolean.FALSE);
        // $NON-NLS-1$
        tf.setMatchCatalog(".*");
        // $NON-NLS-1$
        tf.setMatchSchema(".*");
        // $NON-NLS-1$
        tf.setMatchName(".*");
        repository.addTableFilter(tf);
        String dialogId = ReverseEngineeringEditor.class.getName();
        if (tableFilters.length == 0 && OptionalMessageDialog.isDialogEnabled(dialogId)) {
            int returnCode = OptionalMessageDialog.open(dialogId, getContainer().getShell(), MapperMessages.ReverseEngineeringEditor_no_filters_defined, null, MapperMessages.ReverseEngineeringEditor_no_filters_has_been_defined, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            if (returnCode == Window.CANCEL)
                return null;
        }
        LazyDatabaseSchema lazyDatabaseSchema = new LazyDatabaseSchema(configuration, repository.getReverseEngineeringStrategy(service.newDefaultReverseEngineeringStrategy()));
        return lazyDatabaseSchema;
    } catch (Exception he) {
        HibernateConsolePlugin.getDefault().showError(getContainer().getShell(), MapperMessages.ReverseEngineeringEditor_error_while_refreshing_databasetree, he);
        return null;
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 2 with LazyDatabaseSchema

use of org.hibernate.eclipse.console.workbench.LazyDatabaseSchema in project jbosstools-hibernate by jbosstools.

the class TableFilterFormPart method createClient.

public Control createClient(IManagedForm form) {
    FormToolkit toolkit = form.getToolkit();
    composite = new TableFilterView(getSection(), SWT.NULL) {

        protected void doRefreshTree() {
            LazyDatabaseSchema lazyDatabaseSchema = configNamePart.getLazyDatabaseSchema();
            if (lazyDatabaseSchema != null) {
                viewer.setInput(lazyDatabaseSchema);
            }
        }

        protected String getConsoleConfigurationName() {
            return configNamePart.getConsoleConfigurationName();
        }
    };
    adaptRecursively(toolkit, composite);
    return composite;
}
Also used : FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) TableFilterView(org.hibernate.eclipse.console.wizards.TableFilterView) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema)

Example 3 with LazyDatabaseSchema

use of org.hibernate.eclipse.console.workbench.LazyDatabaseSchema in project jbosstools-hibernate by jbosstools.

the class TypeMappingFormPart method createClient.

public Control createClient(IManagedForm form) {
    FormToolkit toolkit = form.getToolkit();
    composite = new TypeMappingView(getSection(), SWT.NULL) {

        protected void doRefreshTree() {
            LazyDatabaseSchema lazyDatabaseSchema = configNamePart.getLazyDatabaseSchema();
            if (lazyDatabaseSchema != null) {
                viewer.setInput(lazyDatabaseSchema);
            }
        }

        protected String getConsoleConfigurationName() {
            return configNamePart.getConsoleConfigurationName();
        }
    };
    GridData gd = new GridData(SWT.FILL, SWT.FILL);
    gd.heightHint = 400;
    composite.setLayoutData(gd);
    adaptRecursively(toolkit, composite);
    return composite;
}
Also used : FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema) GridData(org.eclipse.swt.layout.GridData)

Example 4 with LazyDatabaseSchema

use of org.hibernate.eclipse.console.workbench.LazyDatabaseSchema in project jbosstools-hibernate by jbosstools.

the class TypeMappingView method doRefreshTree.

protected void doRefreshTree() {
    ConsoleConfiguration configuration = KnownConfigurations.getInstance().find(getConsoleConfigurationName());
    viewer.setInput(new LazyDatabaseSchema(configuration));
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema)

Example 5 with LazyDatabaseSchema

use of org.hibernate.eclipse.console.workbench.LazyDatabaseSchema 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

LazyDatabaseSchema (org.hibernate.eclipse.console.workbench.LazyDatabaseSchema)5 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 GridData (org.eclipse.swt.layout.GridData)1 PartInitException (org.eclipse.ui.PartInitException)1 IRevEngColumn (org.hibernate.eclipse.console.model.IRevEngColumn)1 IRevEngTable (org.hibernate.eclipse.console.model.IRevEngTable)1 TableFilterView (org.hibernate.eclipse.console.wizards.TableFilterView)1 CheckedTreeSelectionDialog (org.hibernate.eclipse.mapper.editors.reveng.xpl.CheckedTreeSelectionDialog)1 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)1 IOverrideRepository (org.jboss.tools.hibernate.runtime.spi.IOverrideRepository)1 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)1 IService (org.jboss.tools.hibernate.runtime.spi.IService)1 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)1 ITableFilter (org.jboss.tools.hibernate.runtime.spi.ITableFilter)1