// Path: src/main/java/org/easycassandra/ClassInformations.java
// public enum ClassInformations {
// 
//     INSTACE;
//     /**
//      * field that contains all class on Cassandra.
//      * Key - qualifield
//      * value - the wrapper of class
//      */
//     private Map<String, ClassInformation> classMap;
// 
//     /**
//      * The integer class is used to enum how default.
//      */
//     public static final Class<?> DEFAULT_ENUM_CLASS = Integer.class;
// 
//     /**
//      * return the wrapper of class.
//      * @param clazz class to find
//      * @return {@link ClassInformation}
//      */
//     public ClassInformation getClass(Class<?> clazz) {
// 
//         if (classMap.get(clazz.getName()) == null) {
//             classMap.put(clazz.getName(), new ClassInformation(clazz));
//         }
//         return classMap.get(clazz.getName());
//     }
// 
//     {
//         classMap = Collections.synchronizedMap(new TreeMap<String, ClassInformation>());
//     }
// }


import java.util.LinkedList;
import java.util.List;
import org.easycassandra.ClassInformation;
import org.easycassandra.ClassInformation.KeySpaceInformation;
import org.easycassandra.ClassInformations;
import org.easycassandra.FieldInformation;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
/*
 * Copyright 2013 Otávio Gonçalves de Santana (otaviojava)
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.easycassandra.persistence.cassandra;




/**
 * Mount and run the query to returns all data from column family.
 * @author otaviojava
 */
public class FindAllQuery {


    private String keySpace;

    /**
     * constructor.
     * @param keySpace
     *            the keyspace
     */
    public FindAllQuery(String keySpace) {
        this.keySpace = keySpace;
    }
    /**
     * list using select * from object.
     * @param bean the bean
     * @param session the sesion
     * @param consistency the consistency
     * @param <T> kind of class
     * @return the entities executing select * from
     */
    public <T> List<T> listAll(Class<T> bean, Session session,
            ConsistencyLevel consistency) {

        QueryBean byKeyBean = createQueryBean(bean, consistency);
        return RecoveryObject.INTANCE.recoverObjet(bean,
                session.execute(byKeyBean.select));
    }
    /**
     * create the {@link QueryBean}.
     * @param bean the bean
     * @param consistency the consistency
     * @param <T> kind of class
     * @return {@link QueryBean}
     */
    protected <T> QueryBean createQueryBean(Class<T> bean,
            ConsistencyLevel consistency) {
// Path: src/main/java/org/easycassandra/ClassInformations.java
// public enum ClassInformations {
// 
//     INSTACE;
//     /**
//      * field that contains all class on Cassandra.
//      * Key - qualifield
//      * value - the wrapper of class
//      */
//     private Map<String, ClassInformation> classMap;
// 
//     /**
//      * The integer class is used to enum how default.
//      */
//     public static final Class<?> DEFAULT_ENUM_CLASS = Integer.class;
// 
//     /**
//      * return the wrapper of class.
//      * @param clazz class to find
//      * @return {@link ClassInformation}
//      */
//     public ClassInformation getClass(Class<?> clazz) {
// 
//         if (classMap.get(clazz.getName()) == null) {
//             classMap.put(clazz.getName(), new ClassInformation(clazz));
//         }
//         return classMap.get(clazz.getName());
//     }
// 
//     {
//         classMap = Collections.synchronizedMap(new TreeMap<String, ClassInformation>());
//     }
// }


// Path: src/main/java/org/easycassandra/persistence/cassandra/FindAllQuery.java
import java.util.LinkedList;
import java.util.List;
import org.easycassandra.ClassInformation;
import org.easycassandra.ClassInformation.KeySpaceInformation;
import org.easycassandra.ClassInformations;
import org.easycassandra.FieldInformation;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;

/*
 * Copyright 2013 Otávio Gonçalves de Santana (otaviojava)
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.easycassandra.persistence.cassandra;




/**
 * Mount and run the query to returns all data from column family.
 * @author otaviojava
 */
public class FindAllQuery {


    private String keySpace;

    /**
     * constructor.
     * @param keySpace
     *            the keyspace
     */
    public FindAllQuery(String keySpace) {
        this.keySpace = keySpace;
    }
    /**
     * list using select * from object.
     * @param bean the bean
     * @param session the sesion
     * @param consistency the consistency
     * @param <T> kind of class
     * @return the entities executing select * from
     */
    public <T> List<T> listAll(Class<T> bean, Session session,
            ConsistencyLevel consistency) {

        QueryBean byKeyBean = createQueryBean(bean, consistency);
        return RecoveryObject.INTANCE.recoverObjet(bean,
                session.execute(byKeyBean.select));
    }
    /**
     * create the {@link QueryBean}.
     * @param bean the bean
     * @param consistency the consistency
     * @param <T> kind of class
     * @return {@link QueryBean}
     */
    protected <T> QueryBean createQueryBean(Class<T> bean,
            ConsistencyLevel consistency) {
        ClassInformation classInformation = ClassInformations.INSTACE.getClass(bean);