当前位置: 首页>>代码示例>>Java>>正文


Java Session.prepare方法代码示例

本文整理汇总了Java中com.datastax.driver.core.Session.prepare方法的典型用法代码示例。如果您正苦于以下问题:Java Session.prepare方法的具体用法?Java Session.prepare怎么用?Java Session.prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.datastax.driver.core.Session的用法示例。


在下文中一共展示了Session.prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDelayOnPreparedStatementWhenIgnoreOnPrepareIsFalse

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Test
public void testDelayOnPreparedStatementWhenIgnoreOnPrepareIsFalse() throws Exception {
  Prime prime =
      PrimeDsl.when("select * from table where c1=?")
          .then(noRows())
          .delay(2, TimeUnit.SECONDS)
          .applyToPrepare()
          .build();
  HttpTestResponse response = server.prime(prime.getPrimedRequest());
  assertNotNull(response);
  RequestPrime responseQuery = om.readValue(response.body, RequestPrime.class);
  assertThat(responseQuery).isEqualTo(prime.getPrimedRequest());

  String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0);
  try (com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build()) {
    Session session = cluster.connect();
    long start = System.currentTimeMillis();
    session.prepare("select * from table where c1=?");
    long duration = System.currentTimeMillis() - start;
    // should have taken longer than 2 seconds.
    assertThat(duration).isGreaterThan(2000);
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:25,代码来源:HttpPrimeQueryIntegrationTest.java

示例2: main

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static void main(String[] args) {

		Session session = Connection.connect();		
		PreparedStatement preparedStatement = session.prepare("insert into user (id, name, age) values (?, ?, ?)");

		try {
			BoundStatement boundStatement = preparedStatement.bind(UUIDs.timeBased(), "Hector", 34);
			ResultSet rs = session.execute(boundStatement);
			System.out.println(rs);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
		Connection.close();

	}
 
开发者ID:abulbasar,项目名称:cassandra-java-driver-examples,代码行数:17,代码来源:PreparedStatementExample.java

示例3: main

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static void main(String[] args) {

		Session session = Connection.connect();		
		BatchStatement batchStatement = new BatchStatement();
		
		PreparedStatement preparedStatement = session.prepare("insert into user (id, name) values (?, ?)");
		int i = 0;
		while(i < 10) {
			batchStatement.add(preparedStatement.bind(UUIDs.timeBased(), "user-" + i));
			++i;
		}

		try {
			ResultSet rs = session.execute(batchStatement);
			System.out.println(rs);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		Connection.close();

	}
 
开发者ID:abulbasar,项目名称:cassandra-java-driver-examples,代码行数:22,代码来源:BatchStatementExample.java

示例4: Indexer

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
Indexer(Session session, @Nullable Integer indexTtl,
    @Nullable ConcurrentMap<PartitionKeyToTraceId, Pair<Long>> sharedState, IndexSupport index) {
  this.index = index;
  this.boundName = UPPER_CAMEL.to(LOWER_HYPHEN, index.getClass().getSimpleName());
  Insert insert = index.declarePartitionKey(QueryBuilder.insertInto(index.table())
      .value("ts", QueryBuilder.bindMarker("ts"))
      .value("trace_id", QueryBuilder.bindMarker("trace_id")));
  if (indexTtl != null) {
    insert.using(QueryBuilder.ttl(QueryBuilder.bindMarker("ttl_")));
  }
  this.prepared = session.prepare(insert);
  this.indexTtl = indexTtl;
  this.session = session;
  this.timestampCodec = new TimestampCodec(session);
  this.sharedState = sharedState;
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:17,代码来源:Indexer.java

示例5: testNoDelayOnPreparedStatementWhenIgnoreOnPrepareIsFalse

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Test
public void testNoDelayOnPreparedStatementWhenIgnoreOnPrepareIsFalse() throws Exception {
  Prime prime =
      PrimeDsl.when("select * from table where c1=?")
          .then(noRows())
          .delay(2, TimeUnit.SECONDS)
          .ignoreOnPrepare()
          .build();
  HttpTestResponse response = server.prime(prime.getPrimedRequest());
  assertNotNull(response);
  RequestPrime responseQuery = om.readValue(response.body, RequestPrime.class);
  assertThat(responseQuery).isEqualTo(prime.getPrimedRequest());

  String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0);
  try (com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build()) {
    Session session = cluster.connect();
    long start = System.currentTimeMillis();
    PreparedStatement prepared = session.prepare("select * from table where c1=?");
    long duration = System.currentTimeMillis() - start;
    // should not have applied delay to prepare.
    assertThat(duration).isLessThan(2000);
    start = System.currentTimeMillis();
    session.execute(prepared.bind());
    duration = System.currentTimeMillis() - start;
    // should have taken longer than 2 seconds as delay is applied to execute.
    assertThat(duration).isGreaterThan(2000);
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:30,代码来源:HttpPrimeQueryIntegrationTest.java

示例6: makeNativeBoundQueryWithNameParams

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static ResultSet makeNativeBoundQueryWithNameParams(
    String query, String contactPoint, Map<String, Long> values) {
  com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build();
  Session session = cluster.connect();
  com.datastax.driver.core.PreparedStatement prepared = session.prepare(query);
  BoundStatement bound = prepared.bind();
  values.forEach((k, v) -> bound.setLong(k, v));
  return executeQueryWithFreshSession(bound, contactPoint, session, cluster);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:11,代码来源:HttpTestUtil.java

示例7: makeNativeBoundQueryWithNameParamsStrings

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static ResultSet makeNativeBoundQueryWithNameParamsStrings(
    String query, String contactPoint, Map<String, String> values) {
  com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build();
  Session session = cluster.connect();
  com.datastax.driver.core.PreparedStatement prepared = session.prepare(query);
  BoundStatement bound = getBoundStatementNamed(query, contactPoint, values);
  return executeQueryWithFreshSession(bound, contactPoint, session, cluster);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:10,代码来源:HttpTestUtil.java

示例8: makeNativeBoundQueryWithPositionalParam

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static ResultSet makeNativeBoundQueryWithPositionalParam(
    String query, String contactPoint, Object param) {
  com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build();
  Session session = cluster.connect();
  com.datastax.driver.core.PreparedStatement prepared = session.prepare(query);
  BoundStatement bound = getBoundStatement(query, contactPoint, param);
  return executeQueryWithFreshSession(bound, contactPoint, session, cluster);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:10,代码来源:HttpTestUtil.java

示例9: getBoundStatement

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static BoundStatement getBoundStatement(String query, String contactPoint, Object param) {
  try (com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build()) {
    Session session = cluster.connect();
    com.datastax.driver.core.PreparedStatement prepared = session.prepare(query);
    BoundStatement bound = prepared.bind(param);
    return bound;
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:10,代码来源:HttpTestUtil.java

示例10: getBoundStatementNamed

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static BoundStatement getBoundStatementNamed(
    String query, String contactPoint, Map<String, String> values) {
  try (com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build()) {
    Session session = cluster.connect();
    com.datastax.driver.core.PreparedStatement prepared = session.prepare(query);
    BoundStatement bound = prepared.bind();
    values.forEach((k, v) -> bound.setString(k, v));
    return bound;
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:12,代码来源:HttpTestUtil.java

示例11: prepareAndQuery

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
private ResultSet prepareAndQuery() throws Exception {
  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder(server.getCluster())
          .withRetryPolicy(FallthroughRetryPolicy.INSTANCE)
          .build()) {
    Session session = driverCluster.connect();
    PreparedStatement prepared = session.prepare(query);
    return session.execute(prepared.bind());
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:11,代码来源:ErrorResultIntegrationTest.java

示例12: insertMulti

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
	public Status insertMulti(List<TsPoint> points) {
		long costTime = 0L;
		if (points != null) {
			Cluster cluster = null;
			try {
//				cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
//				Session session = cluster.connect(KEY_SPACE_NAME);
				Session session = SessionManager.getSession();
				BatchStatement batch = new BatchStatement();
				PreparedStatement ps = session.prepare(
						"INSERT INTO " + TABLE_NAME + "(timestamp,device_code,sensor_code,value) VALUES(?,?,?,?)");
				for (TsPoint point : points) {
					BoundStatement bs = ps.bind(new Date(point.getTimestamp()), point.getDeviceCode(),
							point.getSensorCode(), Double.parseDouble(point.getValue().toString()));
					batch.add(bs);
				}
				long startTime = System.nanoTime();
				session.execute(batch);
				long endTime = System.nanoTime();
				costTime = endTime - startTime;
				batch.clear();
//				session.close();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (cluster != null)
					cluster.close();
			}
		}
//		System.out.println("costTime=" + costTime);
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:34,代码来源:CassandraDB.java

示例13: updatePoints

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
	public Status updatePoints(List<TsPoint> points) {
		long costTime = 0L;
		if (points != null) {
			Cluster cluster = null;
			try {
//				cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
//				Session session = cluster.connect(KEY_SPACE_NAME);
				Session session = SessionManager.getSession();
				BatchStatement batch = new BatchStatement();
				PreparedStatement ps = session.prepare(
						"UPDATE " + TABLE_NAME + " SET value=? WHERE timestamp=? and device_code=? and sensor_code=?");
				for (TsPoint point : points) {
					BoundStatement bs = ps.bind(Double.parseDouble(point.getValue().toString()),new Date(point.getTimestamp()), point.getDeviceCode(),
							point.getSensorCode());
					batch.add(bs);
				}
				long startTime = System.nanoTime();
				session.execute(batch);
				long endTime = System.nanoTime();
				costTime = endTime - startTime;
				batch.clear();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (cluster != null)
					cluster.close();
			}
		}
//		System.out.println("此次更新消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:33,代码来源:CassandraDB.java

示例14: CassandraSpanConsumer

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
CassandraSpanConsumer(Session session) {
  this.session = session;
  this.metadata = Schema.readMetadata(session);

  insertSpan = session.prepare(
      QueryBuilder
          .insertInto(Schema.TABLE_TRACES)
          .value("trace_id", QueryBuilder.bindMarker("trace_id"))
          .value("ts_uuid", QueryBuilder.bindMarker("ts_uuid"))
          .value("id", QueryBuilder.bindMarker("id"))
          .value("ts", QueryBuilder.bindMarker("ts"))
          .value("span_name", QueryBuilder.bindMarker("span_name"))
          .value("parent_id", QueryBuilder.bindMarker("parent_id"))
          .value("duration", QueryBuilder.bindMarker("duration"))
          .value("annotations", QueryBuilder.bindMarker("annotations"))
          .value("binary_annotations", QueryBuilder.bindMarker("binary_annotations"))
          .value("all_annotations", QueryBuilder.bindMarker("all_annotations")));

  insertTraceServiceSpanName = session.prepare(
      QueryBuilder
          .insertInto(Schema.TABLE_TRACE_BY_SERVICE_SPAN)
          .value("service_name", QueryBuilder.bindMarker("service_name"))
          .value("span_name", QueryBuilder.bindMarker("span_name"))
          .value("bucket", QueryBuilder.bindMarker("bucket"))
          .value("ts", QueryBuilder.bindMarker("ts"))
          .value("trace_id", QueryBuilder.bindMarker("trace_id"))
          .value("duration", QueryBuilder.bindMarker("duration")));

  insertServiceSpanName = session.prepare(
      QueryBuilder
          .insertInto(Schema.TABLE_SERVICE_SPANS)
          .value("service_name", QueryBuilder.bindMarker("service_name"))
          .value("span_name", QueryBuilder.bindMarker("span_name")));
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:35,代码来源:CassandraSpanConsumer.java

示例15: CassandraSpanConsumer

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
CassandraSpanConsumer(Session session, int bucketCount, int spanTtl, int indexTtl,
    @Nullable CacheBuilderSpec indexCacheSpec) {
  this.session = session;
  this.timestampCodec = new TimestampCodec(session);
  this.spanTtl = spanTtl;
  this.metadata = Schema.readMetadata(session);
  this.indexTtl = metadata.hasDefaultTtl ? null : indexTtl;
  insertSpan = session.prepare(
      maybeUseTtl(QueryBuilder
          .insertInto("traces")
          .value("trace_id", QueryBuilder.bindMarker("trace_id"))
          .value("ts", QueryBuilder.bindMarker("ts"))
          .value("span_name", QueryBuilder.bindMarker("span_name"))
          .value("span", QueryBuilder.bindMarker("span"))));

  insertServiceName = session.prepare(
      maybeUseTtl(QueryBuilder
          .insertInto(Tables.SERVICE_NAMES)
          .value("service_name", QueryBuilder.bindMarker("service_name"))));

  insertSpanName = session.prepare(
      maybeUseTtl(QueryBuilder
          .insertInto(Tables.SPAN_NAMES)
          .value("service_name", QueryBuilder.bindMarker("service_name"))
          .value("bucket", 0) // bucket is deprecated on this index
          .value("span_name", QueryBuilder.bindMarker("span_name"))));

  deduplicatingExecutor = new DeduplicatingExecutor(session, WRITTEN_NAMES_TTL);
  indexer = new CompositeIndexer(session, indexCacheSpec, bucketCount, this.indexTtl);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:31,代码来源:CassandraSpanConsumer.java


注:本文中的com.datastax.driver.core.Session.prepare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。