private List<Long> createQueryKeyList(ClusterConnection cluster, String metricName, long startTime, long endTime) { List<Long> ret = new ArrayList<>(); if (cluster.psRowKeyTimeQuery != null) //cluster may be old { BoundStatement statement = new BoundStatement(cluster.psRowKeyTimeQuery); statement.setString(0, metricName); statement.setTimestamp(1, new Date(CassandraDatastore.calculateRowTime(startTime))); statement.setTimestamp(2, new Date(endTime)); statement.setConsistencyLevel(cluster.getReadConsistencyLevel()); //printHosts(m_loadBalancingPolicy.newQueryPlan(m_keyspace, statement)); ResultSet rows = cluster.execute(statement); while (!rows.isExhausted()) { ret.add(rows.one().getTimestamp(0).getTime()); } } return ret; }
statement.setTimestamp(1, new Date(keyTime)); statement.setConsistencyLevel(cluster.getReadConsistencyLevel());
public void addRowKey(String metricName, DataPointsRowKey rowKey, int rowKeyTtl) { m_newRowKeys.add(rowKey); ByteBuffer bb = ByteBuffer.allocate(8); bb.putLong(0, rowKey.getTimestamp()); Statement bs = m_clusterConnection.psRowKeyTimeInsert.bind() .setString(0, metricName) .setTimestamp(1, new Date(rowKey.getTimestamp())) //.setBytesUnsafe(1, bb) //Setting timestamp in a more optimal way .setInt(2, rowKeyTtl) .setIdempotent(true); bs.setConsistencyLevel(m_consistencyLevel); rowKeyBatch.add(bs); bs = m_clusterConnection.psRowKeyInsert.bind() .setString(0, metricName) .setTimestamp(1, new Date(rowKey.getTimestamp())) //.setBytesUnsafe(1, bb) //Setting timestamp in a more optimal way .setString(2, rowKey.getDataType()) .setMap(3, rowKey.getTags()) .setInt(4, rowKeyTtl) .setIdempotent(true); bs.setConsistencyLevel(m_consistencyLevel); rowKeyBatch.add(bs); }
statement.setTimestamp(paramIndex, (Date) typeCodec.parse(paramValue));
statement.setTimestamp(1, new Date(rowKey.getTimestamp())); statement.setString(2, rowKey.getDataType()); statement.setMap(3, rowKey.getTags()); statement.setTimestamp(1, new Date(rowKey.getTimestamp())); statement.setConsistencyLevel(cluster.getReadConsistencyLevel()); cluster.execute(statement);
public static void setBoundStatementDate(BoundStatement boundStatement, String columnName, Date date) { // drivers 3.0 boundStatement.setTimestamp(columnName, date); // drivers 2.1 // boundStatement.setDate(columnName, date); }
public void setTimestamp(int parameterIndex, Timestamp value) throws SQLException { checkNotClosed(); checkIndex(parameterIndex); // timestamp type data is handled as an 8 byte Long value of milliseconds since the epoch. Nanos are not supported and are ignored this.statement.setTimestamp(parameterIndex-1, new Date(value.getTime())); }
public void setDate(int parameterIndex, Date value) throws SQLException { checkNotClosed(); checkIndex(parameterIndex); // date type data is handled as an 8 byte Long value of milliseconds since the epoch (handled in decompose() ) //bindValues.put(parameterIndex, value == null ? null : JdbcDate.instance.decompose(value)); this.statement.setTimestamp(parameterIndex-1, value); }
public ListenableFuture<Void> storeDependencies(long epochDayMillis, ByteBuffer dependencies) { Date startFlooredToDay = new Date(epochDayMillis); try { BoundStatement bound = insertDependencies.bind() .setTimestamp("day", startFlooredToDay) .setBytes("dependencies", dependencies); if (LOG.isDebugEnabled()) { LOG.debug(debugInsertDependencies(startFlooredToDay, dependencies)); } return Futures.transform(session.executeAsync(bound), resultSetToVoidFunction); } catch (RuntimeException ex) { LOG.error("failed " + debugInsertDependencies(startFlooredToDay, dependencies), ex); return Futures.immediateFailedFuture(ex); } }
/** * Binds the basic parameters of T into the statement. * @param t the record * @param statement the statement to have the attributes bound to. */ void bindBasicParameters(T t, BoundStatement statement) { statement.setUUID("id", t.getIdAsUUID()); statement.setTimestamp("createdAt", zonedDateTimeAdapter.convertToDatabaseColumn(t.getCreatedAt())); statement.setTimestamp("updatedAt", zonedDateTimeAdapter.convertToDatabaseColumn(t.getUpdatedAt())); }
ListenableFuture<?> storeDependencies(long epochDayMillis, ByteBuffer dependencies) { Date startFlooredToDay = new Date(epochDayMillis); try { BoundStatement bound = CassandraUtil.bindWithName(insertDependencies, "insert-dependencies") .setTimestamp("day", startFlooredToDay) .setBytes("dependencies", dependencies); return session.executeAsync(bound); } catch (RuntimeException ex) { return Futures.immediateFailedFuture(ex); } } }
@DoNotUse(expressUse = "GuildCommand save") public void saveGuild(String guildId, GuildWrapper guildWrapper, final long last_retrieved) { long last_r = (last_retrieved == -1 ? System.currentTimeMillis() : last_retrieved); CassandraController.runTask(session -> { if (saveGuildStatement == null) saveGuildStatement = session.prepare("UPDATE " + GUILD_DATA_TABLE + " SET last_retrieved = ?, data = ? WHERE guild_id = ?"); session.executeAsync(saveGuildStatement.bind() .setTimestamp(0, new Date(last_r)) .setString(1, FlareBot.GSON.toJson(guildWrapper)).setString(2, guildId)); }); LOGGER.debug("Guild " + guildId + "'s data got saved! Last retrieved: " + last_r + " (" + new Date(last_r) + ") - " + guilds.size() + " currently loaded."); }
public void queue() { // I have to minus here since this has the complete end time. Scheduler.delayTask(this::execute, "FutureTask-" + action.name() + "-" + expires.toString(), getExpires().minus(System.currentTimeMillis()).getMillis()); if (update == null) update = CassandraController.prepare("UPDATE flarebot.future_tasks SET responsible = ?, " + "target = ?, content = ?, expires_at = ?, action = ? WHERE guild_id = ? AND channel_id = ? " + "AND created_at = ?"); CassandraController.executeAsync(update.bind().setLong(0, responsible).setLong(1, target).setString(2, content) .setTimestamp(3, expires.toDate()).setString(4, action.name()).setLong(5, guildId).setLong(6, channelId) .setTimestamp(7, created.toDate())); FlareBot.instance().getFutureActions().add(this); }
/** * Updates T, binds the basic parameters to the Statement and executes it, returning the updated T. * @param record the record to be updated * @param statement the statement with the other fields already bound. * @return the updated record */ T update(T record, BoundStatement statement) { record.setUpdatedAt(); statement.setTimestamp("updatedAt", zonedDateTimeAdapter.convertToDatabaseColumn(record.getUpdatedAt())); statement.setUUID("id", record.getIdAsUUID()); session.execute(statement); return record; }
public void delete() { FlareBot.instance().getFutureActions().remove(this); if (delete == null) delete = CassandraController.prepare("DELETE FROM flarebot.future_tasks WHERE guild_id = ? " + "AND channel_id = ? AND created_at = ?"); CassandraController.executeAsync(delete.bind().setLong(0, guildId).setLong(1, channelId) .setTimestamp(2, created.toDate())); Scheduler.cancelTask("FutureTask-" + action.name() + "-" + expires.toString()); }
public CompletableFuture<Void> activate(User user, ScriptName scriptName) { return cassandraAsyncExecutor.executeVoid( insertActive.bind() .setString(USER_NAME, user.asString()) .setString(SCRIPT_NAME, scriptName.getValue()) .setTimestamp(DATE, new Date())); } }
@Override public void markAsDispatched(Invitation invitation) { BoundStatement stmtDispatched = stmtDispatchedInstance.get(); invitation.setDispatched(); stmtDispatched.setUUID("id", invitation.getIdAsUUID()); stmtDispatched.setTimestamp("dispatchedAt", zonedDateTimeAdapter.convertToDatabaseColumn(invitation.getDispatchedAt()) ); update(invitation, stmtDispatched); logger.invitationDispatched(invitation.getId()); }
private Iterator<com.datastax.driver.core.Row> cassandraSelect(Context context, Resource resource, Timestamp start, Timestamp end) { List<Future<ResultSet>> futures = Lists.newArrayList(); Duration resourceShard = m_contextConfigurations.getResourceShard(context); Timestamp lower = start.stepFloor(resourceShard); Timestamp upper = end.stepFloor(resourceShard); for (Timestamp partition : new IntervalGenerator(lower, upper, resourceShard)) { BoundStatement bindStatement = m_selectStatement.bind(); bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId()); bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds()); bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId()); bindStatement.setTimestamp("start", start.asDate()); bindStatement.setTimestamp("end", end.asDate()); // Use the context specific consistency level bindStatement.setConsistencyLevel(m_contextConfigurations.getReadConsistency(context)); futures.add(m_session.executeAsync(bindStatement)); } return new ConcurrentResultWrapper(futures); }
private BoundStatement boundWriteStatement(MailboxMessage message, Pair<BlobId, BlobId> pair) { CassandraMessageId messageId = (CassandraMessageId) message.getMessageId(); return insert.bind() .setUUID(MESSAGE_ID, messageId.get()) .setTimestamp(INTERNAL_DATE, message.getInternalDate()) .setInt(BODY_START_OCTET, (int) (message.getHeaderOctets())) .setLong(FULL_CONTENT_OCTETS, message.getFullContentOctets()) .setLong(BODY_OCTECTS, message.getBodyOctets()) .setString(BODY_CONTENT, pair.getRight().asString()) .setString(HEADER_CONTENT, pair.getLeft().asString()) .setLong(TEXTUAL_LINE_COUNT, Optional.ofNullable(message.getTextualLineCount()).orElse(DEFAULT_LONG_VALUE)) .setList(PROPERTIES, buildPropertiesUdt(message)) .setList(ATTACHMENTS, buildAttachmentUdt(message)); }
@Override public Invitation accept(Invitation invitation, HawkularUser user) { BoundStatement stmtAccept = stmtAcceptInstance.get(); membershipService.create( invitation.getOrganization(), user, invitation.getRole() ); invitation.setAccepted(); invitation.setAcceptedBy(user); stmtAccept.setTimestamp("acceptedAt", zonedDateTimeAdapter.convertToDatabaseColumn(invitation.getAcceptedAt()) ); update(invitation, stmtAccept); logger.invitationAccepted(invitation.getId()); return invitation; }