com.google.cloud.datastore.LongValue Java Examples
The following examples show how to use
com.google.cloud.datastore.LongValue.
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: ShardedCounterMetricsStore.java From nexus-blobstore-google-cloud with Eclipse Public License 1.0 | 6 votes |
private Entity getShardCounter(final String location) { KeyFactory keyFactory = datastore.newKeyFactory().addAncestors( NXRM_ROOT, PathElement.of(METRICS_STORE, 1L) ); Key key = keyFactory.setNamespace(namespace) .setKind(SHARD).newKey(location); Entity exists = datastore.get(key); if (exists != null) { log.trace("counter for {} already present", location); return exists; } log.debug("creating metrics store counter shard for {}", location); // otherwise make it Entity entity = Entity.newBuilder(key) .set(SIZE, LongValue.newBuilder(0L).build()) .set(COUNT, LongValue.newBuilder(0L).build()) .build(); return datastore.put(entity); }
Example #2
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore10() { DecimalMapper mapper = new DecimalMapper(6, 2); Value<?> value = mapper.toDatastore(new BigDecimal("0.1")).build(); assertTrue(value instanceof LongValue); assertEquals(10L, value.get()); }
Example #3
Source File: CurrencyMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } BigDecimal n = new BigDecimal(((LongValue) input).get()); n = n.movePointLeft(fractionalDigits); return n; }
Example #4
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore1() { DecimalMapper mapper = new DecimalMapper(6, 2); Value<?> value = mapper.toDatastore(new BigDecimal("9999.99")).build(); assertTrue(value instanceof LongValue); assertEquals(999999L, value.get()); }
Example #5
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore2() { DecimalMapper mapper = new DecimalMapper(6, 2); Value<?> value = mapper.toDatastore(new BigDecimal("0")).build(); assertTrue(value instanceof LongValue); assertEquals(0L, value.get()); }
Example #6
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore3() { DecimalMapper mapper = new DecimalMapper(18, 6); Value<?> value = mapper.toDatastore(new BigDecimal("123456789012.123456")).build(); assertTrue(value instanceof LongValue); assertEquals(123456789012123456L, value.get()); }
Example #7
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore4() { DecimalMapper mapper = new DecimalMapper(18, 6); Value<?> value = mapper.toDatastore(new BigDecimal("-123456789012.123456")).build(); assertTrue(value instanceof LongValue); assertEquals(-123456789012123456L, value.get()); }
Example #8
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore7() { DecimalMapper mapper = new DecimalMapper(1, 1); Value<?> value = mapper.toDatastore(new BigDecimal("0.5")).build(); assertTrue(value instanceof LongValue); assertEquals(5L, value.get()); }
Example #9
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore9() { DecimalMapper mapper = new DecimalMapper(18, 18); Value<?> value = mapper.toDatastore(new BigDecimal("0.000000000000000565")).build(); assertTrue(value instanceof LongValue); assertEquals(565L, value.get()); }
Example #10
Source File: ByteMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } Long l = ((LongValue) input).get(); if (l < Byte.MIN_VALUE || l > Byte.MAX_VALUE) { throw new MappingException(String.format("Value %d is out of range for byte type", l)); } return l.byteValue(); }
Example #11
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore11() { DecimalMapper mapper = new DecimalMapper(6, 2); Value<?> value = mapper.toDatastore(new BigDecimal("0.10")).build(); assertTrue(value instanceof LongValue); assertEquals(10L, value.get()); }
Example #12
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore12() { DecimalMapper mapper = new DecimalMapper(6, 2); Value<?> value = mapper.toDatastore(new BigDecimal("0.0")).build(); assertTrue(value instanceof LongValue); assertEquals(0L, value.get()); }
Example #13
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToDatastore13() { DecimalMapper mapper = new DecimalMapper(6, 2); Value<?> value = mapper.toDatastore(new BigDecimal("0.01")).build(); assertTrue(value instanceof LongValue); assertEquals(1L, value.get()); }
Example #14
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToModel1() { DecimalMapper mapper = new DecimalMapper(6, 2); LongValue input = LongValue.of(999999L); BigDecimal output = (BigDecimal) mapper.toModel(input); assertEquals(new BigDecimal("9999.99"), output); }
Example #15
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToModel2() { DecimalMapper mapper = new DecimalMapper(6, 2); LongValue input = LongValue.of(0); BigDecimal output = (BigDecimal) mapper.toModel(input); assertEquals(new BigDecimal("0.00"), output); }
Example #16
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToModel3() { DecimalMapper mapper = new DecimalMapper(18, 18); LongValue input = LongValue.of(999999999999999999L); BigDecimal output = (BigDecimal) mapper.toModel(input); assertEquals(new BigDecimal("0.999999999999999999"), output); }
Example #17
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test(expected = MappingException.class) public void testToModel4() { try { DecimalMapper mapper = new DecimalMapper(5, 2); LongValue input = LongValue.of(123456); BigDecimal output = (BigDecimal) mapper.toModel(input); assertEquals(new BigDecimal("123.456"), output); } catch (Exception e) { System.err.println(e); throw e; } }
Example #18
Source File: DecimalMapperTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testToModel5() { try { DecimalMapper mapper = new DecimalMapper(5, 2); LongValue input = LongValue.of(12345L); BigDecimal output = (BigDecimal) mapper.toModel(input); assertEquals(new BigDecimal("123.45"), output); } catch (Exception e) { System.err.println(e); throw e; } }
Example #19
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 #20
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 #21
Source File: DatastoreTemplateTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void writeMapTest() { Map<String, Long> map = new HashMap<>(); map.put("field1", 1L); Key keyForMap = createFakeKey("map1"); when(this.readWriteConversions.convertOnWriteSingle(eq(1L))).thenReturn(LongValue.of(1L)); this.datastoreTemplate.writeMap(keyForMap, map); Entity datastoreEntity = Entity.newBuilder(keyForMap).set("field1", 1L).build(); verify(this.datastore, times(1)).put(eq(datastoreEntity)); }
Example #22
Source File: IntegerMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public ValueBuilder<?, ?, ?> toDatastore(Object input) { if (input == null) { return NullValue.newBuilder(); } return LongValue.newBuilder((int) input); }
Example #23
Source File: IntegerMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } Long l = ((LongValue) input).get(); if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw new MappingException(String.format("Value %d is out of range for integer type", l)); } return l.intValue(); }
Example #24
Source File: ShortMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public ValueBuilder<?, ?, ?> toDatastore(Object input) { if (input == null) { return NullValue.newBuilder(); } return LongValue.newBuilder((short) input); }
Example #25
Source File: ShortMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } Long l = ((LongValue) input).get(); if (l < Short.MIN_VALUE || l > Short.MAX_VALUE) { throw new MappingException(String.format("Value %d is out of range for short type", l)); } return l.shortValue(); }
Example #26
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 #27
Source File: CurrencyMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public ValueBuilder<?, ?, ?> toDatastore(Object input) { if (input == null) { return NullValue.newBuilder(); } try { BigDecimal n = (BigDecimal) input; n = n.movePointRight(fractionalDigits); return LongValue.newBuilder(n.longValueExact()); } catch (Exception e) { throw new MappingException(e); } }
Example #28
Source File: LongMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public ValueBuilder<?, ?, ?> toDatastore(Object input) { if (input == null) { return NullValue.newBuilder(); } return LongValue.newBuilder((long) input); }
Example #29
Source File: LongMapper.java From catatumbo with Apache License 2.0 | 5 votes |
@Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } return ((LongValue) input).get(); }
Example #30
Source File: LowerCaseStringIndexerTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test(expected = IndexingException.class) public void testIndex_3() { LongValue input = LongValue.of(5L); try { Value<?> output = indexer.index(input); } catch (Exception exp) { LOGGER.log(Level.INFO, exp.toString()); throw exp; } }