Search in sources :

Example 6 with ExasolTableBase

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.

the class ExasolExportTableTool method execute.

@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
    List<ExasolTable> tables = CommonUtils.filterCollection(objects, ExasolTable.class);
    List<ExasolView> views = CommonUtils.filterCollection(objects, ExasolView.class);
    List<ExasolSchema> schemas = CommonUtils.filterCollection(objects, ExasolSchema.class);
    // add tables for all Schemas but ignore views in schema
    for (ExasolSchema schema : schemas) {
        tables.addAll(schema.getTables(new VoidProgressMonitor()));
    }
    // create TableBase Objects list
    @SuppressWarnings({ "unchecked", "rawtypes" }) HashSet<ExasolTableBase> tableBaseObjects = new HashSet();
    // add tables
    for (ExasolTable table : tables) {
        tableBaseObjects.add((ExasolTableBase) table);
    }
    // add views
    for (ExasolView view : views) {
        tableBaseObjects.add((ExasolTableBase) view);
    }
    if (!tableBaseObjects.isEmpty()) {
        ExasolExportTableToolDialog dialog = new ExasolExportTableToolDialog(activePart.getSite(), tableBaseObjects);
        dialog.open();
    }
}
Also used : ExasolSchema(org.jkiss.dbeaver.ext.exasol.model.ExasolSchema) ExasolView(org.jkiss.dbeaver.ext.exasol.model.ExasolView) ExasolTableBase(org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) ExasolTable(org.jkiss.dbeaver.ext.exasol.model.ExasolTable) HashSet(java.util.HashSet)

Example 7 with ExasolTableBase

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.

the class ExasolImportTableTool method execute.

@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
    List<ExasolTable> tables = CommonUtils.filterCollection(objects, ExasolTable.class);
    List<ExasolSchema> schemas = CommonUtils.filterCollection(objects, ExasolSchema.class);
    // add tables for all Schemas but ignore views in schema
    for (ExasolSchema schema : schemas) {
        tables.addAll(schema.getTables(new VoidProgressMonitor()));
    }
    // create TableBase Objects list
    @SuppressWarnings({ "unchecked", "rawtypes" }) HashSet<ExasolTableBase> tableBaseObjects = new HashSet();
    // add tables
    for (ExasolTable table : tables) {
        tableBaseObjects.add((ExasolTableBase) table);
    }
    if (!tableBaseObjects.isEmpty()) {
        ExasolImportTableToolDialog dialog = new ExasolImportTableToolDialog(activePart.getSite(), tableBaseObjects);
        dialog.open();
    }
}
Also used : ExasolSchema(org.jkiss.dbeaver.ext.exasol.model.ExasolSchema) ExasolTableBase(org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) ExasolTable(org.jkiss.dbeaver.ext.exasol.model.ExasolTable) HashSet(java.util.HashSet)

Example 8 with ExasolTableBase

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.

the class ExasolBaseTableToolDialog method executeSQL.

@Override
protected void executeSQL() {
    final String jobName = getShell().getText();
    final SQLScriptProgressListener<ExasolTableBase> scriptListener = getScriptListener();
    final List<ExasolTableBase> objects = getCheckedObjects();
    final Map<ExasolTableBase, List<String>> objectsSQL = new LinkedHashMap<>();
    for (ExasolTableBase object : objects) {
        final List<String> lines = new ArrayList<>();
        generateObjectCommand(lines, object);
        objectsSQL.put(object, lines);
    }
    final DataSourceJob job = new DataSourceJob(jobName, null, getExecutionContext()) {

        public Exception objectProcessingError;

        @SuppressWarnings("rawtypes")
        @Override
        protected IStatus run(final DBRProgressMonitor monitor) {
            final DataSourceJob curJob = this;
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    scriptListener.beginScriptProcessing(curJob, objects);
                }
            });
            monitor.beginTask(jobName, objects.size());
            try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, jobName)) {
                for (int i = 0; i < objects.size(); i++) {
                    if (monitor.isCanceled()) {
                        break;
                    }
                    final int objectNumber = i;
                    final ExasolTableBase object = objects.get(i);
                    monitor.subTask("Process " + DBUtils.getObjectFullName(object, DBPEvaluationContext.UI));
                    objectProcessingError = null;
                    DBeaverUI.asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            scriptListener.beginObjectProcessing(object, objectNumber);
                        }
                    });
                    try {
                        final List<String> lines = objectsSQL.get(object);
                        for (String line : lines) {
                            try (final Statement statement = ((JDBCSession) session).getOriginal().createStatement()) {
                                int affectedRows = statement.executeUpdate(line);
                                Integer[] resultSetData = new Integer[] { affectedRows };
                                final LocalResultSet resultSet = new LocalResultSet<>(session, new JDBCStatementImpl<>((JDBCSession) session, statement, true));
                                resultSet.addColumn("ROWS_AFFECTED", DBPDataKind.NUMERIC);
                                resultSet.addRow((Object[]) resultSetData);
                                // Run in sync because we need result set
                                DBeaverUI.syncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        try {
                                            scriptListener.processObjectResults(object, null, resultSet);
                                        } catch (DBCException e) {
                                            objectProcessingError = e;
                                        }
                                    }
                                });
                                if (objectProcessingError != null) {
                                    break;
                                }
                            }
                        }
                    } catch (Exception e) {
                        objectProcessingError = e;
                    } finally {
                        DBeaverUI.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                scriptListener.endObjectProcessing(object, objectProcessingError);
                            }
                        });
                    }
                    monitor.worked(1);
                }
            } finally {
                monitor.done();
                DBeaverUI.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        scriptListener.endScriptProcessing();
                    }
                });
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
        }
    });
    job.schedule();
}
Also used : LocalResultSet(org.jkiss.dbeaver.model.impl.local.LocalResultSet) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) Statement(java.sql.Statement) ExasolTableBase(org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DataSourceJob(org.jkiss.dbeaver.runtime.jobs.DataSourceJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 9 with ExasolTableBase

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.

the class ExasolBaseTableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<ExasolTableBase> getScriptListener() {
    final int nbExtraColumns = getNumberExtraResultingColumns();
    return new SQLScriptStatusDialog<ExasolTableBase>(getShell(), getTitle() + " " + ExasolMessages.dialog_table_tools_progress, null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText(ExasolMessages.dialog_table_tools_result);
            for (int i = 0; i < nbExtraColumns; i++) {
                new TreeColumn(objectTree, SWT.NONE);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull ExasolTableBase exasolTable, Exception exception) {
            TreeItem treeItem = getTreeItem(exasolTable);
            if (exception == null) {
                treeItem.setText(1, ExasolMessages.dialog_table_tools_success_title);
            } else {
                treeItem.setText(1, exception.getMessage());
            }
            UIUtils.packColumns(treeItem.getParent(), false, null);
        }

        // DF: This method is for tools that return resultsets
        @Override
        public void processObjectResults(@NotNull ExasolTableBase exasolTable, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (resultSet == null) {
                return;
            }
            // Retrieve column names
            DBCResultSetMetaData rsMetaData = resultSet.getMeta();
            try {
                TreeItem treeItem = getTreeItem(exasolTable);
                Font f = UIUtils.makeBoldFont(treeItem.getFont());
                if (treeItem != null) {
                    // Display the column names
                    TreeItem subItem = null;
                    subItem = new TreeItem(treeItem, SWT.NONE);
                    subItem.setFont(f);
                    for (DBCAttributeMetaData column : rsMetaData.getAttributes()) {
                        subItem.setText(column.getOrdinalPosition(), column.getName());
                        subItem.setGrayed(true);
                    }
                    // Display the data for each row
                    while (resultSet.nextRow()) {
                        subItem = new TreeItem(treeItem, SWT.NONE);
                        for (int i = 0; i < rsMetaData.getAttributes().size(); i++) {
                            subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
                            i++;
                        }
                    }
                    treeItem.setExpanded(true);
                }
            } catch (Exception e) {
                throw new DBCException(e.getMessage());
            }
        }
    };
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ExasolTableBase(org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase) NotNull(org.jkiss.code.NotNull) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) Font(org.eclipse.swt.graphics.Font) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) Nullable(org.jkiss.code.Nullable)

Example 10 with ExasolTableBase

use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.

the class ExasolExportTableTool method execute.

@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
    List<ExasolTable> tables = CommonUtils.filterCollection(objects, ExasolTable.class);
    List<ExasolView> views = CommonUtils.filterCollection(objects, ExasolView.class);
    List<ExasolSchema> schemas = CommonUtils.filterCollection(objects, ExasolSchema.class);
    //add tables for all Schemas but ignore views in schema
    for (ExasolSchema schema : schemas) {
        tables.addAll(schema.getTables(VoidProgressMonitor.INSTANCE));
    }
    // create TableBase Objects list
    @SuppressWarnings({ "unchecked", "rawtypes" }) HashSet<ExasolTableBase> tableBaseObjects = new HashSet();
    //add tables
    for (ExasolTable table : tables) {
        tableBaseObjects.add((ExasolTableBase) table);
    }
    //add views
    for (ExasolView view : views) {
        tableBaseObjects.add((ExasolTableBase) view);
    }
    if (!tableBaseObjects.isEmpty()) {
        ExasolExportTableToolDialog dialog = new ExasolExportTableToolDialog(activePart.getSite(), tableBaseObjects);
        dialog.open();
    }
}
Also used : ExasolSchema(org.jkiss.dbeaver.ext.exasol.model.ExasolSchema) ExasolView(org.jkiss.dbeaver.ext.exasol.model.ExasolView) ExasolTableBase(org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase) ExasolTable(org.jkiss.dbeaver.ext.exasol.model.ExasolTable) HashSet(java.util.HashSet)

Aggregations

ExasolTableBase (org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase)13 HashSet (java.util.HashSet)6 ExasolSchema (org.jkiss.dbeaver.ext.exasol.model.ExasolSchema)6 ExasolTable (org.jkiss.dbeaver.ext.exasol.model.ExasolTable)6 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)4 Statement (java.sql.Statement)3 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)3 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)3 Font (org.eclipse.swt.graphics.Font)3 Tree (org.eclipse.swt.widgets.Tree)3 TreeColumn (org.eclipse.swt.widgets.TreeColumn)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 NotNull (org.jkiss.code.NotNull)3 Nullable (org.jkiss.code.Nullable)3 ExasolView (org.jkiss.dbeaver.ext.exasol.model.ExasolView)3 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)3 LocalResultSet (org.jkiss.dbeaver.model.impl.local.LocalResultSet)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)3 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)2