use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class SQLSemanticProcessor method patchSelectQuery.
private static boolean patchSelectQuery(DBPDataSource dataSource, PlainSelect select, DBDDataFilter filter) throws JSQLParserException {
// WHERE
if (filter.hasConditions()) {
for (DBDAttributeConstraint co : filter.getConstraints()) {
if (co.hasCondition()) {
Table table = getConstraintTable(select, co);
if (table != null) {
if (table.getAlias() != null) {
co.setEntityAlias(table.getAlias().getName());
} else {
co.setEntityAlias(table.getName());
}
} else {
co.setEntityAlias(null);
}
}
}
StringBuilder whereString = new StringBuilder();
SQLUtils.appendConditionString(filter, dataSource, null, whereString, true);
String condString = whereString.toString();
addWhereToSelect(select, condString);
}
// ORDER
if (filter.hasOrdering()) {
List<OrderByElement> orderByElements = select.getOrderByElements();
if (orderByElements == null) {
orderByElements = new ArrayList<>();
select.setOrderByElements(orderByElements);
}
for (DBDAttributeConstraint co : filter.getOrderConstraints()) {
Expression orderExpr = getConstraintExpression(select, co);
OrderByElement element = new OrderByElement();
element.setExpression(orderExpr);
if (co.isOrderDescending()) {
element.setAsc(false);
element.setAscDescPresent(true);
}
orderByElements.add(element);
}
}
return true;
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class FilterSettingsDialog method moveColumn.
private void moveColumn(int curIndex, int newIndex) {
final DBDAttributeConstraint c1 = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(curIndex).getData());
final DBDAttributeConstraint c2 = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(newIndex).getData());
final int vp2 = c2.getVisualPosition();
c2.setVisualPosition(c1.getVisualPosition());
c1.setVisualPosition(vp2);
refreshData();
moveTopButton.setEnabled(newIndex > 0);
moveUpButton.setEnabled(newIndex > 0);
moveDownButton.setEnabled(newIndex < getItemsCount() - 1);
moveBottomButton.setEnabled(newIndex < getItemsCount() - 1);
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by dbeaver.
the class SQLSemanticProcessor method patchSelectQuery.
private static boolean patchSelectQuery(DBPDataSource dataSource, PlainSelect select, DBDDataFilter filter) throws JSQLParserException {
// WHERE
if (filter.hasConditions()) {
for (DBDAttributeConstraint co : filter.getConstraints()) {
if (co.hasCondition()) {
Table table = getConstraintTable(select, co);
if (table != null) {
if (table.getAlias() != null) {
co.setEntityAlias(table.getAlias().getName());
} else {
co.setEntityAlias(table.getName());
}
} else {
co.setEntityAlias(null);
}
}
}
StringBuilder whereString = new StringBuilder();
SQLUtils.appendConditionString(filter, dataSource, null, whereString, true);
String condString = whereString.toString();
addWhereToSelect(select, condString);
}
// ORDER
if (filter.hasOrdering()) {
List<OrderByElement> orderByElements = select.getOrderByElements();
if (orderByElements == null) {
orderByElements = new ArrayList<>();
select.setOrderByElements(orderByElements);
}
for (DBDAttributeConstraint co : filter.getOrderConstraints()) {
Expression orderExpr = getConstraintExpression(dataSource, select, co);
OrderByElement element = new OrderByElement();
element.setExpression(orderExpr);
if (co.isOrderDescending()) {
element.setAsc(false);
element.setAscDescPresent(true);
}
orderByElements.add(element);
}
}
return true;
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class SQLSemanticProcessor method patchSelectQuery.
private static boolean patchSelectQuery(DBRProgressMonitor monitor, DBPDataSource dataSource, PlainSelect select, DBDDataFilter filter) throws JSQLParserException, DBException {
// WHERE
if (filter.hasConditions()) {
for (DBDAttributeConstraint co : filter.getConstraints()) {
if (co.hasCondition()) {
Table table = getConstraintTable(select, co);
if (!isValidTableColumn(monitor, dataSource, table, co)) {
table = null;
}
if (table != null) {
if (table.getAlias() != null) {
co.setEntityAlias(table.getAlias().getName());
} else {
co.setEntityAlias(table.getName());
}
} else {
co.setEntityAlias(null);
}
}
}
StringBuilder whereString = new StringBuilder();
SQLUtils.appendConditionString(filter, dataSource, null, whereString, true);
String condString = whereString.toString();
addWhereToSelect(select, condString);
}
// ORDER
if (filter.hasOrdering()) {
List<OrderByElement> orderByElements = select.getOrderByElements();
if (orderByElements == null) {
orderByElements = new ArrayList<>();
select.setOrderByElements(orderByElements);
}
for (DBDAttributeConstraint co : filter.getOrderConstraints()) {
String columnName = co.getAttributeName();
boolean forceNumeric = filter.hasNameDuplicates(columnName) || !SQLUtils.PATTERN_SIMPLE_NAME.matcher(columnName).matches();
Expression orderExpr = getOrderConstraintExpression(monitor, dataSource, select, co, forceNumeric);
OrderByElement element = new OrderByElement();
element.setExpression(orderExpr);
if (co.isOrderDescending()) {
element.setAsc(false);
element.setAscDescPresent(true);
}
orderByElements.add(element);
}
}
return true;
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class FilterSettingsDialog method moveColumns.
private void moveColumns(int curIndex, int newIndex) {
if (curIndex == newIndex) {
return;
}
final DBDAttributeConstraint curAttr = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(curIndex).getData());
// Update other constraints indexes
for (DBDAttributeConstraint c : constraints) {
if (newIndex < curIndex) {
if (c.getVisualPosition() >= newIndex && c.getVisualPosition() < curIndex) {
c.setVisualPosition(c.getVisualPosition() + 1);
}
} else {
if (c.getVisualPosition() > curIndex && c.getVisualPosition() <= newIndex) {
c.setVisualPosition(c.getVisualPosition() - 1);
}
}
}
curAttr.setVisualPosition(newIndex);
refreshData();
moveTopButton.setEnabled(newIndex > 0);
moveUpButton.setEnabled(newIndex > 0);
moveDownButton.setEnabled(newIndex < getItemsCount() - 1);
moveBottomButton.setEnabled(newIndex < getItemsCount() - 1);
}
Aggregations