Package org.haystack

Examples of org.haystack.HDict


        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);
View Full Code Here


    //////////////////////////////////////////////////////////////////////////
    // 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));
View Full Code Here

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

    void verifyHisWrite() throws Exception {
        // setup test
        HDict kw = client.read("kw and not siteMeter");
        clearHisWrite(kw);

        // create some items
        HDate date = HDate.make(2010, 6, 7);
        HTimeZone tz = HTimeZone.make(kw.getStr("tz"));
        HHisItem[] write = new HHisItem[5];
        for (int i = 0; i < write.length; ++i) {
            HDateTime ts = HDateTime.make(date, HTime.make(i + 1, 0), tz);
            HVal val = HNum.make(i, "kW");
            write[i] = HHisItem.make(ts, val);
        }

        // 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);
        }
View Full Code Here

    @Override
    public void onService(HServer db, HGrid req, HGridWriter writer) throws Exception {
        HRef id = valToId(db, req.meta().get("id"));

        String action = req.meta().getStr("action");
        HDict args = HDict.EMPTY;
        if (req.numRows() > 0)
            args = req.row(0);
        writeGrid(writer, db.invokeAction(id, action, args));
    }
View Full Code Here

        return ids;
    }

    HRef valToId(HServer db, HVal val) {
        if (val instanceof HUri) {
            HDict rec = db.navReadByUri((HUri) val, false);
            return rec == null ? HRef.nullRef : rec.id();
        }
        return (HRef) val;
    }
View Full Code Here

    //////////////////////////////////////////////////////////////////////////
    // Include
    //////////////////////////////////////////////////////////////////////////

    public void testInclude() {
        HDict a = new HDictBuilder().add("dis", "a").add("num", 100).add("foo", 99)
                .add("date", HDate.make(2011, 10, 5)).toDict();

        HDict b = new HDictBuilder().add("dis", "b").add("num", 200).add("foo", 88)
                .add("date", HDate.make(2011, 10, 20)).add("bar").add("ref", HRef.make("a")).toDict();

        HDict c = new HDictBuilder().add("dis", "c").add("num", 300).add("ref", HRef.make("b")).add("bar").toDict();

        final Map<String, HDict> db = new HashMap<String, HDict>();
        db.put("a", a);
        db.put("b", b);
        db.put("c", c);
View Full Code Here

    @Override
    protected HGrid onReadAll(String filter, int limit) {
        HFilter f = HFilter.make(filter);
        List<HDict> acc = new ArrayList<HDict>();
        for (Iterator<HDict> it = iterator(); it.hasNext();) {
            HDict rec = it.next();
            if (f.include(rec, filterPather)) {
                acc.add(rec);
                if (acc.size() >= limit)
                    break;
            }
View Full Code Here

     * Read a record from the database using a navigation path.
     * If not found then return null or raise UnknownRecException
     * base on checked flag.
     */
    public HDict navReadByUri(HUri uri, boolean checked) {
        HDict rec = onNavReadByUri(uri);
        if (rec != null)
            return rec;
        if (checked)
            throw new UnknownRecException(uri.toString());
        return null;
View Full Code Here

     * - val: current value at level or null
     * - who: who last controlled the value at this level
     */
    public final HGrid pointWriteArray(HRef id) {
        // lookup entity
        HDict rec = readById(id);

        // check that entity has "writable" tag
        if (rec.missing("writable"))
            throw new UnknownNameException("Rec missing 'writable' tag: " + rec.dis());

        return onPointWriteArray(rec);
    }
View Full Code Here

            throw new IllegalArgumentException("Invalid level 1-17: " + level);
        if (who == null)
            throw new IllegalArgumentException("who is null");

        // lookup entity
        HDict rec = readById(id);

        // check that entity has "writable" tag
        if (rec.missing("writable"))
            throw new UnknownNameException("Rec missing 'writable' tag: " + rec.dis());

        onPointWrite(rec, level, val, who, dur);
    }
View Full Code Here

TOP

Related Classes of org.haystack.HDict

Copyright © 2018 www.massapicom. 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.