@Bean @ConditionalOnMissingBean public ObjectToKeyFactory objectToKeyFactory(Datastore datastore) { return new DatastoreServiceObjectToKeyFactory(datastore); }
@Override public Key getKeyFromObject(Object entity, DatastorePersistentEntity datastorePersistentEntity) { Assert.notNull(entity, "Cannot get key for null entity object."); Assert.notNull(datastorePersistentEntity, "Persistent entity must not be null."); PersistentProperty idProp = datastorePersistentEntity.getIdPropertyOrFail(); Object idVal = datastorePersistentEntity.getPropertyAccessor(entity).getProperty(idProp); if (idVal == null) { return null; } else { return getKeyFromId(idVal, datastorePersistentEntity.kindName()); } }
@Override public Key getKeyFromId(Object id, String kindName) { Assert.notNull(id, "Cannot get key for null ID value."); if (id instanceof Key) { return (Key) id; } KeyFactory keyFactory = getKeyFactory(); keyFactory.setKind(kindName); Key key; if (id instanceof String) { key = keyFactory.newKey((String) id); } else if (id instanceof Long) { key = keyFactory.newKey((long) id); } else { // We will use configurable custom converters to try to convert other types to // String or long // in the future. throw new DatastoreDataException( "Keys can only be created using String or long values."); } return key; }
@Override public Key getKeyFromId(Object id, String kindName) { Assert.notNull(id, "Cannot get key for null ID value."); if (id instanceof Key) { return (Key) id; } KeyFactory keyFactory = getKeyFactory(); keyFactory.setKind(kindName); Key key; if (id instanceof String) { key = keyFactory.newKey((String) id); } else if (id instanceof Long) { key = keyFactory.newKey((long) id); } else { // We will use configurable custom converters to try to convert other types to // String or long // in the future. throw new DatastoreDataException( "Keys can only be created using String or long values."); } return key; }
KeyFactory keyFactory = getKeyFactory().setKind(datastorePersistentEntity.kindName()); if (ancestors != null && ancestors.length > 0) { if (!idPropType.equals(Key.class)) {
@Override public Key getKeyFromObject(Object entity, DatastorePersistentEntity datastorePersistentEntity) { Assert.notNull(entity, "Cannot get key for null entity object."); Assert.notNull(datastorePersistentEntity, "Persistent entity must not be null."); PersistentProperty idProp = datastorePersistentEntity.getIdPropertyOrFail(); Object idVal = datastorePersistentEntity.getPropertyAccessor(entity).getProperty(idProp); if (idVal == null) { return null; } else { return getKeyFromId(idVal, datastorePersistentEntity.kindName()); } }
KeyFactory keyFactory = getKeyFactory().setKind(datastorePersistentEntity.kindName()); if (ancestors != null && ancestors.length > 0) { if (!idPropType.equals(Key.class)) {