Search in sources :

Example 31 with BoundStatement

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);
}
Also used : BoundStatement(com.datastax.driver.core.BoundStatement)

Example 32 with BoundStatement

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);
}
Also used : BoundStatement(com.datastax.driver.core.BoundStatement)

Example 33 with BoundStatement

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);
    }
}
Also used : BoundStatement(com.datastax.driver.core.BoundStatement) Span(com.twitter.zipkin.gen.Span) ServerSpan(com.github.kristofa.brave.ServerSpan)

Example 34 with BoundStatement

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);
    }
}
Also used : ArrayList(java.util.ArrayList) BinaryAnnotationUDT(zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT) AnnotationUDT(zipkin.storage.cassandra3.Schema.AnnotationUDT) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) BinaryAnnotation(zipkin.BinaryAnnotation) BinaryAnnotationUDT(zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT) UUID(java.util.UUID) BoundStatement(com.datastax.driver.core.BoundStatement) TraceIdUDT(zipkin.storage.cassandra3.Schema.TraceIdUDT)

Example 35 with BoundStatement

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);
    }
}
Also used : UUID(java.util.UUID) BoundStatement(com.datastax.driver.core.BoundStatement)

Aggregations

BoundStatement (com.datastax.driver.core.BoundStatement)48 ResultSet (com.datastax.driver.core.ResultSet)9 PreparedStatement (com.datastax.driver.core.PreparedStatement)6 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)5 Row (com.datastax.driver.core.Row)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 RegularStatement (com.datastax.driver.core.RegularStatement)3 Session (com.datastax.driver.core.Session)3 DriverException (com.datastax.driver.core.exceptions.DriverException)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 List (java.util.List)3 Map (java.util.Map)3 UUID (java.util.UUID)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 DataType (com.datastax.driver.core.DataType)2 Statement (com.datastax.driver.core.Statement)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)2