![JAR search and dependency download from the Maven repository](/logo.png)
org.eclipse.persistence.eis.interactions.EISInteraction Maven / Gradle / Ivy
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.eis.interactions;
import java.io.*;
import java.util.*;
import jakarta.resource.*;
import jakarta.resource.cci.*;
import org.eclipse.persistence.internal.helper.*;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.internal.databaseaccess.Accessor;
import org.eclipse.persistence.internal.databaseaccess.DatasourceCall;
import org.eclipse.persistence.eis.*;
/**
* Defines the specification for a call to a JCA interaction.
* Builds the input and output records from the arguments.
*
* @author James
* @since OracleAS TopLink 10g (10.0.3)
*/
public abstract class EISInteraction extends DatasourceCall {
/** Adapter specific interaction spec. */
protected InteractionSpec interactionSpec;
/** Name of the function the interaction describes. */
protected String functionName;
/** Name to pass to the input record creation. */
protected String inputRecordName;
/** Adapter specific properties may be added. */
protected Map properties;
/** Holds database row of input values. */
protected AbstractRecord inputRow;
/** Defines the arguments to the interaction, these can be the values or argument names/fields the values come from. */
protected Vector arguments;
/**
* Defines the output argument names as defined in the output record for the interaction.
* This is shared as indexed interaction may still have mapped results.
*/
protected Vector outputArgumentNames;
/** Defines the field values the output arguments of the interaction map to. These are order dependent with the names. */
protected Vector outputArguments;
/** Path to the desired output record if nested. */
protected String outputResultPath;
/**
* PUBLIC:
* Default constructor.
*/
protected EISInteraction() {
super();
this.functionName = "";
this.inputRecordName = "";
this.outputResultPath = "";
}
/**
* PUBLIC:
* Define the output argument to the interaction and the field/argument name to be substitute for it.
* This is only required if an output row is not used.
* The parameterAndArgumentFieldName is the name of the output record argument expected,
* and is the field or argument name to be used to be used for it.
* These names are assumed to be the same, if not this method can be called with two arguments.
*/
public void addOutputArgument(String parameterAndArgumentFieldName) {
addOutputArgument(parameterAndArgumentFieldName, parameterAndArgumentFieldName);
}
/**
* PUBLIC:
* Define the output argument to the interaction and the field/argument name to be substitute for it.
* This is only required if an output row is not used.
* The parameterName is the name of the output record argument expected.
* The argumentFieldName is the field or argument name to be used to be used for it.
* If these names are the same (as they normally are) this method can be called with a single argument.
*/
public void addOutputArgument(String parameterName, String argumentFieldName) {
getOutputArgumentNames().addElement(parameterName);
getOutputArguments().addElement(new DatabaseField(argumentFieldName));
}
/**
* The argument fields or values to the interaction that map into the input record.
*/
public Vector getArguments() {
// This is lazy initialized to conserv space on calls that have no parameters.
if (arguments == null) {
arguments = new Vector();
}
return arguments;
}
/**
* INTERNAL:
* The argument fields or values to the interaction that map into the input record.
*/
public void setArguments(Vector arguments) {
this.arguments = arguments;
}
/**
* Return if argumented.
*/
public boolean hasArguments() {
return (arguments != null) && (!arguments.isEmpty());
}
@Override
public boolean isEISInteraction() {
return true;
}
/**
* PUBLIC:
* The output result path defines the root key for the MappedRecord that
* the desired interaction result is nested into.
* This is required for read interactions that need a nested record to build from the mapped object.
*/
public String getOutputResultPath() {
return outputResultPath;
}
/**
* PUBLIC:
* The output result path defines the root key for the MappedRecord that
* the desired interaction result is nested into.
* This is required for read interactions that need a nested record to build from the mapped object.
*/
public void setOutputResultPath(String outputResultPath) {
this.outputResultPath = outputResultPath;
}
/**
* The argument names for the output record.
*/
public Vector getOutputArgumentNames() {
// This is lazy initialized to conserv space on calls that have no parameters.
if (outputArgumentNames == null) {
outputArgumentNames = new Vector<>();
}
return outputArgumentNames;
}
/**
* The argument fields to the interaction that map into the output record.
*/
public Vector getOutputArguments() {
// This is lazy initialized to conserv space on calls that have no parameters.
if (outputArguments == null) {
outputArguments = new Vector<>();
}
return outputArguments;
}
/**
* The output arguments.
*/
public void setOutputArguments(Vector outputArguments) {
this.outputArguments = outputArguments;
}
/**
* Set the output argument names.
*/
public void setOutputArgumentNames(Vector outputArgumentNames) {
this.outputArgumentNames = outputArgumentNames;
}
/**
* Return if argumented.
*/
public boolean hasOutputArguments() {
return (outputArguments != null) && (!outputArguments.isEmpty());
}
/**
* Set the default record name from the descriptor.
*/
@Override
public void prepare(AbstractSession session) {
if (getInputRecordName().length() == 0) {
if ((getQuery() != null) && (getQuery().getDescriptor() instanceof EISDescriptor)) {
EISDescriptor descriptor = (EISDescriptor)getQuery().getDescriptor();
setInputRecordName(descriptor.getDataTypeName());
} else {
setInputRecordName("input");
}
}
super.prepare(session);
}
/**
* Create the appropriate record element for the data value.
* If the value is a collection, create a collection of elements,
* if the value is a map, create a nested map,
* otherwise just return the value (primitive data).
*/
public Object createRecordElement(String elementName, Object value, EISAccessor accessor) {
try {
Object element = value;
// Handle nested collections.
if (element instanceof List) {
// Convert each element in the list.
@SuppressWarnings({"unchecked"})
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy