Search in sources :

Example 46 with Nullable

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

the class OpenHandler method getCurrentConnection.

@Nullable
private static DBPDataSourceContainer getCurrentConnection(ExecutionEvent event) {
    DBPDataSourceContainer dataSourceContainer = getDataSourceContainer(event, false);
    final ProjectRegistry projectRegistry = DBeaverCore.getInstance().getProjectRegistry();
    IProject project = dataSourceContainer != null ? dataSourceContainer.getRegistry().getProject() : projectRegistry.getActiveProject();
    if (dataSourceContainer == null) {
        final DataSourceRegistry dataSourceRegistry = projectRegistry.getDataSourceRegistry(project);
        if (dataSourceRegistry == null) {
            return null;
        }
        if (dataSourceRegistry.getDataSources().size() == 1) {
            dataSourceContainer = dataSourceRegistry.getDataSources().get(0);
        } else if (!dataSourceRegistry.getDataSources().isEmpty()) {
            dataSourceContainer = SelectDataSourceDialog.selectDataSource(HandlerUtil.getActiveShell(event), project);
        }
    }
    return dataSourceContainer;
}
Also used : DataSourceRegistry(org.jkiss.dbeaver.registry.DataSourceRegistry) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IProject(org.eclipse.core.resources.IProject) Nullable(org.jkiss.code.Nullable)

Example 47 with Nullable

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

the class JDBCNumberValueHandler method fetchColumnValue.

@Nullable
@Override
protected Object fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index) throws DBCException, SQLException {
    Number value;
    switch(type.getTypeID()) {
        case Types.DOUBLE:
        case Types.REAL:
            value = resultSet.getDouble(index);
            break;
        case Types.FLOAT:
            try {
                // Read value with maximum precision. Some drivers reports FLOAT but means double [JDBC:SQLite]
                value = resultSet.getDouble(index);
            } catch (SQLException e) {
                value = resultSet.getFloat(index);
            }
            break;
        case Types.INTEGER:
            try {
                // Read value with maximum precision. Some drivers reports INTEGER but means long [JDBC:SQLite]
                value = resultSet.getLong(index);
            } catch (SQLException e) {
                value = resultSet.getInt(index);
            }
            break;
        case Types.SMALLINT:
            // Read int in case of unsigned shorts
            value = resultSet.getInt(index);
            break;
        case Types.TINYINT:
            // Read short in case of unsigned byte
            value = resultSet.getShort(index);
            break;
        case Types.BIT:
            if (type.getPrecision() <= 1) {
                // single bit
                value = resultSet.getByte(index);
            } else {
                // bit string
                return CommonUtils.toBinaryString(resultSet.getLong(index), type.getPrecision());
            }
            break;
        default:
            // Here may be any numeric value. BigDecimal or BigInteger for example
            boolean gotValue = false;
            value = null;
            try {
                Object objectValue = resultSet.getObject(index);
                if (objectValue == null || objectValue instanceof Number) {
                    value = (Number) objectValue;
                    gotValue = true;
                }
            } catch (SQLException e) {
                log.debug(e);
            }
            if (value == null && !gotValue) {
                if (type.getScale() > 0) {
                    value = resultSet.getDouble(index);
                } else {
                    value = resultSet.getLong(index);
                }
            }
            break;
    }
    if (resultSet.wasNull()) {
        return null;
    } else {
        return value;
    }
}
Also used : SQLException(java.sql.SQLException) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) Nullable(org.jkiss.code.Nullable)

Example 48 with Nullable

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

the class DBNModel method getNodeByObject.

@Nullable
public DBNDatabaseNode getNodeByObject(DBRProgressMonitor monitor, DBSObject object, boolean addFiltered) {
    DBNDatabaseNode node = getNodeByObject(object);
    if (node != null) {
        return node;
    }
    DBSObject[] path = DBUtils.getObjectPath(object, true);
    for (int i = 0; i < path.length - 1; i++) {
        DBSObject item = path[i];
        DBSObject nextItem = path[i + 1];
        node = getNodeByObject(item);
        if (node == null) {
            return null;
        }
        try {
            cacheNodeChildren(monitor, node, nextItem, addFiltered);
        } catch (DBException e) {
            log.error(e.getMessage());
            return null;
        }
    }
    return getNodeByObject(object);
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) Nullable(org.jkiss.code.Nullable)

Example 49 with Nullable

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

the class SQLUtils method getScriptDescription.

@Nullable
public static String getScriptDescription(@NotNull IFile sqlScript) {
    try {
        //log.debug("Read script '" + sqlScript.getName() + "' description");
        StringBuilder sql = new StringBuilder();
        try (BufferedReader is = new BufferedReader(new InputStreamReader(sqlScript.getContents()))) {
            for (; ; ) {
                String line = is.readLine();
                if (line == null) {
                    break;
                }
                line = line.trim();
                if (line.startsWith(SQLConstants.SL_COMMENT) || line.startsWith("Rem") || line.startsWith("rem") || line.startsWith("REM")) {
                    continue;
                }
                sql.append(line).append('\n');
                if (sql.length() > MIN_SQL_DESCRIPTION_LENGTH) {
                    break;
                }
            }
        }
        return SQLUtils.getScriptDescripion(sql.toString());
    } catch (Exception e) {
        log.warn("", e);
    }
    return null;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) 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