use of com.datastax.driver.core.BoundStatement in project cassandra-driver-mapping by valchkou.
the class MappingSession method appendAsync.
/**
* Asynchronously Append value or values to the Set, List or Map.
*
* @param id Primary Key
* @param class Entity.class
* @param propertyName Entity property
* @param item can be a single value, a List, Set or a Map of values
* @param options WriteOptions
* @return ResultSetFuture.
*/
public ResultSetFuture appendAsync(Object id, Class<?> clazz, String propertyName, Object item, WriteOptions options) {
maybeSync(clazz);
BoundStatement bs = MappingBuilder.prepareAppendItemToCollection(id, clazz, propertyName, item, options, keyspace, session);
return executeAsync(bs);
}
use of com.datastax.driver.core.BoundStatement in project cassandra-driver-mapping by valchkou.
the class MappingSession method updateValuesAsync.
/**
* Update values with options.
*
* @param id Primary Key
* @param class Entity.class
* @param propertyNames Array of properties to update
* @param value array of values to update
*/
public ResultSetFuture updateValuesAsync(Object id, Class<?> clazz, String[] propertyNames, Object[] values, WriteOptions options) {
maybeSync(clazz);
BoundStatement bs = MappingBuilder.prepareUpdateValues(id, clazz, propertyNames, values, options, keyspace, session);
return executeAsync(bs);
}
use of com.datastax.driver.core.BoundStatement in project zipkin by openzipkin.
the class TracedSession method update.
@Override
public void update(Host host, Statement statement, Exception e, long nanos) {
if (!(statement instanceof BoundStatement))
return;
Span span = cache.remove(statement);
if (span == null) {
if (statement.isTracing()) {
LOG.warn("{} not in the cache eventhough tracing is on", statement);
}
return;
}
Span previous = brave.clientSpanThreadBinder().getCurrentClientSpan();
brave.clientSpanThreadBinder().setCurrentSpan(span);
try {
if (e != null) {
brave.clientTracer().submitBinaryAnnotation(Constants.ERROR, e.getMessage());
}
} finally {
// TODO: on brave 4, set host to remote address
brave.clientTracer().setClientReceived();
brave.clientSpanThreadBinder().setCurrentSpan(previous);
}
}
use of com.datastax.driver.core.BoundStatement in project zipkin by openzipkin.
the class CassandraSpanConsumer method storeSpan.
/**
* Store the span in the underlying storage for later retrieval.
*/
ListenableFuture<?> storeSpan(Span span, TraceIdUDT traceId, boolean isServerRecvSpan, Long timestamp) {
try {
if ((null == timestamp || 0 == timestamp) && !isServerRecvSpan && metadata.compactionClass.contains("TimeWindowCompactionStrategy")) {
LOG.warn("Span {} in trace {} had no timestamp. " + "If this happens a lot consider switching back to SizeTieredCompactionStrategy for " + "{}.traces", span.id, span.traceId, session.getLoggedKeyspace());
}
List<AnnotationUDT> annotations = new ArrayList<>(span.annotations.size());
for (Annotation annotation : span.annotations) {
annotations.add(new AnnotationUDT(annotation));
}
List<BinaryAnnotationUDT> binaryAnnotations = new ArrayList<>(span.binaryAnnotations.size());
for (BinaryAnnotation annotation : span.binaryAnnotations) {
binaryAnnotations.add(new BinaryAnnotationUDT(annotation));
}
Set<String> annotationKeys = CassandraUtil.annotationKeys(span);
if (!strictTraceId && traceId.getHigh() != 0L) {
storeSpan(span, new TraceIdUDT(0L, traceId.getLow()), isServerRecvSpan, timestamp);
}
BoundStatement bound = bindWithName(insertSpan, "insert-span").set("trace_id", traceId, TraceIdUDT.class).setUUID("ts_uuid", new UUID(UUIDs.startOf(null != timestamp ? (timestamp / 1000) : 0).getMostSignificantBits(), UUIDs.random().getLeastSignificantBits())).setLong("id", span.id).setString("span_name", span.name).setList("annotations", annotations).setList("binary_annotations", binaryAnnotations).setString("all_annotations", Joiner.on(',').join(annotationKeys));
if (null != span.timestamp) {
bound = bound.setLong("ts", span.timestamp);
}
if (null != span.duration) {
bound = bound.setLong("duration", span.duration);
}
if (null != span.parentId) {
bound = bound.setLong("parent_id", span.parentId);
}
return session.executeAsync(bound);
} catch (RuntimeException ex) {
return Futures.immediateFailedFuture(ex);
}
}
use of com.datastax.driver.core.BoundStatement in project zipkin by openzipkin.
the class CassandraSpanConsumer method storeTraceServiceSpanName.
ListenableFuture<?> storeTraceServiceSpanName(String serviceName, String spanName, long timestamp_micro, Long duration, TraceIdUDT traceId) {
int bucket = durationIndexBucket(timestamp_micro);
UUID ts = new UUID(UUIDs.startOf(timestamp_micro / 1000).getMostSignificantBits(), UUIDs.random().getLeastSignificantBits());
try {
BoundStatement bound = bindWithName(insertTraceServiceSpanName, "insert-trace-service-span-name").setString("service_name", serviceName).setString("span_name", spanName).setInt("bucket", bucket).setUUID("ts", ts).set("trace_id", traceId, TraceIdUDT.class);
if (null != duration) {
bound = bound.setLong("duration", duration);
}
return session.executeAsync(bound);
} catch (RuntimeException ex) {
return Futures.immediateFailedFuture(ex);
}
}
Aggregations