-
Notifications
You must be signed in to change notification settings - Fork 3
Home
This project attempts to build an Android app that uses Apache Cassandra.
Steps used to learn Cassandra:
- [Setting up Cassandra] (http://wiki.apache.org/cassandra/GettingStarted)
- [Linux JVM_OPTS Issue] (http://stackoverflow.com/questions/11901421/cannot-start-cassandra-db-using-bin-cassandra/14447535#14447535)
##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)
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
andcassandra-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:
- Copy the
driver-examples
folder and place it in a you new folder. i.e you new project folder. - 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). - In the
POM.xml
insideYourProjectFolder/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 importedcassandra-driver-examples-stress
in the Eclipse Workspace. - Navigate in the Terminal to
YourProjectFolder/driver-examples/
and domvn clean install
followed byeclipse:clean eclipse:eclipse
- 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 sameKEYSPACE
:android
andTABLE
:users_profiles