Search in sources :

Example 1 with MetaComputedAttribute

use of io.crnk.jpa.internal.query.MetaComputedAttribute in project crnk-framework by crnk-project.

the class MetaComputedAttributeTest method getValueNotSupported.

@Test(expected = UnsupportedOperationException.class)
public void getValueNotSupported() {
    MetaComputedAttribute attr = new MetaComputedAttribute();
    attr.getValue(null);
}
Also used : MetaComputedAttribute(io.crnk.jpa.internal.query.MetaComputedAttribute) Test(org.junit.Test)

Example 2 with MetaComputedAttribute

use of io.crnk.jpa.internal.query.MetaComputedAttribute in project crnk-framework by crnk-project.

the class MetaComputedAttributeTest method setValueNotSupported.

@Test(expected = UnsupportedOperationException.class)
public void setValueNotSupported() {
    MetaComputedAttribute attr = new MetaComputedAttribute();
    attr.setValue(null, null);
}
Also used : MetaComputedAttribute(io.crnk.jpa.internal.query.MetaComputedAttribute) Test(org.junit.Test)

Example 3 with MetaComputedAttribute

use of io.crnk.jpa.internal.query.MetaComputedAttribute in project crnk-framework by crnk-project.

the class QuerydslQueryBackend method getAttribute.

@Override
public Expression<?> getAttribute(final Expression<?> expression, MetaAttribute pathElement) {
    if (pathElement instanceof MetaComputedAttribute) {
        ComputedAttributeRegistryImpl virtualAttrs = queryImpl.getComputedAttrs();
        QuerydslExpressionFactory expressionFactory = (QuerydslExpressionFactory) virtualAttrs.get((MetaComputedAttribute) pathElement);
        return expressionFactory.getExpression(expression, getQuery());
    } else {
        return QuerydslUtils.get(expression, pathElement.getName());
    }
}
Also used : QuerydslExpressionFactory(io.crnk.jpa.query.querydsl.QuerydslExpressionFactory) ComputedAttributeRegistryImpl(io.crnk.jpa.internal.query.ComputedAttributeRegistryImpl) MetaComputedAttribute(io.crnk.jpa.internal.query.MetaComputedAttribute)

Example 4 with MetaComputedAttribute

use of io.crnk.jpa.internal.query.MetaComputedAttribute in project crnk-framework by crnk-project.

the class QuerydslQueryBackend method doJoin.

@Override
public Expression<?> doJoin(MetaAttribute targetAttr, JoinType joinType, Expression<?> parent) {
    if (targetAttr instanceof MetaComputedAttribute) {
        MetaComputedAttribute computedAttr = (MetaComputedAttribute) targetAttr;
        QuerydslExpressionFactory expressionFactory = (QuerydslExpressionFactory<?>) queryImpl.getComputedAttrs().get(computedAttr);
        return expressionFactory.getExpression(parent, getQuery());
    } else {
        Expression<Object> expression = QuerydslUtils.get(parent, targetAttr.getName());
        querydslQuery.getMetadata().addJoin(QuerydslUtils.convertJoinType(joinType), expression);
        return expression;
    }
}
Also used : QuerydslExpressionFactory(io.crnk.jpa.query.querydsl.QuerydslExpressionFactory) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaComputedAttribute(io.crnk.jpa.internal.query.MetaComputedAttribute)

Example 5 with MetaComputedAttribute

use of io.crnk.jpa.internal.query.MetaComputedAttribute in project crnk-framework by crnk-project.

the class JpaCriteriaQueryBackend method doJoin.

@SuppressWarnings("unchecked")
@Override
public From<?, ?> doJoin(MetaAttribute targetAttr, JoinType joinType, From<?, ?> parent) {
    if (targetAttr instanceof MetaComputedAttribute) {
        MetaComputedAttribute projAttr = (MetaComputedAttribute) targetAttr;
        @SuppressWarnings("rawtypes") JpaCriteriaExpressionFactory expressionFactory = (JpaCriteriaExpressionFactory<?>) queryImpl.getComputedAttrs().get(projAttr);
        return (From<?, ?>) expressionFactory.getExpression(parent, getCriteriaQuery());
    } else {
        return parent.join(targetAttr.getName(), joinType);
    }
}
Also used : JpaCriteriaExpressionFactory(io.crnk.jpa.query.criteria.JpaCriteriaExpressionFactory) MetaComputedAttribute(io.crnk.jpa.internal.query.MetaComputedAttribute)

Aggregations

MetaComputedAttribute (io.crnk.jpa.internal.query.MetaComputedAttribute)6 JpaCriteriaExpressionFactory (io.crnk.jpa.query.criteria.JpaCriteriaExpressionFactory)2 QuerydslExpressionFactory (io.crnk.jpa.query.querydsl.QuerydslExpressionFactory)2 Test (org.junit.Test)2 ComputedAttributeRegistryImpl (io.crnk.jpa.internal.query.ComputedAttributeRegistryImpl)1 MetaAttributePath (io.crnk.meta.model.MetaAttributePath)1 MetaDataObject (io.crnk.meta.model.MetaDataObject)1