Search in sources :

Example 1 with MapEntryExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(EntryExpression expression) {
    // Create the expression for the collection-valued path expression
    expression.getExpression().accept(this);
    // Now create the ENTRY expression
    MapEntryExpression entryExpression = new MapEntryExpression(queryExpression);
    entryExpression.returnMapEntry();
    queryExpression = entryExpression;
    // Set the expression type
    type[0] = Map.Entry.class;
}
Also used : MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with MapEntryExpression

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

the class MapKeyNode method generateExpression.

/**
 * INTERNAL
 * Generate the a new EclipseLink TableEntryExpression for this node.
 */
@Override
public Expression generateExpression(GenerationContext context) {
    Expression owningExpression = getLeft().generateExpression(context);
    MapEntryExpression whereClause = new MapEntryExpression(owningExpression);
    return whereClause;
}
Also used : MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) Expression(org.eclipse.persistence.expressions.Expression) MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression)

Example 3 with MapEntryExpression

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

the class ConstructorReportItem method initialize.

/**
 * INTERNAL:
 * Looks up mapping for attribute during preExecute of ReportQuery
 */
@Override
public void initialize(ReportQuery query) throws QueryException {
    int size = getReportItems().size();
    List<DatabaseMapping> mappings = new ArrayList<>();
    for (int index = 0; index < size; index++) {
        ReportItem item = reportItems.get(index);
        item.initialize(query);
        mappings.add(item.getMapping());
    }
    setConstructorMappings(mappings);
    int numberOfItems = getReportItems().size();
    // Arguments may be initialized depending on how the query was constructed, so types may be undefined though.
    if (getConstructorArgTypes() == null) {
        setConstructorArgTypes(new Class<?>[numberOfItems]);
    }
    Class<?>[] constructorArgTypes = getConstructorArgTypes();
    for (int index = 0; index < numberOfItems; index++) {
        if (constructorArgTypes[index] == null) {
            ReportItem argumentItem = getReportItems().get(index);
            if (mappings.get(index) != null) {
                DatabaseMapping mapping = constructorMappings.get(index);
                if (argumentItem.getAttributeExpression() != null && argumentItem.getAttributeExpression().isMapEntryExpression()) {
                    if (((MapEntryExpression) argumentItem.getAttributeExpression()).shouldReturnMapEntry()) {
                        constructorArgTypes[index] = Map.Entry.class;
                    } else {
                        constructorArgTypes[index] = (Class) mapping.getContainerPolicy().getKeyType();
                    }
                } else {
                    constructorArgTypes[index] = mapping.getAttributeClassification();
                }
            } else if (argumentItem.getResultType() != null) {
                constructorArgTypes[index] = argumentItem.getResultType();
            } else if (argumentItem.getDescriptor() != null) {
                constructorArgTypes[index] = argumentItem.getDescriptor().getJavaClass();
            } else if (argumentItem.getAttributeExpression() != null && argumentItem.getAttributeExpression().isConstantExpression()) {
                constructorArgTypes[index] = ((ConstantExpression) argumentItem.getAttributeExpression()).getValue().getClass();
            } else {
                // Use Object.class by default.
                constructorArgTypes[index] = ClassConstants.OBJECT;
            }
        }
    }
    if (getConstructor() == null) {
        try {
            Constructor<?> constructor = null;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                try {
                    constructor = AccessController.doPrivileged(new PrivilegedGetConstructorFor<>(getResultType(), constructorArgTypes, true));
                } catch (PrivilegedActionException exception) {
                    throw QueryException.exceptionWhileUsingConstructorExpression(exception.getException(), query);
                }
            } else {
                constructor = PrivilegedAccessHelper.getConstructorFor(getResultType(), constructorArgTypes, true);
            }
            setConstructor(constructor);
        } catch (NoSuchMethodException exception) {
            throw QueryException.exceptionWhileUsingConstructorExpression(exception, query);
        }
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) ReportItem(org.eclipse.persistence.internal.queries.ReportItem) MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) PrivilegedGetConstructorFor(org.eclipse.persistence.internal.security.PrivilegedGetConstructorFor) Map(java.util.Map)

Example 4 with MapEntryExpression

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

the class Expression method mapEntry.

/**
 * PUBLIC:
 * Return a Map.Entry containing the key and the value from a mapping that maps to a java.util.Map
 * This expression can only be used as a return value in a ReportQuery and cannot be used as part of
 * the WHERE clause in any query
 *
 * EclipseLink: eb.get("mapAttribute").mapEntry()
 */
public Expression mapEntry() {
    MapEntryExpression expression = new MapEntryExpression(this);
    expression.returnMapEntry();
    return expression;
}
Also used : MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression)

Example 5 with MapEntryExpression

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

the class ExpressionBuilderVisitor method visit.

@Override
public void visit(KeyExpression expression) {
    // First visit the parent Expression
    expression.getExpression().accept(this);
    // Now create the Expression of the KEY expression
    queryExpression = new MapEntryExpression(queryExpression);
}
Also used : MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression)

Aggregations

MapEntryExpression (org.eclipse.persistence.internal.expressions.MapEntryExpression)8 ReportItem (org.eclipse.persistence.internal.queries.ReportItem)3 Map (java.util.Map)2 Expression (org.eclipse.persistence.expressions.Expression)2 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)2 ReportQuery (org.eclipse.persistence.queries.ReportQuery)2 DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)2 PrivilegedActionException (java.security.PrivilegedActionException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkTemplate (org.eclipse.persistence.internal.jpa.rs.metadata.model.LinkTemplate)1 Query (org.eclipse.persistence.internal.jpa.rs.metadata.model.Query)1 Property (org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Property)1 Reference (org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.Reference)1 ResourceSchema (org.eclipse.persistence.internal.jpa.rs.metadata.model.v2.ResourceSchema)1 PrivilegedGetConstructorFor (org.eclipse.persistence.internal.security.PrivilegedGetConstructorFor)1 ItemLinksBuilder (org.eclipse.persistence.jpa.rs.features.ItemLinksBuilder)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)1