本文整理匯總了Java中com.datastax.driver.core.Session.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.close方法的具體用法?Java Session.close怎麽用?Java Session.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.Session
的用法示例。
在下文中一共展示了Session.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRequestMessageStatement
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
/**
* Test with incoming message containing a header with RegularStatement.
*/
@Test
public void testRequestMessageStatement() throws Exception {
Update.Where update = update("camel_user")
.with(set("first_name", bindMarker()))
.and(set("last_name", bindMarker()))
.where(eq("login", bindMarker()));
Object response = producerTemplate.requestBodyAndHeader(new Object[]{"Claus 2", "Ibsen 2", "c_ibsen"},
CassandraConstants.CQL_QUERY, update);
Cluster cluster = CassandraUnitUtils.cassandraCluster();
Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
Row row = resultSet.one();
assertNotNull(row);
assertEquals("Claus 2", row.getString("first_name"));
assertEquals("Ibsen 2", row.getString("last_name"));
session.close();
cluster.close();
}
示例2: testRequestMessageStatement
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
/**
* Test with incoming message containing a header with RegularStatement.
*/
@Test
public void testRequestMessageStatement() throws Exception {
Update.Where update = update("camel_user")
.with(set("first_name", "Claus 2"))
.and(set("last_name", "Ibsen 2"))
.where(eq("login", "c_ibsen"));
Object response = producerTemplate.requestBodyAndHeader(null,
CassandraConstants.CQL_QUERY, update);
Cluster cluster = CassandraUnitUtils.cassandraCluster();
Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
Row row = resultSet.one();
assertNotNull(row);
assertEquals("Claus 2", row.getString("first_name"));
assertEquals("Ibsen 2", row.getString("last_name"));
session.close();
cluster.close();
}
示例3: createTable
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
private static void createTable(IOTestPipelineOptions options, String tableName) {
Cluster cluster = null;
Session session = null;
try {
cluster = getCluster(options);
session = cluster.connect();
LOG.info("Create {} keyspace if not exists", KEYSPACE);
session.execute("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE + " WITH REPLICATION = "
+ "{'class':'SimpleStrategy', 'replication_factor':3};");
session.execute("USE " + KEYSPACE);
LOG.info("Create {} table if not exists", tableName);
session.execute("CREATE TABLE IF NOT EXISTS " + tableName + "(id int, name text, PRIMARY "
+ "KEY(id))");
} finally {
if (session != null) {
session.close();
}
if (cluster != null) {
cluster.close();
}
}
}
示例4: cleanUpDataTable
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
public static void cleanUpDataTable(IOTestPipelineOptions options) {
Cluster cluster = null;
Session session = null;
try {
cluster = getCluster(options);
session = cluster.connect();
session.execute("TRUNCATE TABLE " + KEYSPACE + "." + TABLE_WRITE_NAME);
} finally {
if (session != null) {
session.close();
}
if (cluster != null) {
cluster.close();
}
}
}
示例5: before
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
@Override
protected void before() throws Throwable {
dependency.before();
Cluster cluster = Cluster.builder().addContactPoint(getHost()).withPort(getPort())
.withNettyOptions(new NettyOptions() {
@Override
public void onClusterClose(EventLoopGroup eventLoopGroup) {
eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
}
}).build();
Session session = cluster.newSession();
try {
if (requiredVersion != null) {
Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session);
if (cassandraReleaseVersion.isLessThan(requiredVersion)) {
throw new AssumptionViolatedException(
String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", getHost(), getPort(),
cassandraReleaseVersion, requiredVersion));
}
}
session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s \n"
+ "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName));
} finally {
session.close();
cluster.close();
}
}
示例6: init
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
public void init() {
Session session = cluster.connect();
session.execute(CREATE_KEYSPACE_QUERY);
session.close();
session = cluster.connect(KEYSPACE_NAME);
session.execute(CREATE_TABLE_QUERY);
session.execute(String.format(INSERT_QUERY, "A", 1000));
session.execute(String.format(INSERT_QUERY, "B", 1000));
session.close();
}
示例7: testRequestMessageCql
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
@Test
public void testRequestMessageCql() throws Exception {
Object response = producerTemplate.requestBodyAndHeader(new Object[]{"Claus 2", "Ibsen 2", "c_ibsen"},
CassandraConstants.CQL_QUERY, "update camel_user set first_name=?, last_name=? where login=?");
Cluster cluster = CassandraUnitUtils.cassandraCluster();
Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
Row row = resultSet.one();
assertNotNull(row);
assertEquals("Claus 2", row.getString("first_name"));
assertEquals("Ibsen 2", row.getString("last_name"));
session.close();
cluster.close();
}
示例8: closeSessionQuietly
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
private void closeSessionQuietly(Session cassandraSession) {
if (cassandraSession == null)
return;
try {
cassandraSession.close();
} catch (Exception e) {
Exception wrappedException = wrapException(e);
logger.warn("Error closing Cassandra session", wrappedException);
}
}
示例9: createTestKeyspaceIfNotExists
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
private void createTestKeyspaceIfNotExists() {
Session session = this.cassandra.getCluster().connect();
try {
session.execute("CREATE KEYSPACE IF NOT EXISTS boot_test"
+ " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };");
}
finally {
session.close();
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:11,代碼來源:CassandraDataAutoConfigurationIntegrationTests.java
示例10: main
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
public static void main(String[] args) {
if(args.length < 3 ) {
System.out.println("usage: NS_ChildUpdate machine mechid (encrypted)passwd");
} else {
try {
AuthzEnv env = new AuthzEnv();
env.setLog4JNames("log.properties","authz","authz","audit","init","trace");
Cluster cluster = Cluster.builder()
.addContactPoint(args[0])
.withCredentials(args[1],env.decrypt(args[2], false))
.build();
Session session = cluster.connect("authz");
try {
ResultSet result = session.execute("SELECT name,parent FROM ns");
int count = 0;
for(Row r : result.all()) {
++count;
String name = r.getString(0);
String parent = r.getString(1);
if(parent==null) {
int idx = name.lastIndexOf('.');
parent = idx>0?name.substring(0, idx):".";
System.out.println("UPDATE " + name + " to " + parent);
session.execute("UPDATE ns SET parent='" + parent + "' WHERE name='" + name + "';");
}
}
System.out.println("Processed " + count + " records");
} finally {
session.close();
cluster.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例11: oldestHintIsPickedFromOneNode
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
@Test
public void oldestHintIsPickedFromOneNode() {
long hintTimestamp = System.currentTimeMillis();
Cluster cluster = Cluster.builder()
.addContactPoint("127.0.0.1")
.withPort(9164)
.withClusterName("Test Cluster")
.build();
Session clusterSession = cluster.connect("system");
// Insert two hints with different timestamps on the same node.
clusterSession.execute(getInsertHintsQuery(hintTimestamp));
clusterSession.execute(getInsertHintsQuery(hintTimestamp + 10000));
// Get oldestHint
ClusterHintsPoller clusterHintsPoller = new ClusterHintsPoller();
HintsPollerResult oldestHintsInfo = clusterHintsPoller.getOldestHintsInfo(clusterSession);
Assert.assertNotNull(oldestHintsInfo);
// Since we know there should be only one entry
long retrievedHintTimeStamp = oldestHintsInfo.getOldestHintTimestamp().or(Long.MAX_VALUE);
Assert.assertEquals(retrievedHintTimeStamp, hintTimestamp);
cluster.close();
clusterSession.close();
}
示例12: shouldConnectUsingCassandraClient
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
@Test
public void shouldConnectUsingCassandraClient() throws SQLException {
Cluster cluster = Cluster.builder().addContactPoint(CASSANDRA_HOST)
.withAuthProvider(new PlainTextAuthProvider(username, password)).build();
Session session = cluster.connect();
session.close();
cluster.close();
}
示例13: insertTestData
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
private static void insertTestData(IOTestPipelineOptions options, String tableName) {
Cluster cluster = null;
Session session = null;
try {
cluster = getCluster(options);
session = cluster.connect();
LOG.info("Insert test dataset");
String[] scientists = {
"Lovelace",
"Franklin",
"Meitner",
"Hopper",
"Curie",
"Faraday",
"Newton",
"Bohr",
"Galilei",
"Maxwell"
};
for (int i = 0; i < 1000; i++) {
int index = i % scientists.length;
session.execute("INSERT INTO " + KEYSPACE + "." + tableName + "(id, name) values("
+ i + ",'" + scientists[index] + "');");
}
} finally {
if (session != null) {
session.close();
}
if (cluster != null) {
cluster.close();
}
}
}
示例14: doPreSetup
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
@Override
protected void doPreSetup() throws Exception {
CassandraUnitUtils.startEmbeddedCassandra();
cluster = CassandraUnitUtils.cassandraCluster();
Session rootSession = cluster.connect();
CassandraUnitUtils.loadCQLDataSet(rootSession, "NamedAggregationDataSet.cql");
rootSession.close();
aggregationRepository = new NamedCassandraAggregationRepository(cluster, CassandraUnitUtils.KEYSPACE, "ID");
aggregationRepository.setTable("NAMED_CAMEL_AGGREGATION");
aggregationRepository.start();
super.doPreSetup();
}
示例15: doPreSetup
import com.datastax.driver.core.Session; //導入方法依賴的package包/類
@Override
protected void doPreSetup() throws Exception {
CassandraUnitUtils.startEmbeddedCassandra();
cluster = CassandraUnitUtils.cassandraCluster();
Session rootSession = cluster.connect();
CassandraUnitUtils.loadCQLDataSet(rootSession, "NamedIdempotentDataSet.cql");
rootSession.close();
idempotentRepository = new NamedCassandraIdempotentRepository(cluster, CassandraUnitUtils.KEYSPACE, "ID");
idempotentRepository.setTable("NAMED_CAMEL_IDEMPOTENT");
idempotentRepository.start();
super.doPreSetup();
}