// Path: src/main/java/in/cubestack/android/lib/storm/FetchType.java
// public enum FetchType {
// 
// 	EAGER, LAZY;
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/SortOrder.java
// public enum SortOrder {
//     ASC,
//     DESC
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/Order.java
// public class Order {
// 
// 	private SortOrder sortOrder;
// 	private String orderSql;
// 	private TableInformation information;
// 	private QueryGenerator queryGenerator = new QueryGenerator();
// 
// 	public Order(SortOrder order, TableInformation information) {
// 		this.sortOrder = order;
// 		this.information = information;
// 	}
// 
// 	public static <T> Order orderFor(Class<T> entity, String[] props, SortOrder sortOrder) {
// 		try {
// 			TableInformation information = EntityMetaDataCache.getMetaData(entity);
// 			Order order = new Order(sortOrder, information);
// 			validate(props, information);
// 			order.addProperty(props);
// 			return order;
// 		} catch (Exception e) {
// 			throw new StormRuntimeException("Invalid entity, please check your mapppings for " + entity, e);
// 		}
// 	}
// 
// 	private static void validate(String[] props, TableInformation tabInformation) {
// 		for(String prop: props) {
// 			ColumnMetaData columnInfo = tabInformation.getColumnMetaData(prop);
// 			if(columnInfo == null) {
// 				throw new StormRuntimeException("Could not find column mapped to alias " + prop +". Pl check your mapppings for " + tabInformation.getMappedClass());
// 			}
// 		}
// 	}
// 
// 	public void addProperty(String[] props) {
// 		orderSql = queryGenerator.orderBy(props, information, sortOrder);
// 	}
// 
// 	public String orderSql() {
// 		return orderSql;
// 	}
// 
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/Projection.java
// public interface Projection {
// 	
// 	Projection add(String property);
// 	
// 	Projection sum(String property);
// 	
// 	Projection count(String property);
// 
// 	Projection max(String property);
// 	
// 	Projection min(String property);
// 
// 	Projection average(String property);
// 
// 	Projection total(String property);
// 	
// 	List<SQLFunction> getAggregateFunctions() ;
// 	List<String> getColumns();
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/Restriction.java
// public interface Restriction {
// 
// 	public String toSqlString();
// 
// 	boolean valueStored();
// 
// 	String[] values();
// 
// 	Restriction page(int page);
// 
// 	Restriction limit(int offset, int limit);
// 
// 	public Object sqlString(Order order);
// 	
// 	public TableInformation getTableInformation();
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/SQLFunction.java
// public interface SQLFunction {
// 
// 	public String toSqlString();
// }


import in.cubestack.android.lib.storm.FetchType;
import in.cubestack.android.lib.storm.SortOrder;
import in.cubestack.android.lib.storm.criteria.Order;
import in.cubestack.android.lib.storm.criteria.Projection;
import in.cubestack.android.lib.storm.criteria.Restriction;
import in.cubestack.android.lib.storm.criteria.SQLFunction;

/**
 * 
 */
package in.cubestack.android.lib.storm.core;


/**
 * A core Android SQLite ORM framework build for speed and raw execution.
 * Copyright (c) 2014 CubeStack. Version built for Flash Back..
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
public class QueryGenerator {

	private static final String DELETE = "DELETE ";
	private static final String ORDER_BY = " ORDER BY ";
	private static final String INSERT_INTO = "INSERT INTO ";
	private static final String GROUP_BY = " GROUP BY ";
	private static final String WHERE = " WHERE ";
	private static final String EQUALS = " = ";
	private static final String ON = " ON ";
	private static final String LEFT_JOIN = " LEFT OUTER JOIN ";
	private static final String FROM = " FROM ";
	private static final String SELECT_INIT = "SELECT ";
	private static final char DOT = '.';
	private static final char COMMA = ',';
	private static final char SPACE = ' ';
	private static final char OPEN_BRACES = '(';
	private static final char CLOSE_BRACES = ')';
	private static final String VALUES = " VALUES ( ";
	private static final char QUESTION_MARK = '?';



// Path: src/main/java/in/cubestack/android/lib/storm/FetchType.java
// public enum FetchType {
// 
// 	EAGER, LAZY;
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/SortOrder.java
// public enum SortOrder {
//     ASC,
//     DESC
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/Order.java
// public class Order {
// 
// 	private SortOrder sortOrder;
// 	private String orderSql;
// 	private TableInformation information;
// 	private QueryGenerator queryGenerator = new QueryGenerator();
// 
// 	public Order(SortOrder order, TableInformation information) {
// 		this.sortOrder = order;
// 		this.information = information;
// 	}
// 
// 	public static <T> Order orderFor(Class<T> entity, String[] props, SortOrder sortOrder) {
// 		try {
// 			TableInformation information = EntityMetaDataCache.getMetaData(entity);
// 			Order order = new Order(sortOrder, information);
// 			validate(props, information);
// 			order.addProperty(props);
// 			return order;
// 		} catch (Exception e) {
// 			throw new StormRuntimeException("Invalid entity, please check your mapppings for " + entity, e);
// 		}
// 	}
// 
// 	private static void validate(String[] props, TableInformation tabInformation) {
// 		for(String prop: props) {
// 			ColumnMetaData columnInfo = tabInformation.getColumnMetaData(prop);
// 			if(columnInfo == null) {
// 				throw new StormRuntimeException("Could not find column mapped to alias " + prop +". Pl check your mapppings for " + tabInformation.getMappedClass());
// 			}
// 		}
// 	}
// 
// 	public void addProperty(String[] props) {
// 		orderSql = queryGenerator.orderBy(props, information, sortOrder);
// 	}
// 
// 	public String orderSql() {
// 		return orderSql;
// 	}
// 
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/Projection.java
// public interface Projection {
// 	
// 	Projection add(String property);
// 	
// 	Projection sum(String property);
// 	
// 	Projection count(String property);
// 
// 	Projection max(String property);
// 	
// 	Projection min(String property);
// 
// 	Projection average(String property);
// 
// 	Projection total(String property);
// 	
// 	List<SQLFunction> getAggregateFunctions() ;
// 	List<String> getColumns();
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/Restriction.java
// public interface Restriction {
// 
// 	public String toSqlString();
// 
// 	boolean valueStored();
// 
// 	String[] values();
// 
// 	Restriction page(int page);
// 
// 	Restriction limit(int offset, int limit);
// 
// 	public Object sqlString(Order order);
// 	
// 	public TableInformation getTableInformation();
// }
// 
// Path: src/main/java/in/cubestack/android/lib/storm/criteria/SQLFunction.java
// public interface SQLFunction {
// 
// 	public String toSqlString();
// }


// Path: src/main/java/in/cubestack/android/lib/storm/core/QueryGenerator.java
import in.cubestack.android.lib.storm.FetchType;
import in.cubestack.android.lib.storm.SortOrder;
import in.cubestack.android.lib.storm.criteria.Order;
import in.cubestack.android.lib.storm.criteria.Projection;
import in.cubestack.android.lib.storm.criteria.Restriction;
import in.cubestack.android.lib.storm.criteria.SQLFunction;

/**
 * 
 */
package in.cubestack.android.lib.storm.core;


/**
 * A core Android SQLite ORM framework build for speed and raw execution.
 * Copyright (c) 2014 CubeStack. Version built for Flash Back..
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
public class QueryGenerator {

	private static final String DELETE = "DELETE ";
	private static final String ORDER_BY = " ORDER BY ";
	private static final String INSERT_INTO = "INSERT INTO ";
	private static final String GROUP_BY = " GROUP BY ";
	private static final String WHERE = " WHERE ";
	private static final String EQUALS = " = ";
	private static final String ON = " ON ";
	private static final String LEFT_JOIN = " LEFT OUTER JOIN ";
	private static final String FROM = " FROM ";
	private static final String SELECT_INIT = "SELECT ";
	private static final char DOT = '.';
	private static final char COMMA = ',';
	private static final char SPACE = ' ';
	private static final char OPEN_BRACES = '(';
	private static final char CLOSE_BRACES = ')';
	private static final String VALUES = " VALUES ( ";
	private static final char QUESTION_MARK = '?';



	public String rawQuery(Class<?> entityClass, Restriction restriction, Projection projection) throws IllegalArgumentException, IllegalAccessException, InstantiationException, StormException {
