use of org.eclipse.persistence.internal.expressions.SQLUpdateStatement in project eclipselink by eclipse-ee4j.
the class HistoryPolicy method mappingLogicalDelete.
/**
* INTERNAL:
* Performs a logical delete (update) on the historical schema. Direct
* collections and many to many mappings are maintained through the session
* events.
*/
public void mappingLogicalDelete(ModifyQuery originalQuery, AbstractRecord arguments, AbstractSession session) {
SQLDeleteStatement originalStatement = (SQLDeleteStatement) originalQuery.getSQLStatement();
DataModifyQuery historyQuery = new DataModifyQuery();
SQLUpdateStatement historyStatement = new SQLUpdateStatement();
DatabaseTable histTable = getHistoricalTables().get(0);
historyStatement.setTable(histTable);
Expression whereClause = (Expression) originalStatement.getWhereClause().clone();
DatabaseField endField = getEnd();
whereClause = whereClause.getBuilder().getField(endField).isNull().and(whereClause);
historyStatement.setWhereClause(whereClause);
AbstractRecord modifyRow = new DatabaseRecord();
AbstractRecord translationRow = arguments.clone();
Object time = getCurrentTime(session);
modifyRow.add(getEnd(), time);
translationRow.add(getEnd(), time);
historyStatement.setModifyRow(modifyRow);
historyQuery.setSQLStatement(historyStatement);
historyQuery.setModifyRow(modifyRow);
session.executeQuery(historyQuery, translationRow);
}
use of org.eclipse.persistence.internal.expressions.SQLUpdateStatement in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method initializeChangeOrderTargetQuery.
/**
* INTERNAL:
* Initialize changeOrderTargetQuery.
*/
@Override
protected void initializeChangeOrderTargetQuery(AbstractSession session) {
boolean hasChangeOrderTargetQuery = changeOrderTargetQuery != null;
if (!hasChangeOrderTargetQuery) {
changeOrderTargetQuery = new DataModifyQuery();
}
changeOrderTargetQuery = new DataModifyQuery();
if (!changeOrderTargetQuery.hasSessionName()) {
changeOrderTargetQuery.setSessionName(session.getName());
}
if (hasChangeOrderTargetQuery) {
return;
}
DatabaseTable table = this.listOrderField.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);
}
AbstractRecord modifyRow = new DatabaseRecord();
modifyRow.add(this.listOrderField, null);
SQLUpdateStatement statement = new SQLUpdateStatement();
statement.setTable(table);
statement.setWhereClause(whereClause);
statement.setModifyRow(modifyRow);
changeOrderTargetQuery.setSQLStatement(statement);
}
use of org.eclipse.persistence.internal.expressions.SQLUpdateStatement in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method initializeRemoveAllTargetsQuery.
/**
* INTERNAL:
* Initialize removeAllTargetsQuery.
*/
protected void initializeRemoveAllTargetsQuery(AbstractSession session) {
if (!removeAllTargetsQuery.hasSessionName()) {
removeAllTargetsQuery.setSessionName(session.getName());
}
if (hasCustomRemoveAllTargetsQuery) {
return;
}
// All targetForeignKeys should have the same table
DatabaseTable table = targetForeignKeyFields.get(0).getTable();
// Build where clause expression.
Expression whereClause = null;
Expression builder = new ExpressionBuilder();
AbstractRecord modifyRow = new DatabaseRecord();
int size = targetForeignKeyFields.size();
for (int index = 0; index < size; index++) {
DatabaseField targetForeignKey = targetForeignKeyFields.get(index);
if (shouldRemoveTargetQueryModifyTargetForeignKey()) {
modifyRow.put(targetForeignKey, null);
}
Expression expression = builder.getField(targetForeignKey).equal(builder.getParameter(targetForeignKey));
whereClause = expression.and(whereClause);
}
if (this.listOrderField != null) {
// targetForeignKeys and listOrderField should have the same table
modifyRow.add(this.listOrderField, null);
}
SQLUpdateStatement statement = new SQLUpdateStatement();
statement.setTable(table);
statement.setWhereClause(whereClause);
statement.setModifyRow(modifyRow);
removeAllTargetsQuery.setSQLStatement(statement);
}
use of org.eclipse.persistence.internal.expressions.SQLUpdateStatement 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.internal.expressions.SQLUpdateStatement in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method initializeRemoveTargetQuery.
/**
* INTERNAL:
* Initialize removeTargetQuery.
*/
protected void initializeRemoveTargetQuery(AbstractSession session) {
if (!removeTargetQuery.hasSessionName()) {
removeTargetQuery.setSessionName(session.getName());
}
if (hasCustomRemoveTargetQuery) {
return;
}
// All targetForeignKeys should have the same table
DatabaseTable table = targetForeignKeyFields.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);
}
AbstractRecord modifyRow = new DatabaseRecord();
if (shouldRemoveTargetQueryModifyTargetForeignKey()) {
size = targetForeignKeyFields.size();
for (int index = 0; index < size; index++) {
DatabaseField targetForeignKey = targetForeignKeyFields.get(index);
modifyRow.put(targetForeignKey, null);
Expression expression = builder.getField(targetForeignKey).equal(builder.getParameter(targetForeignKey));
whereClause = expression.and(whereClause);
}
}
if (listOrderField != null) {
modifyRow.add(listOrderField, null);
}
SQLUpdateStatement statement = new SQLUpdateStatement();
statement.setTable(table);
statement.setWhereClause(whereClause);
statement.setModifyRow(modifyRow);
removeTargetQuery.setSQLStatement(statement);
}
Aggregations