Java Code Examples for com.datastax.driver.core.BoundStatement#setBytes()
The following examples show how to use
com.datastax.driver.core.BoundStatement#setBytes() .
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: SceneDaoImpl.java From arcusplatform with Apache License 2.0 | 6 votes |
protected Statement prepareUpsert(SceneDefinition sd, Date ts) { BoundStatement bs = upsert.bind(); bs.setUUID(Column.PLACE_ID.columnName(), sd.getPlaceId()); bs.setInt(Column.ID.columnName(), sd.getSequenceId()); bs.setTimestamp(Column.CREATED.columnName(), sd.getCreated()); bs.setTimestamp(Column.MODIFIED.columnName(), sd.getModified()); bs.setString(Column.NAME.columnName(), sd.getName()); bs.setString(Column.DESCRIPTION.columnName(), sd.getDescription()); bs.setSet(Column.TAGS.columnName(), sd.getTags()); bs.setString(SceneColumn.TEMPLATE.columnName(), sd.getTemplate()); bs.setBool(SceneColumn.SATISFIABLE.columnName(), sd.isSatisfiable()); bs.setBool(SceneColumn.NOTIFICATION.columnName(), sd.isNotification()); bs.setTimestamp(SceneColumn.LAST_FIRE_TIME.columnName(), sd.getLastFireTime()); bs.setString(SceneColumn.LAST_FIRE_STATE.columnName(), sd.getLastFireState()); bs.setBool(SceneColumn.ENABLED.columnName(),sd.isEnabled()); if(sd.getAction() != null) { bs.setBytes(ActionColumn.ACTION.columnName(), ByteBuffer.wrap(sd.getAction())); } else { bs.setBytes(ActionColumn.ACTION.columnName(), ByteBuffer.wrap(new byte [] {})); } return bs; }
Example 2
Source File: IncidentDao.java From glowroot with Apache License 2.0 | 6 votes |
@Override public @Nullable OpenIncident readOpenIncident(String agentRollupId, AlertCondition condition, AlertSeverity severity) throws Exception { BoundStatement boundStatement = readOpenIncidentPS.bind(); int i = 0; boundStatement.setString(i++, agentRollupId); boundStatement.setBytes(i++, ByteBuffer.wrap(condition.toByteArray())); boundStatement.setString(i++, severity.name().toLowerCase(Locale.ENGLISH)); ResultSet results = session.read(boundStatement); Row row = results.one(); if (row == null) { return null; } AlertNotification notification = AlertNotification.parseFrom(checkNotNull(row.getBytes(0))); long openTime = checkNotNull(row.getTimestamp(1)).getTime(); return ImmutableOpenIncident.builder() .agentRollupId(agentRollupId) .condition(condition) .severity(severity) .notification(notification) .openTime(openTime) .build(); }
Example 3
Source File: AggregateDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
private ListenableFuture<?> rollupThreadProfileFromRows(RollupParams rollup, AggregateQuery query, Iterable<Row> rows, Table table) throws Exception { MutableProfile profile = new MutableProfile(); for (Row row : rows) { ByteBuffer bytes = checkNotNull(row.getBytes(0)); profile.merge(Profile.parseFrom(bytes)); } BoundStatement boundStatement; if (query.transactionName() == null) { boundStatement = getInsertOverallPS(table, rollup.rollupLevel()).bind(); } else { boundStatement = getInsertTransactionPS(table, rollup.rollupLevel()).bind(); } int i = 0; boundStatement.setString(i++, rollup.agentRollupId()); boundStatement.setString(i++, query.transactionType()); if (query.transactionName() != null) { boundStatement.setString(i++, query.transactionName()); } boundStatement.setTimestamp(i++, new Date(query.to())); boundStatement.setBytes(i++, toByteBuffer(profile.toProto())); boundStatement.setInt(i++, rollup.adjustedTTL().profileTTL()); return session.writeAsync(boundStatement); }
Example 4
Source File: DataAccessImpl.java From hawkular-metrics with Apache License 2.0 | 6 votes |
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 5
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 6 votes |
private void renameAgentColumnFromSystemInfoToEnvironment() throws Exception { if (!columnExists("agent", "system_info")) { // previously failed mid-upgrade prior to updating schema version return; } addColumnIfNotExists("agent", "environment", "blob"); ResultSet results = session.read("select agent_id, system_info from agent"); PreparedStatement preparedStatement = session.prepare("insert into agent (agent_id, environment) values (?, ?)"); for (Row row : results) { BoundStatement boundStatement = preparedStatement.bind(); boundStatement.setString(0, row.getString(0)); boundStatement.setBytes(1, row.getBytes(1)); session.write(boundStatement); } session.updateSchemaWithRetry("alter table agent drop system_info"); }
Example 6
Source File: TraceDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
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 7
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 6 votes |
private void addDefaultGaugeNameToUiConfigs() throws Exception { PreparedStatement insertPS = session.prepare("insert into agent_config (agent_rollup_id," + " config, config_update, config_update_token) values (?, ?, ?, ?)"); ResultSet results = session.read("select agent_rollup_id, config from agent_config"); for (Row row : results) { String agentRollupId = row.getString(0); AgentConfig oldAgentConfig; try { oldAgentConfig = AgentConfig.parseFrom(checkNotNull(row.getBytes(1))); } catch (InvalidProtocolBufferException e) { logger.error(e.getMessage(), e); continue; } AgentConfig agentConfig = oldAgentConfig.toBuilder() .setUiDefaultsConfig(oldAgentConfig.getUiDefaultsConfig().toBuilder() .addAllDefaultGaugeName(ConfigDefaults.UI_DEFAULTS_GAUGE_NAMES)) .build(); BoundStatement boundStatement = insertPS.bind(); int i = 0; boundStatement.setString(i++, agentRollupId); boundStatement.setBytes(i++, ByteBuffer.wrap(agentConfig.toByteArray())); boundStatement.setBool(i++, true); boundStatement.setUUID(i++, UUIDs.random()); session.write(boundStatement); } }
Example 8
Source File: TraceDaoImpl.java From glowroot with Apache License 2.0 | 6 votes |
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 9
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 6 votes |
private void rewriteOpenIncidentTablePart1() throws Exception { if (!tableExists("open_incident")) { // must be upgrading all the way from a glowroot version prior to open_incident return; } dropTableIfExists("open_incident_temp"); session.updateSchemaWithRetry("create table if not exists open_incident_temp (one int," + " agent_rollup_id varchar, condition blob, severity varchar, notification blob," + " open_time timestamp, primary key (one, agent_rollup_id, condition, severity))"); PreparedStatement insertTempPS = session.prepare("insert into open_incident_temp (one," + " agent_rollup_id, condition, severity, notification, open_time) values" + " (1, ?, ?, ?, ?, ?)"); ResultSet results = session.read("select agent_rollup_id, condition, severity," + " notification, open_time from open_incident where one = 1"); for (Row row : results) { BoundStatement boundStatement = insertTempPS.bind(); boundStatement.setString(0, row.getString(0)); boundStatement.setBytes(1, row.getBytes(1)); boundStatement.setString(2, row.getString(2)); boundStatement.setBytes(3, row.getBytes(3)); boundStatement.setTimestamp(4, row.getTimestamp(4)); session.write(boundStatement); } }
Example 10
Source File: CQLTransaction.java From Doradus with Apache License 2.0 | 5 votes |
private BoundStatement addColumnUpdate(String tableName, String key, DColumn column, boolean isBinaryValue) { PreparedStatement prepState = m_dbservice.getPreparedUpdate(Update.INSERT_ROW, tableName); BoundStatement boundState = prepState.bind(); boundState.setString(0, key); boundState.setString(1, column.getName()); if (isBinaryValue) { boundState.setBytes(2, ByteBuffer.wrap(column.getRawValue())); } else { boundState.setString(2, column.getValue()); } return boundState; }
Example 11
Source File: IncidentDao.java From glowroot with Apache License 2.0 | 5 votes |
@Override public void resolveIncident(OpenIncident openIncident, long resolveTime) throws Exception { int adjustedTTL = Common.getAdjustedTTL( Ints.saturatedCast( HOURS.toSeconds(Constants.RESOLVED_INCIDENT_EXPIRATION_HOURS)), resolveTime, clock); BoundStatement boundStatement = insertResolvedIncidentPS.bind(); int i = 0; boundStatement.setTimestamp(i++, new Date(resolveTime)); boundStatement.setString(i++, openIncident.agentRollupId()); ByteBuffer conditionBytes = ByteBuffer.wrap(openIncident.condition().toByteArray()); boundStatement.setBytes(i++, conditionBytes); boundStatement.setString(i++, openIncident.severity().name().toLowerCase(Locale.ENGLISH)); ByteBuffer notificationBytes = ByteBuffer.wrap(openIncident.notification().toByteArray()); boundStatement.setBytes(i++, notificationBytes); boundStatement.setTimestamp(i++, new Date(openIncident.openTime())); boundStatement.setInt(i++, adjustedTTL); session.write(boundStatement); boundStatement = deleteOpenIncidentPS.bind(); i = 0; boundStatement.setString(i++, openIncident.agentRollupId()); boundStatement.setBytes(i++, conditionBytes); boundStatement.setString(i++, openIncident.severity().name().toLowerCase(Locale.ENGLISH)); session.write(boundStatement); }
Example 12
Source File: TraceDaoImpl.java From glowroot with Apache License 2.0 | 5 votes |
private static void bindThreadProfile(BoundStatement boundStatement, String agentId, String traceId, Profile profile, int adjustedTTL) { int i = 0; boundStatement.setString(i++, agentId); boundStatement.setString(i++, traceId); boundStatement.setBytes(i++, ByteBuffer.wrap(profile.toByteArray())); boundStatement.setInt(i++, adjustedTTL); }
Example 13
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 5 votes |
private void rewriteResolvedIncidentTablePart1() throws Exception { if (!tableExists("resolved_incident")) { // must be upgrading all the way from a glowroot version prior to resolved_incident return; } dropTableIfExists("resolved_incident_temp"); session.updateSchemaWithRetry("create table if not exists resolved_incident_temp (one int," + " resolve_time timestamp, agent_rollup_id varchar, condition blob, severity" + " varchar, notification blob, open_time timestamp, primary key (one," + " resolve_time, agent_rollup_id, condition)) with clustering order by" + " (resolve_time desc)"); PreparedStatement insertTempPS = session.prepare("insert into resolved_incident_temp" + " (one, resolve_time, agent_rollup_id, condition, severity, notification," + " open_time) values (1, ?, ?, ?, ?, ?, ?)"); ResultSet results = session.read("select resolve_time, agent_rollup_id, condition," + " severity, notification, open_time from resolved_incident where one = 1"); for (Row row : results) { BoundStatement boundStatement = insertTempPS.bind(); boundStatement.setTimestamp(0, row.getTimestamp(0)); boundStatement.setString(1, row.getString(1)); boundStatement.setBytes(2, row.getBytes(2)); boundStatement.setString(3, row.getString(3)); boundStatement.setBytes(4, row.getBytes(4)); boundStatement.setTimestamp(5, row.getTimestamp(5)); session.write(boundStatement); } }
Example 14
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 5 votes |
private void rewriteOpenIncidentTablePart2() throws Exception { if (!tableExists("open_incident_temp")) { // previously failed mid-upgrade prior to updating schema version return; } dropTableIfExists("open_incident"); session.createTableWithLCS("create table if not exists open_incident (one int," + " agent_rollup_id varchar, condition blob, severity varchar, notification blob," + " open_time timestamp, primary key (one, agent_rollup_id, condition, severity))"); PreparedStatement insertPS = session.prepare("insert into open_incident (one," + " agent_rollup_id, condition, severity, notification, open_time) values" + " (1, ?, ?, ?, ?, ?)"); Map<String, V09AgentRollup> v09AgentRollups = getV09AgentRollupsFromAgentRollupTable(); ResultSet results = session.read("select agent_rollup_id, condition, severity," + " notification, open_time from open_incident_temp where one = 1"); for (Row row : results) { String v09AgentRollupId = row.getString(0); V09AgentRollup v09AgentRollup = v09AgentRollups.get(v09AgentRollupId); if (v09AgentRollup == null) { // v09AgentRollupId was manually deleted (via the UI) from the agent_rollup // table in which case its parent is no longer known and best to ignore continue; } BoundStatement boundStatement = insertPS.bind(); boundStatement.setString(0, v09AgentRollup.agentRollupId()); boundStatement.setBytes(1, row.getBytes(1)); boundStatement.setString(2, row.getString(2)); boundStatement.setBytes(3, row.getBytes(3)); boundStatement.setTimestamp(4, row.getTimestamp(4)); session.write(boundStatement); } dropTableIfExists("open_incident_temp"); }
Example 15
Source File: IncidentDao.java From glowroot with Apache License 2.0 | 5 votes |
@Override public void insertOpenIncident(String agentRollupId, AlertCondition condition, AlertSeverity severity, AlertNotification notification, long openTime) throws Exception { BoundStatement boundStatement = insertOpenIncidentPS.bind(); int i = 0; boundStatement.setString(i++, agentRollupId); boundStatement.setBytes(i++, ByteBuffer.wrap(condition.toByteArray())); boundStatement.setString(i++, severity.name().toLowerCase(Locale.ENGLISH)); boundStatement.setBytes(i++, ByteBuffer.wrap(notification.toByteArray())); boundStatement.setTimestamp(i++, new Date(openTime)); session.write(boundStatement); }
Example 16
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 5 votes |
private void rewriteEnvironmentTablePart1() throws Exception { dropTableIfExists("environment_temp"); session.updateSchemaWithRetry("create table if not exists environment_temp (agent_id" + " varchar, environment blob, primary key (agent_id))"); PreparedStatement insertTempPS = session .prepare("insert into environment_temp (agent_id, environment) values (?, ?)"); ResultSet results = session.read("select agent_id, environment from environment"); for (Row row : results) { BoundStatement boundStatement = insertTempPS.bind(); boundStatement.setString(0, row.getString(0)); boundStatement.setBytes(1, row.getBytes(1)); session.write(boundStatement); } }
Example 17
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 5 votes |
private void rewriteAgentConfigTablePart2() throws Exception { if (!tableExists("agent_config_temp")) { // previously failed mid-upgrade prior to updating schema version return; } dropTableIfExists("agent_config"); session.createTableWithLCS("create table if not exists agent_config (agent_rollup_id" + " varchar, config blob, config_update boolean, config_update_token uuid, primary" + " key (agent_rollup_id))"); PreparedStatement insertPS = session.prepare("insert into agent_config" + " (agent_rollup_id, config, config_update, config_update_token) values" + " (?, ?, ?, ?)"); Map<String, V09AgentRollup> v09AgentRollups = getV09AgentRollupsFromAgentRollupTable(); ResultSet results = session.read("select agent_rollup_id, config, config_update," + " config_update_token from agent_config_temp"); for (Row row : results) { String v09AgentRollupId = row.getString(0); V09AgentRollup v09AgentRollup = v09AgentRollups.get(v09AgentRollupId); if (v09AgentRollup == null) { // v09AgentRollupId was manually deleted (via the UI) from the agent_rollup // table in which case its parent is no longer known and best to ignore continue; } BoundStatement boundStatement = insertPS.bind(); boundStatement.setString(0, v09AgentRollup.agentRollupId()); boundStatement.setBytes(1, row.getBytes(1)); boundStatement.setBool(2, row.getBool(2)); boundStatement.setUUID(3, row.getUUID(3)); session.write(boundStatement); } dropTableIfExists("agent_config_temp"); }
Example 18
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 5 votes |
private void populateAgentConfigGeneral() throws Exception { if (!columnExists("agent_rollup", "display")) { // previously failed mid-upgrade prior to updating schema version return; } ResultSet results = session.read("select agent_rollup_id, display from agent_rollup where one = 1"); PreparedStatement readConfigPS = session.prepare("select config from agent_config where agent_rollup_id = ?"); PreparedStatement insertConfigPS = session.prepare("insert into agent_config (agent_rollup_id, config) values (?, ?)"); for (Row row : results) { String agentRollupId = row.getString(0); String display = row.getString(1); if (display == null) { continue; } BoundStatement boundStatement = readConfigPS.bind(); boundStatement.setString(0, agentRollupId); Row configRow = session.read(boundStatement).one(); if (configRow == null) { logger.warn("could not find config for agent rollup id: {}", agentRollupId); continue; } AgentConfig agentConfig = AgentConfig.parseFrom(checkNotNull(configRow.getBytes(0))); AgentConfig updatedAgentConfig = agentConfig.toBuilder() .setGeneralConfig(GeneralConfig.newBuilder() .setDisplay(display)) .build(); boundStatement = insertConfigPS.bind(); boundStatement.setString(0, agentRollupId); boundStatement.setBytes(1, ByteBuffer.wrap(updatedAgentConfig.toByteArray())); session.write(boundStatement); } dropColumnIfExists("agent_rollup", "display"); }
Example 19
Source File: SchemaUpgrade.java From glowroot with Apache License 2.0 | 5 votes |
private void upgradeAlertConfigs() throws Exception { PreparedStatement insertPS = session.prepare("insert into agent_config (agent_rollup_id," + " config, config_update, config_update_token) values (?, ?, ?, ?)"); ResultSet results = session.read("select agent_rollup_id, config from agent_config"); for (Row row : results) { String agentRollupId = row.getString(0); AgentConfig oldAgentConfig; try { oldAgentConfig = AgentConfig.parseFrom(checkNotNull(row.getBytes(1))); } catch (InvalidProtocolBufferException e) { logger.error(e.getMessage(), e); continue; } List<OldAlertConfig> oldAlertConfigs = oldAgentConfig.getOldAlertConfigList(); if (oldAlertConfigs.isEmpty()) { continue; } AgentConfig agentConfig = upgradeOldAgentConfig(oldAgentConfig); BoundStatement boundStatement = insertPS.bind(); int i = 0; boundStatement.setString(i++, agentRollupId); boundStatement.setBytes(i++, ByteBuffer.wrap(agentConfig.toByteArray())); boundStatement.setBool(i++, true); boundStatement.setUUID(i++, UUIDs.random()); session.write(boundStatement); } }
Example 20
Source File: CassandraIntervalCollectionPersistor.java From brein-time-utilities with Apache License 2.0 | 5 votes |
@Override public void upsert(final IntervalCollectionEvent event) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Upserting IntervalCollection '" + event.getKey() + "': " + event.getCollection()); } if (this.upsert == null) { this.upsert = getSession().prepare(QueryBuilder .update(this.keySpace, this.columnFamily) .with(QueryBuilder.set(COLL_COLUMN, QueryBuilder.bindMarker())) .where(eq(KEY_COLUMN, QueryBuilder.bindMarker()))); } final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try (final ObjectOutputStream out = new ObjectOutputStream(byteStream)) { final IntervalCollection coll = event.getCollection(); if (Serializable.class.isInstance(coll)) { out.writeObject(coll); } else { throw new IllegalConfiguration("The collection to be written is not serializable."); } out.flush(); } catch (final IOException e) { throw new FailedIO("Unable ot upsert instance for " + event.getKey(), e); } final BoundStatement boundStmt = new BoundStatement(this.upsert); boundStmt.setBytes(0, ByteBuffer.wrap(byteStream.toByteArray())); boundStmt.setString(1, event.getKey()); getSession().execute(boundStmt); }