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;
}
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;
}
}
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);
}
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;
}
Aggregations