Search in sources :

Example 1 with Expression

use of org.eclipse.persistence.expressions.Expression in project cuba by cuba-platform.

the class JoinCriteriaMappingProcessor method process.

@Override
public void process(MappingProcessorContext context) {
    DatabaseMapping mapping = context.getMapping();
    Expression expression = AppBeans.getAll(JoinExpressionProvider.class).values().stream().map(provider -> provider.getJoinCriteriaExpression(mapping)).filter(Objects::nonNull).reduce(Expression::and).orElse(null);
    // Applying additional join criteria, e.g. for soft delete or multitenancy -> move to mapping processor
    if (mapping.isOneToManyMapping() || mapping.isOneToOneMapping()) {
        // Apply expression to mappings
        if (mapping.isOneToManyMapping()) {
            ((OneToManyMapping) mapping).setAdditionalJoinCriteria(expression);
        } else if (mapping.isOneToOneMapping()) {
            ((OneToOneMapping) mapping).setAdditionalJoinCriteria(expression);
        }
    }
}
Also used : Objects(java.util.Objects) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) Component(org.springframework.stereotype.Component) Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) AppBeans(com.haulmont.cuba.core.global.AppBeans) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) Objects(java.util.Objects) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 2 with Expression

use of org.eclipse.persistence.expressions.Expression in project blaze-persistence by Blazebit.

the class JpqlFunctionExpressionOperator method printCollection.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void printCollection(Vector items, ExpressionSQLPrinter printer) {
    prepare((List<Expression>) items, printer);
    // Certain functions don't allow binding on some platforms.
    if (printer.getPlatform().isDynamicSQLRequiredForFunctions() && !isBindingSupported()) {
        printer.getCall().setUsesBinding(false);
    }
    int dbStringIndex = 0;
    try {
        if (isPrefix()) {
            printer.getWriter().write(getDatabaseStrings()[0]);
            dbStringIndex = 1;
        } else {
            dbStringIndex = 0;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (argumentIndices == null) {
        argumentIndices = new int[items.size()];
        for (int i = 0; i < argumentIndices.length; i++) {
            argumentIndices[i] = i;
        }
    }
    for (int i = 0; i < argumentIndices.length; i++) {
        int index = argumentIndices[i];
        Expression item;
        if (index == -1) {
            item = (Expression) items.elementAt(i);
            Writer w = printer.getWriter();
            try {
                printer.setWriter(NULL_WRITER);
                item.printSQL(printer);
            } finally {
                printer.setWriter(w);
            }
            continue;
        }
        item = (Expression) items.elementAt(index);
        if ((this.selector == Ref) || ((this.selector == Deref) && (item.isObjectExpression()))) {
            DatabaseTable alias = ((ObjectExpression) item).aliasForTable(((ObjectExpression) item).getDescriptor().getTables().firstElement());
            printer.printString(alias.getNameDelimited(printer.getPlatform()));
        } else if ((this.selector == Count) && (item.isExpressionBuilder())) {
            printer.printString("*");
        } else {
            item.printSQL(printer);
        }
        if (dbStringIndex < getDatabaseStrings().length) {
            printer.printString(getDatabaseStrings()[dbStringIndex++]);
        }
    }
    for (; dbStringIndex < getDatabaseStrings().length; dbStringIndex++) {
        printer.printString(getDatabaseStrings()[dbStringIndex]);
    }
}
Also used : FromSubSelectExpression(org.eclipse.persistence.internal.expressions.FromSubSelectExpression) ClassTypeExpression(org.eclipse.persistence.internal.expressions.ClassTypeExpression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) QueryKeyExpression(org.eclipse.persistence.internal.expressions.QueryKeyExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) CompoundExpression(org.eclipse.persistence.internal.expressions.CompoundExpression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) Expression(org.eclipse.persistence.expressions.Expression) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) IOException(java.io.IOException) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) Writer(java.io.Writer)

Example 3 with Expression

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

the class InMemoryDirectEntity1MTest method test.

@Override
public void test() {
    getSession().readAllObjects(DirectEntity1MMapHolder.class);
    ReadAllQuery query = new ReadAllQuery(DirectEntity1MMapHolder.class);
    ExpressionBuilder holders = query.getExpressionBuilder();
    Expression exp = holders.anyOf("directToEntityMap").mapKey().equal(11);
    query.checkCacheOnly();
    results = (List) getSession().executeQuery(query);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 4 with Expression

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

the class MapCollectionsTestModel method getDirectMapMappingTestSuite.

public static TestSuite getDirectMapMappingTestSuite() {
    TestSuite suite = new TestSuite();
    suite.setName("Direct Map Mapping Map Test Suite");
    suite.setDescription("This suite tests using DirectMapMapping with different types of keys.");
    // Read
    suite.addTest(new TestReadDirectDirectMapMapping());
    suite.addTest(new TestReadAggregateDirectMapMapping());
    suite.addTest(new TestReadEntityDirectMapMapping());
    // Update
    suite.addTest(new TestUpdateDirectDirectMapMapping());
    suite.addTest(new TestUpdateAggregateDirectMapMapping());
    suite.addTest(new TestUpdateEntityDirectMapMapping());
    // Private Owned - DirectMapMappings are automatically private owned
    // as a result, the only relevant test here is one with an EntityKey
    suite.addTest(new TestUpdateEntityDirectMapMapping(true));
    // Join
    suite.addTest(new TestReadDirectDirectMapMapping(ForeignReferenceMapping.INNER_JOIN));
    suite.addTest(new TestReadAggregateDirectMapMapping(ForeignReferenceMapping.INNER_JOIN));
    suite.addTest(new TestReadEntityDirectMapMapping(ForeignReferenceMapping.INNER_JOIN));
    // Expressions
    ReadAllExpressionTest test = new ReadAllExpressionTest(DirectDirectMapHolder.class, 1);
    ExpressionBuilder holders = new ExpressionBuilder();
    Expression exp = holders.anyOf("directToDirectMap").mapKey().equal(1);
    test.setExpression(exp);
    suite.addTest(test);
    test = new ReadAllExpressionTest(AggregateDirectMapHolder.class, 1);
    AggregateMapKey aggkey = new AggregateMapKey();
    aggkey.setKey(11);
    holders = new ExpressionBuilder();
    exp = holders.anyOf("aggregateToDirectMap").mapKey().equal(aggkey);
    test.setExpression(exp);
    suite.addTest(test);
    test = new ReadAllExpressionTest(EntityDirectMapHolder.class, 1);
    EntityMapKey entKey = new EntityMapKey();
    entKey.setId(333);
    entKey.setData("data3");
    holders = new ExpressionBuilder();
    exp = holders.anyOf("entityToDirectMap").mapKey().equal(entKey);
    test.setExpression(exp);
    suite.addTest(test);
    return suite;
}
Also used : AggregateMapKey(org.eclipse.persistence.testing.models.collections.map.AggregateMapKey) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) AggregateDirectMapHolder(org.eclipse.persistence.testing.models.collections.map.AggregateDirectMapHolder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey) EntityDirectMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityDirectMapHolder) TestSuite(org.eclipse.persistence.testing.framework.TestSuite) Expression(org.eclipse.persistence.expressions.Expression) ReadAllExpressionTest(org.eclipse.persistence.testing.tests.expressions.ReadAllExpressionTest)

Example 5 with Expression

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

the class MapCollectionsTestModel method getUnidirectionalOneToManyMappingTestSuite.

public static TestSuite getUnidirectionalOneToManyMappingTestSuite() {
    TestSuite suite = new TestSuite();
    suite.setName("UnidirectionalOneToManyMapping Map Test Suite");
    suite.setDescription("This suite tests using UnidirectionalOneToManyMapping with a Map");
    // Read
    suite.addTest(new TestReadDirectEntityU1MMapMapping());
    suite.addTest(new TestReadAggregateEntityU1MMapMapping());
    suite.addTest(new TestReadEntityEntityU1MMapMapping());
    // Update
    suite.addTest(new TestUpdateDirectEntityU1MMapMapping());
    suite.addTest(new TestUpdateAggregateEntityU1MMapMapping());
    suite.addTest(new TestUpdateEntityEntityU1MMapMapping());
    // Private Owned
    suite.addTest(new TestUpdateDirectEntityU1MMapMapping(true));
    suite.addTest(new TestUpdateAggregateEntityU1MMapMapping(true));
    suite.addTest(new TestUpdateEntityEntityU1MMapMapping(true));
    // Joining
    suite.addTest(new TestReadDirectEntityU1MMapMapping(ForeignReferenceMapping.INNER_JOIN));
    suite.addTest(new TestReadAggregateEntityU1MMapMapping(ForeignReferenceMapping.INNER_JOIN));
    suite.addTest(new TestReadEntityEntityU1MMapMapping(ForeignReferenceMapping.INNER_JOIN));
    // Expressions
    ReadAllExpressionTest test = new ReadAllExpressionTest(DirectEntityU1MMapHolder.class, 1);
    ExpressionBuilder holders = new ExpressionBuilder();
    Expression exp = holders.anyOf("directToEntityMap").mapKey().equal(11);
    test.setExpression(exp);
    suite.addTest(test);
    test = new ReadAllExpressionTest(AggregateEntityU1MMapHolder.class, 1);
    AggregateMapKey aggkey = new AggregateMapKey();
    aggkey.setKey(11);
    holders = new ExpressionBuilder();
    exp = holders.anyOf("aggregateToEntityMap").mapKey().equal(aggkey);
    test.setExpression(exp);
    suite.addTest(test);
    test = new ReadAllExpressionTest(EntityEntityU1MMapHolder.class, 1);
    EntityMapKey entKey = new EntityMapKey();
    entKey.setId(999);
    entKey.setData("data9");
    holders = new ExpressionBuilder();
    exp = holders.anyOf("entityToEntityMap").mapKey().equal(entKey);
    test.setExpression(exp);
    suite.addTest(test);
    return suite;
}
Also used : AggregateMapKey(org.eclipse.persistence.testing.models.collections.map.AggregateMapKey) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey) TestSuite(org.eclipse.persistence.testing.framework.TestSuite) Expression(org.eclipse.persistence.expressions.Expression) EntityEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder) ReadAllExpressionTest(org.eclipse.persistence.testing.tests.expressions.ReadAllExpressionTest) AggregateEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.AggregateEntityU1MMapHolder)

Aggregations

Expression (org.eclipse.persistence.expressions.Expression)740 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)485 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)280 List (java.util.List)211 EntityManager (jakarta.persistence.EntityManager)168 Vector (java.util.Vector)138 ReportQuery (org.eclipse.persistence.queries.ReportQuery)138 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)135 ArrayList (java.util.ArrayList)111 SpatialParameters (org.eclipse.persistence.expressions.spatial.SpatialParameters)81 Spatial (org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial)78 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)77 ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)73 QueryKeyExpression (org.eclipse.persistence.internal.expressions.QueryKeyExpression)71 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)67 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)66 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)64 KeyExpression (org.eclipse.persistence.jpa.jpql.parser.KeyExpression)64 ObjectExpression (org.eclipse.persistence.jpa.jpql.parser.ObjectExpression)64 StateFieldPathExpression (org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)64