@Override public <T> QueryBinder<ENTITY> setUDTValue(String name, UDTValue v) { for (BoundStatement statement : statements.values()) { statement.setUDTValue(name, v); } return this; }
@Override public <T> QueryBinder<ENTITY> setUDTValue(int i, UDTValue v) { for (BoundStatement statement : statements.values()) { statement.setUDTValue(i, v); } return this; } }
@Test(groups = "short") public void should_handle_udts_with_default_codecs() { setUpUserTypes(cluster()); // simple statement session().execute(insertQuery, uuid, "John Doe", addressValue); ResultSet rows = session().execute(selectQuery, uuid); Row row = rows.one(); assertRow(row); // prepared + values PreparedStatement ps = session().prepare(insertQuery); session().execute(ps.bind(uuid, "John Doe", addressValue)); rows = session().execute(selectQuery, uuid); row = rows.one(); assertRow(row); // bound with setUDTValue session() .execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setUDTValue(2, addressValue)); rows = session().execute(selectQuery, uuid); row = rows.one(); assertRow(row); }
@Override public CompletableFuture<Stream<CassandraIdAndPath>> listUserMailboxes(String namespace, String user) { return cassandraAsyncExecutor.execute( selectAllForUser.bind() .setUDTValue(NAMESPACE_AND_USER, mailboxBaseTupleUtil.createMailboxBaseUDT(namespace, user))) .thenApply(resultSet -> cassandraUtils.convertToStream(resultSet) .map(this::fromRowToCassandraIdAndPath) .peek(this::logReadSuccess)); }
public CompletableFuture<Optional<CassandraIdAndPath>> retrieveId(MailboxPath mailboxPath) { return cassandraAsyncExecutor.executeSingleRow( select.bind() .setUDTValue(NAMESPACE_AND_USER, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName())) .thenApply(rowOptional -> rowOptional.map(this::fromRowToCassandraIdAndPath)) .thenApply(value -> logGhostMailbox(mailboxPath, value)); }
@Override public CompletableFuture<Void> delete(MailboxPath mailboxPath) { return cassandraAsyncExecutor.executeVoid(delete.bind() .setUDTValue(NAMESPACE_AND_USER, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName())); }
bstm.setTupleValue(key, (TupleValue) value); } else if (value instanceof UDTValue) { bstm.setUDTValue(key, (UDTValue) value); } else if (value instanceof UUID) { bstm.setUUID(key, (UUID) value);
/** * Bind fields from a device measurements event to an existing * {@link BoundStatement}. * * @param client * @param bound * @param mx * @throws SiteWhereException */ public static void bindFields(CassandraEventManagementClient client, BoundStatement bound, IDeviceMeasurement mx) throws SiteWhereException { CassandraDeviceEvent.bindEventFields(bound, mx); UDTValue udt = client.getMeasurementType().newValue(); udt.setString(FIELD_MXNAME, mx.getName()); udt.setDouble(FIELD_MXVALUE, mx.getValue()); bound.setUDTValue(FIELD_MEASUREMENT, udt); }
public CompletableFuture<Void> updatePath(CassandraId mailboxId, MailboxPath mailboxPath) { return executor.executeVoid(updateStatement.bind() .setUUID(ID, mailboxId.asUuid()) .setString(NAME, mailboxPath.getName()) .setUDTValue(MAILBOX_BASE, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser()))); }
@Override public CompletableFuture<Boolean> save(MailboxPath mailboxPath, CassandraId mailboxId) { return cassandraAsyncExecutor.executeReturnApplied(insert.bind() .setUDTValue(NAMESPACE_AND_USER, mailboxBaseTupleUtil.createMailboxBaseUDT(mailboxPath.getNamespace(), mailboxPath.getUser())) .setString(MAILBOX_NAME, mailboxPath.getName()) .setUUID(MAILBOX_ID, mailboxId.asUuid())); }
bstm.setTupleValue(i, (TupleValue) value); } else if (value instanceof UDTValue) { bstm.setUDTValue(i, (UDTValue) value); } else if (value instanceof UUID) { bstm.setUUID(i, (UUID) value);
/** * Bind fields from a device location to an existing {@link BoundStatement}. * * @param client * @param bound * @param location * @throws SiteWhereException */ public static void bindFields(CassandraEventManagementClient client, BoundStatement bound, IDeviceLocation location) throws SiteWhereException { CassandraDeviceEvent.bindEventFields(bound, location); UDTValue udt = client.getLocationType().newValue(); udt.setDouble(FIELD_LATITUDE, location.getLatitude()); udt.setDouble(FIELD_LONGITUDE, location.getLongitude()); udt.setDouble(FIELD_ELEVATION, location.getElevation()); bound.setUDTValue(FIELD_LOCATION, udt); }
/** * Bind fields from a device alert to an existing {@link BoundStatement}. * * @param client * @param bound * @param response * @throws SiteWhereException */ public static void bindFields(CassandraEventManagementClient client, BoundStatement bound, IDeviceCommandResponse response) throws SiteWhereException { CassandraDeviceEvent.bindEventFields(bound, response); UDTValue udt = client.getResponseType().newValue(); udt.setUUID(FIELD_ORIGINATING_EVENT_ID, response.getOriginatingEventId()); udt.setUUID(FIELD_RESPONSE_EVENT_ID, response.getResponseEventId()); udt.setString(FIELD_RESPONSE_CONTENT, response.getResponse()); bound.setUDTValue(FIELD_RESPONSE, udt); }
public CompletableFuture<Void> save(Mailbox mailbox) { CassandraId cassandraId = (CassandraId) mailbox.getMailboxId(); return executor.executeVoid(insertStatement.bind() .setUUID(ID, cassandraId.asUuid()) .setString(NAME, mailbox.getName()) .setLong(UIDVALIDITY, mailbox.getUidValidity()) .setUDTValue(MAILBOX_BASE, mailboxBaseTupleUtil.createMailboxBaseUDT(mailbox.getNamespace(), mailbox.getUser()))); }
/** * Bind fields from a device state change to an existing {@link BoundStatement}. * * @param client * @param bound * @param state * @throws SiteWhereException */ public static void bindFields(CassandraEventManagementClient client, BoundStatement bound, IDeviceStateChange state) throws SiteWhereException { CassandraDeviceEvent.bindEventFields(bound, state); UDTValue udt = client.getStateChangeType().newValue(); udt.setString(FIELD_ATTRIBUTE, state.getAttribute()); udt.setString(FIELD_TYPE, state.getType()); udt.setString(FIELD_PREVIOUS_STATE, state.getPreviousState()); udt.setString(FIELD_NEW_STATE, state.getNewState()); bound.setUDTValue(FIELD_STATE_CHANGE, udt); }
@Test(groups = "short") public void should_handle_udts_with_default_codecs() { setUpUserTypes(cluster()); // simple statement session().execute(insertQuery, uuid, "John Doe", addressValue); ResultSet rows = session().execute(selectQuery, uuid); Row row = rows.one(); assertRow(row); // prepared + values PreparedStatement ps = session().prepare(insertQuery); session().execute(ps.bind(uuid, "John Doe", addressValue)); rows = session().execute(selectQuery, uuid); row = rows.one(); assertRow(row); // bound with setUDTValue session() .execute(ps.bind().setUUID(0, uuid).setString(1, "John Doe").setUDTValue(2, addressValue)); rows = session().execute(selectQuery, uuid); row = rows.one(); assertRow(row); }
/** * Bind fields from a device alert to an existing {@link BoundStatement}. * * @param client * @param bound * @param alert * @throws SiteWhereException */ public static void bindFields(CassandraEventManagementClient client, BoundStatement bound, IDeviceAlert alert) throws SiteWhereException { CassandraDeviceEvent.bindEventFields(bound, alert); UDTValue udt = client.getAlertType().newValue(); udt.setByte(FIELD_SOURCE, getIndicatorForAlertSource(alert.getSource())); udt.setByte(FIELD_LEVEL, getIndicatorForAlertLevel(alert.getLevel())); udt.setString(FIELD_TYPE, alert.getType()); udt.setString(FIELD_MESSAGE, alert.getMessage()); bound.setUDTValue(FIELD_ALERT, udt); }
boundStatement.unset(cassandraColName); } else { boundStatement.setUDTValue(cassandraColName, null);
boundStatement.unset(cassandraColName); } else { boundStatement.setUDTValue(cassandraColName, null);
/** * Bind fields from a device command invocation to an existing * {@link BoundStatement}. * * @param client * @param bound * @param invocation * @throws SiteWhereException */ public static void bindFields(CassandraEventManagementClient client, BoundStatement bound, IDeviceCommandInvocation invocation) throws SiteWhereException { CassandraDeviceEvent.bindEventFields(bound, invocation); UDTValue udt = client.getInvocationType().newValue(); udt.setByte(FIELD_INITIATOR, getIndicatorForCommandInitiator(invocation.getInitiator())); udt.setString(FIELD_INITIATOR_ID, invocation.getInitiatorId()); udt.setByte(FIELD_TARGET, getIndicatorForCommandTarget(invocation.getTarget())); udt.setString(FIELD_TARGET_ID, invocation.getTargetId()); udt.setString(FIELD_COMMAND_TOKEN, invocation.getCommandToken()); udt.setMap(FIELD_COMMAND_PARAMS, invocation.getParameterValues()); bound.setUDTValue(FIELD_INVOCATION, udt); }