@Override
  public UniqueValueSet load(
      final ApplicationScope appScope,
      final ConsistencyLevel consistencyLevel,
      final String type,
      final Collection<Field> fields)
      throws ConnectionException {

    Preconditions.checkNotNull(fields, "fields are required");
    Preconditions.checkArgument(fields.size() > 0, "More than 1 field must be specified");

    final List<ScopedRowKey<FieldKey>> keys = new ArrayList<>(fields.size());

    final Id applicationId = appScope.getApplication();

    for (Field field : fields) {

      final FieldKey key = createUniqueValueKey(applicationId, type, field);

      final ScopedRowKey<FieldKey> rowKey = ScopedRowKey.fromKey(applicationId, key);

      keys.add(rowKey);
    }

    final UniqueValueSetImpl uniqueValueSet = new UniqueValueSetImpl(fields.size());

    Iterator<Row<ScopedRowKey<FieldKey>, EntityVersion>> results =
        keyspace
            .prepareQuery(CF_UNIQUE_VALUES)
            .setConsistencyLevel(consistencyLevel)
            .getKeySlice(keys)
            .withColumnRange(new RangeBuilder().setLimit(1).build())
            .execute()
            .getResult()
            .iterator();

    while (results.hasNext()) {

      final Row<ScopedRowKey<FieldKey>, EntityVersion> unique = results.next();

      final Field field = parseRowKey(unique.getKey());

      final Iterator<Column<EntityVersion>> columnList = unique.getColumns().iterator();

      // sanity check, nothing to do, skip it
      if (!columnList.hasNext()) {
        continue;
      }

      final EntityVersion entityVersion = columnList.next().getName();

      final UniqueValueImpl uniqueValue =
          new UniqueValueImpl(field, entityVersion.getEntityId(), entityVersion.getEntityVersion());

      uniqueValueSet.addValue(uniqueValue);
    }

    return uniqueValueSet;
  }
예제 #2
0
 /** Parses the entity, client identification and execution options from the given json object */
 protected void parse(ObjectNode node) {
   entityVersion = new EntityVersion();
   JsonNode x = node.get("entity");
   if (x != null && !(x instanceof NullNode)) {
     entityVersion.setEntity(x.asText());
   }
   x = node.get("entityVersion");
   if (x != null && !(x instanceof NullNode)) {
     entityVersion.setVersion(x.asText());
   }
   // TODO: clientIdentification
   x = node.get("execution");
   if (x != null) {
     execution = ExecutionOptions.fromJson((ObjectNode) x);
   }
 }
예제 #3
0
 /** Returns a JSON representation of this */
 @Override
 public JsonNode toJson() {
   ObjectNode node = getFactory().objectNode();
   node.put("entity", entityVersion.getEntity());
   if (entityVersion.getVersion() != null) node.put("entityVersion", entityVersion.getVersion());
   if (client != null) {
     node.set("client", client.toJson());
   }
   if (execution != null) {
     node.set("execution", execution.toJson());
   }
   if (getOperation() != null) {
     node.put("op", getOperation().name());
   }
   return node;
 }