use of com.servoy.j2db.query.AndCondition in project servoy-client by Servoy.
the class QBSelect method having.
/**
* Get the having-part of the query, used to add conditions.
* The conditions added here are AND-ed.
* @sample
* var query = datasources.db.example_data.orders.createSelect();
* query.groupBy.addPk() // have to group by on pk when using having-conditions in (foundset) pk queries
* .root.having.add(query.joins.orders_to_order_details.columns.quantity.count.eq(0))
* foundset.loadRecords(query)
*/
@JSReadonlyProperty
public QBLogicalCondition having() throws RepositoryException {
if (having == null) {
ISQLCondition c = getQuery().getHaving();
if (!(c instanceof AndOrCondition)) {
getQuery().setHaving(c = AndCondition.and(c, new AndCondition()));
}
having = new QBLogicalCondition(this, this, (AndOrCondition) c);
}
return having;
}
use of com.servoy.j2db.query.AndCondition in project servoy-client by Servoy.
the class QBJoins method add.
public QBJoin add(IQueryBuilder subqueryBuilder, int joinType, String alias) {
if (!DataSourceUtils.isSameServer(getRoot().getDataSource(), subqueryBuilder.getDataSource())) {
throw new RuntimeException("Cannot add derived table join from different server: " + getRoot().getDataSource() + " vs " + subqueryBuilder.getDataSource());
}
QuerySelect subquery = ((QBSelect) subqueryBuilder).getQuery();
QBJoin join = getJoin(alias);
if (join == null) {
join = addJoin(new QueryJoin(alias, parent.getQueryTable(), new DerivedTable(subquery, alias), new AndCondition(), joinType, true), subqueryBuilder.getDataSource(), alias);
}
return join;
}
use of com.servoy.j2db.query.AndCondition in project servoy-client by Servoy.
the class FoundSet method invert.
public void invert() throws ServoyException {
int sizeBefore;
QuerySelect sqlSelect;
ArrayList<String> invertConditionNames = new ArrayList<String>();
IFoundSetChanges changes = null;
synchronized (pksAndRecords) {
sizeBefore = getSize();
sqlSelect = pksAndRecords.getQuerySelectForReading();
Map<String, AndCondition> conditions = sqlSelect.getConditions();
if (conditions != null) {
Iterator<String> conditionNamesIte = conditions.keySet().iterator();
String conditionName;
while (conditionNamesIte.hasNext()) {
conditionName = conditionNamesIte.next();
if (conditionName != null && (conditionName.equals(SQLGenerator.CONDITION_SEARCH) || !conditionName.startsWith(SQLGenerator.SERVOY_CONDITION_PREFIX))) {
invertConditionNames.add(conditionName);
}
}
}
if (invertConditionNames.size() == 0) {
changes = pksAndRecords.setPksAndQuery(new BufferedDataSet(), 0, sqlSelect);
} else {
sqlSelect = pksAndRecords.getQuerySelectForModification();
for (String inverConditionName : invertConditionNames) {
sqlSelect.setCondition(inverConditionName, conditions.get(inverConditionName).negate());
}
clearOmit(sqlSelect);
// set pks here in case a refresh comes along
changes = pksAndRecords.setPksAndQuery(pksAndRecords.getPks(), pksAndRecords.getDbIndexLastPk(), sqlSelect);
}
}
if (invertConditionNames.size() > 0) {
// cache pks
String transaction_id = fsm.getTransactionID(sheet);
try {
IDataSet pks = performQuery(transaction_id, sqlSelect, getRowIdentColumnTypes(), 0, fsm.config.pkChunkSize(), IDataServer.FOUNDSET_LOAD_QUERY);
synchronized (pksAndRecords) {
// optimistic locking, if the query has been changed in the mean time forget about the refresh
if (sqlSelect != pksAndRecords.getQuerySelectForReading()) {
// $NON-NLS-1$
Debug.log("invert: query was changed during refresh, not resetting old query");
return;
}
changes = pksAndRecords.setPksAndQuery(pks, pks.getRowCount(), sqlSelect);
}
} catch (RemoteException e) {
changes = pksAndRecords.setPksAndQuery(new BufferedDataSet(), 0, sqlSelect);
throw new RepositoryException(e);
}
}
if (aggregateCache.size() > 0) {
fireAggregateChangeWithEvents(null);
}
fireDifference(sizeBefore, getSize(), changes);
}
Aggregations