package com.kryptnostic.rhizome.mapstores.cassandra;

import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.kryptnostic.rhizome.mappers.SetProxy;

public class CassandraSetProxy<T> implements SetProxy<T> {
    public static final String SET_ID_FIELD = "setId";
    private final Session session;
    private final String  table;
    private final UUID setId;

    public CassandraSetProxy( Cluster cluster, String keyspace, String table, UUID setId ) {
        this.session = cluster.connect( keyspace );
        this.table = table;
        this.setId = setId;
    }

    @Override
    public int size() {
        session.execute( QueryBuilder.select().all().from( table ).where( QueryBuilder.eq(  SET_ID_FIELD, setId ) );
    }

    @Override
    public boolean isEmpty() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean contains( Object o ) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Iterator<T> iterator() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object[] toArray() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T> T[] toArray( T[] a ) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean add( T e ) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean remove( Object o ) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean containsAll( Collection<?> c ) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean addAll( Collection<? extends T> c ) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean retainAll( Collection<?> c ) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean removeAll( Collection<?> c ) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void clear() {
        // TODO Auto-generated method stub

    }

}

@@ -164,24 +164,67 @@
 re.Cluster;%0A
+import com.datastax.driver.core.ResultSet;%0A
 import com.d
@@ -307,24 +307,83 @@
 eryBuilder;%0A
+import com.datastax.driver.core.querybuilder.Select.Where;%0A
 import com.k
@@ -405,14 +405,24 @@
 ome.
-mapper
+hazelcast.object
 s.Se
@@ -437,16 +437,25 @@
 %0Apublic 
+abstract 
 class Ca
@@ -579,16 +579,21 @@
 Session 
+     
 session;
@@ -619,16 +619,21 @@
 String  
+     
 table;%0A 
@@ -650,24 +650,32 @@
  final UUID 
+        
 setId;%0A%0A    
@@ -928,24 +928,26 @@
     
-session.execute(
+Where countQuery =
  Que
@@ -965,17 +965,22 @@
 elect().
-a
+countA
 ll().fro
@@ -1013,17 +1013,16 @@
 lder.eq(
- 
  SET_ID_
@@ -1035,24 +1035,120 @@
  setId ) );%0A
+        ResultSet execute = session.execute( countQuery );%0A        return execute.all().size();%0A
     %7D%0A%0A    @
@@ -1199,63 +1199,26 @@
     
-// TODO Auto-generated method stub%0A        return false
+return size() == 0
 ;%0A  
@@ -2591,17 +2591,16 @@
 od stub%0A
-%0A
     %7D%0A%0A%7D

fix setproxy