use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class ConnectionPageSettings method getSubPages.
@Nullable
@Override
public IDialogPage[] getSubPages() {
if (subPages != null) {
return subPages;
}
if (this.connectionEditor == null) {
this.connectionEditor = viewDescriptor.createView(IDataSourceConnectionEditor.class);
this.connectionEditor.setSite(this);
}
if (connectionEditor instanceof ICompositeDialogPage) {
subPages = ((ICompositeDialogPage) connectionEditor).getSubPages();
if (!ArrayUtils.isEmpty(subPages)) {
for (IDialogPage page : subPages) {
if (page instanceof IDataSourceConnectionEditor) {
((IDataSourceConnectionEditor) page).setSite(this);
}
}
}
if (extraPages != null) {
subPages = ArrayUtils.concatArrays(subPages, extraPages);
}
return subPages;
} else {
return extraPages;
}
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class ExasolDataSource 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) {
return null;
}
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(2)) - 1;
pos.position = Integer.parseInt(matcher.group(3)) - 1;
positions.add(pos);
}
if (!positions.isEmpty()) {
return positions.toArray(new ErrorPosition[positions.size()]);
}
}
return null;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class SQLSemanticProcessor method getConstraintTable.
/**
* Extract alias (or source table name) for specified constraint from SQL select.
* Searches in FROM and JOIN
*/
@Nullable
public static Table getConstraintTable(PlainSelect select, DBDAttributeConstraint constraint) {
String constrTable;
DBSAttributeBase ca = constraint.getAttribute();
if (ca instanceof DBDAttributeBinding) {
constrTable = ((DBDAttributeBinding) ca).getMetaAttribute().getEntityName();
} else if (ca instanceof DBSEntityAttribute) {
constrTable = ((DBSEntityAttribute) ca).getParentObject().getName();
} else {
return null;
}
if (constrTable == null) {
return null;
}
FromItem fromItem = select.getFromItem();
Table table = findTableInFrom(fromItem, constrTable);
if (table == null) {
// Maybe it is a join
if (!CommonUtils.isEmpty(select.getJoins())) {
for (Join join : select.getJoins()) {
table = findTableInFrom(join.getRightItem(), constrTable);
if (table != null) {
break;
}
}
}
}
return table;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class SQLUtils method getConstraintCondition.
@Nullable
public static String getConstraintCondition(@NotNull DBPDataSource dataSource, @NotNull DBDAttributeConstraint constraint, boolean inlineCriteria) {
String criteria = constraint.getCriteria();
if (!CommonUtils.isEmpty(criteria)) {
final char firstChar = criteria.trim().charAt(0);
if (!Character.isLetter(firstChar) && firstChar != '=' && firstChar != '>' && firstChar != '<' && firstChar != '!') {
return '=' + criteria;
} else {
return criteria;
}
} else if (constraint.getOperator() != null) {
DBCLogicalOperator operator = constraint.getOperator();
StringBuilder conString = new StringBuilder();
Object value = constraint.getValue();
if (DBUtils.isNullValue(value)) {
if (operator.getArgumentCount() == 0) {
return operator.getStringValue();
}
conString.append("IS ");
if (constraint.isReverseOperator()) {
conString.append("NOT ");
}
conString.append("NULL");
return conString.toString();
}
if (constraint.isReverseOperator()) {
conString.append("NOT ");
}
if (operator.getArgumentCount() > 0) {
conString.append(operator.getStringValue());
for (int i = 0; i < operator.getArgumentCount(); i++) {
if (i > 0) {
conString.append(" AND");
}
if (inlineCriteria) {
conString.append(' ').append(convertValueToSQL(dataSource, constraint.getAttribute(), value));
} else {
conString.append(" ?");
}
}
} else if (operator.getArgumentCount() < 0) {
// Multiple arguments
int valueCount = Array.getLength(value);
boolean hasNull = false, hasNotNull = false;
for (int i = 0; i < valueCount; i++) {
final boolean isNull = DBUtils.isNullValue(Array.get(value, i));
if (isNull && !hasNull) {
hasNull = true;
}
if (!isNull && !hasNotNull) {
hasNotNull = true;
}
}
if (!hasNotNull) {
return "IS NULL";
}
if (hasNull) {
conString.append("IS NULL OR ").append(DBUtils.getObjectFullName(dataSource, constraint.getAttribute(), DBPEvaluationContext.DML)).append(" ");
}
conString.append(operator.getStringValue());
conString.append(" (");
if (!value.getClass().isArray()) {
value = new Object[] { value };
}
boolean hasValue = false;
for (int i = 0; i < valueCount; i++) {
Object itemValue = Array.get(value, i);
if (DBUtils.isNullValue(itemValue)) {
continue;
}
if (hasValue) {
conString.append(",");
}
hasValue = true;
if (inlineCriteria) {
conString.append(convertValueToSQL(dataSource, constraint.getAttribute(), itemValue));
} else {
conString.append("?");
}
}
conString.append(")");
}
return conString.toString();
} else {
return null;
}
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class DBNModel method getParentNode.
@Nullable
public DBNDatabaseNode getParentNode(DBSObject object) {
DBNDatabaseNode node = getNodeByObject(object);
if (node != null) {
if (node.getParentNode() instanceof DBNDatabaseNode) {
return (DBNDatabaseNode) node.getParentNode();
} else {
log.error("Object's " + object.getName() + "' parent node is not a database node: " + node.getParentNode());
return null;
}
}
DBSObject[] path = DBUtils.getObjectPath(object, false);
for (int i = 0; i < path.length; i++) {
DBSObject item = path[i];
node = getNodeByObject(item);
if (node == null) {
// Parent node read
return null;
}
DBNDatabaseNode[] children = node.getChildNodes();
if (ArrayUtils.isEmpty(children)) {
// Parent node is not read
return null;
}
if (item == object.getParentObject()) {
// Try to find parent node withing children
for (DBNDatabaseNode child : children) {
if (child instanceof DBNDatabaseFolder) {
Class<?> itemsClass = ((DBNDatabaseFolder) child).getChildrenClass();
if (itemsClass != null && itemsClass.isAssignableFrom(object.getClass())) {
return child;
}
}
}
}
}
// Not found
return null;
}
Aggregations