com.google.datastore.v1.ArrayValue Java Examples
The following examples show how to use
com.google.datastore.v1.ArrayValue.
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: DatastoreConverters.java From DataflowTemplates with Apache License 2.0 | 6 votes |
/** * Grabs the schema for what data is in the Array. * @param arrayValue a populated array * @return a schema of what kind of data is in the array */ private JsonArray arraySchema(ArrayValue arrayValue) { Set<JsonObject> entities = new HashSet<>(); Set<String> primitives = new HashSet<>(); Set<JsonArray> subArrays = new HashSet<>(); arrayValue.getValuesList().stream().forEach(value -> { switch (value.getValueTypeCase()) { case ENTITY_VALUE: entities.add(entitySchema(value.getEntityValue())); break; case ARRAY_VALUE: subArrays.add(arraySchema(value.getArrayValue())); break; default: primitives.add(value.getValueTypeCase().toString()); break; } }); JsonArray jsonArray = new JsonArray(); entities.stream().forEach(jsonArray::add); primitives.stream().forEach(jsonArray::add); subArrays.stream().forEach(jsonArray::add); return jsonArray; }
Example #2
Source File: Value.java From async-datastore-client with Apache License 2.0 | 5 votes |
/** * Set a list of values for this {@code Value}. * <p> * The supplied value items must comply with the data types supported by Datastore. * * @param values a list of values to set. * @return this value builder. * @throws IllegalArgumentException if supplied {@code values} contains types * that are not recognised. */ public Builder value(final List<Object> values) { final ArrayValue arrayValues = ArrayValue .newBuilder() .addAllValues( values .stream() .map(v -> Value.builder(v).build().getPb()).collect(Collectors.toList())) .build(); this.value.setArrayValue(arrayValues); return this; }
Example #3
Source File: Value.java From async-datastore-client with Apache License 2.0 | 5 votes |
/** * Create a new value containing a list of values. * * @param values List of values to add to builder. * @return A new value builder containing a list. */ public static Value.Builder from(final List<Value> values) { final com.google.datastore.v1.ArrayValue.Builder builder = com.google.datastore.v1.ArrayValue.newBuilder(); values.stream().forEach(v -> builder.addValues(v.getPb())); return new Value.Builder(com.google.datastore.v1.Value.newBuilder().setArrayValue(builder).build()); }
Example #4
Source File: Value.java From async-datastore-client with Apache License 2.0 | 5 votes |
/** * Create a new value containing an array of values. * * @param first First value to add. * @param values Array of values to add to builder. * @return A new value builder containing a list. */ public static Value.Builder from(final Value first, final Value... values) { final com.google.datastore.v1.ArrayValue.Builder builder = com.google.datastore.v1.ArrayValue.newBuilder(); builder.addValues(first.getPb()); for (final Value v : values) { builder.addValues(v.getPb()); } return new Value.Builder( com.google.datastore.v1.Value.newBuilder().setArrayValue(builder).build()); }
Example #5
Source File: DatastoreHelper.java From google-cloud-datastore with Apache License 2.0 | 5 votes |
/** * Make a list value containing the specified values. */ public static Value.Builder makeValue(Value value1, Value value2, Value... rest) { ArrayValue.Builder arrayValue = ArrayValue.newBuilder(); arrayValue.addValues(value1); arrayValue.addValues(value2); arrayValue.addAllValues(Arrays.asList(rest)); return Value.newBuilder().setArrayValue(arrayValue); }
Example #6
Source File: DatastoreHelper.java From google-cloud-datastore with Apache License 2.0 | 5 votes |
/** * Make an array value containing the specified values. */ public static Value.Builder makeValue(Value.Builder value1, Value.Builder value2, Value.Builder... rest) { ArrayValue.Builder arrayValue = ArrayValue.newBuilder(); arrayValue.addValues(value1); arrayValue.addValues(value2); for (Value.Builder builder : rest) { arrayValue.addValues(builder); } return Value.newBuilder().setArrayValue(arrayValue); }
Example #7
Source File: DatastoreConvertersTest.java From DataflowTemplates with Apache License 2.0 | 4 votes |
@Before public void testData() { entities = new ArrayList<>(); entities.add(Entity.newBuilder() .setKey(Key.newBuilder() .setPartitionId(PartitionId.newBuilder() .setProjectId("my-project") .setNamespaceId("some-namespace")) .addPath(PathElement.newBuilder() .setId(1234) .setKind("monkey"))) .putProperties("someString", Value.newBuilder() .setStringValue("someValue") .build()) .build()); entities.add(Entity.newBuilder() .setKey(Key.newBuilder() .setPartitionId(PartitionId.newBuilder() .setProjectId("my-project") .setNamespaceId("some-namespace")) .addPath(PathElement.newBuilder() .setName("SomeName") .setKind("monkey"))) .putProperties("someString", Value.newBuilder() .setIntegerValue(100L) .build()) .putProperties("someSubRecord", Value.newBuilder() .setEntityValue(Entity.newBuilder() .putProperties("someSubFloat", Value.newBuilder() .setDoubleValue(0.234) .build())) .build()) .putProperties("someArray", Value.newBuilder() .setArrayValue(ArrayValue.newBuilder() .addValues(Value.newBuilder() .setIntegerValue(1234L)) .addValues(Value.newBuilder() .setIntegerValue(1234L)) .addValues(Value.newBuilder() .setArrayValue(ArrayValue.newBuilder() .addValues(Value.newBuilder() .setStringValue("Some nested string in a nested array")))) .build()) .build()) .build()); entitiesJson = new LinkedList<>(); entitiesJson.add( "{\"key\":{\"partitionId\":{\"projectId\":\"my-project\"," + "\"namespaceId\":\"some-namespace\"},\"path\":" + "[{\"kind\":\"monkey\",\"id\":\"1234\"}]}," + "\"properties\":{\"someString\":{\"stringValue\":\"someValue\"}}}"); }
Example #8
Source File: DatastoreHelper.java From google-cloud-datastore with Apache License 2.0 | 4 votes |
/** * Make an array value containing the specified values. */ public static Value.Builder makeValue(Iterable<Value> values) { return Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(values)); }