Search in sources :

Example 1 with PathMetadata

use of com.querydsl.core.types.PathMetadata in project querydsl by querydsl.

the class CollectionPathBase method newInstance.

@SuppressWarnings("unchecked")
protected Q newInstance(Class<Q> queryType, PathMetadata pm) {
    try {
        if (constructor == null) {
            if (Constants.isTyped(queryType)) {
                try {
                    constructor = queryType.getDeclaredConstructor(Class.class, PathMetadata.class, PathInits.class);
                    usePathInits = true;
                } catch (NoSuchMethodException e) {
                    constructor = queryType.getDeclaredConstructor(Class.class, PathMetadata.class);
                }
            } else {
                try {
                    constructor = queryType.getDeclaredConstructor(PathMetadata.class, PathInits.class);
                    usePathInits = true;
                } catch (NoSuchMethodException e) {
                    constructor = queryType.getDeclaredConstructor(PathMetadata.class);
                }
            }
            constructor.setAccessible(true);
        }
        if (Constants.isTyped(queryType)) {
            if (usePathInits) {
                return (Q) constructor.newInstance(getElementType(), pm, inits);
            } else {
                return (Q) constructor.newInstance(getElementType(), pm);
            }
        } else {
            if (usePathInits) {
                return (Q) constructor.newInstance(pm, inits);
            } else {
                return (Q) constructor.newInstance(pm);
            }
        }
    } catch (NoSuchMethodException e) {
        throw new ExpressionException(e);
    } catch (InstantiationException e) {
        throw new ExpressionException(e);
    } catch (IllegalAccessException e) {
        throw new ExpressionException(e);
    } catch (InvocationTargetException e) {
        throw new ExpressionException(e);
    }
}
Also used : PathMetadata(com.querydsl.core.types.PathMetadata) ExpressionException(com.querydsl.core.types.ExpressionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with PathMetadata

use of com.querydsl.core.types.PathMetadata in project spring-data-mongodb by spring-projects.

the class SpringDataMongodbSerializer method getPropertyForPotentialDbRef.

/**
 * Checks the given {@literal path} for referencing the {@literal id} property of a {@link DBRef} referenced object.
 * If so it returns the referenced {@link MongoPersistentProperty} of the {@link DBRef} instead of the {@literal id}
 * property.
 *
 * @param path
 * @return
 */
private MongoPersistentProperty getPropertyForPotentialDbRef(Path<?> path) {
    if (path == null) {
        return null;
    }
    MongoPersistentProperty property = getPropertyFor(path);
    PathMetadata metadata = path.getMetadata();
    if (property != null && property.isIdProperty() && metadata != null && metadata.getParent() != null) {
        return getPropertyFor(metadata.getParent());
    }
    return property;
}
Also used : PathMetadata(com.querydsl.core.types.PathMetadata) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)

Aggregations

PathMetadata (com.querydsl.core.types.PathMetadata)2 ExpressionException (com.querydsl.core.types.ExpressionException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MongoPersistentProperty (org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)1