Search in sources :

Example 36 with NotNull

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

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

the class OracleStructureAssistant method findObjectsByMask.

@NotNull
@Override
public List<DBSObjectReference> findObjectsByMask(DBRProgressMonitor monitor, DBSObject parentObject, DBSObjectType[] objectTypes, String objectNameMask, boolean caseSensitive, boolean globalSearch, int maxResults) throws DBException {
    OracleSchema schema = parentObject instanceof OracleSchema ? (OracleSchema) parentObject : null;
    try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Find objects by name")) {
        List<DBSObjectReference> objects = new ArrayList<>();
        // Search all objects
        searchAllObjects(session, schema, objectNameMask, objectTypes, caseSensitive, maxResults, objects);
        if (ArrayUtils.contains(objectTypes, OracleObjectType.CONSTRAINT, OracleObjectType.FOREIGN_KEY) && objects.size() < maxResults) {
            // Search constraints
            findConstraintsByMask(session, schema, objectNameMask, objectTypes, maxResults, objects);
        }
        // Sort objects. Put ones in the current schema first
        final OracleSchema activeSchema = dataSource.getDefaultObject();
        Collections.sort(objects, new Comparator<DBSObjectReference>() {

            @Override
            public int compare(DBSObjectReference o1, DBSObjectReference o2) {
                if (CommonUtils.equalObjects(o1.getContainer(), o2.getContainer())) {
                    return o1.getName().compareTo(o2.getName());
                }
                if (o1.getContainer() == null || o1.getContainer() == activeSchema) {
                    return -1;
                }
                if (o2.getContainer() == null || o2.getContainer() == activeSchema) {
                    return 1;
                }
                return o1.getContainer().getName().compareTo(o2.getContainer().getName());
            }
        });
        return objects;
    } catch (SQLException ex) {
        throw new DBException(ex, dataSource);
    }
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) NotNull(org.jkiss.code.NotNull)

Example 38 with NotNull

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

the class DefaultResourceHandlerImpl method makeNavigatorNode.

@NotNull
@Override
public DBNResource makeNavigatorNode(@NotNull DBNNode parentNode, @NotNull IResource resource) throws CoreException, DBException {
    DBNResource node = super.makeNavigatorNode(parentNode, resource);
    ProgramInfo program = ProgramInfo.getProgram(resource);
    if (program != null && program.getImage() != null) {
        node.setResourceImage(program.getImage());
    }
    return node;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) ProgramInfo(org.jkiss.dbeaver.ui.ProgramInfo) NotNull(org.jkiss.code.NotNull)

Example 39 with NotNull

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

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

the class WMIClass method readData.

@NotNull
@Override
public DBCStatistics readData(@NotNull DBCExecutionSource source, @NotNull DBCSession session, @NotNull DBDDataReceiver dataReceiver, DBDDataFilter dataFilter, long firstRow, long maxRows, long flags) throws DBCException {
    DBCStatistics statistics = new DBCStatistics();
    try {
        long startTime = System.currentTimeMillis();
        WMIObjectCollectorSink sink = new WMIObjectCollectorSink(session.getProgressMonitor(), getNamespace().getService(), firstRow, maxRows);
        getNamespace().getService().enumInstances(getName(), sink, WMIConstants.WBEM_FLAG_SHALLOW);
        statistics.setExecuteTime(System.currentTimeMillis() - startTime);
        startTime = System.currentTimeMillis();
        sink.waitForFinish();
        WMIResultSet resultSet = new WMIResultSet(session, this, sink.getObjectList());
        long resultCount = 0;
        try {
            dataReceiver.fetchStart(session, resultSet, firstRow, maxRows);
            while (resultSet.nextRow()) {
                resultCount++;
                dataReceiver.fetchRow(session, resultSet);
            }
        } finally {
            try {
                dataReceiver.fetchEnd(session, resultSet);
            } catch (DBCException e) {
                //$NON-NLS-1$
                log.error("Error while finishing result set fetch", e);
            }
            resultSet.close();
            dataReceiver.close();
        }
        statistics.setFetchTime(System.currentTimeMillis() - startTime);
        statistics.setRowsFetched(resultCount);
        return statistics;
    } catch (WMIException e) {
        throw new DBCException(e, getDataSource());
    }
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCStatistics(org.jkiss.dbeaver.model.exec.DBCStatistics) 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