com.google.cloud.datastore.BooleanValue Java Examples
The following examples show how to use
com.google.cloud.datastore.BooleanValue.
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: GoogleJobStore.java From data-transfer-project with Apache License 2.0 | 5 votes |
private static Map<String, Object> getProperties(Entity entity) throws IOException, ClassNotFoundException { if (entity == null) { return null; } ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>(); for (String property : entity.getNames()) { // builder.put(property, entity.getValue(property)); if (entity.getValue(property) instanceof StringValue) { builder.put(property, (String) entity.getString(property)); } else if (entity.getValue(property) instanceof LongValue) { // This conversion is safe because of integer to long conversion above builder.put(property, new Long(entity.getLong(property)).intValue()); } else if (entity.getValue(property) instanceof DoubleValue) { builder.put(property, (Double) entity.getDouble(property)); } else if (entity.getValue(property) instanceof BooleanValue) { builder.put(property, (Boolean) entity.getBoolean(property)); } else if (entity.getValue(property) instanceof TimestampValue) { builder.put(property, (Timestamp) entity.getTimestamp(property)); } else { Blob blob = entity.getBlob(property); Object obj = null; try (ObjectInputStream in = new ObjectInputStream(blob.asInputStream())) { obj = in.readObject(); } builder.put(property, obj); // BlobValue } } return builder.build(); }
Example #2
Source File: CatchAllMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public ValueBuilder<?, ?, ?> toDatastore(Object input) { ValueBuilder<?, ?, ?> builder; if (input == null) { builder = NullValue.newBuilder(); } else if (input instanceof Long) { builder = LongValue.newBuilder((long) input); } else if (input instanceof Double) { builder = DoubleValue.newBuilder((double) input); } else if (input instanceof Boolean) { builder = BooleanValue.newBuilder((boolean) input); } else if (input instanceof String) { builder = StringValue.newBuilder((String) input); } else if (input instanceof DatastoreKey) { builder = KeyValue.newBuilder(((DatastoreKey) input).nativeKey()); } else if (input instanceof GeoLocation) { GeoLocation geoLocation = (GeoLocation) input; builder = LatLngValue .newBuilder(LatLng.of(geoLocation.getLatitude(), geoLocation.getLongitude())); } else if (input instanceof Map) { @SuppressWarnings("unchecked") Map<String, ?> map = (Map<String, ?>) input; FullEntity.Builder<IncompleteKey> entityBuilder = FullEntity.newBuilder(); for (Map.Entry<String, ?> entry : map.entrySet()) { String key = entry.getKey(); entityBuilder.set(key, toDatastore(entry.getValue()).build()); } builder = EntityValue.newBuilder(entityBuilder.build()); } else { throw new MappingException(String.format("Unsupported type: %s", input.getClass().getName())); } return builder; }
Example #3
Source File: CatchAllMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public Object toModel(Value<?> input) { Object javaValue; if (input instanceof NullValue) { javaValue = null; } else if (input instanceof StringValue) { javaValue = input.get(); } else if (input instanceof LongValue) { javaValue = input.get(); } else if (input instanceof DoubleValue) { javaValue = input.get(); } else if (input instanceof BooleanValue) { javaValue = input.get(); } else if (input instanceof KeyValue) { javaValue = new DefaultDatastoreKey(((KeyValue) input).get()); } else if (input instanceof LatLngValue) { LatLng latLong = ((LatLngValue) input).get(); javaValue = new GeoLocation(latLong.getLatitude(), latLong.getLongitude()); } else if (input instanceof EntityValue) { EntityValue entityValue = (EntityValue) input; FullEntity<?> entity = entityValue.get(); Map<String, Object> map = new HashMap<>(); for (String property : entity.getNames()) { map.put(property, toModel(entity.getValue(property))); } javaValue = map; } else { throw new MappingException(String.format("Unsupported type %s", input.getClass().getName())); } return javaValue; }
Example #4
Source File: BooleanMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public ValueBuilder<?, ?, ?> toDatastore(Object input) { if (input == null) { return NullValue.newBuilder(); } return BooleanValue.newBuilder((boolean) input); }
Example #5
Source File: BooleanMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } return ((BooleanValue) input).get(); }