package org.apache.hadoop.hbase.contrib.hbql;

import org.apache.expreval.util.Lists;
import org.apache.hadoop.hbase.contrib.hbql.client.Batch;
import org.apache.hadoop.hbase.contrib.hbql.client.Connection;
import org.apache.hadoop.hbase.contrib.hbql.client.ConnectionManager;
import org.apache.hadoop.hbase.contrib.hbql.client.HBqlException;
import org.apache.hadoop.hbase.contrib.hbql.client.Query;
import org.apache.hadoop.hbase.contrib.hbql.util.TestSupport;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

public class AnnotationAllTypesTest extends TestSupport {

    static Connection conn = null;

    static List<AnnotatedAllTypes> vals = Lists.newArrayList();

    static int cnt = 10;

    @BeforeClass
    public static void emptyTable() throws HBqlException, IOException {

        conn = ConnectionManager.newConnection();

        if (!conn.tableExists("alltypes"))
            System.out.println(conn.execute("create table using schema AnnotatedAllTypes"));
        else {
            System.out.println(conn.execute("delete from AnnotatedAllTypes"));
        }
    }

    public static List<AnnotatedAllTypes> insertSomeData(int cnt, boolean noRandomData) throws HBqlException, IOException {

        List<AnnotatedAllTypes> retval = Lists.newArrayList();
        final Batch batch = new Batch();

        for (int i = 0; i < cnt; i++) {

            AnnotatedAllTypes aat = new AnnotatedAllTypes();
            aat.setATestValue(i, noRandomData);

            retval.add(aat);

            batch.insert(aat);
        }

        conn.apply(batch);

        return retval;
    }


    @Test
    public void simpleSelect() throws HBqlException, IOException {

        vals.addAll(insertSomeData(cnt, true));

        assertTrue(vals.size() == cnt);

        Query<AnnotatedAllTypes> recs = conn.newQuery("select * from AnnotatedAllTypes");

        int reccnt = 0;
        for (final AnnotatedAllTypes rec : recs.getResults())
            assertTrue(rec.equals(vals.get(reccnt++)));

        assertTrue(reccnt == cnt);
    }

    @Test
    public void simpleSparseSelect() throws HBqlException, IOException {

        vals.clear();
        vals.addAll(insertSomeData(cnt, false));

        assertTrue(vals.size() == cnt);

        Query<AnnotatedAllTypes> recs = conn.newQuery("select * from AnnotatedAllTypes");

        int reccnt = 0;
        for (final AnnotatedAllTypes rec : recs.getResults())
            assertTrue(rec.equals(vals.get(reccnt++)));

        assertTrue(reccnt == cnt);
    }
}

@@ -661,73 +661,8 @@
 l;%0A%0A
-    static List%3CAnnotatedAllTypes%3E vals = Lists.newArrayList();%0A%0A
     
@@ -682,16 +682,16 @@
 t = 10;%0A
+
 %0A    @Be
@@ -1665,36 +1665,55 @@
  %7B%0A%0A        
-vals.addAll(
+List%3CAnnotatedAllTypes%3E vals = 
 insertSomeDa
@@ -1724,13 +1724,13 @@
 nt, 
-true)
+false
 );%0A%0A
@@ -2142,42 +2142,39 @@
     
-vals.clear();%0A        vals.addAll(
+List%3CAnnotatedAllTypes%3E vals = 
 inse
@@ -2189,22 +2189,20 @@
 ta(cnt, 
-false)
+true
 );%0A%0A    
@@ -2464,32 +2464,32 @@
 t(reccnt++)));%0A%0A
-
         assertTr
@@ -2512,11 +2512,546 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void simpleLimitSelect() throws HBqlException, IOException %7B%0A%0A        List%3CAnnotatedAllTypes%3E vals = insertSomeData(cnt, true);%0A%0A        assertTrue(vals.size() == cnt);%0A%0A        Query%3CAnnotatedAllTypes%3E recs = conn.newQuery(%22select * from AnnotatedAllTypes WITH LIMIT :limit%22);%0A%0A        recs.setParameter(%22limit%22, cnt / 2);%0A%0A        int reccnt = 0;%0A        for (final AnnotatedAllTypes rec : recs.getResults())%0A            assertTrue(rec.equals(vals.get(reccnt++)));%0A%0A        assertTrue(reccnt == cnt / 2);%0A    %7D
 %0A%7D%0A

Work on AllTypes Tests