@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public PropertyBox read(final PropertyBox propertyBox, final T instance, final boolean ignoreMissing) { ObjectUtils.argumentNotNull(propertyBox, "PropertyBox must be not null"); ObjectUtils.argumentNotNull(instance, "Bean instance must be not null"); propertyBox.stream().filter(p -> !p.isReadOnly()).filter(p -> Path.class.isAssignableFrom(p.getClass())) .map(p -> (Path<?>) p).forEach(p -> { getProperty(p, ignoreMissing).ifPresent( bp -> propertyBox.setValue((Property) p, read(bp, instance, (Class<Object>) p.getType()))); }); return propertyBox; }
if (node.isJsonPrimitive()) { try { return Optional.ofNullable(deserializeValue(path, context.deserialize(node, path.getType()))); } catch (JsonParseException e) { throw new JsonDeserializationException("Failed to deserialize path [" + path if (PropertyBox.class.isAssignableFrom(path.getType())) { return Optional.ofNullable((T) deserializePropertyBox(context, node, config.getParameter(PropertySet.PROPERTY_CONFIGURATION_ATTRIBUTE) return Optional.ofNullable(context.deserialize(node, path.getType())); } catch (JsonParseException e) { throw new JsonDeserializationException("Failed to deserialize path [" + path
/** * Create a {@link PathExpression} from given {@link Path}. * @param <T> Path type * @param path Suorce path * @return A new {@link PathExpression} with the same name, type and parent of the given path */ static <T> PathExpression<T> from(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); DefaultPathExpression<T> expression = new DefaultPathExpression<>(path.getName(), path.getType()); path.getParent().ifPresent(p -> expression.parent(p)); return expression; }
/** * Create a new {@link NumericProperty} from given <code>path</code>, using given {@link Path} <code>name</code>and * <code>type</code>. * @param <T> Path type * @param path Path from which to obtain the property path name and type (not null) * @return {@link NumericProperty} builder */ static <T extends Number> NumericPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); NumericPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a new {@link PathProperty} from given <code>path</code>, using given {@link Path} <code>name</code> and * <code>type</code>. * @param <T> Property (path) type * @param path Path from which to obtain the property path name and type (not null) * @return {@link PathProperty} builder */ static <T> PathPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); PathPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
/** * Create a new {@link TemporalProperty} from given <code>path</code>, using given {@link Path} <code>name</code>and * <code>type</code>. * @param <T> Path type * @param path Path from which to obtain the property path name and type (not null) * @return {@link TemporalProperty} builder */ static <T> TemporalPropertyBuilder<T> create(Path<T> path) { ObjectUtils.argumentNotNull(path, "Path must be not null"); TemporalPropertyBuilder<T> builder = create(path.getName(), path.getType()); path.getParent().ifPresent(p -> builder.parent(p)); return builder; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public T write(PropertyBox propertyBox, T instance, boolean ignoreMissing) { ObjectUtils.argumentNotNull(propertyBox, "PropertyBox must be not null"); ObjectUtils.argumentNotNull(instance, "Bean instance must be not null"); propertyBox.stream().filter(p -> !p.isReadOnly()).filter(p -> Path.class.isAssignableFrom(p.getClass())) .map(p -> (Path<?>) p).forEach(p -> { getProperty(p, ignoreMissing).ifPresent(bp -> { final Property<Object> property = ((Property) p); final Object boxValue = propertyBox.getValue(property); Object value = boxValue; // check conversion if (!TypeUtils.isAssignable(bp.getType(), property.getType())) { value = property.getConverter() .filter(c -> TypeUtils.isAssignable(bp.getType(), c.getModelType())) .map(c -> ((PropertyValueConverter) c).toModel(boxValue, property)) .orElse(boxValue); } write(bp, p.getType(), value, instance); }); }); return instance; }
@Override public <V> V read(Path<V> path, T instance) { ObjectUtils.argumentNotNull(path, "Path must be not null"); ObjectUtils.argumentNotNull(instance, "Bean instance must be not null"); final BeanProperty<?> property = (BeanProperty<?>) property(path.relativeName()); return read(property, instance, path.getType()); }
@Override public <P> void write(Path<P> path, P value, T instance) { ObjectUtils.argumentNotNull(path, "Path must be not null"); ObjectUtils.argumentNotNull(instance, "Bean instance must be not null"); final BeanProperty<?> property = (BeanProperty<?>) property(path.relativeName()); write(property, path.getType(), value, instance); }
final Object idPropertyValue = documentContext.getDocumentIdResolver().decode(oid, idp.getType()); builder.withInsertedKey(idp, idPropertyValue);
private static <T> T deserializeValue(Path<T> path, T value) throws JsonDeserializationException { if (value != null) { final Class<? extends T> type = path.getType(); try { if (TypeUtils.isEnum(type)) {
@Override public Optional<QueryDslExpression> resolve(Path expression, QueryDslResolutionContext context) throws InvalidExpressionException { // validate expression.validate(); // intermediate resolution and validation Path path = context.resolve(expression, Path.class).orElse(expression); path.validate(); // get root com.querydsl.core.types.Path<?> root = getParentRootPath(path, context).orElse(getQueryRootPath(path, context)); // get query path from property final String queryPath = path.getName(); PathBuilder<?> rootPathBuilder = new PathBuilder<>(root.getType(), root.getMetadata()); @SuppressWarnings("unchecked") PathBuilder<?> pb = rootPathBuilder.get(queryPath, path.getType()); if (pb == null) { throw new InvalidExpressionException("Cannot get a valid PathBuilder for path expression [" + path + "]"); } return Optional.of(QueryDslExpression.create(pb)); }
/** * Check generated document id after an upsert type operation, setting the inserted key using given * {@link OperationResult} builder. * @param builder OperationResult builder * @param documentContext Document context * @param configuration Operation configuration * @param upsertedId Optional upserted id value * @param value Original {@link PropertyBox} value */ @SuppressWarnings("unchecked") public static void checkUpsertedKey(OperationResult.Builder builder, MongoDocumentContext<?> documentContext, DatastoreOperationConfiguration configuration, BsonValue upsertedId, PropertyBox value) { if (upsertedId != null) { final ObjectId oid = upsertedId.asObjectId().getValue(); documentContext.getDocumentIdPath().ifPresent(idp -> { final Object idPropertyValue = documentContext.getDocumentIdResolver().decode(oid, idp.getType()); builder.withInsertedKey(idp, idPropertyValue); // check bring back ids if (configuration.hasWriteOption(DefaultWriteOption.BRING_BACK_GENERATED_IDS)) { documentContext.getDocumentIdProperty().ifPresent(idprp -> { if (value.contains(idprp)) { value.setValue((Property<Object>) idprp, idPropertyValue); } }); } }); } }