Search in sources :

Example 1 with DataModifyQuery

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;
}
Also used : DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 2 with DataModifyQuery

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);
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) SQLDeleteStatement(org.eclipse.persistence.internal.expressions.SQLDeleteStatement) ObjectExpression(org.eclipse.persistence.internal.expressions.ObjectExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) Expression(org.eclipse.persistence.expressions.Expression) TableExpression(org.eclipse.persistence.internal.expressions.TableExpression) 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) HistoricalDatabaseTable(org.eclipse.persistence.internal.history.HistoricalDatabaseTable) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 3 with DataModifyQuery

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);
}
Also used : AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) SQLInsertStatement(org.eclipse.persistence.internal.expressions.SQLInsertStatement) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) HistoricalDatabaseTable(org.eclipse.persistence.internal.history.HistoricalDatabaseTable) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 4 with DataModifyQuery

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);
}
Also used : ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) QName(javax.xml.namespace.QName) ValueReadQuery(org.eclipse.persistence.queries.ValueReadQuery) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) DataReadQuery(org.eclipse.persistence.queries.DataReadQuery) DataModifyQuery(org.eclipse.persistence.queries.DataModifyQuery)

Example 5 with DataModifyQuery

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;
}
Also used : PLSQLStoredProcedureCall(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall) 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