Search in sources :

Example 1 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class ProjectXMLStoredProcedureCallTest method verifyNamedArgumentStoredProcedureCall.

private void verifyNamedArgumentStoredProcedureCall() {
    if (query == null) {
        throw new TestErrorException("The query was incorrectly either read from or write to XML. Expected: [StoredProcedureCallInDataReadQuery]");
    }
    if (storedProcedureCall == null) {
        throw new TestErrorException("The stored procedure was incorrectly either read from or write to XML.");
    }
    Vector parameters = new Vector();
    DatabaseRecord row = (DatabaseRecord) ((Vector) getSession().executeQuery(query, parameters)).firstElement();
    Integer P_INOUT_FIELD_NAME = (Integer) row.get("P_INOUT_FIELD_NAME");
    Integer P_OUT_FIELD_NAME = (Integer) row.get("P_OUT_FIELD_NAME");
    if (!P_INOUT_FIELD_NAME.equals(1000) || !P_OUT_FIELD_NAME.equals(100)) {
        throw new TestErrorException("Stored Procedure which write to or read from XML does not execute as expected.");
    }
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) Vector(java.util.Vector)

Example 2 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class ProjectXMLStoredProcedureCallTest method verifyUNamedArgumentStoredProcedureCall.

private void verifyUNamedArgumentStoredProcedureCall() {
    if (UNamedQuery == null) {
        throw new TestErrorException("The UNamed query name was not incorrectly either read from or write to XML. Expected: [UNamedStoredProcedureCallInDataReadQuery]");
    }
    if (UNamedstoredProcedureCall == null) {
        throw new TestErrorException("The UNamed stored procedure was incorrectly either read from or write to XML.");
    }
    Vector parameters = new Vector();
    DatabaseRecord unamedrow = (DatabaseRecord) ((Vector) getSession().executeQuery(UNamedQuery, parameters)).firstElement();
    Integer UNAMED_P_INOUT_FIELD_NAME = (Integer) unamedrow.get("P_INOUT_FIELD_NAME");
    Integer UNAMED_P_OUT_FIELD_NAME = (Integer) unamedrow.get("P_OUT_FIELD_NAME");
    if (!UNAMED_P_INOUT_FIELD_NAME.equals(1000) || !UNAMED_P_OUT_FIELD_NAME.equals(100)) {
        throw new TestErrorException("UNnamed Stored Procedure which write to or read from XML dose not execute as expected.");
    }
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) Vector(java.util.Vector)

Example 3 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class DatabaseCall method addContext.

/**
 * INTERNAL:
 * Add a field - value pair for LOB field into the context.
 */
public void addContext(DatabaseField field, Object value) {
    if (this.contexts == null) {
        this.contexts = new DatabaseRecord(2);
    }
    this.contexts.add(field, value);
    this.isBatchExecutionSupported = false;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord)

Example 4 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class DatabaseCall method buildOutputRow.

/**
 * INTERNAL:
 * Return Record containing output fields and values.
 * Called only if shouldBuildOutputRow method returns true.
 */
public AbstractRecord buildOutputRow(CallableStatement statement, DatabaseAccessor accessor, AbstractSession session) throws SQLException {
    AbstractRecord row = new DatabaseRecord();
    int size = this.parameters.size();
    for (int index = 0; index < size; index++) {
        Object parameter = this.parameters.get(index);
        if (parameter instanceof OutputParameterForCallableStatement) {
            OutputParameterForCallableStatement outParameter = (OutputParameterForCallableStatement) parameter;
            if (!outParameter.isCursor() || !isCursorOutputProcedure()) {
                Object value = getOutputParameterValue(statement, index, session);
                DatabaseField field = outParameter.getOutputField();
                if (value instanceof Struct) {
                    ClassDescriptor descriptor = session.getDescriptor(field.getType());
                    if ((descriptor != null) && descriptor.isObjectRelationalDataTypeDescriptor()) {
                        AbstractRecord nestedRow = ((ObjectRelationalDataTypeDescriptor) descriptor).buildRowFromStructure((Struct) value);
                        ReadObjectQuery query = new ReadObjectQuery();
                        query.setSession(session);
                        value = descriptor.getObjectBuilder().buildNewInstance();
                        descriptor.getObjectBuilder().buildAttributesIntoObject(value, null, nestedRow, query, null, null, false, this.getQuery().getSession());
                    }
                } else if ((value instanceof Array) && (field.isObjectRelationalDatabaseField())) {
                    value = ObjectRelationalDataTypeDescriptor.buildContainerFromArray((Array) value, (ObjectRelationalDatabaseField) field, session);
                } else if (value instanceof ResultSet) {
                    // Support multiple out cursors, put list of records in row.
                    ResultSet resultSet = (ResultSet) value;
                    setFields(null);
                    matchFieldOrder(resultSet, accessor, session);
                    value = accessor.processResultSet(resultSet, this, statement, session);
                }
                row.put(field, value);
            }
        }
    }
    return row;
}
Also used : Array(java.sql.Array) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) ResultSet(java.sql.ResultSet) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor) Struct(java.sql.Struct)

Example 5 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord 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)

Aggregations

DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)110 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)44 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)43 Vector (java.util.Vector)31 ArrayList (java.util.ArrayList)17 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)17 BigDecimal (java.math.BigDecimal)14 List (java.util.List)14 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)14 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)14 Test (org.junit.Test)14 Expression (org.eclipse.persistence.expressions.Expression)12 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)12 HashMap (java.util.HashMap)11 Map (java.util.Map)10 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)7 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)7 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)6 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)6 SQLUpdateStatement (org.eclipse.persistence.internal.expressions.SQLUpdateStatement)6