use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryExpressionMathTest method test.
@Override
public void test() {
ExpressionBuilder eb = new ExpressionBuilder();
UpdateAllQuery updateQuery = new UpdateAllQuery(org.eclipse.persistence.testing.models.insurance.Claim.class);
updateQuery.setSelectionCriteria(eb.get("amount").greaterThan(1000));
updateQuery.addUpdate(eb.get("amount"), ExpressionMath.multiply(eb.get("amount"), 1.10));
m_session.executeQuery(updateQuery);
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryRollbackTest method test.
@Override
public void test() {
m_uow = m_session.acquireUnitOfWork();
ExpressionBuilder eb = new ExpressionBuilder();
UpdateAllQuery uaq1 = new UpdateAllQuery(Employee.class);
uaq1.addUpdate(eb.get("lastName"), "shouldRollback");
m_uow.executeQuery(uaq1);
UpdateAllQuery uaq2 = new UpdateAllQuery(Employee.class);
uaq2.addUpdate(eb.getField("BAD"), 10000);
m_uow.executeQuery(uaq2);
try {
m_uow.commit();
} catch (Exception e) {
m_exceptionCaught = true;
}
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryTest method test.
@Override
public void test() {
Employee emp = (Employee) m_session.readObject(Employee.class);
// Store a first name (any first name will do)
m_firstName = emp.getFirstName();
ExpressionBuilder eb = new ExpressionBuilder();
UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class);
updateQuery.setSelectionCriteria(eb.get("firstName").equal(m_firstName));
updateQuery.addUpdate(eb.get("lastName"), "oneverynonelikelylastname");
m_session.executeQuery(updateQuery);
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateTests method testUpdateAllToNull.
public void testUpdateAllToNull() throws Exception {
session.getLogin().setShouldBindAllParameters(false);
UnitOfWork uow = session.acquireUnitOfWork();
UpdateAllQuery uaq = new UpdateAllQuery(SimpleSpatial.class);
uaq.addUpdate("geometry", (Object) null);
// BUG: 5102352 - workaround requires selection criteria
uaq.setSelectionCriteria(uaq.getExpressionBuilder().get("id").notNull());
try {
uow.executeQuery(uaq);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
uow.writeChanges();
uow.release();
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateQueryVisitor method visit.
@Override
public void visit(UpdateItem expression) {
// Create the Expression for the state field path expression
Expression leftExpression = queryContext.buildExpression(expression.getStateFieldPathExpression());
// Create the Expression for the new value
Expression rightExpression = queryContext.buildExpression(expression.getNewValue());
// Add the expressions to the query
((UpdateAllQuery) query).addUpdate(leftExpression, rightExpression);
}
Aggregations