Java Code Examples for com.google.cloud.datastore.Value#getType()

The following examples show how to use com.google.cloud.datastore.Value#getType() . 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: LowerCaseStringListIndexer.java    From catatumbo with Apache License 2.0 6 votes vote down vote up
@Override
public Value<?> index(Value<?> input) {
  if (input.getType() == ValueType.NULL) {
    return NullValue.of();
  }
  try {
    List<? extends Value<?>> list = ((ListValue) input).get();
    ListValue.Builder builder = ListValue.newBuilder();
    for (Value<?> item : list) {
      builder.addValue(ITEM_INDEXER.index(item));
    }
    return builder.build();
  } catch (Exception exp) {
    throw new IndexingException(exp);
  }
}
 
Example 2
Source File: UpperCaseStringListIndexer.java    From catatumbo with Apache License 2.0 6 votes vote down vote up
@Override
public Value<?> index(Value<?> input) {
  if (input.getType() == ValueType.NULL) {
    return NullValue.of();
  }
  try {
    ListValue.Builder builder = ListValue.newBuilder();
    List<? extends Value<?>> list = ((ListValue) input).get();
    for (Value<?> item : list) {
      builder.addValue(ITEM_INDEXER.index(item));
    }
    return builder.build();
  } catch (Exception exp) {
    throw new IndexingException(exp);
  }
}
 
Example 3
Source File: EmbeddedObjectMapper.java    From catatumbo with Apache License 2.0 6 votes vote down vote up
@Override
public Object toModel(Value<?> input) {
  if (input.getType() == ValueType.NULL) {
    return null;
  }
  try {
    FullEntity<?> entity = ((EntityValue) input).get();
    ConstructorMetadata constructorMetadata = metadata.getConstructorMetadata();
    Object embeddedObject = constructorMetadata.getConstructorMethodHandle().invoke();
    for (PropertyMetadata propertyMetadata : metadata.getPropertyMetadataCollection()) {
      String mappedName = propertyMetadata.getMappedName();
      if (entity.contains(mappedName)) {
        Value<?> propertyValue = entity.getValue(mappedName);
        Object fieldValue = propertyMetadata.getMapper().toModel(propertyValue);
        propertyMetadata.getWriteMethod().invoke(embeddedObject, fieldValue);
      }
    }
    if (constructorMetadata.isBuilderConstructionStrategy()) {
      embeddedObject = metadata.getConstructorMetadata().getBuildMethodHandle()
          .invoke(embeddedObject);
    }
    return embeddedObject;
  } catch (Throwable exp) {
    throw new MappingException(exp);
  }
}
 
Example 4
Source File: UpperCaseStringIndexer.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
@Override
public Value<?> index(Value<?> input) {
  if (input.getType() == ValueType.NULL) {
    return NullValue.of();
  }
  try {
    String str = ((StringValue) input).get();
    return StringValue.of(str.toUpperCase(Locale.ENGLISH));
  } catch (Exception exp) {
    throw new IndexingException(exp);
  }
}
 
Example 5
Source File: LowerCaseStringIndexer.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
@Override
public Value<?> index(Value<?> input) {
  if (input.getType() == ValueType.NULL) {
    return NullValue.of();
  }
  try {
    String str = ((StringValue) input).get();
    return StringValue.of(str.toLowerCase(Locale.ENGLISH));
  } catch (Exception exp) {
    throw new IndexingException(exp);
  }
}