// Path: webservice/src/main/java/com/griddelta/memnon/exception/MemnonException.java
// public class MemnonException extends Exception {
//     private static final long serialVersionUID = 1L;
// 
//     public MemnonException(String message){
//         super(message);
//     }   
// }
// 
// Path: webservice/src/main/java/com/griddelta/memnon/resource/JsonMarshaller.java
// public class JsonMarshaller {
//     private static Logger logger = LoggerFactory.getLogger(JsonMarshaller.class);
// 
//     @SuppressWarnings("unchecked")
//     public static JSONArray marshallKeyspaces(List<KeyspaceMetadata> keyspaces, boolean flatten)
//             throws UnsupportedEncodingException {
//         JSONArray keyspaceJson = new JSONArray();
//         if (flatten) {
//             for (KeyspaceMetadata keyspace : keyspaces) {
//                 for (TableMetadata table : keyspace.getTables()) {
//                     JSONObject json = new JSONObject();
//                     json.put("keyspace", keyspace.getName());
//                     json.put("columnFamily", table.getName());
//                     keyspaceJson.add(json);
//                 }
//             }
//         } 
//         return keyspaceJson;
//     }
//     
//     @SuppressWarnings("unchecked")
//     public static JSONArray marshallResultSet(ResultSet resultSet) {
//         JSONArray resultJson = new JSONArray();
//         for (Row row : resultSet){
//             JSONArray rowJson = new JSONArray();
//             resultJson.add(rowJson);
//             Iterator<Definition> definitionIterator = row.getColumnDefinitions().iterator();
//             while(definitionIterator.hasNext()){
//                 Definition definition = definitionIterator.next();
//                 logger.debug("Marshalling [" + definition.getName() + "] of type [" + definition.getType() + "]");
//                 if (definition.getType() == DataType.text()){     
//                     String value = row.getString(definition.getName());
//                     rowJson.add(value);
//                     logger.debug("Adding [" + value + "]");
//                 }
//             }
//         }
//         return resultJson;
//     }
// }


import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.CharacterCodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.Query;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
import com.datastax.driver.core.querybuilder.Assignment;
import com.datastax.driver.core.querybuilder.Clause;
import com.datastax.driver.core.querybuilder.Delete;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.querybuilder.Select.Selection;
import com.datastax.driver.core.querybuilder.Update;
import com.griddelta.memnon.exception.MemnonException;
import com.griddelta.memnon.resource.JsonMarshaller;
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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 com.griddelta.memnon;




public class CassandraStorage {
	protected static Cluster cluster;
	private static Logger LOG = LoggerFactory.getLogger(CassandraStorage.class);

	private Map<String, Session> sessions = new HashMap<String, Session>();
	private Session defaultSession = null;

	public CassandraStorage(String host, int port) throws Exception {
		LOG.debug("Connecting to Cassandra Storage @ [{}:{}]", host, port);
		try {
			cluster = Cluster.builder().addContactPoints(host).withPort(port)
					.build();
		} catch (NoHostAvailableException e) {
			throw new RuntimeException(e);
		}
	}

// Path: webservice/src/main/java/com/griddelta/memnon/exception/MemnonException.java
// public class MemnonException extends Exception {
//     private static final long serialVersionUID = 1L;
// 
//     public MemnonException(String message){
//         super(message);
//     }   
// }
// 
// Path: webservice/src/main/java/com/griddelta/memnon/resource/JsonMarshaller.java
// public class JsonMarshaller {
//     private static Logger logger = LoggerFactory.getLogger(JsonMarshaller.class);
// 
//     @SuppressWarnings("unchecked")
//     public static JSONArray marshallKeyspaces(List<KeyspaceMetadata> keyspaces, boolean flatten)
//             throws UnsupportedEncodingException {
//         JSONArray keyspaceJson = new JSONArray();
//         if (flatten) {
//             for (KeyspaceMetadata keyspace : keyspaces) {
//                 for (TableMetadata table : keyspace.getTables()) {
//                     JSONObject json = new JSONObject();
//                     json.put("keyspace", keyspace.getName());
//                     json.put("columnFamily", table.getName());
//                     keyspaceJson.add(json);
//                 }
//             }
//         } 
//         return keyspaceJson;
//     }
//     
//     @SuppressWarnings("unchecked")
//     public static JSONArray marshallResultSet(ResultSet resultSet) {
//         JSONArray resultJson = new JSONArray();
//         for (Row row : resultSet){
//             JSONArray rowJson = new JSONArray();
//             resultJson.add(rowJson);
//             Iterator<Definition> definitionIterator = row.getColumnDefinitions().iterator();
//             while(definitionIterator.hasNext()){
//                 Definition definition = definitionIterator.next();
//                 logger.debug("Marshalling [" + definition.getName() + "] of type [" + definition.getType() + "]");
//                 if (definition.getType() == DataType.text()){     
//                     String value = row.getString(definition.getName());
//                     rowJson.add(value);
//                     logger.debug("Adding [" + value + "]");
//                 }
//             }
//         }
//         return resultJson;
//     }
// }


// Path: webservice/src/main/java/com/griddelta/memnon/CassandraStorage.java
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.CharacterCodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.Query;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
import com.datastax.driver.core.querybuilder.Assignment;
import com.datastax.driver.core.querybuilder.Clause;
import com.datastax.driver.core.querybuilder.Delete;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.querybuilder.Select.Selection;
import com.datastax.driver.core.querybuilder.Update;
import com.griddelta.memnon.exception.MemnonException;
import com.griddelta.memnon.resource.JsonMarshaller;

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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 com.griddelta.memnon;




public class CassandraStorage {
	protected static Cluster cluster;
	private static Logger LOG = LoggerFactory.getLogger(CassandraStorage.class);

	private Map<String, Session> sessions = new HashMap<String, Session>();
	private Session defaultSession = null;

	public CassandraStorage(String host, int port) throws Exception {
		LOG.debug("Connecting to Cassandra Storage @ [{}:{}]", host, port);
		try {
			cluster = Cluster.builder().addContactPoints(host).withPort(port)
					.build();
		} catch (NoHostAvailableException e) {
			throw new RuntimeException(e);
		}
	}

	public JSONArray getKeyspaces() throws MemnonException,