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);
}
}
}
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]);
}
}
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);
}
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;
}
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;
}
Aggregations