Search in sources :

Example 11 with Nullable

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

the class EditorUtils method getFileDataSource.

@Nullable
public static DBPDataSourceContainer getFileDataSource(IFile file) {
    try {
        if (!file.exists()) {
            return null;
        }
        String projectId = file.getPersistentProperty(QN_PROJECT_ID);
        String dataSourceId = file.getPersistentProperty(QN_DATA_SOURCE_ID);
        if (dataSourceId != null) {
            IProject project = file.getProject();
            if (projectId != null) {
                final IProject fileProject = DBeaverCore.getInstance().getWorkspace().getRoot().getProject(projectId);
                if (fileProject != null && fileProject.exists()) {
                    project = fileProject;
                }
            }
            DataSourceRegistry dataSourceRegistry = DBeaverCore.getInstance().getProjectRegistry().getDataSourceRegistry(project);
            return dataSourceRegistry == null ? null : dataSourceRegistry.getDataSource(dataSourceId);
        } else {
            return null;
        }
    } catch (CoreException e) {
        log.error("Internal error while reading file property", e);
        return null;
    }
}
Also used : DataSourceRegistry(org.jkiss.dbeaver.registry.DataSourceRegistry) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) Nullable(org.jkiss.code.Nullable)

Example 12 with Nullable

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

the class DB2TableForeignKeyCache method fetchObjectRow.

@Nullable
@Override
protected DB2TableKeyColumn[] fetchObjectRow(JDBCSession session, DB2Table db2Table, DB2TableForeignKey object, JDBCResultSet dbResult) throws SQLException, DBException {
    String colName = JDBCUtils.safeGetString(dbResult, "COLNAME");
    DB2TableColumn tableColumn = db2Table.getAttribute(session.getProgressMonitor(), colName);
    if (tableColumn == null) {
        log.debug("DB2TableForeignKeyCache : Column '" + colName + "' not found in table '" + db2Table.getFullyQualifiedName(DBPEvaluationContext.UI) + "' ??");
        return null;
    } else {
        return new DB2TableKeyColumn[] { new DB2TableKeyColumn(object, 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 13 with Nullable

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

the class OracleMaintenanceDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<T> getScriptListener() {
    return new SQLScriptStatusDialog<T>(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 T object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
        }

        @Override
        public void endObjectProcessing(@NotNull T object, Exception error) {
            super.endObjectProcessing(object, error);
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                treeItem.setText(1, error == null ? "Done" : error.getMessage());
            }
        }
    };
}
Also used : SWT(org.eclipse.swt.SWT) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) Nullable(org.jkiss.code.Nullable) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 14 with Nullable

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

the class PostgreDataSource method getErrorPosition.

@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull DBRProgressMonitor monitor, @NotNull DBCExecutionContext context, @NotNull String query, @NotNull Throwable error) {
    String message = error.getMessage();
    if (!CommonUtils.isEmpty(message)) {
        Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
        if (matcher.find()) {
            DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
            pos.position = Integer.parseInt(matcher.group(1)) - 1;
            return new ErrorPosition[] { pos };
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) DBPErrorAssistant(org.jkiss.dbeaver.model.DBPErrorAssistant) Nullable(org.jkiss.code.Nullable)

Example 15 with Nullable

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

the class OracleDataSource method getErrorPosition.

@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull DBRProgressMonitor monitor, @NotNull DBCExecutionContext context, @NotNull String query, @NotNull Throwable error) {
    while (error instanceof DBException) {
        if (error.getCause() == null) {
            break;
        }
        error = error.getCause();
    }
    String message = error.getMessage();
    if (!CommonUtils.isEmpty(message)) {
        Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
        List<ErrorPosition> positions = new ArrayList<>();
        while (matcher.find()) {
            DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
            pos.info = matcher.group(1);
            pos.line = Integer.parseInt(matcher.group(1)) - 1;
            pos.position = Integer.parseInt(matcher.group(2)) - 1;
            positions.add(pos);
        }
        if (!positions.isEmpty()) {
            return positions.toArray(new ErrorPosition[positions.size()]);
        }
    }
    if (error instanceof SQLException && SQLState.SQL_42000.getCode().equals(((SQLException) error).getSQLState())) {
        try (JDBCSession session = (JDBCSession) context.openSession(monitor, DBCExecutionPurpose.UTIL, "Extract last error position")) {
            try (CallableStatement stat = session.prepareCall("declare\n" + "  l_cursor integer default dbms_sql.open_cursor; \n" + "begin \n" + "  begin \n" + "  dbms_sql.parse(  l_cursor, ?, dbms_sql.native ); \n" + "    exception \n" + "      when others then ? := dbms_sql.last_error_position; \n" + "    end; \n" + "    dbms_sql.close_cursor( l_cursor );\n" + "end;")) {
                stat.setString(1, query);
                stat.registerOutParameter(2, Types.INTEGER);
                stat.execute();
                int errorPos = stat.getInt(2);
                if (errorPos <= 0) {
                    return null;
                }
                DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
                pos.position = errorPos;
                return new ErrorPosition[] { pos };
            } catch (SQLException e) {
                // Something went wrong
                log.debug("Can't extract parse error info: " + e.getMessage());
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Matcher(java.util.regex.Matcher) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) 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