cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ali Akhtar <ali.rac...@gmail.com>
Subject Re: schema generation in cassandra
Date Wed, 18 Mar 2015 09:59:19 GMT
Why are you creating new tables dynamically? I would try to use a static
schema and use a collection (list / map / set) for storing arbitrary data.

On Wed, Mar 18, 2015 at 2:52 PM, Ankit Agarwal <agarwalankit.kiet@gmail.com>
wrote:

> Hi,
>
> I am new to Cassandra, we are planning to use Cassandra for cloud base
> application in our development environment, so for this looking forward for
> best strategies to sync the schema for micro-services while deploy
> application on cloud foundry
>
> One way which I could use is   Accessor interface with datastax-mapper and
> casandra-core driver.
>
>
>
> 1.)  I have created a keyspace using  core driver which will be generated
> on initialization of servlet
>
> *public* *void* init() *throws* ServletException
>
> {
> Cluster cluster = Cluster.*builder*().addContactPoint("127.0.0.1"
> ).build();
>
> Session session = cluster.connect();
>
>  String keySpace="sampletest";
>
> session.execute("CREATE KEYSPACE IF NOT EXISTS "+ keySpace +
>
> " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' :
> 1 }");
>
> ..............
>
>
> 2.) This is my Accessor Interface which I used to generate Query
> for creating column family ..........
>
> @Accessor
>
> *public* *interface* UserAccessor
>
> {
>
> @Query(" CREATE TABLE sampletest.emp (id uuid PRIMARY KEY,name
> text,department text,location text,phone bigint ) WITH caching = '{
> \"keys\" : \"ALL\" , \"rows_per_partition\" : \"NONE\" }' " )
>
> ResultSet create_table();
>
> }
>
>
>
>
> 3.) Creating  an  instance of Accessor interface to provide mapping  to
> our query to generate column family
>
> ................
>
> MappingManager mapper=*new* MappingManager(session);
>
> UserAccessor ua= mapper.createAccessor(UserAccessor.*class*);
>
>  ua.create_table();
>
>  ................
>
>
>
> 4.) So far I have created a keyspace with a column family , now I want to
> map my data using POJO class mentioned below
>
>
> @Table(keyspace = "sampletest", name = "emp")
> *public* *class* Employee {
>
>  @PartitionKey
>
> *private* UUID id;
>
> *private* String name;
>
> *private* String department;
>
> *private* String location;
>
> *private* Long phone;
>
> // getter setter method
> .................
> }
>
>
>
> Is there any other better approach to achieve this especially for cloud
> environment
>
>
> --
> Thanks
>
> Ankit Agarwal
>
>

Mime
View raw message