Search in sources :

Example 1 with UpdateAllQuery

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);
}
Also used : ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 2 with UpdateAllQuery

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;
    }
}
Also used : ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 3 with UpdateAllQuery

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);
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 4 with UpdateAllQuery

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();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 5 with UpdateAllQuery

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);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Aggregations

UpdateAllQuery (org.eclipse.persistence.queries.UpdateAllQuery)57 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)36 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)22 Expression (org.eclipse.persistence.expressions.Expression)19 EntityManager (jakarta.persistence.EntityManager)13 DeleteAllQuery (org.eclipse.persistence.queries.DeleteAllQuery)12 ReportQuery (org.eclipse.persistence.queries.ReportQuery)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Vector (java.util.Vector)9 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)8 Iterator (java.util.Iterator)7 HashMap (java.util.HashMap)5 Map (java.util.Map)4 IdentityHashMap (java.util.IdentityHashMap)3 DataExpression (org.eclipse.persistence.internal.expressions.DataExpression)3 ExpressionIterator (org.eclipse.persistence.internal.expressions.ExpressionIterator)3 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)3 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)2 FieldExpression (org.eclipse.persistence.internal.expressions.FieldExpression)2