Java Code Examples for com.google.cloud.spanner.Key#getParts()
The following examples show how to use
com.google.cloud.spanner.Key#getParts() .
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: SpannerCompositeKeyProperty.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
Key getId(Object entity) { PersistentPropertyAccessor accessor = getOwner().getPropertyAccessor(entity); List keyParts = new ArrayList(); for (SpannerPersistentProperty spannerPersistentProperty : this.primaryKeyColumns) { Object value = accessor.getProperty(spannerPersistentProperty); if (spannerPersistentProperty.isEmbedded()) { Key embeddedKeyParts = this.spannerPersistentEntity .getSpannerMappingContext() .getPersistentEntity(spannerPersistentProperty.getType()) .getIdProperty() .getId(value); for (Object keyPart : embeddedKeyParts.getParts()) { keyParts.add(keyPart); } } else if (spannerPersistentProperty.getAnnotatedColumnItemType() == null || value == null) { keyParts.add(value); } else { keyParts.add(this.spannerPersistentEntity.getSpannerEntityProcessor().getSpannerWriteConverter() .convert(value, SpannerTypeMapper .getSimpleJavaClassFor(spannerPersistentProperty.getAnnotatedColumnItemType()))); } } return this.spannerPersistentEntity.getSpannerEntityProcessor().convertToKey(keyParts); }
Example 2
Source File: MutationSizeEstimator.java From beam with Apache License 2.0 | 6 votes |
private static long sizeOf(Key k) { long result = 0; for (Object part : k.getParts()) { if (part == null) { continue; } if (part instanceof Boolean) { result += 1; } else if (part instanceof Long) { result += 8; } else if (part instanceof Double) { result += 8; } else if (part instanceof String) { result += ((String) part).length(); } else if (part instanceof ByteArray) { result += ((ByteArray) part).length(); } else if (part instanceof Timestamp) { result += 12; } else if (part instanceof Date) { result += 12; } } return result; }