Examples of HGrid


Examples of org.haystack.HGrid

        HWatch w = client.watchOpen("Java Haystack Test");
        verifyEq(w.id(), null);
        verifyEq(w.dis(), "Java Haystack Test");

        // do query to get some recs
        HGrid recs = client.readAll("ahu");
        verify(recs.numRows() >= 4);
        HDict a = recs.row(0);
        HDict b = recs.row(1);
        HDict c = recs.row(2);
        HDict d = recs.row(3);

        // do first sub
        HGrid sub = w.sub(new HRef[] { a.id(), b.id() });
        verifyEq(sub.numRows(), 2);
        verifyEq(sub.row(0).dis(), a.dis());
        verifyEq(sub.row(1).dis(), b.dis());

        // now add c, bad, d
        HRef badId = HRef.make("badBadBad");
        try {
            w.sub(new HRef[] { badId }).dump();
            fail();
        }
        catch (UnknownRecException e) {
            verifyException(e);
        }
        sub = w.sub(new HRef[] { c.id(), badId, d.id() }, false);
        verifyEq(sub.numRows(), 3);
        verifyEq(sub.row(0).dis(), c.dis());
        verifyEq(sub.row(1).missing("id"), true);
        verifyEq(sub.row(2).dis(), d.dis());

        // verify state of watch now
        verify(client.watch(w.id()) == w);
        verifyEq(client.watches().length, 1);
        verify(client.watches()[0] == w);
        verifyEq(w.lease().millis(), 60000L);

        // poll for changes (should be none yet)
        HGrid poll = w.pollChanges();
        verifyEq(poll.numRows(), 0);

        // make change to b and d
        verifyEq(b.has("javaTest"), false);
        verifyEq(d.has("javaTest"), false);
        client.eval("commit(diff(readById(@" + b.id().val + "), {javaTest:123}))");
        client.eval("commit(diff(readById(@" + d.id().val + "), {javaTest:456}))");
        poll = w.pollChanges();
        verifyEq(poll.numRows(), 2);
        HDict newb, newd;
        if (poll.row(0).id().equals(b.id())) {
            newb = poll.row(0);
            newd = poll.row(1);
        }
        else {
            newb = poll.row(1);
            newd = poll.row(0);
        }
        verifyEq(newb.dis(), b.dis());
        verifyEq(newd.dis(), d.dis());
        verifyEq(newb.get("javaTest"), HNum.make(123));
        verifyEq(newd.get("javaTest"), HNum.make(456));

        // poll refresh
        poll = w.pollRefresh();
        verifyEq(poll.numRows(), 4);
        verifyGridContains(poll, "id", a.id());
        verifyGridContains(poll, "id", b.id());
        verifyGridContains(poll, "id", c.id());
        verifyGridContains(poll, "id", d.id());

        // remove d, and then poll changes
        w.unsub(new HRef[] { d.id() });
        client.eval("commit(diff(readById(@" + b.id().val + "), {-javaTest}))");
        client.eval("commit(diff(readById(@" + d.id().val + "), {-javaTest}))");
        poll = w.pollChanges();
        verifyEq(poll.numRows(), 1);
        verifyEq(poll.row(0).dis(), b.dis());
        verifyEq(poll.row(0).has("javaTest"), false);

        // remove a and c and poll refresh
        w.unsub(new HRef[] { a.id(), c.id() });
        poll = w.pollRefresh();
        verifyEq(poll.numRows(), 1);
        verifyEq(poll.row(0).dis(), b.dis());

        // close
        String expr = "folioDebugWatches().findAll(x=>x->dis.contains(\"Java Haystack Test\")).size";
        verifyEq(client.eval(expr).row(0).getInt("val"), 1);
        w.close();
View Full Code Here

Examples of org.haystack.HGrid

    // His Reads
    //////////////////////////////////////////////////////////////////////////

    void verifyHisRead() throws Exception {
        HDict kw = client.read("kw and siteMeter");
        HGrid his = client.hisRead(kw.id(), "yesterday");
        verifyEq(his.meta().id(), kw.id());
        verifyEq(ts(his.meta(), "hisStart").date, HDate.today().minusDays(1));
        verifyEq(ts(his.meta(), "hisEnd").date, HDate.today());
        verify(his.numRows() > 90);
        int last = his.numRows() - 1;
        verifyEq(ts(his.row(0)).date, HDate.today().minusDays(1));
        verifyEq(ts(his.row(0)).time, HTime.make(0, 15));
        verifyEq(ts(his.row(last)).date, HDate.today());
        verifyEq(ts(his.row(last)).time, HTime.make(0, 0));
        verifyEq(numVal(his.row(0)).unit, "kW");
    }
View Full Code Here

Examples of org.haystack.HGrid

        }

        // write and verify
        client.hisWrite(kw.id(), write);
        Thread.sleep(200);
        HGrid read = client.hisRead(kw.id(), "2010-06-07");
        verifyEq(read.numRows(), write.length);
        for (int i = 0; i < read.numRows(); ++i) {
            verifyEq(read.row(i).get("ts"), write[i].ts);
            verifyEq(read.row(i).get("val"), write[i].val);
        }

        // clean test
        clearHisWrite(kw);
    }
View Full Code Here

Examples of org.haystack.HGrid

    private void clearHisWrite(HDict rec) {
        // existing data and verify we don't have any data for 7 June 20120
        String expr = "hisClear(@" + rec.id().val + ", 2010-06)";
        client.eval(expr);
        HGrid his = client.hisRead(rec.id(), "2010-06-07");
        verifyEq(his.numRows(), 0);
    }
View Full Code Here

Examples of org.haystack.HGrid

    // Reads
    //////////////////////////////////////////////////////////////////////////

    @Override
    protected HDict onReadById(HRef id) {
        HGrid res = readByIds(new HRef[] { id }, false);
        if (res.isEmpty())
            return null;
        HDict rec = res.row(0);
        if (rec.missing("id"))
            return null;
        return rec;
    }
View Full Code Here

Examples of org.haystack.HGrid

    protected HGrid onReadByIds(HRef[] ids) {
        HGridBuilder b = new HGridBuilder();
        b.addCol("id");
        for (int i = 0; i < ids.length; ++i)
            b.addRow(new HVal[] { ids[i] });
        HGrid req = b.toGrid();
        return call("read", req);
    }
View Full Code Here

Examples of org.haystack.HGrid

    protected HGrid onReadAll(String filter, int limit) {
        HGridBuilder b = new HGridBuilder();
        b.addCol("filter");
        b.addCol("limit");
        b.addRow(new HVal[] { HStr.make(filter), HNum.make(limit) });
        HGrid req = b.toGrid();
        return call("read", req);
    }
View Full Code Here

Examples of org.haystack.HGrid

     */
    public HGrid eval(String expr) {
        HGridBuilder b = new HGridBuilder();
        b.addCol("expr");
        b.addRow(new HVal[] { HStr.make(expr) });
        HGrid req = b.toGrid();
        return call("eval", req);
    }
View Full Code Here

Examples of org.haystack.HGrid

        b.addCol("id");
        for (int i = 0; i < ids.length; ++i)
            b.addRow(new HVal[] { ids[i] });

        // make request
        HGrid res;
        try {
            HGrid req = b.toGrid();
            res = call("watchSub", req);
        }
        catch (CallErrException e) {
            // any server side error is considered close
            watchClose(w, false);
View Full Code Here

Examples of org.haystack.HGrid

        b.addCol("id");
        for (int i = 0; i < ids.length; ++i)
            b.addRow(new HVal[] { ids[i] });

        // make request
        HGrid req = b.toGrid();
        call("watchUnsub", req);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.