Search in sources :

Example 6 with AndCondition

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;
}
Also used : AndOrCondition(com.servoy.j2db.query.AndOrCondition) ISQLCondition(com.servoy.j2db.query.ISQLCondition) AndCondition(com.servoy.j2db.query.AndCondition) JSReadonlyProperty(com.servoy.j2db.scripting.annotations.JSReadonlyProperty)

Example 7 with AndCondition

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;
}
Also used : DerivedTable(com.servoy.j2db.query.DerivedTable) QueryJoin(com.servoy.j2db.query.QueryJoin) QuerySelect(com.servoy.j2db.query.QuerySelect) AndCondition(com.servoy.j2db.query.AndCondition)

Example 8 with AndCondition

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);
}
Also used : ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) RepositoryException(com.servoy.j2db.persistence.RepositoryException) QuerySelect(com.servoy.j2db.query.QuerySelect) AndCondition(com.servoy.j2db.query.AndCondition) RemoteException(java.rmi.RemoteException)

Aggregations

AndCondition (com.servoy.j2db.query.AndCondition)8 QueryJoin (com.servoy.j2db.query.QueryJoin)4 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 QuerySelect (com.servoy.j2db.query.QuerySelect)3 Column (com.servoy.j2db.persistence.Column)2 IColumn (com.servoy.j2db.persistence.IColumn)2 Table (com.servoy.j2db.persistence.Table)2 CompareCondition (com.servoy.j2db.query.CompareCondition)2 DerivedTable (com.servoy.j2db.query.DerivedTable)2 ISQLTableJoin (com.servoy.j2db.query.ISQLTableJoin)2 Placeholder (com.servoy.j2db.query.Placeholder)2 QueryColumn (com.servoy.j2db.query.QueryColumn)2 QueryTable (com.servoy.j2db.query.QueryTable)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 JSFunction (org.mozilla.javascript.annotations.JSFunction)2 BaseQueryColumn (com.servoy.base.query.BaseQueryColumn)1 IGlobalValueEntry (com.servoy.j2db.dataprocessing.IGlobalValueEntry)1 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1 IDataProvider (com.servoy.j2db.persistence.IDataProvider)1