Search in sources :

Example 1 with NoResultsQueryOperation

use of com.zimbra.cs.index.NoResultsQueryOperation in project zm-mailbox by Zimbra.

the class ItemQuery method compile.

@Override
public QueryOperation compile(Mailbox mbox, boolean bool) {
    DBQueryOperation dbOp = new DBQueryOperation();
    bool = evalBool(bool);
    if (bool && isAllQuery || !bool && isNoneQuery) {
    // adding no constraints should match everything...
    } else if (bool && isNoneQuery || !bool && isAllQuery) {
        return new NoResultsQueryOperation();
    } else if (isRangeQuery && itemIds.size() == 2) {
        dbOp.addItemIdRange(itemIds.get(0).getId(), true, itemIds.get(1).getId(), true, bool);
    } else {
        for (ItemId iid : itemIds) {
            dbOp.addItemIdClause(mbox, iid, bool);
        }
    }
    return dbOp;
}
Also used : DBQueryOperation(com.zimbra.cs.index.DBQueryOperation) ItemId(com.zimbra.cs.service.util.ItemId) NoResultsQueryOperation(com.zimbra.cs.index.NoResultsQueryOperation)

Example 2 with NoResultsQueryOperation

use of com.zimbra.cs.index.NoResultsQueryOperation in project zm-mailbox by Zimbra.

the class InQuery method compile.

@Override
public QueryOperation compile(Mailbox mbox, boolean bool) {
    if (specialTarget != null) {
        if (specialTarget == In.NONE) {
            return new NoResultsQueryOperation();
        } else if (specialTarget == In.ANY) {
            DBQueryOperation op = new DBQueryOperation();
            op.addAnyFolder(evalBool(bool));
            return op;
        } else {
            if (evalBool(bool)) {
                if (specialTarget == In.REMOTE) {
                    DBQueryOperation dbop = new DBQueryOperation();
                    dbop.addIsRemoteClause();
                    return dbop;
                } else {
                    assert (specialTarget == In.LOCAL);
                    DBQueryOperation dbop = new DBQueryOperation();
                    dbop.addIsLocalClause();
                    return dbop;
                }
            } else {
                if (specialTarget == In.REMOTE) {
                    DBQueryOperation dbop = new DBQueryOperation();
                    dbop.addIsLocalClause();
                    return dbop;
                } else {
                    assert (specialTarget == In.LOCAL);
                    DBQueryOperation dbop = new DBQueryOperation();
                    dbop.addIsRemoteClause();
                    return dbop;
                }
            }
        }
    }
    DBQueryOperation dbOp = new DBQueryOperation();
    if (folder != null) {
        if (includeSubfolders) {
            List<Folder> subFolders = folder.getSubfolderHierarchy();
            if (evalBool(bool)) {
                // (A or B or C)
                UnionQueryOperation union = new UnionQueryOperation();
                for (Folder sub : subFolders) {
                    DBQueryOperation dbop = new DBQueryOperation();
                    union.add(dbop);
                    if (sub instanceof Mountpoint) {
                        Mountpoint mpt = (Mountpoint) sub;
                        if (!mpt.isLocal()) {
                            dbop.addInRemoteFolder(mpt.getTarget(), "", includeSubfolders, evalBool(bool));
                        } else {
                        // TODO FIXME handle local mountpoints. Don't forget to check for infinite recursion!
                        }
                    } else {
                        dbop.addInFolder(sub, evalBool(bool));
                    }
                }
                return union;
            } else {
                // -(A or B or C) ==> -A and -B and -C
                IntersectionQueryOperation iop = new IntersectionQueryOperation();
                for (Folder f : subFolders) {
                    DBQueryOperation dbop = new DBQueryOperation();
                    iop.addQueryOp(dbop);
                    if (f instanceof Mountpoint) {
                        Mountpoint mpt = (Mountpoint) f;
                        if (!mpt.isLocal()) {
                            dbop.addInRemoteFolder(mpt.getTarget(), "", includeSubfolders, evalBool(bool));
                        } else {
                        // TODO FIXME handle local mountpoints.  Don't forget to check for infinite recursion!
                        }
                    } else {
                        dbop.addInFolder(f, evalBool(bool));
                    }
                }
                return iop;
            }
        } else {
            dbOp.addInFolder(folder, evalBool(bool));
        }
    } else if (remoteId != null) {
        dbOp.addInRemoteFolder(remoteId, subfolderPath, includeSubfolders, evalBool(bool));
    } else {
        assert (false);
    }
    return dbOp;
}
Also used : IntersectionQueryOperation(com.zimbra.cs.index.IntersectionQueryOperation) UnionQueryOperation(com.zimbra.cs.index.UnionQueryOperation) Folder(com.zimbra.cs.mailbox.Folder) DBQueryOperation(com.zimbra.cs.index.DBQueryOperation) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) NoResultsQueryOperation(com.zimbra.cs.index.NoResultsQueryOperation)

Aggregations

DBQueryOperation (com.zimbra.cs.index.DBQueryOperation)2 NoResultsQueryOperation (com.zimbra.cs.index.NoResultsQueryOperation)2 IntersectionQueryOperation (com.zimbra.cs.index.IntersectionQueryOperation)1 UnionQueryOperation (com.zimbra.cs.index.UnionQueryOperation)1 Folder (com.zimbra.cs.mailbox.Folder)1 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)1 ItemId (com.zimbra.cs.service.util.ItemId)1