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