private String comparatorForSerializer(Serializer<?> s) {
   String comparator = serializerToComparatorMapping.get(s.getClass());
   if (comparator != null) {
     return comparator;
   }
   return BYTESTYPE.getTypeName();
 }
Beispiel #2
0
 /** {@inheritDoc} */
 @Override
 public <N> Mutator<K> addDeletion(
     K key, String cf, N columnName, Serializer<N> nameSerializer, long clock) {
   SlicePredicate sp = new SlicePredicate();
   sp.addToColumn_names(nameSerializer.toByteBuffer(columnName));
   Deletion d = columnName != null ? new Deletion(clock).setPredicate(sp) : new Deletion(clock);
   getPendingMutations().addDeletion(key, Arrays.asList(cf), d);
   return this;
 }
  @SuppressWarnings("unchecked")
  public <K, V, T> Composite createForQuery(
      PropertyMeta<K, V> propertyMeta, T keyValue, ComponentEquality equality) {
    log.trace("Creating query composite for propertyMeta {}", propertyMeta.getPropertyName());

    Composite composite = new Composite();
    String propertyName = propertyMeta.getPropertyName();

    if (propertyMeta.isSingleKey()) {
      if (keyValue == null) {
        composite = null;
      } else {
        composite.addComponent(0, keyValue, equality);
      }
    } else {
      MultiKeyProperties multiKeyProperties = propertyMeta.getMultiKeyProperties();
      List<Serializer<?>> componentSerializers = multiKeyProperties.getComponentSerializers();
      List<Object> keyValues =
          entityHelper.determineMultiKey(keyValue, multiKeyProperties.getComponentGetters());
      int srzCount = componentSerializers.size();
      int valueCount = keyValues.size();

      Validator.validateTrue(
          srzCount >= valueCount,
          "There should be at most"
              + srzCount
              + " values for the key of WideMap '"
              + propertyName
              + "'");

      int lastNotNullIndex = helper.findLastNonNullIndexForComponents(propertyName, keyValues);

      for (int i = 0; i <= lastNotNullIndex; i++) {
        Serializer<Object> srz = (Serializer<Object>) componentSerializers.get(i);
        Object value = keyValues.get(i);
        if (i < lastNotNullIndex) {
          composite.setComponent(i, value, srz, srz.getComparatorType().getTypeName(), EQUAL);
        } else {
          composite.setComponent(i, value, srz, srz.getComparatorType().getTypeName(), equality);
        }
      }
    }
    return composite;
  }
  @SuppressWarnings("unchecked")
  public <K, V, T> Composite createBaseComposite(PropertyMeta<K, V> propertyMeta, T keyValue) {
    log.trace("Creating base composite for propertyMeta {}", propertyMeta.getPropertyName());

    Composite composite = new Composite();
    String propertyName = propertyMeta.getPropertyName();

    if (propertyMeta.isSingleKey()) {
      Validator.validateNotNull(
          keyValue,
          "The values for the for the key of WideMap '" + propertyName + "' should not be null");

      Serializer<T> keySerializer = (Serializer<T>) propertyMeta.getKeySerializer();
      composite.setComponent(
          0, keyValue, keySerializer, keySerializer.getComparatorType().getTypeName());
    } else {
      MultiKeyProperties multiKeyProperties = propertyMeta.getMultiKeyProperties();
      List<Serializer<?>> componentSerializers = multiKeyProperties.getComponentSerializers();
      List<Object> keyValues =
          entityHelper.determineMultiKey(keyValue, multiKeyProperties.getComponentGetters());
      int srzCount = componentSerializers.size();
      int valueCount = keyValues.size();

      Validator.validateTrue(
          srzCount == valueCount,
          "There should be " + srzCount + " values for the key of WideMap '" + propertyName + "'");

      for (Object value : keyValues) {
        Validator.validateNotNull(
            value,
            "The values for the for the key of WideMap '" + propertyName + "' should not be null");
      }

      for (int i = 0; i < srzCount; i++) {
        Serializer<Object> srz = (Serializer<Object>) componentSerializers.get(i);
        composite.setComponent(i, keyValues.get(i), srz, srz.getComparatorType().getTypeName());
      }
    }
    return composite;
  }
 @SuppressWarnings("unchecked")
 public <A> A getValue(Serializer<A> s) {
   if (s == null) {
     s = (Serializer<A>) serializer;
   }
   if ((value == null) && (bytes != null) && (s != null)) {
     ByteBuffer cb = bytes.duplicate();
     return s.fromByteBuffer(cb);
   }
   if (value instanceof ByteBuffer) {
     return (A) ((ByteBuffer) value).duplicate();
   }
   return (A) value;
 }
    @SuppressWarnings("unchecked")
    public <A> ByteBuffer getBytes(Serializer<A> s) {
      if (bytes == null) {
        if (value instanceof ByteBuffer) {
          return ((ByteBuffer) value).duplicate();
        }

        if (value == null) {
          return null;
        }

        if (s == null) {
          s = (Serializer<A>) serializer;
        }
        if (s != null) {
          return s.toByteBuffer((A) value).duplicate();
        }
      }

      return bytes.duplicate();
    }