use of org.eclipse.persistence.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.
the class QueryImpl method setAsDataModifyQuery.
/**
* INTERNAL:
* Change the internal query to data modify query.
*/
protected void setAsDataModifyQuery() {
DataModifyQuery query = new DataModifyQuery();
query.setIsUserDefined(this.databaseQuery.isUserDefined());
// By default, do not batch user native queries, as row count must be returned.
query.setIsBatchExecutionSupported(false);
query.copyFromQuery(this.databaseQuery);
// Need to clone call, in case was executed as read.
query.setDatasourceCall((Call) this.databaseQuery.getDatasourceCall().clone());
this.databaseQuery = query;
}
use of org.eclipse.persistence.queries.DataModifyQuery 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.queries.DataModifyQuery 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.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.
the class StoredProcedureQueryHandler method initializeDatabaseQuery.
@Override
public void initializeDatabaseQuery(XRServiceAdapter xrService, QueryOperation queryOperation) {
DatabaseQuery databaseQueryToInitialize;
if (queryOperation.hasResponse()) {
QName type = queryOperation.getResult().getType();
if (queryOperation.isCollection()) {
if (queryOperation.isSimpleXMLFormat()) {
databaseQueryToInitialize = new DataReadQuery();
} else {
if (!xrService.descriptorsByQName.containsKey(type)) {
// data-read query
databaseQueryToInitialize = new DataReadQuery();
} else {
// check if descriptor is aggregate
Class<?> typeClass = xrService.getTypeClass(type);
if (xrService.getORSession().getDescriptor(typeClass).isAggregateDescriptor()) {
databaseQueryToInitialize = new DataReadQuery();
} else {
// read-all query for the class mapped to the type
databaseQueryToInitialize = new ReadAllQuery(typeClass);
}
}
}
} else {
if (getOutArguments().size() == 0 && getInOutArguments().size() == 0) {
if (isStoredFunctionQueryHandler()) {
if (!xrService.descriptorsByQName.containsKey(type)) {
databaseQueryToInitialize = new ValueReadQuery();
} else {
// read object query for the class mapped to the type
databaseQueryToInitialize = new ReadObjectQuery(xrService.getTypeClass(type));
}
} else {
// special case - no out args for SP: the return
// will be a single int
// rowcount
databaseQueryToInitialize = new DataModifyQuery();
}
} else {
if (!xrService.descriptorsByQName.containsKey(type)) {
if (type.equals(SXF_QNAME)) {
databaseQueryToInitialize = new DataReadQuery();
} else {
databaseQueryToInitialize = new ValueReadQuery();
}
} else {
// read object query for the class mapped to the type
databaseQueryToInitialize = new ReadObjectQuery(xrService.getTypeClass(type));
}
}
}
} else {
databaseQueryToInitialize = new ValueReadQuery();
}
databaseQueryToInitialize.bindAllParameters();
setDatabaseQuery(databaseQueryToInitialize);
}
use of org.eclipse.persistence.queries.DataModifyQuery in project eclipselink by eclipse-ee4j.
the class PLSQLProject method buildSimpleInDefaultsQuery.
protected DatabaseQuery buildSimpleInDefaultsQuery() {
PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
call.setProcedureName("PLSQL_SIMPLE_IN");
call.addNamedArgument("P_BOOLEAN", OraclePLSQLTypes.PLSQLBoolean);
call.addNamedArgument("P_BINARY_INTEGER", OraclePLSQLTypes.BinaryInteger);
call.addNamedArgument("P_DEC", OraclePLSQLTypes.Dec);
call.addNamedArgument("P_INT", OraclePLSQLTypes.Int);
call.addNamedArgument("P_NATURAL", OraclePLSQLTypes.Natural);
call.addNamedArgument("P_NATURALN", OraclePLSQLTypes.NaturalN);
call.addNamedArgument("P_PLS_INTEGER", OraclePLSQLTypes.PLSQLInteger);
call.addNamedArgument("P_POSITIVE", OraclePLSQLTypes.Positive);
call.addNamedArgument("P_POSITIVEN", OraclePLSQLTypes.PositiveN);
call.addNamedArgument("P_SIGNTYPE", OraclePLSQLTypes.SignType);
call.addNamedArgument("P_NUMBER", JDBCTypes.NUMERIC_TYPE, 10, 2);
DataModifyQuery query = new DataModifyQuery();
query.addArgument("P_BOOLEAN", Integer.class);
query.addArgument("P_BINARY_INTEGER", Integer.class);
query.addArgument("P_DEC", Integer.class);
query.addArgument("P_INT", Integer.class);
query.addArgument("P_NATURAL", Integer.class);
query.addArgument("P_NATURALN", Integer.class);
query.addArgument("P_PLS_INTEGER", Integer.class);
query.addArgument("P_POSITIVE", Integer.class);
query.addArgument("P_POSITIVEN", Integer.class);
query.addArgument("P_SIGNTYPE", BigDecimal.class);
query.addArgument("P_NUMBER", BigDecimal.class);
query.setCall(call);
return query;
}
Aggregations