Search in sources :

Example 21 with DataModifyQuery

use of org.eclipse.persistence.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.

the class OneToManyMapping method setAddTargetSQLString.

/**
 * PUBLIC:
 */
public void setAddTargetSQLString(String sqlString) {
    DataModifyQuery query = new DataModifyQuery();
    query.setSQLString(sqlString);
    setCustomAddTargetQuery(query);
}
Also used : DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 22 with DataModifyQuery

use of org.eclipse.persistence.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.

the class OneToManyMapping method initializeAddTargetQuery.

/**
 * INTERNAL:
 * Initialize addTargetQuery.
 */
protected void initializeAddTargetQuery(AbstractSession session) {
    AbstractRecord modifyRow = createModifyRowForAddTargetQuery();
    if (modifyRow.isEmpty()) {
        return;
    }
    if (!hasCustomAddTargetQuery) {
        addTargetQuery = new DataModifyQuery();
    }
    if (!addTargetQuery.hasSessionName()) {
        addTargetQuery.setSessionName(session.getName());
    }
    if (hasCustomAddTargetQuery) {
        return;
    }
    // all fields in modifyRow must have the same table
    DatabaseTable table = (modifyRow.getFields().get(0)).getTable();
    // Build where clause expression.
    Expression whereClause = null;
    Expression builder = new ExpressionBuilder();
    int size = targetPrimaryKeyFields.size();
    for (int index = 0; index < size; index++) {
        DatabaseField targetPrimaryKey = targetPrimaryKeyFields.get(index);
        Expression expression = builder.getField(targetPrimaryKey).equal(builder.getParameter(targetPrimaryKey));
        whereClause = expression.and(whereClause);
    }
    SQLUpdateStatement statement = new SQLUpdateStatement();
    statement.setTable(table);
    statement.setWhereClause(whereClause);
    statement.setModifyRow(modifyRow);
    addTargetQuery.setSQLStatement(statement);
}
Also used : FieldExpression(org.eclipse.persistence.internal.expressions.FieldExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) Expression(org.eclipse.persistence.expressions.Expression) SQLUpdateStatement(org.eclipse.persistence.internal.expressions.SQLUpdateStatement) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 23 with DataModifyQuery

use of org.eclipse.persistence.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.

the class DirectCollectionMapping method performDataModificationEvent.

/**
 * INTERNAL:
 * Perform the commit event.
 * This is used in the uow to delay data modifications.
 */
@Override
public void performDataModificationEvent(Object[] event, AbstractSession session) throws DatabaseException, DescriptorException {
    // Hey I might actually want to use an inner class here... ok array for now.
    if (event[0] == Delete) {
        session.executeQuery((DataModifyQuery) event[1], (AbstractRecord) event[2]);
        if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) {
            getHistoryPolicy().mappingLogicalDelete((DataModifyQuery) event[1], (AbstractRecord) event[2], session);
        }
    } else if (event[0] == Insert) {
        session.executeQuery((DataModifyQuery) event[1], (AbstractRecord) event[2]);
        if ((getHistoryPolicy() != null) && getHistoryPolicy().shouldHandleWrites()) {
            getHistoryPolicy().mappingLogicalInsert((DataModifyQuery) event[1], (AbstractRecord) event[2], session);
        }
    } else if (event[0] == DeleteAll) {
        preDelete((DeleteObjectQuery) event[1]);
    } else if (event[0] == DeleteAtIndex) {
        session.executeQuery((DataModifyQuery) event[1], (AbstractRecord) event[2]);
    } else if (event[0] == UpdateAtIndex) {
        DataModifyQuery updateAtIndexQuery = (DataModifyQuery) ((DataModifyQuery) event[1]).clone();
        updateAtIndexQuery.setModifyRow((AbstractRecord) event[3]);
        updateAtIndexQuery.setHasModifyRow(true);
        updateAtIndexQuery.setIsExecutionClone(true);
        session.executeQuery(updateAtIndexQuery, (AbstractRecord) event[2]);
    } else {
        throw DescriptorException.invalidDataModificationEventCode(event[0], this);
    }
}
Also used : AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 24 with DataModifyQuery

use of org.eclipse.persistence.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.

the class RelationTableMechanism method setDeleteSQLString.

/**
 * PUBLIC:
 * Set the receiver's delete SQL string. This allows the user to override the SQL
 * generated by TOPLink, with there own SQL or procedure call. The arguments are
 * translated from the fields of the source row, through replacing the field names
 * marked by '#' with the values for those fields.
 * This is used to delete a single entry from the M-M join table.
 * Example, 'delete from PROJ_EMP where PROJ_ID = #PROJ_ID AND EMP_ID = #EMP_ID'.
 */
public void setDeleteSQLString(String sqlString) {
    DataModifyQuery query = new DataModifyQuery();
    query.setSQLString(sqlString);
    setCustomDeleteQuery(query);
}
Also used : DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 25 with DataModifyQuery

use of org.eclipse.persistence.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.

the class RelationTableMechanism method setDeleteCall.

/**
 * PUBLIC:
 * Set the receiver's delete Call. This allows the user to override the SQL
 * generated by TOPLink, with there own SQL or procedure call. The arguments are
 * translated from the fields of the source row.
 * This is used to delete a single entry from the M-M join table.
 * Example, 'new SQLCall("delete from PROJ_EMP where PROJ_ID = #PROJ_ID AND EMP_ID = #EMP_ID")'.
 */
public void setDeleteCall(Call call) {
    DataModifyQuery query = new DataModifyQuery();
    query.setCall(call);
    setCustomDeleteQuery(query);
}
Also used : DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Aggregations

DataModifyQuery (org.eclipse.persistence.queries.DataModifyQuery)72 PLSQLStoredProcedureCall (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall)32 Test (org.junit.Test)24 StringReader (java.io.StringReader)23 Project (org.eclipse.persistence.sessions.Project)22 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)21 XMLContext (org.eclipse.persistence.oxm.XMLContext)21 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)21 Document (org.w3c.dom.Document)21 NonJDBCTestHelper.buildTestProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildTestProject)17 NonJDBCTestHelper.buildWorkbenchXMLProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildWorkbenchXMLProject)17 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)12 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)10 PLSQLrecord (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLrecord)8 DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)7 Expression (org.eclipse.persistence.expressions.Expression)5 SQLUpdateStatement (org.eclipse.persistence.internal.expressions.SQLUpdateStatement)5 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)4 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)4 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)4