Package org.haystack

Examples of org.haystack.HGrid


            else
                filter = "navNoChildren";
        }

        // read children of base record
        HGrid grid = readAll(filter);

        // add navId column to results
        HDict[] rows = new HDict[grid.numRows()];
        Iterator<HRow> it = grid.iterator();
        for (int i = 0; it.hasNext();)
            rows[i++] = it.next();
        for (int i = 0; i < rows.length; ++i)
            rows[i] = new HDictBuilder().add(rows[i]).add("navId", rows[i].id().val).toDict();
        return HGridBuilder.dictsToGrid(rows);
View Full Code Here


    //////////////////////////////////////////////////////////////////////////
    // Ops
    //////////////////////////////////////////////////////////////////////////

    void verifyOps() throws Exception {
        HGrid g = client.ops();

        // verify required columns
        verify(g.col("name") != null);
        verify(g.col("summary") != null);

        // verify required ops
        verifyGridContains(g, "name", "about");
        verifyGridContains(g, "name", "ops");
        verifyGridContains(g, "name", "formats");
View Full Code Here

    //////////////////////////////////////////////////////////////////////////
    // Formats
    //////////////////////////////////////////////////////////////////////////

    void verifyFormats() throws Exception {
        HGrid g = client.formats();

        // verify required columns
        verify(g.col("mime") != null);
        verify(g.col("read") != null);
        verify(g.col("write") != null);

        // verify required ops
        verifyGridContains(g, "mime", "text/plain");
        verifyGridContains(g, "mime", "text/zinc");
    }
View Full Code Here

        catch (UnknownRecException e) {
            verifyException(e);
        }

        // readAll
        HGrid grid = client.readAll("site");
        verifyGridContains(grid, "dis", disA);
        verifyGridContains(grid, "dis", disB);
        verifyGridContains(grid, "id", recA.id());
        verifyGridContains(grid, "id", recB.id());

        // readAll limit
        verify(grid.numRows() > 2);
        verifyEq(client.readAll("site", 2).numRows(), 2);

        // readById
        HDict rec = client.readById(recA.id());
        verifyEq(rec.dis(), disA);
        HRef badId = HRef.make("badBadId");
        verifyEq(client.readById(badId, false), null);
        try {
            client.readById(badId);
            fail();
        }
        catch (UnknownRecException e) {
            verifyException(e);
        }

        // readByIds
        grid = client.readByIds(new HRef[] { recA.id(), recB.id() });
        verifyEq(grid.numRows(), 2);
        verifyEq(grid.row(0).dis(), disA);
        verifyEq(grid.row(1).dis(), disB);
        grid = client.readByIds(new HRef[] { recA.id(), badId, recB.id() }, false);
        verifyEq(grid.numRows(), 3);
        verifyEq(grid.row(0).dis(), disA);
        verifyEq(grid.row(1).missing("id"), true);
        verifyEq(grid.row(2).dis(), disB);
        try {
            client.readByIds(new HRef[] { recA.id(), badId });
            fail();
        }
        catch (UnknownRecException e) {
View Full Code Here

     * Service the request and return response.
     * This method routes to "onService(HServer,HGrid)".
     */
    public void onService(HServer db, HttpServletRequest req, HttpServletResponse res) throws Exception {
        // parse GET query parameters or POST body into grid
        HGrid reqGrid = HGrid.EMPTY;
        String method = req.getMethod();
        if (method.equals("GET"))
            reqGrid = getToGrid(req);
        if (method.equals("POST"))
            reqGrid = postToGrid(req, res);
View Full Code Here

        for (int i = 0; i < cols.length; ++i)
            if (cols[i] == null)
                cols[i] = HDict.EMPTY;

        // read from zinc
        HGrid grid = new HZincReader(str).readGrid();
        verifyGridEq(grid, meta, cols, rows);

        // write grid and verify we can parse that too
        String writeStr = HZincWriter.gridToString(grid);
        HGrid writeGrid = new HZincReader(writeStr).readGrid();
        verifyGridEq(writeGrid, meta, cols, rows);
    }
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 {
            g.col("foo");
            fail();
        }
        catch (UnknownNameException e) {
            verifyException(e);
        }
View Full Code Here

    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"));

        // cols
        HCol c;
        verifyEq(g.numCols(), 2);
        c = verifyCol(g, 0, "a");
        verifyEq(c.dis(), "Alpha");
        verifyEq(c.meta().size(), 1);
        verifyEq(c.meta().get("dis"), HStr.make("Alpha"));

        // rows
        verifyEq(g.numRows(), 0);
        verifyEq(g.isEmpty(), true);

        // iterator
        verifyGridIterator(g);
    }
View Full Code Here

        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");
        verifyCol(g, 1, "dis");
        verifyCol(g, 2, "area");

        // rows
        verifyEq(g.numRows(), 2);
        verifyEq(g.isEmpty(), false);
        HRow r;
        r = g.row(0);
        verifyEq(r.get("id"), HRef.make("a"));
        verifyEq(r.get("dis"), HStr.make("Alpha"));
        verifyEq(r.get("area"), HNum.make(1200));
        r = g.row(1);
        verifyEq(r.get("id"), HRef.make("b"));
        verifyEq(r.get("dis"), HStr.make("Beta"));
        verifyEq(r.get("area", false), null);
        try {
            r.get("area");
            fail();
        }
        catch (UnknownNameException e) {
            verifyException(e);
        }
        verifyEq(r.get("fooBar", false), null);
        try {
            r.get("fooBar");
            fail();
        }
        catch (UnknownNameException e) {
            verifyException(e);
        }

        // HRow.iterator no-nulls
        Iterator<Entry<String, HVal>> it = g.row(0).iterator();
        verifyRowIterator(it, "id", HRef.make("a"));
        verifyRowIterator(it, "dis", HStr.make("Alpha"));
        verifyRowIterator(it, "area", HNum.make(1200));
        verifyEq(it.hasNext(), false);

        // HRow.iterator with nulls
        it = g.row(1).iterator();
        verifyRowIterator(it, "id", HRef.make("b"));
        verifyRowIterator(it, "dis", HStr.make("Beta"));
        verifyEq(it.hasNext(), false);

        // iterator
View Full Code Here

    //////////////////////////////////////////////////////////////////////////
    // Eval
    //////////////////////////////////////////////////////////////////////////

    void verifyEval() throws Exception {
        HGrid g = client.eval("today()");
        verifyEq(g.row(0).get("val"), HDate.today());

        g = client.eval("readAll(ahu)");
        verify(g.numRows() > 0);
        verifyGridContains(g, "navName", "RTU-1");

        HGrid[] grids = client.evalAll(new String[] { "today()", "[10, 20, 30]", "readAll(site)" });
        verifyEq(grids.length, 3);
        g = grids[0];
        verifyEq(g.numRows(), 1);
        verifyEq(g.row(0).get("val"), HDate.today());
        g = grids[1];
        verifyEq(g.numRows(), 3);
        verifyEq(g.row(0).get("val"), HNum.make(10));
        verifyEq(g.row(1).get("val"), HNum.make(20));
        verifyEq(g.row(2).get("val"), HNum.make(30));
        g = grids[2];
        verify(g.numRows() > 2);
        verifyGridContains(g, "dis", "Carytown");

        grids = client.evalAll(new String[] { "today()", "readById(@badBadBadId)" }, false);
        // for (int i=0; i<grids.length; ++i) grids[i].dump();
        verifyEq(grids.length, 2);
View Full Code Here

TOP

Related Classes of org.haystack.HGrid

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.