-
Notifications
You must be signed in to change notification settings - Fork 354
Java driver simple named columns
opuneet edited this page Jan 11, 2014
·
1 revision
See Java-driver-direct-cql3 as reference for the schema that is being used for this example.
Assume that we have this row in the table
ColumnFamily<Integer, String> CF_EMPLOYEES =
new ColumnFamily<Integer, String>("EmployeeInfo",
IntegerSerializer.get(),
StringSerializer.get());
MutationBatch m = keyspace.prepareMutationBatch();
m.withRow(CF_EMPLOYEES, 1)
.putColumn("fname", "Joe")
.putColumn("fname", "Smith")
.putColumn("age", 35)
.putColumn("salary", 10000);
m.execute();
ColumnList<String> columns = keyspace.prepareQuery(CF_EMPLOYEES)
.getRow(1)
.execute()
.getResult();
System.out.println("FirstName: " + columns.getColumnByName("fname").getStringValue());
System.out.println("LastName: " + columns.getColumnByName("lname").getStringValue());
System.out.println("Age: " + columns.getColumnByName("age").getIntegerValue());
System.out.println("Salary: " + columns.getColumnByName("salary").getLongValue());
columns = keyspace.prepareQuery(CF_EMPLOYEES)
.getRow(1)
.withColumnSlice("fname", "age", "salary")
.execute()
.getResult();
Rows<Integer, String> rows = keyspace.prepareQuery(CF_EMPLOYEES)
.getRowSlice(1,3,5)
.execute()
.getResult();
rows = keyspace.prepareQuery(CF_EMPLOYEES)
.getRowSlice(1,3,5)
.withColumnSlice("fname", "age", "salary")
.execute()
.getResult();
A Netflix Original Production
Tech Blog | Twitter @NetflixOSS | Jobs
- Getting-Started
- Configuration
- Features
- Monitoring
- Thread Safety
- Timeouts
- Recipes
- Examples
- Javadoc
- Utilities
- Cassandra-Compatibility
- FAQ
- End-to-End Examples
- Astyanax Integration with Java Driver