/** * Returns true if property is an instance of NullValue. * * @throws DatastoreException if no such property */ public boolean isNull(String name) { return getValue(name) instanceof NullValue; }
/** * Returns the property value as a string. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a string */ @SuppressWarnings("unchecked") public String getString(String name) { return ((Value<String>) getValue(name)).get(); }
/** * Returns the property value as a Timestamp. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a Timestamp */ @SuppressWarnings("unchecked") public Timestamp getTimestamp(String name) { return ((Value<Timestamp>) getValue(name)).get(); }
/** * Returns the property value as a LatLng. * * @throws DatastoreException if no such property. * @throws ClassCastException if value is not a LatLng. */ @SuppressWarnings("unchecked") public LatLng getLatLng(String name) { return ((Value<LatLng>) getValue(name)).get(); }
/** * Returns the property value as a list of values. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a list of values */ @SuppressWarnings("unchecked") public <T extends Value<?>> List<T> getList(String name) { return (List<T>) getValue(name).get(); }
/** * Returns the property value as a double. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a double */ @SuppressWarnings("unchecked") public double getDouble(String name) { return ((Value<Double>) getValue(name)).get(); }
/** * Returns the property value as a blob. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a blob */ @SuppressWarnings("unchecked") public Blob getBlob(String name) { return ((Value<Blob>) getValue(name)).get(); }
/** * Returns the property value as long. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a long */ @SuppressWarnings("unchecked") public long getLong(String name) { return ((Value<Long>) getValue(name)).get(); }
/** * Returns the property value as a boolean. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a boolean */ @SuppressWarnings("unchecked") public boolean getBoolean(String name) { return ((Value<Boolean>) getValue(name)).get(); }
/** * Returns the property value as a Key. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a Key */ @SuppressWarnings("unchecked") public Key getKey(String name) { return ((Value<Key>) getValue(name)).get(); }
/** * Returns the property value as an entity. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not an entity */ @SuppressWarnings("unchecked") public <K extends IncompleteKey> FullEntity<K> getEntity(String name) { return ((Value<FullEntity<K>>) getValue(name)).get(); }
@Test(expected = DatastoreException.class) public void testGetValueNotFound() throws Exception { BaseEntity<Key> entity = builder.clear().build(); entity.getValue("blob"); }
@Test public void testGetValue() throws Exception { BaseEntity<Key> entity = builder.build(); assertEquals(BlobValue.of(BLOB), entity.getValue("blob")); }
/** * The problem is ProjectionEntity; there's no way to create an EntityValue with a ProjectionEntity * so we can't use the standard translation system for {@code Value<Entity>}. Instead of making the * translation API really complicated, just convert it to a FullEntity. */ private EntityValue makeLoadEntityValue(final BaseEntity<?> ent) { if (ent instanceof FullEntity<?>) { return EntityValue.of((FullEntity<?>)ent); } else { // Sadly there's no more graceful way of doing this final Builder<?> builder = FullEntity.newBuilder(ent.getKey()); for (final String name : ent.getNames()) { final Value<?> value = ent.getValue(name); builder.set(name, value); } return EntityValue.of(builder.build()); } }
/** * Returns true if property is an instance of NullValue. * * @throws DatastoreException if no such property */ public boolean isNull(String name) { return getValue(name) instanceof NullValue; }
/** * Returns the property value as a blob. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a blob */ @SuppressWarnings("unchecked") public Blob getBlob(String name) { return ((Value<Blob>) getValue(name)).get(); }
/** * Returns the property value as long. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a long */ @SuppressWarnings("unchecked") public long getLong(String name) { return ((Value<Long>) getValue(name)).get(); }
/** * Returns the property value as a boolean. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a boolean */ @SuppressWarnings("unchecked") public boolean getBoolean(String name) { return ((Value<Boolean>) getValue(name)).get(); }
/** * Returns the property value as a Timestamp. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a Timestamp */ @SuppressWarnings("unchecked") public Timestamp getTimestamp(String name) { return ((Value<Timestamp>) getValue(name)).get(); }
/** * Returns the property value as a Key. * * @throws DatastoreException if no such property * @throws ClassCastException if value is not a Key */ @SuppressWarnings("unchecked") public Key getKey(String name) { return ((Value<Key>) getValue(name)).get(); }