View RSS Feed

Cassandra

Cassandra Add Operation

Rate this Entry
by , 02-23-2012 at 06:15 PM (660 Views)
Following code explains add operation in java.
Java Code: This is the code to explain Cassandra Add Operation
Map<String, List<ColumnOrSuperColumn>> data = new HashMap<String, List<ColumnOrSuperColumn>>();        
List<ColumnOrSuperColumn> columns = new ArrayList<ColumnOrSuperColumn>();
// Create the email column.
ColumnOrSuperColumn c = new ColumnOrSuperColumn();
c.setColumn(new Column("email".getBytes("utf-8"), "ronald (at) sodeso.nl".getBytes("utf-8"), timestamp))
columns.add(c);
// Create the country column.
ColumnOrSuperColumn c = new ColumnOrSuperColumn();
c.setColumn(new Column("country".getBytes("utf-8"), "Netherlands, The".getBytes("utf-8"), timestamp))
columns.add(c);
// Create the registeredSince column.
ColumnOrSuperColumn c = new ColumnOrSuperColumn();
c.setColumn(new Column("registeredSince".getBytes("utf-8"), "01/01/2010".getBytes("utf-8"), timestamp));
columns.add(c);
data.put("Authors", columns);       
client.batch_insert("Blog", "Ronald Mathies", data, ConsistencyLevel.ANY);
A timestamp is created in above code and it is used by columns. This timestamp is always required and cannot be replaced with a 0. In case of multiple nodes, this 0 value may cause different issues. After this a map is created to hold rows that will be inserted. The Map holds the name of ColunFamily that is defined in configuration file. Also the list holds Column or SuperColumn objects.

Submit "Cassandra Add Operation" to Facebook Submit "Cassandra Add Operation" to Digg Submit "Cassandra Add Operation" to del.icio.us Submit "Cassandra Add Operation" to StumbleUpon Submit "Cassandra Add Operation" to Google

Categories
Development

Comments