Search in sources :

Example 16 with ConstantExpression

use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.

the class UnaryMinus method generateExpression.

/**
 * INTERNAL
 * Generate the expression.
 */
@Override
public Expression generateExpression(GenerationContext context) {
    Expression whereClause = new ConstantExpression(0, new ExpressionBuilder());
    whereClause = ExpressionMath.subtract(whereClause, getLeft().generateExpression(context));
    return whereClause;
}
Also used : ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression)

Example 17 with ConstantExpression

use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.

the class SubQueryImpl method integrateRoot.

@Override
protected void integrateRoot(RootImpl root) {
    if (this.roots.isEmpty()) {
        TypeImpl type = ((MetamodelImpl) this.metamodel).getType(this.queryType);
        if ((type != null && type.getPersistenceType() == PersistenceType.ENTITY) || queryType.equals(ClassConstants.OBJECT)) {
            // this is the first root, set return type and selection and query type
            if (this.selection == null) {
                this.selection = root;
                this.subQuery.getItems().clear();
                this.subQuery.addAttribute("", new ConstantExpression(1, root.getCurrentNode().getBuilder()));
                this.queryResult = ResultType.ENTITY;
            }
        }
        this.subQuery.setReferenceClass(root.getJavaType());
        this.subQuery.setExpressionBuilder(root.getCurrentNode().getBuilder());
        this.queryType = root.getJavaType();
        this.currentNode.setBaseExpression(((CommonAbstractCriteriaImpl) this.parent).getBaseExpression());
    }
    // assign the baseExpression based on the SubQuery's roots - Bug 509693
    if (!this.roots.contains(root) && this.parent instanceof CriteriaQueryImpl && ((CriteriaQueryImpl) this.parent).getRoots().size() > 1) {
        this.currentNode.setBaseExpression(((CriteriaQueryImpl) this.parent).getBaseExpression(root));
    }
    super.integrateRoot(root);
}
Also used : MetamodelImpl(org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) TypeImpl(org.eclipse.persistence.internal.jpa.metamodel.TypeImpl)

Example 18 with ConstantExpression

use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.

the class AbstractPersistenceUnitResource method getQuery.

private Query getQuery(DatabaseQuery query, PersistenceContext context) {
    String method = query.isReadQuery() ? "get" : "post";
    String jpql = query.getJPQLString() == null ? "" : query.getJPQLString();
    StringBuilder parameterString = new StringBuilder();
    Iterator<String> argumentsIterator = query.getArguments().iterator();
    while (argumentsIterator.hasNext()) {
        String argument = argumentsIterator.next();
        parameterString.append(";");
        parameterString.append(argument).append("={").append(argument).append("}");
    }
    String version = context.getVersion();
    Query returnQuery = null;
    if (version != null) {
        returnQuery = new Query(query.getName(), jpql, new LinkTemplate("execute", method, context.getBaseURI() + version + "/" + context.getName() + "/query/" + query.getName() + parameterString));
    } else {
        returnQuery = new Query(query.getName(), jpql, new LinkTemplate("execute", method, context.getBaseURI() + context.getName() + "/query/" + query.getName() + parameterString));
    }
    if (query.isReportQuery()) {
        query.checkPrepare((AbstractSession) context.getServerSession(), new DatabaseRecord());
        for (ReportItem item : ((ReportQuery) query).getItems()) {
            if (item.getMapping() != null) {
                if (item.getAttributeExpression() != null && item.getAttributeExpression().isMapEntryExpression()) {
                    if (((MapEntryExpression) item.getAttributeExpression()).shouldReturnMapEntry()) {
                        returnQuery.getReturnTypes().add(Map.Entry.class.getSimpleName());
                    } else {
                        returnQuery.getReturnTypes().add(((Class<?>) item.getMapping().getContainerPolicy().getKeyType()).getSimpleName());
                    }
                } else {
                    returnQuery.getReturnTypes().add(item.getMapping().getAttributeClassification().getSimpleName());
                }
            } else if (item.getResultType() != null) {
                returnQuery.getReturnTypes().add(item.getResultType().getSimpleName());
            } else if (item.getDescriptor() != null) {
                returnQuery.getReturnTypes().add(item.getDescriptor().getJavaClass().getSimpleName());
            } else if (item.getAttributeExpression() != null && item.getAttributeExpression().isConstantExpression()) {
                returnQuery.getReturnTypes().add(((ConstantExpression) item.getAttributeExpression()).getValue().getClass().getSimpleName());
            } else {
                // Use Object.class by default.
                returnQuery.getReturnTypes().add(ClassConstants.OBJECT.getSimpleName());
            }
        }
    } else {
        returnQuery.getReturnTypes().add(query.getReferenceClassName() == null ? "" : query.getReferenceClass().getSimpleName());
    }
    return returnQuery;
}
Also used : MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) ReportQuery(org.eclipse.persistence.queries.ReportQuery) Query(org.eclipse.persistence.internal.jpa.rs.metadata.model.Query) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) ReportQuery(org.eclipse.persistence.queries.ReportQuery) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) LinkTemplate(org.eclipse.persistence.internal.jpa.rs.metadata.model.LinkTemplate) ReportItem(org.eclipse.persistence.internal.queries.ReportItem)

Example 19 with ConstantExpression

use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.

the class MetadataResource method buildQuerySchema.

private ResourceSchema buildQuerySchema(PersistenceContext context, DatabaseQuery query) {
    final ResourceSchema schema = new ResourceSchema();
    schema.setTitle(query.getName());
    schema.setSchema(HrefHelper.buildQueryMetadataHref(context, query.getName()) + "#");
    schema.addAllOf(new Reference(HrefHelper.buildBaseRestSchemaRef("#/collectionBaseResource")));
    // Link
    final String method = query.isReadQuery() ? "GET" : "POST";
    schema.setLinks((new ItemLinksBuilder()).addExecute(HrefHelper.buildQueryHref(context, query.getName(), getQueryParamString(query)), method).getList());
    // Definitions
    if (query.isReportQuery()) {
        // In case of report query we need to define a returned type
        final ResourceSchema returnType = new ResourceSchema();
        query.checkPrepare((AbstractSession) context.getServerSession(), new DatabaseRecord());
        for (ReportItem item : ((ReportQuery) query).getItems()) {
            final Property property;
            if (item.getMapping() != null) {
                if (item.getAttributeExpression() != null && item.getAttributeExpression().isMapEntryExpression()) {
                    if (((MapEntryExpression) item.getAttributeExpression()).shouldReturnMapEntry()) {
                        property = buildProperty(context, Map.Entry.class);
                    } else {
                        property = buildProperty(context, ((Class<?>) item.getMapping().getContainerPolicy().getKeyType()));
                    }
                } else {
                    property = buildProperty(context, item.getMapping().getAttributeClassification());
                }
            } else if (item.getResultType() != null) {
                property = buildProperty(context, item.getResultType());
            } else if (item.getDescriptor() != null) {
                property = buildProperty(context, item.getDescriptor().getJavaClass());
            } else if (item.getAttributeExpression() != null && item.getAttributeExpression().isConstantExpression()) {
                property = buildProperty(context, ((ConstantExpression) item.getAttributeExpression()).getValue().getClass());
            } else {
                // Use Object.class by default.
                property = buildProperty(context, Object.class);
            }
            returnType.addProperty(item.getName(), property);
        }
        schema.addDefinition("result", returnType);
        final Property items = new Property();
        items.setType("array");
        items.setItems(new Property("#/definitions/result"));
        schema.addProperty("items", items);
    } else {
        // Read all query. Each item is an entity. Make a JSON pointer.
        if (query.getReferenceClassName() != null) {
            final Property items = new Property();
            items.setType("array");
            items.setItems(new Property(HrefHelper.buildEntityMetadataHref(context, query.getReferenceClass().getSimpleName()) + "#"));
            schema.addProperty("items", items);
        }
    }
    return schema;
}
Also used : ItemLinksBuilder(org.eclipse.persistence.jpa.rs.features.ItemLinksBuilder) MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) ResourceSchema(org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.ResourceSchema) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) Reference(org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference) ReportQuery(org.eclipse.persistence.queries.ReportQuery) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) ReportItem(org.eclipse.persistence.internal.queries.ReportItem) Property(org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Property)

Aggregations

ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)19 Expression (org.eclipse.persistence.expressions.Expression)7 DateConstantExpression (org.eclipse.persistence.internal.expressions.DateConstantExpression)6 ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)5 ReportQuery (org.eclipse.persistence.queries.ReportQuery)5 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)4 MapEntryExpression (org.eclipse.persistence.internal.expressions.MapEntryExpression)4 ReportItem (org.eclipse.persistence.internal.queries.ReportItem)4 List (java.util.List)3 FieldExpression (org.eclipse.persistence.internal.expressions.FieldExpression)3 ObjectExpression (org.eclipse.persistence.internal.expressions.ObjectExpression)3 QueryKeyExpression (org.eclipse.persistence.internal.expressions.QueryKeyExpression)3 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Vector (java.util.Vector)2 ExpressionIterator (org.eclipse.persistence.internal.expressions.ExpressionIterator)2