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

The following examples show how to use com.datastax.driver.core.BoundStatement#setDouble() . 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 File: AggregateDaoImpl.java    From glowroot with 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 2
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
private <T> void bindValue(BoundStatement bs, MetricType<T> type, DataPoint<T> dataPoint) {
    switch(type.getCode()) {
        case 0:
            bs.setDouble(0, (Double) dataPoint.getValue());
            break;
        case 1:
            bs.setBytes(0, getBytes((DataPoint<AvailabilityType>) dataPoint));
            break;
        case 2:
            bs.setLong(0, (Long) dataPoint.getValue());
            break;
        case 3:
            bs.setLong(0, (Long) dataPoint.getValue());
            break;
        case 4:
            throw new IllegalArgumentException("Not implemented yet");
        case 5:
            bs.setDouble(0, (Double) dataPoint.getValue());
            break;
        default:
            throw new IllegalArgumentException("Unsupported metricType");
    }
}
 
Example 3
Source File: GaugeValueDaoImpl.java    From glowroot with 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 4
Source File: AggregateDaoImpl.java    From glowroot with 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 5
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
public void insertRanges(final byte[][] ids, final double value) throws DataAccessLayerException {
	/*
	 * insert in CF_RN_SP_O
	 */
	final BoundStatement nspoStatement = _insertNSPOStatement.bind();
	nspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	nspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	nspoStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));
	nspoStatement.setDouble(3, value);
	_batchStatements.get().add(nspoStatement);

	/*
	 * insert in CF_RN_P_OS
	 */
	final BoundStatement nposStatement = _insertNPOSStatement.bind();
	nposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
	nposStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[2]));
	nposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));
	nposStatement.setDouble(3, value);
	_batchStatements.get().add(nposStatement);
}
 
Example 6
Source File: CassandraBaseTimeseriesDao.java    From iotplatform with Apache License 2.0 6 votes vote down vote up
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 7
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<byte[][]> numericRangeQuery(
		final Value[] query, 
		final double lowerBound, 
		final boolean equalsLower, 
		final double upperBound, 
		final boolean equalsUpper, 
		final boolean reverse, 
		final int limit) throws DataAccessLayerException {
	
	final byte[] s = _dictionary.getID(query[0], false);
	final byte[] p = _dictionary.getID(query[1], true);

	final boolean subjectIsVariable = isVariable(s);
	final BoundStatement statement = _rangeQueries[getRangeQueryIndex(reverse, subjectIsVariable, true, !equalsUpper, !equalsLower)].bind();
	int queryParameterIndex = 0;

	if (!subjectIsVariable) {
		statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(s));
	}

	statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(p));
	statement.setDouble(queryParameterIndex++, lowerBound);
	statement.setDouble(queryParameterIndex++, upperBound);
	statement.setInt(queryParameterIndex, limit);

	return new SPOCResultIterator(_session.executeAsync(statement), false);
}
 
Example 8
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<byte[][]> dateRangeQuery(
		final Value[] query, 
		final long lowerBound, 
		final boolean equalsLower, 
		final long upperBound, 
		final boolean equalsUpper, 
		final boolean reverse, 
		final int limit) throws DataAccessLayerException {
	final byte[] s = _dictionary.getID(query[0], false);
	final byte[] p = _dictionary.getID(query[1], true);
	final boolean subjectIsVariable = isVariable(s);
	
	final BoundStatement statement = _rangeQueries[getRangeQueryIndex(reverse, subjectIsVariable, false, !equalsUpper, !equalsLower)].bind();

	int queryParameterIndex = 0;

	if (!subjectIsVariable) {
		statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(s));
	}

	statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(p));
	statement.setDouble(queryParameterIndex++, lowerBound);
	statement.setDouble(queryParameterIndex++, upperBound);
	statement.setInt(queryParameterIndex, limit);

	return new SPOCResultIterator(_session.executeAsync(statement), false);
}
 
Example 9
Source File: CassandraBaseAttributesDao.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<Void> save(EntityId entityId, String attributeType, AttributeKvEntry attribute) {
    BoundStatement stmt = getSaveStmt().bind();
    stmt.setString(0, entityId.getEntityType().name());
    stmt.setUUID(1, entityId.getId());
    stmt.setString(2, attributeType);
    stmt.setString(3, attribute.getKey());
    stmt.setLong(4, attribute.getLastUpdateTs());
    stmt.setString(5, attribute.getStrValue().orElse(null));
    if (attribute.getBooleanValue().isPresent()) {
        stmt.setBool(6, attribute.getBooleanValue().get());
    } else {
        stmt.setToNull(6);
    }
    if (attribute.getLongValue().isPresent()) {
        stmt.setLong(7, attribute.getLongValue().get());
    } else {
        stmt.setToNull(7);
    }
    if (attribute.getDoubleValue().isPresent()) {
        stmt.setDouble(8, attribute.getDoubleValue().get());
    } else {
        stmt.setToNull(8);
    }
    log.trace("Generated save stmt [{}] for entityId {} and attributeType {} and attribute", stmt, entityId, attributeType, attribute);
    return getFuture(executeAsyncWrite(stmt), rs -> null);
}
 
Example 10
Source File: AggregateDaoImpl.java    From glowroot with 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 11
Source File: AggregateDaoImpl.java    From glowroot with 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 12
Source File: AggregateDaoImpl.java    From glowroot with 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 13
Source File: AggregateDaoImpl.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private ListenableFuture<?> insertServiceCalls(List<MutableServiceCall> serviceCalls,
        int rollupLevel, String agentRollupId, String transactionType,
        @Nullable String transactionName, long captureTime, TTL adjustedTTL) throws Exception {
    List<ListenableFuture<?>> futures = new ArrayList<>();
    for (MutableServiceCall 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.allAsList(futures);
}
 
Example 14
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
/**
 * Internal method used for reuse delete stuff.
 * 
 * @param ids the triple identifiers.
 * @param rangesEnabled if ranges have been enabled on the current store.
 * @throws DataAccessLayerException in case of data access failure.
 */
void internalDelete(final byte [][]ids, final boolean rangesEnabled) throws DataAccessLayerException {
	// delete in CF_PO_SC
	final BoundStatement poscStatement = _deletePOSCStatement.bind();
	poscStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
	poscStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[2]));
	poscStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));

	if (ids.length == 4) {
		poscStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		poscStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	_batchStatements.get().add(poscStatement);

	// delete in CF_S_POC
	final BoundStatement spocStatement = _deleteSPOCStatement.bind();
	spocStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	spocStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	spocStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));

	if (ids.length == 4) {
		spocStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		spocStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	_batchStatements.get().add(spocStatement);

	// delete in CF_O_SPC
	final BoundStatement ospcStatement = _deleteOSPCStatement.bind();
	ospcStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[2]));
	ospcStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[0]));
	ospcStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[1]));

	if (ids.length == 4) {
		ospcStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		ospcStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	_batchStatements.get().add(ospcStatement);

	/*
	 * delete in: CF_RN_SP_O + CF_RN_PO_S
	 */
	if (rangesEnabled && _dictionary.isLiteral(ids[2])) {
		final Literal lit = (Literal) _dictionary.getValue(ids[2], false);
		final URI dt = lit.getDatatype();

		if (Environment.NUMERIC_RANGETYPES.contains(dt)) {

			double number = Double.parseDouble(lit.getLabel());

			// delete in CF_RN_SP_O
			final BoundStatement nspoStatement = _deleteNSPOStatement.bind();
			nspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
			nspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
			nspoStatement.setDouble(2, number);

			_batchStatements.get().add(nspoStatement);

			// delete in CF_RN_PO_S
			final BoundStatement nposStatement = _deleteNPOSStatement.bind();
			nposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
			nposStatement.setDouble(1, number);
			nposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));

			_batchStatements.get().add(nposStatement);

		} else if (Environment.DATETIME_RANGETYPES.contains(dt)) {

			long ms = parseXMLSchemaDateTimeAsMSecs(lit);

			// delete in CF_RN_SP_O
			final BoundStatement dspoStatement = _deleteDSPOStatement.bind();
			dspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
			dspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
			dspoStatement.setLong(2, ms);

			_batchStatements.get().add(dspoStatement);

			// delete in CF_RN_PO_S
			final BoundStatement dposStatement = _deleteDPOSStatement.bind();
			dposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
			dposStatement.setLong(1, ms);
			dposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));

			_batchStatements.get().add(dposStatement);
		}		
	}
}
 
Example 15
Source File: AggregateDaoImpl.java    From glowroot with 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;
}
 
Example 16
Source File: SyntheticResultDaoImpl.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@Override
public void store(String agentRollupId, String syntheticMonitorId,
        String syntheticMonitorDisplay, long captureTime, long durationNanos,
        @Nullable String errorMessage) throws Exception {
    int ttl = getTTLs().get(0);
    long maxCaptureTime = 0;
    BoundStatement boundStatement = insertResultPS.get(0).bind();
    maxCaptureTime = Math.max(captureTime, maxCaptureTime);
    int adjustedTTL = Common.getAdjustedTTL(ttl, captureTime, clock);
    int i = 0;
    boundStatement.setString(i++, agentRollupId);
    boundStatement.setString(i++, syntheticMonitorId);
    boundStatement.setTimestamp(i++, new Date(captureTime));
    boundStatement.setDouble(i++, durationNanos);
    boundStatement.setLong(i++, 1);
    if (errorMessage == null) {
        boundStatement.setToNull(i++);
    } else {
        Stored.ErrorInterval errorInterval = Stored.ErrorInterval.newBuilder()
                .setFrom(captureTime)
                .setTo(captureTime)
                .setCount(1)
                .setMessage(errorMessage)
                .setDoNotMergeToTheLeft(false)
                .setDoNotMergeToTheRight(false)
                .build();
        boundStatement.setBytes(i++, Messages.toByteBuffer(ImmutableList.of(errorInterval)));
    }
    boundStatement.setInt(i++, adjustedTTL);
    List<Future<?>> futures = new ArrayList<>();
    futures.add(session.writeAsync(boundStatement));
    futures.addAll(syntheticMonitorIdDao.insert(agentRollupId, captureTime, syntheticMonitorId,
            syntheticMonitorDisplay));

    // wait for success before inserting "needs rollup" records
    MoreFutures.waitForAll(futures);

    // insert into synthetic_needs_rollup_1
    List<RollupConfig> rollupConfigs = configRepository.getRollupConfigs();
    long intervalMillis = rollupConfigs.get(1).intervalMillis();
    long rollupCaptureTime = CaptureTimes.getRollup(captureTime, intervalMillis);
    int needsRollupAdjustedTTL =
            Common.getNeedsRollupAdjustedTTL(adjustedTTL, configRepository.getRollupConfigs());
    boundStatement = insertNeedsRollup.get(0).bind();
    i = 0;
    boundStatement.setString(i++, agentRollupId);
    boundStatement.setTimestamp(i++, new Date(rollupCaptureTime));
    boundStatement.setUUID(i++, UUIDs.timeBased());
    boundStatement.setSet(i++, ImmutableSet.of(syntheticMonitorId));
    boundStatement.setInt(i++, needsRollupAdjustedTTL);
    session.write(boundStatement);
}
 
Example 17
Source File: CassandraPOJOOutputOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected Statement setStatementParameters(PreparedStatement updateCommand, Object tuple) throws DriverException
{
  final BoundStatement boundStmnt = new BoundStatement(updateCommand);
  final int size = columnDataTypes.size();
  for (int i = 0; i < size; i++) {
    final DataType type = columnDataTypes.get(i);
    switch (type.getName()) {
      case UUID:
        final UUID id = ((Getter<Object, UUID>)getters.get(i)).get(tuple);
        boundStmnt.setUUID(i, id);
        break;
      case ASCII:
      case VARCHAR:
      case TEXT:
        final String ascii = ((Getter<Object, String>)getters.get(i)).get(tuple);
        boundStmnt.setString(i, ascii);
        break;
      case BOOLEAN:
        final boolean bool = ((GetterBoolean<Object>)getters.get(i)).get(tuple);
        boundStmnt.setBool(i, bool);
        break;
      case INT:
        final int intValue = ((GetterInt<Object>)getters.get(i)).get(tuple);
        boundStmnt.setInt(i, intValue);
        break;
      case BIGINT:
      case COUNTER:
        final long longValue = ((GetterLong<Object>)getters.get(i)).get(tuple);
        boundStmnt.setLong(i, longValue);
        break;
      case FLOAT:
        final float floatValue = ((GetterFloat<Object>)getters.get(i)).get(tuple);
        boundStmnt.setFloat(i, floatValue);
        break;
      case DOUBLE:
        final double doubleValue = ((GetterDouble<Object>)getters.get(i)).get(tuple);
        boundStmnt.setDouble(i, doubleValue);
        break;
      case DECIMAL:
        final BigDecimal decimal = ((Getter<Object, BigDecimal>)getters.get(i)).get(tuple);
        boundStmnt.setDecimal(i, decimal);
        break;
      case SET:
        Set<?> set = ((Getter<Object, Set<?>>)getters.get(i)).get(tuple);
        boundStmnt.setSet(i, set);
        break;
      case MAP:
        final Map<?,?> map = ((Getter<Object, Map<?,?>>)getters.get(i)).get(tuple);
        boundStmnt.setMap(i, map);
        break;
      case LIST:
        final List<?> list = ((Getter<Object, List<?>>)getters.get(i)).get(tuple);
        boundStmnt.setList(i, list);
        break;
      case TIMESTAMP:
        final Date date = ((Getter<Object, Date>)getters.get(i)).get(tuple);
        boundStmnt.setDate(i, LocalDate.fromMillisSinceEpoch(date.getTime()));
        break;
      default:
        throw new RuntimeException("unsupported data type " + type.getName());
    }
  }
  return boundStmnt;
}