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.");
}
}
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.");
}
}
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;
}
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;
}
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);
}
Aggregations