/** * Sets a property of type {@link StringValue}. * * @param name name of the property * @param value value associated with the property */ public B set(String name, String value) { properties.put(name, of(value)); return self(); }
public static PropertyFilter lt(String property, String value) { return new PropertyFilter(property, Operator.LESS_THAN, of(value)); }
public static PropertyFilter gt(String property, String value) { return new PropertyFilter(property, Operator.GREATER_THAN, of(value)); }
public static PropertyFilter le(String property, String value) { return new PropertyFilter(property, Operator.LESS_THAN_OR_EQUAL, of(value)); }
public static PropertyFilter ge(String property, String value) { return new PropertyFilter(property, Operator.GREATER_THAN_OR_EQUAL, of(value)); }
public static PropertyFilter eq(String property, String value) { return new PropertyFilter(property, Operator.EQUAL, of(value)); }
/** * Sets a list property containing elements of type {@link StringValue}. * * @param name name of the property * @param first the first string in the list * @param second the second string in the list * @param others other strings in the list */ public B set(String name, String first, String second, String... others) { List<StringValue> values = new LinkedList<>(); values.add(of(first)); values.add(of(second)); for (String other : others) { values.add(of(other)); } properties.put(name, of(values)); return self(); }
@Test public void testToBuilder() throws Exception { StringValue value = StringValue.of(CONTENT); assertEquals(value, value.toBuilder().build()); }
@Test public void testOf() throws Exception { StringValue value = StringValue.of(CONTENT); assertEquals(CONTENT, value.get()); assertFalse(value.excludeFromIndexes()); }
@Test public void testGetList() throws Exception { BaseEntity<Key> entity = builder.build(); List<? extends Value<?>> list = entity.getList("list1"); assertEquals(3, list.size()); assertEquals(NullValue.of(), list.get(0)); assertEquals("foo", list.get(1).get()); assertEquals(LAT_LNG, list.get(2).get()); list = entity.getList("list2"); assertEquals(2, list.size()); assertEquals(Long.valueOf(10), list.get(0).get()); assertEquals(Double.valueOf(2), list.get(1).get()); list = entity.getList("list3"); assertEquals(1, list.size()); assertEquals(Boolean.TRUE, list.get(0).get()); entity = builder.set("list1", ListValue.of(list)).build(); assertEquals(list, entity.getList("list1")); List<Value<?>> stringList = entity.getList("stringList"); assertEquals( ImmutableList.of(StringValue.of("s1"), StringValue.of("s2"), StringValue.of("s3")), stringList); List<Value<Double>> doubleList = entity.getList("doubleList"); assertEquals( ImmutableList.of(DoubleValue.of(12.3), DoubleValue.of(4.56), DoubleValue.of(.789)), doubleList); List<EntityValue> entityList = entity.getList("entityList"); assertEquals( ImmutableList.of(EntityValue.of(ENTITY), EntityValue.of(PARTIAL_ENTITY)), entityList); }
.build()); lookupRequests.add(LookupRequest.newBuilder().addKeys(keysPb.get(4)).build()); Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); List<LookupResponse> lookupResponses = new ArrayList<>();
@Test public void testNewTransactionRollback() { Transaction transaction = datastore.newTransaction(); transaction.add(ENTITY3); Entity entity2 = Entity.newBuilder(ENTITY2) .clear() .setNull("bla") .set("list3", StringValue.of("bla"), StringValue.newBuilder("bla").build()) .build(); transaction.update(entity2); transaction.delete(KEY1); transaction.rollback(); transaction.rollback(); // should be safe to repeat rollback calls try { transaction.commit(); fail("Expecting a failure"); } catch (DatastoreException ex) { // expected to fail } verifyNotUsable(transaction); List<Entity> list = datastore.fetch(KEY1, KEY2, KEY3); assertEquals(ENTITY1, list.get(0)); assertEquals(ENTITY2, list.get(1)); assertNull(list.get(2)); assertEquals(3, list.size()); }
@Test public void testNewTransactionRollback() { Transaction transaction = DATASTORE.newTransaction(); transaction.add(ENTITY3); Entity entity2 = Entity.newBuilder(ENTITY2) .clear() .setNull("bla") .set("list3", StringValue.of("bla"), StringValue.newBuilder("bla").build()) .build(); transaction.update(entity2); transaction.delete(KEY1); transaction.rollback(); transaction.rollback(); // should be safe to repeat rollback calls try { transaction.commit(); fail("Expecting a failure"); } catch (DatastoreException expected) { assertEquals("FAILED_PRECONDITION", expected.getReason()); } List<Entity> list = DATASTORE.fetch(KEY1, KEY2, KEY3); assertEquals(ENTITY1, list.get(0)); assertEquals(ENTITY2, list.get(1)); assertNull(list.get(2)); assertEquals(3, list.size()); }
assertFalse(value.excludeFromIndexes()); value = ListValue.of(STRING1); assertEquals(ImmutableList.of(StringValue.of(STRING1)), value.get()); value = ListValue.of(STRING1, STRING2); assertEquals(ImmutableList.of(StringValue.of(STRING1), StringValue.of(STRING2)), value.get()); value = ListValue.of(LONG1); assertEquals(ImmutableList.of(LongValue.of(LONG1)), value.get());
private List<RunQueryResponse> buildResponsesForQueryPaginationWithLimit() { Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); datastore.add(ENTITY3, entity4, entity5);
private List<RunQueryResponse> buildResponsesForQueryPagination() { Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); datastore.add(ENTITY3, entity4, entity5);
Entity entity1 = Entity.newBuilder(ENTITY1).clear().build(); Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build(); Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build();
Entity entity1 = Entity.newBuilder(ENTITY1).clear().build(); Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build(); Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build();
@Before public void setUp() { builder = new Builder(); builder.set("blob", BLOB).set("boolean", true).set("timestamp", TIMESTAMP); builder.set("double", 1.25).set("key", KEY).set("string", "hello world"); builder.set("long", 125).setNull("null").set("entity", ENTITY).set("latLng", LAT_LNG); builder.set("partialEntity", PARTIAL_ENTITY).set("stringValue", StringValue.of("bla")); builder.set("list1", NullValue.of(), StringValue.of("foo"), LatLngValue.of(LAT_LNG)); builder.set("list2", ImmutableList.of(LongValue.of(10), DoubleValue.of(2))); builder.set("list3", Collections.singletonList(BooleanValue.of(true))); builder.set( "blobList", BLOB, Blob.copyFrom(new byte[] {3, 4}), Blob.copyFrom(new byte[] {5, 6})); builder.set("booleanList", true, false, true); builder.set("timestampList", Timestamp.now(), Timestamp.now(), Timestamp.now()); builder.set("doubleList", 12.3, 4.56, .789); builder.set( "keyList", KEY, Key.newBuilder("ds2", "k2", "n2").build(), Key.newBuilder("ds3", "k3", "n3").build()); builder.set("entityList", ENTITY, PARTIAL_ENTITY); builder.set("stringList", "s1", "s2", "s3"); builder.set("longList", 1, 23, 456); builder.set("latLngList", LAT_LNG, LAT_LNG); }