Skip to content
shehaaz edited this page Apr 23, 2013 · 14 revisions

Welcome to the AndroidCassandra wiki!

This project attempts to build an Android app that uses Apache Cassandra.

Steps used to learn Cassandra:

##Using the CQL 3 shell

  • Checkout [Cassandra Query Language (CQL3)] (http://cassandra.apache.org/doc/cql3/CQL.html) reference
  • Navigate in terminal to apache-cassandra-***/bin
  • Run: python cqlsh localhost 9160 NEED HELP?
  • $ cqlsh>
    create keyspace android with replication = {'class' : 'SimpleStrategy', 'replication_factor' : 3};
  • $ cqlsh>
    use android;
  • $ cqlsh>
    CREATE TABLE user_profiles ( user_id text PRIMARY KEY, first_name text, last_name text, year_of_birth int ) WITH COMPACT STORAGE;
  • $ cqlsh>
    INSERT INTO user_profiles (user_id, first_name, last_name, year_of_birth) VALUES ('1', 'John', 'Locke', 1632); John Locke?
  • $ cqlsh>
    Select * from user_profiles; (This displays a pretty table)

Find the perfect java-driver

Java-Driver by Datastax was used to communicate with the database.

  • These are the steps to build and create an Eclipse project. (Prerequisite: Maven) git clone https://github.com/joaquincasares/java-driver.git mvn clean install mvn eclipse:clean eclipse:eclipse

Don't forget to get the "native transport server" (that is used by the Datastax's Java-Driver) to work you have to un-comment start_native_transport: true in cassandra.yaml to activate port:9042. It doesn't doesn't use the thrift server (Port:9160)

  • Start the server(/bin): cassandra -f

  • Import cassandra-driver-core and cassandra-driver-example-stress into eclipse. To look at how the example calls the Driver.

  • Once understood...you need to create your own Java project...In summary you need to Maven-ize the POM's inside the driver-examples and create your own eclipse project, why are we using Maven? because there are a LOT of dependency .jars and it would take you hours to get them all....follow these steps make it work:

  1. Copy the driver-examples folder and place it in a you new folder. i.e you new project folder.
  2. Delete all the java files inside com\datastax\driver\stress and create two classes [CassandraDAO.java] (https://gist.github.com/shehaaz/5279566) and [Runner.java] (https://gist.github.com/shehaaz/5282948).
  3. In the POM.xml inside YourProjectFolder/driver-examples/stress change the artifactId <artifactId>cassandra-driver-examples-stress</artifactId> to your project name...we are doing this to avoid the conflict with the already imported cassandra-driver-examples-stress in the Eclipse Workspace.
  4. Navigate in the Terminal to YourProjectFolder/driver-examples/ and do mvn clean install followed by eclipse:clean eclipse:eclipse
  5. Voila! Now you can import you new project to eclipse. btw running the code should print out Row[1, John, Locke, 1632] because the example code is using the same KEYSPACE : android and TABLE : users_profiles