Search in sources :

Example 41 with NotNull

use of org.jkiss.code.NotNull in project dbeaver by serge-rider.

the class PostgreTable method getSubInheritance.

@NotNull
public List<PostgreTableInheritance> getSubInheritance(@NotNull DBRProgressMonitor monitor) throws DBException {
    if (subTables == null) {
        try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load table inheritance info")) {
            try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT i.*,c.relnamespace " + "FROM pg_catalog.pg_inherits i,pg_catalog.pg_class c " + "WHERE i.inhparent=? AND c.oid=i.inhrelid")) {
                dbStat.setLong(1, getObjectId());
                try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                    while (dbResult.next()) {
                        final long subSchemaId = JDBCUtils.safeGetLong(dbResult, "relnamespace");
                        final long subTableId = JDBCUtils.safeGetLong(dbResult, "inhrelid");
                        PostgreSchema schema = getDatabase().getSchema(monitor, subSchemaId);
                        if (schema == null) {
                            log.warn("Can't find sub-table's schema '" + subSchemaId + "'");
                            continue;
                        }
                        PostgreTableBase subTable = schema.getTable(monitor, subTableId);
                        if (subTable == null) {
                            log.warn("Can't find sub-table '" + subTableId + "' in '" + schema.getName() + "'");
                            continue;
                        }
                        if (subTables == null) {
                            subTables = new ArrayList<>();
                        }
                        subTables.add(new PostgreTableInheritance(subTable, this, JDBCUtils.safeGetInt(dbResult, "inhseqno"), true));
                    }
                }
            }
        } catch (SQLException e) {
            throw new DBCException(e, getDataSource());
        }
        if (subTables == null) {
            subTables = Collections.emptyList();
        }
    }
    return subTables;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException) NotNull(org.jkiss.code.NotNull)

Example 42 with NotNull

use of org.jkiss.code.NotNull in project dbeaver by serge-rider.

the class SharedTextColors method getColor.

@NotNull
@Override
public Color getColor(@NotNull RGB rgb) {
    Display display = Display.getCurrent();
    if (display == null) {
        display = Display.getDefault();
    }
    final Display curDisplay = display;
    Map<RGB, Color> colorTable;
    synchronized (fDisplayTable) {
        colorTable = fDisplayTable.get(display);
        if (colorTable == null) {
            colorTable = new HashMap<>(10);
            fDisplayTable.put(curDisplay, colorTable);
            display.disposeExec(new Runnable() {

                @Override
                public void run() {
                    dispose(curDisplay);
                }
            });
        }
    }
    Color color = colorTable.get(rgb);
    if (color == null) {
        color = new Color(curDisplay, rgb);
        colorTable.put(rgb, color);
    }
    return color;
}
Also used : Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) Display(org.eclipse.swt.widgets.Display) NotNull(org.jkiss.code.NotNull)

Example 43 with NotNull

use of org.jkiss.code.NotNull 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 44 with NotNull

use of org.jkiss.code.NotNull in project dbeaver by serge-rider.

the class ExasolTableForeignKeyCache method prepareObjectsStatement.

@SuppressWarnings("rawtypes")
@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, ExasolSchema exasolSchema, ExasolTable forTable) throws SQLException {
    String sql;
    if (forTable != null) {
        sql = String.format(SQL_FK_TAB, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forTable.getName()));
    } else {
        sql = String.format(SQL_FK_ALL, ExasolUtils.quoteString(exasolSchema.getName()));
    }
    JDBCStatement dbStat = session.createStatement();
    ((JDBCStatementImpl) dbStat).setQueryString(sql);
    return dbStat;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) JDBCStatementImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl) NotNull(org.jkiss.code.NotNull)

Example 45 with NotNull

use of org.jkiss.code.NotNull in project dbeaver by serge-rider.

the class BaseSQLDialog method createSQLPanel.

protected Composite createSQLPanel(Composite parent) {
    Composite panel = UIUtils.createPlaceholder(parent, 1);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (isLabelVisible()) {
        UIUtils.createControlLabel(panel, "SQL Preview");
    }
    //        new Label(panel, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Composite editorPH = new Composite(panel, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.verticalIndent = 3;
    gd.horizontalSpan = 1;
    gd.minimumHeight = 100;
    gd.minimumWidth = 100;
    editorPH.setLayoutData(gd);
    editorPH.setLayout(new FillLayout());
    sqlViewer = new SQLEditorBase() {

        @NotNull
        @Override
        protected SQLDialect getSQLDialect() {
            return BaseSQLDialog.this.getSQLDialect();
        }

        @Override
        public DBCExecutionContext getExecutionContext() {
            return BaseSQLDialog.this.getExecutionContext();
        }
    };
    updateSQL();
    sqlViewer.createPartControl(editorPH);
    if (isWordWrap()) {
        Object text = sqlViewer.getAdapter(Control.class);
        if (text instanceof StyledText) {
            ((StyledText) text).setWordWrap(true);
        }
    }
    sqlViewer.reloadSyntaxRules();
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            sqlViewer.dispose();
        }
    });
    return panel;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent) NotNull(org.jkiss.code.NotNull)

Aggregations

NotNull (org.jkiss.code.NotNull)58 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)11 SQLException (java.sql.SQLException)9 DBCException (org.jkiss.dbeaver.model.exec.DBCException)9 DBException (org.jkiss.dbeaver.DBException)7 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)7 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)6 ArrayList (java.util.ArrayList)5 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 Nullable (org.jkiss.code.Nullable)5 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)5 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)5 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)5 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)5 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DBDValueHandler (org.jkiss.dbeaver.model.data.DBDValueHandler)3 SQLDataSource (org.jkiss.dbeaver.model.sql.SQLDataSource)3 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)3