Search in sources :

Example 1 with IntersectionQueryOperation

use of com.zimbra.cs.index.IntersectionQueryOperation 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)1 IntersectionQueryOperation (com.zimbra.cs.index.IntersectionQueryOperation)1 NoResultsQueryOperation (com.zimbra.cs.index.NoResultsQueryOperation)1 UnionQueryOperation (com.zimbra.cs.index.UnionQueryOperation)1 Folder (com.zimbra.cs.mailbox.Folder)1 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)1