Search in sources :

Example 6 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class EclipseLinkJPQLQueryHelperTest2_4 method test_ResultType_FromSubquery_4.

@Test
public void test_ResultType_FromSubquery_4() throws Exception {
    // Select e3.result from Employee e, (Select count(e2) + 2.2 as result, e2.department from Employee e2 group by e2.department) e3 where e.department = e3.department
    IQuery namedQuery = namedQuery("Employee", "employee.fromSubquery4");
    AbstractJPQLQueryHelper helper = buildQueryHelper(namedQuery);
    IType type = helper.getResultType();
    assertNotNull("The result type should have been found", type);
    assertEquals("The result type was not calculated correctly", getType(namedQuery, Double.class), type);
}
Also used : IQuery(org.eclipse.persistence.jpa.jpql.tools.spi.IQuery) AbstractJPQLQueryHelper(org.eclipse.persistence.jpa.jpql.tools.AbstractJPQLQueryHelper) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType) Test(org.junit.Test)

Example 7 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class AbstractContentAssistVisitor method buildNonCollectionCompoundTypeFilter.

protected Filter<Expression> buildNonCollectionCompoundTypeFilter() {
    return new Filter<Expression>() {

        @Override
        public boolean accept(Expression expression) {
            IType type = queryContext.getType(expression);
            TypeHelper typeHelper = queryContext.getTypeHelper();
            return !typeHelper.isCollectionType(type) && !typeHelper.isMapType(type);
        }
    };
}
Also used : Filter(org.eclipse.persistence.jpa.jpql.utility.filter.Filter) NullFilter(org.eclipse.persistence.jpa.jpql.utility.filter.NullFilter) AndFilter(org.eclipse.persistence.jpa.jpql.tools.utility.filter.AndFilter) ArithmeticExpression(org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression) TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) AbstractExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) AbstractSingleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression) AbstractDoubleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractDoubleEncapsulatedExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) IndexExpression(org.eclipse.persistence.jpa.jpql.parser.IndexExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) UpperExpression(org.eclipse.persistence.jpa.jpql.parser.UpperExpression) ExistsExpression(org.eclipse.persistence.jpa.jpql.parser.ExistsExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) AllOrAnyExpression(org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression) LengthExpression(org.eclipse.persistence.jpa.jpql.parser.LengthExpression) MultiplicationExpression(org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) NullComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.NullComparisonExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) ComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression) InExpression(org.eclipse.persistence.jpa.jpql.parser.InExpression) NotExpression(org.eclipse.persistence.jpa.jpql.parser.NotExpression) BadExpression(org.eclipse.persistence.jpa.jpql.parser.BadExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) CompoundExpression(org.eclipse.persistence.jpa.jpql.parser.CompoundExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) AbstractPathExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) LogicalExpression(org.eclipse.persistence.jpa.jpql.parser.LogicalExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) TreatExpression(org.eclipse.persistence.jpa.jpql.parser.TreatExpression) TypeExpression(org.eclipse.persistence.jpa.jpql.parser.TypeExpression) EmptyCollectionComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.EmptyCollectionComparisonExpression) SubtractionExpression(org.eclipse.persistence.jpa.jpql.parser.SubtractionExpression) AbstractTripleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractTripleEncapsulatedExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 8 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class AbstractContentAssistVisitor method buildCollectionCompoundTypeFilter.

protected Filter<Expression> buildCollectionCompoundTypeFilter() {
    return new Filter<Expression>() {

        @Override
        public boolean accept(Expression expression) {
            IType type = queryContext.getType(expression);
            TypeHelper typeHelper = queryContext.getTypeHelper();
            return typeHelper.isCollectionType(type) || typeHelper.isMapType(type);
        }
    };
}
Also used : Filter(org.eclipse.persistence.jpa.jpql.utility.filter.Filter) NullFilter(org.eclipse.persistence.jpa.jpql.utility.filter.NullFilter) AndFilter(org.eclipse.persistence.jpa.jpql.tools.utility.filter.AndFilter) ArithmeticExpression(org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression) TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) AbstractExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) AbstractSingleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression) AbstractDoubleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractDoubleEncapsulatedExpression) AndExpression(org.eclipse.persistence.jpa.jpql.parser.AndExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) IndexExpression(org.eclipse.persistence.jpa.jpql.parser.IndexExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) UpperExpression(org.eclipse.persistence.jpa.jpql.parser.UpperExpression) ExistsExpression(org.eclipse.persistence.jpa.jpql.parser.ExistsExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) AllOrAnyExpression(org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression) LengthExpression(org.eclipse.persistence.jpa.jpql.parser.LengthExpression) MultiplicationExpression(org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) NullComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.NullComparisonExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) ComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression) InExpression(org.eclipse.persistence.jpa.jpql.parser.InExpression) NotExpression(org.eclipse.persistence.jpa.jpql.parser.NotExpression) BadExpression(org.eclipse.persistence.jpa.jpql.parser.BadExpression) BetweenExpression(org.eclipse.persistence.jpa.jpql.parser.BetweenExpression) CompoundExpression(org.eclipse.persistence.jpa.jpql.parser.CompoundExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) CollectionMemberExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression) AbstractPathExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression) NullExpression(org.eclipse.persistence.jpa.jpql.parser.NullExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) LogicalExpression(org.eclipse.persistence.jpa.jpql.parser.LogicalExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) OrExpression(org.eclipse.persistence.jpa.jpql.parser.OrExpression) TreatExpression(org.eclipse.persistence.jpa.jpql.parser.TreatExpression) TypeExpression(org.eclipse.persistence.jpa.jpql.parser.TypeExpression) EmptyCollectionComparisonExpression(org.eclipse.persistence.jpa.jpql.parser.EmptyCollectionComparisonExpression) SubtractionExpression(org.eclipse.persistence.jpa.jpql.parser.SubtractionExpression) AbstractTripleEncapsulatedExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractTripleEncapsulatedExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 9 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class CollectionValuedPathExpressionStateObject method resolveManagedType.

@Override
protected IManagedType resolveManagedType() {
    IMapping mapping = getMapping();
    if (mapping == null) {
        return null;
    }
    TypeHelper typeHelper = getTypeHelper();
    ITypeDeclaration typeDeclaration = mapping.getTypeDeclaration();
    IType type = typeDeclaration.getType();
    // it cannot be traversed
    if (typeHelper.isCollectionType(type)) {
        return null;
    }
    // Primitive types cannot have a managed type
    if (typeHelper.isPrimitiveType(type)) {
        return null;
    }
    // Retrieve the corresponding managed type for the mapping's type
    return getManagedTypeProvider().getManagedType(type);
}
Also used : TypeHelper(org.eclipse.persistence.jpa.jpql.tools.TypeHelper) ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) IMapping(org.eclipse.persistence.jpa.jpql.tools.spi.IMapping) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Example 10 with IType

use of org.eclipse.persistence.jpa.jpql.tools.spi.IType in project eclipselink by eclipse-ee4j.

the class CollectionValuedPathExpressionStateObject method resolveType.

@Override
protected IType resolveType() {
    TypeHelper typeHelper = getTypeHelper();
    ITypeDeclaration typeDeclaration = getTypeDeclaration();
    IType type = typeDeclaration.getType();
    // For a collection type, return the first type parameter
    if (typeHelper.isCollectionType(type)) {
        ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();
        if (typeParameters.length > 0) {
            type = typeParameters[0].getType();
        }
    } else // For a map type, by default the value is the actual type to return
    if (typeHelper.isMapType(type)) {
        ITypeDeclaration[] typeParameters = typeDeclaration.getTypeParameters();
        if (typeParameters.length == 2) {
            type = typeParameters[1].getType();
        }
    }
    // only deals with the primitive wrapper type
    return typeHelper.convertPrimitive(type);
}
Also used : TypeHelper(org.eclipse.persistence.jpa.jpql.tools.TypeHelper) ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Aggregations

IType (org.eclipse.persistence.jpa.jpql.tools.spi.IType)137 Test (org.junit.Test)113 AbstractJPQLQueryHelper (org.eclipse.persistence.jpa.jpql.tools.AbstractJPQLQueryHelper)112 IQuery (org.eclipse.persistence.jpa.jpql.tools.spi.IQuery)112 JPQLCoreTest (org.eclipse.persistence.jpa.tests.jpql.JPQLCoreTest)103 BigInteger (java.math.BigInteger)16 TypeHelper (org.eclipse.persistence.jpa.jpql.tools.TypeHelper)8 ITypeDeclaration (org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration)7 Date (java.util.Date)6 ArrayList (java.util.ArrayList)3 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)2 AbstractDoubleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractDoubleEncapsulatedExpression)2 AbstractExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractExpression)2 AbstractPathExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression)2 AbstractSingleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression)2 AbstractTripleEncapsulatedExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractTripleEncapsulatedExpression)2 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)2 AllOrAnyExpression (org.eclipse.persistence.jpa.jpql.parser.AllOrAnyExpression)2 AndExpression (org.eclipse.persistence.jpa.jpql.parser.AndExpression)2 ArithmeticExpression (org.eclipse.persistence.jpa.jpql.parser.ArithmeticExpression)2