DataStax Java Driver Walkthrough

14

Transcript of DataStax Java Driver Walkthrough

Page 1: DataStax Java Driver Walkthrough
Page 2: DataStax Java Driver Walkthrough

DataStax Java Driver Walkthrough

Page 3: DataStax Java Driver Walkthrough

DataStax Java Driver Walkthrough

At

New Delhi Cassandra Users Meetup – November 2014

By: Narinder Kumar

Page 4: DataStax Java Driver Walkthrough

1. Driver Options with different languages2. DataStax Java Driver Highlights3. Key Features

a. Asynchronous I/Ob. Automatic Failoverc. Batch Statementsd. CQL – Java Data Types conversion

4. Code Demosa. Hello World Clientb. Loading & Querying Data in

Cassandrac. PreparedStatement & QueryBuilder

5. Debugging & Testing6. Key Points to keep in mind

Agenda

Page 5: DataStax Java Driver Walkthrough

• DataStax maintained language drivers are available in– C#– Java– Node.js– Python– Ruby– Go

• Other open source implementations also available

Driver Options with different languages

Page 6: DataStax Java Driver Walkthrough

• Current version 2.1.2

• What’s new

– Parameterized Statements

– Batching prepared Statements

– Automatic Result Set Pagination

– Lightweight Transactions

– Latency Aware Policies

– Fewer Dependencies

– Improved Testability

DataStax Java Driver – Highlights

Page 7: DataStax Java Driver Walkthrough

• session.execute(Query) ➔ session.executeAsync(Query)

• Returns ResultSet ➔ ResultSetFuture

• ResultSetFuture

– Implements java.util.concurrent.Future<V> interface

Asynchronous I/O

Page 8: DataStax Java Driver Walkthrough

• In case of one / multiple Node failure, Java driver automatically– Tries other nodes– Schedules reconnections

• Driver behavior is determined by cluster configuration optionsCluster.builder().addContactPoints(192.168.1.1, 192.168.1.5,…).withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE).withReconnectionPolicy(new

ConstantReconnectionPoloicy(100L)).build();

Automatic Failover

Page 9: DataStax Java Driver Walkthrough

• Allows execution of multiple statements in one group

• Works for Simple as well as PreparedStatements

• Can apply timestamp for later queries

• May be used to form mini transaction

Batch Statements

Page 10: DataStax Java Driver Walkthrough

CQL Java

ascii Stringbigint longblob Java.nio.ByteBuffer

counter Longdecimal java.math.BigDecimal

CQL to Java

Page 11: DataStax Java Driver Walkthrough

Code Demos

Refer Github repo : https://github.com/narinder-kumar/cassandrasample

Page 12: DataStax Java Driver Walkthrough

• Debugging– Enable Tracing on server side

• QueryBuilder….enableTracing()• ResultSet.getExecutionInfo()

– Adjust log4j configuration settings– JMX Monitoring

• connectedToHosts(), errorMetrics(), openConnections()

• Testing– In latest release, lot of classes have been implementing

Interfaces. Helps using Mocking frameworks during unit testing

Debugging & Testing

Page 13: DataStax Java Driver Walkthrough

• One cluster instance per cluster per application life-time– Easy Configurability

• One session instance per keyspace– Expensive object, better shared

• If executing one statement multiple times, considerPreparedStatement– Faster execution

• Consider Batch Operations

Key points while coding with Driver

Page 14: DataStax Java Driver Walkthrough

Contact us

Have more queries related to AngularJS?

Talk To Our Experts!

Our Office

Client Location

Click Here To Know More!

Here’s how TOTHENEW helps your customers outsource across the globe using BIG DATA!