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