Java Code Examples for com.datastax.driver.core.BoundStatement#setLong()

The following examples show how to use com.datastax.driver.core.BoundStatement#setLong() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: glowroot   File: TraceDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static void bindSlowPoint(BoundStatement boundStatement, String agentRollupId,
        String agentId, String traceId, Trace.Header header, int adjustedTTL, boolean overall,
        boolean partial, boolean cassandra2x) throws IOException {
    int i = bind(boundStatement, agentRollupId, agentId, traceId, header, overall,
            partial && !cassandra2x);
    if (partial) {
        if (cassandra2x) {
            // don't set real_capture_time, so this still looks like data prior to 0.13.1
            boundStatement.setToNull(i++);
        } else {
            boundStatement.setTimestamp(i++, new Date(header.getCaptureTime()));
        }
    }
    boundStatement.setLong(i++, header.getDurationNanos());
    boundStatement.setBool(i++, header.hasError());
    boundStatement.setString(i++, header.getHeadline());
    boundStatement.setString(i++, Strings.emptyToNull(header.getUser()));
    List<Trace.Attribute> attributes = header.getAttributeList();
    if (attributes.isEmpty()) {
        boundStatement.setToNull(i++);
    } else {
        boundStatement.setBytes(i++, Messages.toByteBuffer(attributes));
    }
    boundStatement.setInt(i++, adjustedTTL);
}
 
Example 2
private AsyncFunction<List<Long>, List<ResultSet>> getFetchChunksAsyncFunction(EntityId entityId, String key, Aggregation aggregation, long startTs, long endTs) {
    return partitions -> {
        try {
            PreparedStatement proto = getFetchStmt(aggregation);
            List<ResultSetFuture> futures = new ArrayList<>(partitions.size());
            for (Long partition : partitions) {
                log.trace("Fetching data for partition [{}] for entityType {} and entityId {}", partition, entityId.getEntityType(), entityId.getId());
                BoundStatement stmt = proto.bind();
                stmt.setString(0, entityId.getEntityType().name());
                stmt.setUUID(1, entityId.getId());
                stmt.setString(2, key);
                stmt.setLong(3, partition);
                stmt.setLong(4, startTs);
                stmt.setLong(5, endTs);
                log.debug("Generated query [{}] for entityType {} and entityId {}", stmt, entityId.getEntityType(), entityId.getId());
                futures.add(executeAsyncRead(stmt));
            }
            return Futures.allAsList(futures);
        } catch (Throwable e) {
            log.error("Failed to fetch data", e);
            throw e;
        }
    };
}
 
Example 3
private static void addValue(KvEntry kvEntry, BoundStatement stmt, int column) {
    switch (kvEntry.getDataType()) {
        case BOOLEAN:
            stmt.setBool(column, kvEntry.getBooleanValue().get().booleanValue());
            break;
        case STRING:
            stmt.setString(column, kvEntry.getStrValue().get());
            break;
        case LONG:
            stmt.setLong(column, kvEntry.getLongValue().get().longValue());
            break;
        case DOUBLE:
            stmt.setDouble(column, kvEntry.getDoubleValue().get().doubleValue());
            break;
    }
}
 
Example 4
@Override
protected Statement setStatementParameters(PreparedStatement updateCommand, EnrichedCustomerService tuple)
    throws DriverException
{
  final BoundStatement boundStmnt = new BoundStatement(updateCommand);
  boundStmnt.setLong(0, ++id);
  boundStmnt.setString(1, tuple.imsi);
  boundStmnt.setInt(2, tuple.totalDuration);
  boundStmnt.setInt(3, tuple.wait);
  boundStmnt.setString(4, tuple.zipCode);
  boundStmnt.setString(5, tuple.issueType.name());
  boundStmnt.setBool(6, tuple.satisfied);
  boundStmnt.setString(7, tuple.operatorCode);
  boundStmnt.setString(8, tuple.deviceBrand);
  boundStmnt.setString(9, tuple.deviceModel);

  //or boundStatement.bind();
  return boundStmnt;

}
 
Example 5
@Override
protected Statement setStatementParameters(PreparedStatement updateCommand, CustomerService tuple)
    throws DriverException
{
  final BoundStatement boundStmnt = new BoundStatement(updateCommand);
  boundStmnt.setLong(0, ++id);
  boundStmnt.setString(1, tuple.imsi);
  boundStmnt.setInt(2, tuple.totalDuration);
  boundStmnt.setInt(3, tuple.wait);
  boundStmnt.setString(4, tuple.zipCode);
  boundStmnt.setString(5, tuple.issueType.name());
  boundStmnt.setBool(6, tuple.satisfied);

  //or boundStatement.bind();
  return boundStmnt;

}
 
Example 6
@Override
public void insertRanges(final byte[][] ids, final long value) throws DataAccessLayerException {
	/*
	 * insert in: CF_RDT_SP_O
	 */
	// row key: subject + predicate
	final BoundStatement dspoStatement = _insertDSPOStatement.bind();
	dspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	dspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	dspoStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));
	dspoStatement.setLong(3, value);
	_batchStatements.get().add(dspoStatement);

	/*
	 * insert in: CF_RDT_P_OS
	 */
	final BoundStatement dposStatement = _insertDPOSStatement.bind();
	dposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
	dposStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[2]));
	dposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));
	dposStatement.setLong(3, value);
	_batchStatements.get().add(dposStatement);

}
 
Example 7
Source Project: glowroot   File: GaugeValueDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
private ListenableFuture<?> rollupOneFromRows(int rollupLevel, String agentRollupId,
        String gaugeName, long to, int adjustedTTL, Iterable<Row> rows) throws Exception {
    double totalWeightedValue = 0;
    long totalWeight = 0;
    for (Row row : rows) {
        double value = row.getDouble(0);
        long weight = row.getLong(1);
        totalWeightedValue += value * weight;
        totalWeight += weight;
    }
    BoundStatement boundStatement = insertValuePS.get(rollupLevel).bind();
    int i = 0;
    boundStatement.setString(i++, agentRollupId);
    boundStatement.setString(i++, gaugeName);
    boundStatement.setTimestamp(i++, new Date(to));
    // individual gauge value weights cannot be zero, and rows is non-empty
    // (see callers of this method), so totalWeight is guaranteed non-zero
    checkState(totalWeight != 0);
    boundStatement.setDouble(i++, totalWeightedValue / totalWeight);
    boundStatement.setLong(i++, totalWeight);
    boundStatement.setInt(i++, adjustedTTL);
    return session.writeAsync(boundStatement);
}
 
Example 8
Source Project: glowroot   File: AggregateDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
private ListenableFuture<?> rollupOverallSummaryFromRows(RollupParams rollup,
        AggregateQuery query, Iterable<Row> rows) throws Exception {
    double totalDurationNanos = 0;
    long transactionCount = 0;
    for (Row row : rows) {
        totalDurationNanos += row.getDouble(0);
        transactionCount += row.getLong(1);
    }
    BoundStatement boundStatement =
            getInsertOverallPS(summaryTable, rollup.rollupLevel()).bind();
    int i = 0;
    boundStatement.setString(i++, rollup.agentRollupId());
    boundStatement.setString(i++, query.transactionType());
    boundStatement.setTimestamp(i++, new Date(query.to()));
    boundStatement.setDouble(i++, totalDurationNanos);
    boundStatement.setLong(i++, transactionCount);
    boundStatement.setInt(i++, rollup.adjustedTTL().generalTTL());
    return session.writeAsync(boundStatement);
}
 
Example 9
Source Project: glowroot   File: AggregateDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
private ListenableFuture<?> rollupErrorSummaryFromRows(RollupParams rollup,
        AggregateQuery query, Iterable<Row> rows) throws Exception {
    long errorCount = 0;
    long transactionCount = 0;
    for (Row row : rows) {
        errorCount += row.getLong(0);
        transactionCount += row.getLong(1);
    }
    BoundStatement boundStatement =
            getInsertOverallPS(errorSummaryTable, rollup.rollupLevel()).bind();
    int i = 0;
    boundStatement.setString(i++, rollup.agentRollupId());
    boundStatement.setString(i++, query.transactionType());
    boundStatement.setTimestamp(i++, new Date(query.to()));
    boundStatement.setLong(i++, errorCount);
    boundStatement.setLong(i++, transactionCount);
    boundStatement.setInt(i++, rollup.adjustedTTL().generalTTL());
    return session.writeAsync(boundStatement);
}
 
Example 10
Source Project: glowroot   File: AggregateDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
private ListenableFuture<?> insertTransactionSummaries(RollupParams rollup,
        AggregateQuery query, Map<String, MutableSummary> summaries) throws Exception {
    BoundStatement boundStatement;
    List<ListenableFuture<?>> futures = new ArrayList<>();
    PreparedStatement preparedStatement =
            getInsertTransactionPS(summaryTable, rollup.rollupLevel());
    for (Map.Entry<String, MutableSummary> entry : summaries.entrySet()) {
        MutableSummary summary = entry.getValue();
        boundStatement = preparedStatement.bind();
        int i = 0;
        boundStatement.setString(i++, rollup.agentRollupId());
        boundStatement.setString(i++, query.transactionType());
        boundStatement.setTimestamp(i++, new Date(query.to()));
        boundStatement.setString(i++, entry.getKey());
        boundStatement.setDouble(i++, summary.totalDurationNanos);
        boundStatement.setLong(i++, summary.transactionCount);
        boundStatement.setInt(i++, rollup.adjustedTTL().generalTTL());
        futures.add(session.writeAsync(boundStatement));
    }
    return Futures.allAsList(futures);
}
 
Example 11
Source Project: glowroot   File: TraceDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static void bindErrorPoint(BoundStatement boundStatement, String agentRollupId,
        String agentId, String traceId, Trace.Header header, int adjustedTTL, boolean overall)
        throws IOException {
    int i = bind(boundStatement, agentRollupId, agentId, traceId, header, overall, false);
    boundStatement.setLong(i++, header.getDurationNanos());
    boundStatement.setString(i++, header.getError().getMessage());
    boundStatement.setString(i++, header.getHeadline());
    boundStatement.setString(i++, Strings.emptyToNull(header.getUser()));
    List<Trace.Attribute> attributes = header.getAttributeList();
    if (attributes.isEmpty()) {
        boundStatement.setToNull(i++);
    } else {
        boundStatement.setBytes(i++, Messages.toByteBuffer(attributes));
    }
    boundStatement.setInt(i++, adjustedTTL);
}
 
Example 12
@Override
protected Statement setStatementParameters(PreparedStatement updateCommand, EnrichedCDR tuple) throws DriverException
{
  final BoundStatement boundStmnt = new BoundStatement(updateCommand);
  int index = 0;
  boundStmnt.setLong(index++, ++id);
  boundStmnt.setString(index++, tuple.getImsi());
  boundStmnt.setString(index++, tuple.getIsdn());
  boundStmnt.setString(index++, tuple.getImei());
  boundStmnt.setString(index++, tuple.getPlan());
  boundStmnt.setString(index++, tuple.getCallType());
  boundStmnt.setString(index++, tuple.getCallType());
  boundStmnt.setString(index++, tuple.getCorrespType());
  boundStmnt.setInt(index++, tuple.getDuration());
  boundStmnt.setInt(index++, tuple.getBytes());
  boundStmnt.setInt(index++, tuple.getDr());
  boundStmnt.setFloat(index++, tuple.getLat());
  boundStmnt.setFloat(index++, tuple.getLon());
  boundStmnt.setString(index++, tuple.getDate());
  boundStmnt.setString(index++, tuple.getTimeInDay());
  boundStmnt.setString(index++, tuple.getDrLabel());
  boundStmnt.setString(index++, tuple.getOperatorCode());
  boundStmnt.setString(index++, tuple.getDeviceBrand());
  boundStmnt.setString(index++, tuple.getDeviceModel());
  boundStmnt.setString(index++, tuple.getZipCode());

  //or boundStatement.bind();
  return boundStmnt;
}
 
Example 13
Source Project: glowroot   File: AggregateDaoImpl.java    License: Apache License 2.0 5 votes vote down vote up
private ListenableFuture<?> insertQueries(List<MutableQuery> queries, int rollupLevel,
        String agentRollupId, String transactionType, @Nullable String transactionName,
        long captureTime, TTL adjustedTTL) throws Exception {
    List<ListenableFuture<?>> futures = new ArrayList<>();
    for (MutableQuery query : queries) {
        BoundStatement boundStatement;
        if (transactionName == null) {
            boundStatement = getInsertOverallPS(queryTable, rollupLevel).bind();
        } else {
            boundStatement = getInsertTransactionPS(queryTable, rollupLevel).bind();
        }
        String fullTextSha1 = query.getFullTextSha1();
        int i = 0;
        boundStatement.setString(i++, agentRollupId);
        boundStatement.setString(i++, transactionType);
        if (transactionName != null) {
            boundStatement.setString(i++, transactionName);
        }
        boundStatement.setTimestamp(i++, new Date(captureTime));
        boundStatement.setString(i++, query.getType());
        boundStatement.setString(i++, query.getTruncatedText());
        // full_query_text_sha1 cannot be null since it is used in clustering key
        boundStatement.setString(i++, Strings.nullToEmpty(fullTextSha1));
        boundStatement.setDouble(i++, query.getTotalDurationNanos());
        boundStatement.setLong(i++, query.getExecutionCount());
        if (query.hasTotalRows()) {
            boundStatement.setLong(i++, query.getTotalRows());
        } else {
            boundStatement.setToNull(i++);
        }
        boundStatement.setInt(i++, adjustedTTL.queryTTL());
        futures.add(session.writeAsync(boundStatement));
    }
    return Futures.allAsList(futures);
}
 
Example 14
@Override
public void set(final K key, final V value) {
	BoundStatement insertStatement = _insertStatement.bind();
	insertStatement.setBytesUnsafe(0, _keySerializer.serialize(key));
	insertStatement.setLong(1, getValueHash(value));
	insertStatement.setBytesUnsafe(2, _valueSerializer.serialize(value));
	_session.execute(insertStatement);
}
 
Example 15
Source Project: glowroot   File: AggregateDaoImpl.java    License: Apache License 2.0 5 votes vote down vote up
private List<ListenableFuture<?>> insertServiceCallsProto(
        List<Aggregate.ServiceCall> serviceCalls, int rollupLevel, String agentRollupId,
        String transactionType, @Nullable String transactionName, long captureTime,
        TTL adjustedTTL) throws Exception {
    List<ListenableFuture<?>> futures = new ArrayList<>();
    for (Aggregate.ServiceCall serviceCall : serviceCalls) {
        BoundStatement boundStatement;
        if (transactionName == null) {
            boundStatement = getInsertOverallPS(serviceCallTable, rollupLevel).bind();
        } else {
            boundStatement = getInsertTransactionPS(serviceCallTable, rollupLevel).bind();
        }
        int i = 0;
        boundStatement.setString(i++, agentRollupId);
        boundStatement.setString(i++, transactionType);
        if (transactionName != null) {
            boundStatement.setString(i++, transactionName);
        }
        boundStatement.setTimestamp(i++, new Date(captureTime));
        boundStatement.setString(i++, serviceCall.getType());
        boundStatement.setString(i++, serviceCall.getText());
        boundStatement.setDouble(i++, serviceCall.getTotalDurationNanos());
        boundStatement.setLong(i++, serviceCall.getExecutionCount());
        boundStatement.setInt(i++, adjustedTTL.serviceCallTTL());
        futures.add(session.writeAsync(boundStatement));
    }
    return futures;
}
 
Example 16
Source Project: SimpleFlatMapper   File: DatastaxCrud.java    License: MIT License 5 votes vote down vote up
public BoundStatement saveQueryWithTimestamp(T value, long timestamp) {
    BoundStatement boundStatement = insertQueryWithTimestamp.bind();
    insertSetter.mapTo(value, boundStatement);

    boundStatement.setLong(numberOfColumns, timestamp);

    return boundStatement;
}
 
Example 17
Source Project: glowroot   File: AggregateDaoImpl.java    License: Apache License 2.0 5 votes vote down vote up
private List<Future<?>> storeTransactionNameSummary(String agentRollupId,
        String transactionType, String transactionName, long captureTime, Aggregate aggregate,
        TTL adjustedTTL) throws Exception {

    final int rollupLevel = 0;

    List<Future<?>> futures = new ArrayList<>();
    BoundStatement boundStatement = getInsertTransactionPS(summaryTable, rollupLevel).bind();
    int i = 0;
    boundStatement.setString(i++, agentRollupId);
    boundStatement.setString(i++, transactionType);
    boundStatement.setTimestamp(i++, new Date(captureTime));
    boundStatement.setString(i++, transactionName);
    boundStatement.setDouble(i++, aggregate.getTotalDurationNanos());
    boundStatement.setLong(i++, aggregate.getTransactionCount());
    boundStatement.setInt(i++, adjustedTTL.generalTTL());
    futures.add(session.writeAsync(boundStatement));

    if (aggregate.getErrorCount() > 0) {
        boundStatement = getInsertTransactionPS(errorSummaryTable, rollupLevel).bind();
        i = 0;
        boundStatement.setString(i++, agentRollupId);
        boundStatement.setString(i++, transactionType);
        boundStatement.setTimestamp(i++, new Date(captureTime));
        boundStatement.setString(i++, transactionName);
        boundStatement.setLong(i++, aggregate.getErrorCount());
        boundStatement.setLong(i++, aggregate.getTransactionCount());
        boundStatement.setInt(i++, adjustedTTL.generalTTL());
        futures.add(session.writeAsync(boundStatement));
    }
    return futures;
}
 
Example 18
Source Project: glowroot   File: SchemaUpgrade.java    License: Apache License 2.0 4 votes vote down vote up
private static void copyLong(Row row, BoundStatement boundStatement, int i) {
    boundStatement.setLong(i, row.getLong(i));
}
 
Example 19
Source Project: SimpleFlatMapper   File: DatastaxCrud.java    License: MIT License 4 votes vote down vote up
public BoundStatement deleteQuery(K key, long timestamp) {
    BoundStatement boundStatement = deleteQueryWithTimestamp.bind();
    boundStatement.setLong(0, timestamp);
    return keySetterWith1Option.mapTo(key, boundStatement);
}
 
Example 20
Source Project: glowroot   File: AggregateDaoImpl.java    License: Apache License 2.0 4 votes vote down vote up
private List<ListenableFuture<?>> insertQueries(List<Aggregate.Query> queries,
        List<Aggregate.SharedQueryText> sharedQueryTexts, int rollupLevel, String agentRollupId,
        String transactionType, @Nullable String transactionName, long captureTime,
        TTL adjustedTTL) throws Exception {
    List<ListenableFuture<?>> futures = new ArrayList<>();
    for (Aggregate.Query query : queries) {
        Aggregate.SharedQueryText sharedQueryText =
                sharedQueryTexts.get(query.getSharedQueryTextIndex());
        BoundStatement boundStatement;
        if (transactionName == null) {
            boundStatement = getInsertOverallPS(queryTable, rollupLevel).bind();
        } else {
            boundStatement = getInsertTransactionPS(queryTable, rollupLevel).bind();
        }
        int i = 0;
        boundStatement.setString(i++, agentRollupId);
        boundStatement.setString(i++, transactionType);
        if (transactionName != null) {
            boundStatement.setString(i++, transactionName);
        }
        boundStatement.setTimestamp(i++, new Date(captureTime));
        boundStatement.setString(i++, query.getType());
        String fullTextSha1 = sharedQueryText.getFullTextSha1();
        if (fullTextSha1.isEmpty()) {
            boundStatement.setString(i++, sharedQueryText.getFullText());
            // full_query_text_sha1 cannot be null since it is used in clustering key
            boundStatement.setString(i++, "");
        } else {
            boundStatement.setString(i++, sharedQueryText.getTruncatedText());
            boundStatement.setString(i++, fullTextSha1);
        }
        boundStatement.setDouble(i++, query.getTotalDurationNanos());
        boundStatement.setLong(i++, query.getExecutionCount());
        if (query.hasTotalRows()) {
            boundStatement.setLong(i++, query.getTotalRows().getValue());
        } else {
            boundStatement.setToNull(i++);
        }
        boundStatement.setInt(i++, adjustedTTL.queryTTL());
        futures.add(session.writeAsync(boundStatement));
    }
    return futures;
}