use of org.eclipse.persistence.internal.expressions.SQLInsertStatement in project eclipselink by eclipse-ee4j.
the class HistoryPolicy method mappingLogicalInsert.
/**
* INTERNAL:
* Performs a logical insert into the historical schema. Direct
* collections and many to many mappings are maintained through the session
* events.
*/
public void mappingLogicalInsert(DataModifyQuery originalQuery, AbstractRecord arguments, AbstractSession session) {
DataModifyQuery historyQuery = new DataModifyQuery();
SQLInsertStatement historyStatement = new SQLInsertStatement();
DatabaseTable histTable = getHistoricalTables().get(0);
historyStatement.setTable(histTable);
AbstractRecord modifyRow = originalQuery.getModifyRow().clone();
AbstractRecord translationRow = arguments.clone();
// Start could be the version field in timestamp locking.
if (!modifyRow.containsKey(getStart())) {
Object time = getCurrentTime(session);
modifyRow.add(getStart(), time);
translationRow.add(getStart(), time);
}
historyQuery.setSQLStatement(historyStatement);
historyQuery.setModifyRow(modifyRow);
historyStatement.setModifyRow(modifyRow);
session.executeQuery(historyQuery, translationRow);
}
use of org.eclipse.persistence.internal.expressions.SQLInsertStatement in project eclipselink by eclipse-ee4j.
the class RelationTableMechanism method initializeInsertQuery.
/**
* INTERNAL:
* Initialize insert query. This query is used to insert the collection of objects into the
* relation table.
*/
protected void initializeInsertQuery(AbstractSession session, ForeignReferenceMapping mapping) {
if (!getInsertQuery().hasSessionName()) {
getInsertQuery().setSessionName(session.getName());
}
if (getInsertQuery().getPartitioningPolicy() == null) {
getInsertQuery().setPartitioningPolicy(mapping.getPartitioningPolicy());
}
getInsertQuery().setName(mapping.getAttributeName());
if (hasCustomInsertQuery()) {
return;
}
SQLInsertStatement statement = new SQLInsertStatement();
statement.setTable(getRelationTable());
AbstractRecord joinRow = new DatabaseRecord();
for (DatabaseField field : getTargetRelationKeyFields()) {
joinRow.put(field, null);
}
for (DatabaseField field : getSourceRelationKeyFields()) {
joinRow.put(field, null);
}
if (mapping.isCollectionMapping()) {
CollectionMapping collectionMapping = (CollectionMapping) mapping;
if (collectionMapping.getListOrderField() != null) {
joinRow.put(collectionMapping.getListOrderField(), null);
}
collectionMapping.getContainerPolicy().addFieldsForMapKey(joinRow);
}
statement.setModifyRow(joinRow);
getInsertQuery().setSQLStatement(statement);
getInsertQuery().setModifyRow(joinRow);
}
use of org.eclipse.persistence.internal.expressions.SQLInsertStatement in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method initializeInsertQuery.
/**
* Initialize insert query. This query is used to insert the collection of objects into the
* reference table.
*/
protected void initializeInsertQuery(AbstractSession session) {
if (!getInsertQuery().hasSessionName()) {
getInsertQuery().setSessionName(session.getName());
}
if (getInsertQuery().getPartitioningPolicy() == null) {
getInsertQuery().setPartitioningPolicy(getPartitioningPolicy());
}
if (hasCustomInsertQuery()) {
return;
}
SQLInsertStatement statement = new SQLInsertStatement();
statement.setTable(getReferenceTable());
AbstractRecord directRow = new DatabaseRecord();
for (Enumeration<DatabaseField> referenceEnum = getReferenceKeyFields().elements(); referenceEnum.hasMoreElements(); ) {
directRow.put(referenceEnum.nextElement(), null);
}
directRow.put(getDirectField(), null);
if (listOrderField != null) {
directRow.put(listOrderField, null);
}
statement.setModifyRow(directRow);
getInsertQuery().setSQLStatement(statement);
getInsertQuery().setModifyRow(directRow);
}
use of org.eclipse.persistence.internal.expressions.SQLInsertStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method buildInsertStatement.
/**
* Return the appropriate insert statement
*/
protected SQLInsertStatement buildInsertStatement(DatabaseTable table) {
SQLInsertStatement insertStatement = new SQLInsertStatement();
insertStatement.setTable(table);
insertStatement.setModifyRow(getModifyRow());
if (getDescriptor().hasReturningPolicies() && getDescriptor().getReturnFieldsToGenerateInsert() != null) {
// In case of RelationalDescriptor only return fields for current table must be used.
Vector<DatabaseField> returnFieldsForTable = new NonSynchronizedVector<>();
for (DatabaseField item : getDescriptor().getReturnFieldsToGenerateInsert()) {
if (table.equals(item.getTable())) {
returnFieldsForTable.add(item);
}
}
if (!returnFieldsForTable.isEmpty()) {
insertStatement.setReturnFields(getDescriptor().getReturnFieldsToGenerateInsert());
}
}
insertStatement.setHintString(getQuery().getHintString());
return insertStatement;
}
use of org.eclipse.persistence.internal.expressions.SQLInsertStatement in project eclipselink by eclipse-ee4j.
the class ExpressionQueryMechanism method prepareInsertObject.
/**
* Pre-build the SQL statement from the expression.
*/
@Override
public void prepareInsertObject() {
// Require modify row to prepare.
if (getModifyRow() == null) {
return;
}
// Add and prepare to a call a update statement for each table.
// In the case of multiple tables, build the sql statements in insert order.
ClassDescriptor descriptor = getDescriptor();
if (descriptor.getTables().size() == 1) {
setSQLStatement(buildInsertStatement(descriptor.getTables().get(0)));
} else {
for (DatabaseTable table : descriptor.getMultipleTableInsertOrder()) {
SQLInsertStatement insertStatement = buildInsertStatement(table);
getSQLStatements().addElement(insertStatement);
}
}
super.prepareInsertObject();
}
Aggregations