/** * Bind a given tag and value to a GQL query builder. * @param builder the builder holding a GQL query that is being built. * @param tagName the name of the tag to bind. * @param val the value to bind to the tag. */ public static void bindValueToGqlBuilder(Builder builder, String tagName, Object val) { Class valClass = getTypeForWrappingInDatastoreValue(val); if (!GQL_PARAM_BINDING_FUNC_MAP.containsKey(valClass)) { throw new DatastoreDataException( "Param value for GQL annotated query is not a supported Cloud " + "Datastore GQL param type: " + valClass); } // this value must be set due to compiler rule Object unusued = GQL_PARAM_BINDING_FUNC_MAP.get(valClass).apply(builder) .apply(tagName, val); }
private Optional<Class<?>> getCustomWriteTarget(Class<?> sourceType) { if (DatastoreNativeTypes.isNativeType(sourceType)) { return Optional.empty(); } return this.writeConverters.computeIfAbsent(sourceType, this::getDatastoreCompatibleType); }
@Override @SuppressWarnings("unchecked") public Value convertOnWriteSingle(Object propertyVal) { Object result = propertyVal; if (result != null) { TypeTargets typeTargets = computeTypeTargets(result.getClass()); if (typeTargets.getFirstStepTarget() != null) { result = this.conversionService.convert(propertyVal, typeTargets.getFirstStepTarget()); } if (typeTargets.getSecondStepTarget() != null) { result = this.internalConversionService.convert(result, typeTargets.getSecondStepTarget()); } } return DatastoreNativeTypes.wrapValue(result); }
private GqlQuery<? extends BaseEntity> bindArgsToGqlQuery(String gql, List<String> tags, List vals) { Builder builder = GqlQuery.newGqlQueryBuilder(gql); builder.setAllowLiteral(true); if (tags.size() != vals.size()) { throw new DatastoreDataException("Annotated GQL Query Method " + this.queryMethod.getName() + " has " + tags.size() + " tags but a different number of parameter values: " + vals.size()); } for (int i = 0; i < tags.size(); i++) { Object val = vals.get(i); Object boundVal; if (ValueUtil.isCollectionLike(val.getClass())) { boundVal = convertCollectionParamToCompatibleArray((List) ValueUtil.toListIfArray(val)); } else { boundVal = this.datastoreTemplate.getDatastoreEntityConverter().getConversions() .convertOnWriteSingle(val).get(); } DatastoreNativeTypes.bindValueToGqlBuilder(builder, tags.get(i), boundVal); } return builder.build(); }
@Override @SuppressWarnings("unchecked") public Value convertOnWriteSingle(Object propertyVal) { Object result = propertyVal; if (result != null) { TypeTargets typeTargets = computeTypeTargets(result.getClass()); if (typeTargets.getFirstStepTarget() != null) { result = this.conversionService.convert(propertyVal, typeTargets.getFirstStepTarget()); } if (typeTargets.getSecondStepTarget() != null) { result = this.internalConversionService.convert(result, typeTargets.getSecondStepTarget()); } } return DatastoreNativeTypes.wrapValue(result); }
private GqlQuery<? extends BaseEntity> bindArgsToGqlQuery(String gql, List<String> tags, List vals) { Builder builder = GqlQuery.newGqlQueryBuilder(gql); builder.setAllowLiteral(true); if (tags.size() != vals.size()) { throw new DatastoreDataException("Annotated GQL Query Method " + this.queryMethod.getName() + " has " + tags.size() + " tags but a different number of parameter values: " + vals.size()); } for (int i = 0; i < tags.size(); i++) { Object val = vals.get(i); Object boundVal; if (ValueUtil.isCollectionLike(val.getClass())) { boundVal = convertCollectionParamToCompatibleArray((List) ValueUtil.toListIfArray(val)); } else { boundVal = this.datastoreTemplate.getDatastoreEntityConverter().getConversions() .convertOnWriteSingle(val).get(); } DatastoreNativeTypes.bindValueToGqlBuilder(builder, tags.get(i), boundVal); } return builder.build(); }
private Optional<Class<?>> getCustomWriteTarget(Class<?> sourceType) { if (DatastoreNativeTypes.isNativeType(sourceType)) { return Optional.empty(); } return this.writeConverters.computeIfAbsent(sourceType, this::getDatastoreCompatibleType); }
/** * Bind a given tag and value to a GQL query builder. * @param builder the builder holding a GQL query that is being built. * @param tagName the name of the tag to bind. * @param val the value to bind to the tag. */ public static void bindValueToGqlBuilder(Builder builder, String tagName, Object val) { Class valClass = getTypeForWrappingInDatastoreValue(val); if (!GQL_PARAM_BINDING_FUNC_MAP.containsKey(valClass)) { throw new DatastoreDataException( "Param value for GQL annotated query is not a supported Cloud " + "Datastore GQL param type: " + valClass); } // this value must be set due to compiler rule Object unusued = GQL_PARAM_BINDING_FUNC_MAP.get(valClass).apply(builder) .apply(tagName, val); }
private TypeTargets computeTypeTargets(Class<?> firstStepSource) { Class<?> firstStepTarget = null; Class<?> secondStepTarget = null; if (!DatastoreNativeTypes.isNativeType(firstStepSource)) { Optional<Class<?>> simpleType = this.customConversions.getCustomWriteTarget(firstStepSource); if (simpleType.isPresent()) { firstStepTarget = simpleType.get(); } Class<?> effectiveFirstStepTarget = (firstStepTarget != null) ? firstStepTarget : firstStepSource; Optional<Class<?>> datastoreBasicType = getCustomWriteTarget(effectiveFirstStepTarget); if (datastoreBasicType.isPresent()) { secondStepTarget = datastoreBasicType.get(); } } return new TypeTargets(firstStepTarget, secondStepTarget); }
/** * Wraps Datastore native type to Datastore value type. * @param propertyVal the property value to wrap * @return the wrapped value */ @SuppressWarnings("unchecked") public static Value wrapValue(Object propertyVal) { if (propertyVal == null) { return new NullValue(); } Class propertyClass = getTypeForWrappingInDatastoreValue(propertyVal); Function wrapper = DatastoreNativeTypes.DATASTORE_TYPE_WRAPPERS .get(propertyClass); if (wrapper != null) { return (Value) wrapper.apply(propertyVal); } throw new DatastoreDataException( "Unable to convert " + propertyClass + " to Datastore supported type."); }
private TypeTargets computeTypeTargets(Class<?> firstStepSource) { Class<?> firstStepTarget = null; Class<?> secondStepTarget = null; if (!DatastoreNativeTypes.isNativeType(firstStepSource)) { Optional<Class<?>> simpleType = this.customConversions.getCustomWriteTarget(firstStepSource); if (simpleType.isPresent()) { firstStepTarget = simpleType.get(); } Class<?> effectiveFirstStepTarget = (firstStepTarget != null) ? firstStepTarget : firstStepSource; Optional<Class<?>> datastoreBasicType = getCustomWriteTarget(effectiveFirstStepTarget); if (datastoreBasicType.isPresent()) { secondStepTarget = datastoreBasicType.get(); } } return new TypeTargets(firstStepTarget, secondStepTarget); }
/** * Wraps Datastore native type to Datastore value type. * @param propertyVal the property value to wrap * @return the wrapped value */ @SuppressWarnings("unchecked") public static Value wrapValue(Object propertyVal) { if (propertyVal == null) { return new NullValue(); } Class propertyClass = getTypeForWrappingInDatastoreValue(propertyVal); Function wrapper = DatastoreNativeTypes.DATASTORE_TYPE_WRAPPERS .get(propertyClass); if (wrapper != null) { return (Value) wrapper.apply(propertyVal); } throw new DatastoreDataException( "Unable to convert " + propertyClass + " to Datastore supported type."); }
else if (DatastoreNativeTypes.isNativeType(sourceType) && this.conversionService.canConvert(sourceType, targetType)) { result = this.conversionService.convert(val, targetType); else if (DatastoreNativeTypes.isNativeType(sourceType) && this.internalConversionService.canConvert(sourceType, targetType)) { result = this.internalConversionService.convert(val, targetType);
else if (DatastoreNativeTypes.isNativeType(sourceType) && this.conversionService.canConvert(sourceType, targetType)) { result = this.conversionService.convert(val, targetType); else if (DatastoreNativeTypes.isNativeType(sourceType) && this.internalConversionService.canConvert(sourceType, targetType)) { result = this.internalConversionService.convert(val, targetType);