Package org.haystack

Examples of org.haystack.HGridBuilder


        return "Operations supported by this server";
    }

    @Override
    public void onService(HServer db, HGrid req, HGridWriter writer) {
        HGridBuilder b = new HGridBuilder();
        b.addCol("name");
        b.addCol("summary");
        HOp[] ops = db.ops();
        for (int i = 0; i < ops.length; ++i) {
            HOp op = ops[i];
            b.addRow(new HVal[] { HStr.make(op.name()), HStr.make(op.summary()), });
        }

        writeGrid(writer, b.toGrid());
    }
View Full Code Here


        return "Grid data formats supported by this server";
    }

    @Override
    public void onService(HServer db, HGrid req, HGridWriter writer) {
        HGridBuilder b = new HGridBuilder();
        b.addCol("mime");
        b.addCol("read");
        b.addCol("write");
        HGridFormat[] formats = HGridFormat.list();
        for (int i = 0; i < formats.length; ++i) {
            HGridFormat format = formats[i];
            b.addRow(new HVal[] { HStr.make(format.mime), format.reader != null ? HMarker.VAL : null,
                    format.writer != null ? HMarker.VAL : null, });
        }

        writeGrid(writer, b.toGrid());
    }
View Full Code Here

    protected HGrid onPointWriteArray(HDict rec) {
        WriteArray array = writeArrays.get(rec.id());
        if (array == null)
            array = new WriteArray();

        HGridBuilder b = new HGridBuilder();
        b.addCol("level");
        b.addCol("levelDis");
        b.addCol("val");
        b.addCol("who");

        for (int i = 0; i < 17; ++i)
            b.addRow(new HVal[] { HNum.make(i + 1), HStr.make("" + (i + 1)), array.val[i], HStr.make(array.who[i]), });
        return b.toGrid();
    }
View Full Code Here

/**
* GridTest tests the HGrid class
*/
public class GridTest extends Test {
    public void testEmpty() {
        HGrid g = new HGridBuilder().toGrid();
        verifyEq(g.meta(), HDict.EMPTY);
        verifyEq(g.numRows(), 0);
        verifyEq(g.isEmpty(), true);
        verifyEq(g.col("foo", false), null);
        try {
View Full Code Here

            verifyException(e);
        }
    }

    public void testNoRows() {
        HGridBuilder b = new HGridBuilder();
        b.meta().add("dis", "Title");
        b.addCol("a").add("dis", "Alpha");
        b.addCol("b");
        HGrid g = b.toGrid();

        // meta
        verifyEq(g.meta().size(), 1);
        verifyEq(g.meta().get("dis"), HStr.make("Title"));
View Full Code Here

        // iterator
        verifyGridIterator(g);
    }

    public void testSimple() {
        HGridBuilder b = new HGridBuilder();
        b.addCol("id");
        b.addCol("dis");
        b.addCol("area");
        b.addRow(new HVal[] { HRef.make("a"), HStr.make("Alpha"), HNum.make(1200) });
        b.addRow(new HVal[] { HRef.make("b"), HStr.make("Beta"), null });

        // meta
        HGrid g = b.toGrid();
        verifyEq(g.meta().size(), 0);

        // cols
        verifyEq(g.numCols(), 3);
        verifyCol(g, 0, "id");
View Full Code Here

            throw new IllegalArgumentException("ids are empty");
        if (w.closed)
            throw new IllegalStateException("watch is closed");

        // grid meta
        HGridBuilder b = new HGridBuilder();
        if (w.id != null)
            b.meta().add("watchId", w.id);
        b.meta().add("watchDis", w.dis);

        // grid rows
        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

            throw new IllegalStateException("nothing subscribed yet");
        if (w.closed)
            throw new IllegalStateException("watch is closed");

        // grid meta
        HGridBuilder b = new HGridBuilder();
        b.meta().add("watchId", w.id);

        // grid rows
        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

            throw new IllegalStateException("nothing subscribed yet");
        if (w.closed)
            throw new IllegalStateException("watch is closed");

        // grid meta
        HGridBuilder b = new HGridBuilder();
        b.meta().add("watchId", w.id);
        if (refresh)
            b.meta().add("refresh");
        b.addCol("empty");

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

            watches.remove(w.id);

        // optionally send close message to server
        if (send) {
            try {
                HGridBuilder b = new HGridBuilder();
                b.meta().add("watchId", w.id).add("close");
                b.addCol("id");
                call("watchUnsub", b.toGrid());
            }
            catch (Exception e) {
                // ignore
            }
        }
View Full Code Here

TOP

Related Classes of org.haystack.HGridBuilder

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.