Search in sources :

Example 26 with Nullable

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

the class DB2TableReferenceCache method fetchObjectRow.

@Nullable
@Override
protected DB2TableKeyColumn[] fetchObjectRow(JDBCSession session, DB2Table db2Table, DB2TableReference db2TableReference, JDBCResultSet dbResult) throws SQLException, DBException {
    String colName = JDBCUtils.safeGetString(dbResult, "COLNAME");
    DB2TableColumn tableColumn = db2Table.getAttribute(session.getProgressMonitor(), colName);
    if (tableColumn == null) {
        log.debug("DB2TableReferenceCache : Column '" + colName + "' not found in table '" + db2Table.getName() + "' ??");
        return null;
    } else {
        return new DB2TableKeyColumn[] { new DB2TableKeyColumn(db2TableReference, tableColumn, JDBCUtils.safeGetInt(dbResult, "COLSEQ")) };
    }
}
Also used : DB2TableKeyColumn(org.jkiss.dbeaver.ext.db2.model.DB2TableKeyColumn) DB2TableColumn(org.jkiss.dbeaver.ext.db2.model.DB2TableColumn) Nullable(org.jkiss.code.Nullable)

Example 27 with Nullable

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

the class TableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<MySQLTable> getScriptListener() {
    return new SQLScriptStatusDialog<MySQLTable>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull MySQLTable object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (resultSet == null) {
                return;
            }
            Map<String, String> statusMap = new LinkedHashMap<>();
            while (resultSet.nextRow()) {
                statusMap.put(CommonUtils.toString(resultSet.getAttributeValue("Msg_type")), CommonUtils.toString(resultSet.getAttributeValue("Msg_text")));
            }
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null && !statusMap.isEmpty()) {
                if (statusMap.size() == 1) {
                    treeItem.setText(1, statusMap.values().iterator().next());
                } else {
                    String statusText = statusMap.get("status");
                    if (!CommonUtils.isEmpty(statusText)) {
                        treeItem.setText(1, statusText);
                    }
                    for (Map.Entry<String, String> status : statusMap.entrySet()) {
                        if (!status.getKey().equals("status")) {
                            TreeItem subItem = new TreeItem(treeItem, SWT.NONE);
                            subItem.setText(0, status.getKey());
                            subItem.setText(1, status.getValue());
                        }
                    }
                    treeItem.setExpanded(true);
                }
            }
        }
    };
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) MySQLTable(org.jkiss.dbeaver.ext.mysql.model.MySQLTable) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) LinkedHashMap(java.util.LinkedHashMap) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Nullable(org.jkiss.code.Nullable)

Example 28 with Nullable

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

the class TableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
    return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (statement == null) {
                return;
            }
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                try {
                    int warnNum = 0;
                    SQLWarning warning = ((JDBCStatement) statement).getWarnings();
                    while (warning != null) {
                        if (warnNum == 0) {
                            treeItem.setText(1, warning.getMessage());
                        } else {
                            TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
                            warnItem.setText(0, "");
                            warnItem.setText(1, warning.getMessage());
                        }
                        warnNum++;
                        warning = warning.getNextWarning();
                    }
                    if (warnNum == 0) {
                        treeItem.setText(1, "Done");
                    }
                } catch (SQLException e) {
                // ignore
                }
                treeItem.setExpanded(true);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
            super.endObjectProcessing(object, error);
            if (error != null) {
                TreeItem treeItem = getTreeItem(object);
                if (treeItem != null) {
                    treeItem.setText(1, error.getMessage());
                }
            }
        }
    };
}
Also used : SQLWarning(java.sql.SQLWarning) TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) PostgreObject(org.jkiss.dbeaver.ext.postgresql.model.PostgreObject) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 29 with Nullable

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

the class DBObjectNameCaseTransformer method transformName.

@Nullable
public static String transformName(@NotNull DBPDataSource dataSource, @Nullable String value) {
    if (value == null) {
        return null;
    }
    final boolean isNameCaseSensitive = dataSource.getContainer().getPreferenceStore().getBoolean(ModelPreferences.META_CASE_SENSITIVE);
    if (isNameCaseSensitive || !(dataSource instanceof SQLDataSource)) {
        return value;
    }
    final SQLDialect dialect = ((SQLDataSource) dataSource).getSQLDialect();
    if (DBUtils.isQuotedIdentifier(dataSource, value)) {
        if (dialect.supportsQuotedMixedCase()) {
            return value;
        }
    }
    if (dialect.supportsUnquotedMixedCase()) {
        return value;
    }
    String xName = dialect.storesUnquotedCase().transform(value);
    if (!DBUtils.getQuotedIdentifier(dataSource, xName).equals(xName)) {
        // Name contains special characters and has to be quoted - leave it as is
        return value;
    }
    return xName;
}
Also used : SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) SQLDataSource(org.jkiss.dbeaver.model.sql.SQLDataSource) Nullable(org.jkiss.code.Nullable)

Example 30 with Nullable

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

the class DataSourcePropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof DBPContextProvider)) {
        return false;
    }
    DBPContextProvider contextProvider = (DBPContextProvider) receiver;
    @Nullable DBCExecutionContext context = contextProvider.getExecutionContext();
    switch(property) {
        case PROP_CONNECTED:
            boolean isConnected;
            if (context != null) {
                isConnected = context.getDataSource().getContainer().isConnected();
            } else if (receiver instanceof IDataSourceContainerProvider) {
                DBPDataSourceContainer container = ((IDataSourceContainerProvider) receiver).getDataSourceContainer();
                isConnected = container != null && container.isConnected();
            } else {
                isConnected = false;
            }
            boolean checkConnected = Boolean.TRUE.equals(expectedValue);
            return checkConnected ? isConnected : !isConnected;
        case PROP_TRANSACTIONAL:
            if (context == null) {
                return false;
            }
            if (!context.isConnected()) {
                return Boolean.FALSE.equals(expectedValue);
            }
            DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
            try {
                return txnManager != null && Boolean.valueOf(!txnManager.isAutoCommit()).equals(expectedValue);
            } catch (DBCException e) {
                log.debug("Error checking auto-commit state", e);
                return false;
            }
        case PROP_TRANSACTION_ACTIVE:
            if (context != null && context.isConnected()) {
                boolean active = QMUtils.isTransactionActive(context);
                return Boolean.valueOf(active).equals(expectedValue);
            }
            return Boolean.FALSE.equals(expectedValue);
    }
    return false;
}
Also used : IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) Nullable(org.jkiss.code.Nullable)

Aggregations

Nullable (org.jkiss.code.Nullable)49 DBException (org.jkiss.dbeaver.DBException)6 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NotNull (org.jkiss.code.NotNull)5 SQLException (java.sql.SQLException)4 Matcher (java.util.regex.Matcher)4 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)3 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 Font (org.eclipse.swt.graphics.Font)2