use of org.eclipse.persistence.eis.EISException in project eclipselink by eclipse-ee4j.
the class OracleNoSQLPlatform method buildInteractionSpec.
/**
* Allow the platform to build the interaction spec based on properties defined in the interaction.
*/
@Override
public InteractionSpec buildInteractionSpec(EISInteraction interaction) {
InteractionSpec spec = interaction.getInteractionSpec();
if (spec == null) {
OracleNoSQLInteractionSpec noSqlSpec = new OracleNoSQLInteractionSpec();
Object operation = interaction.getProperty(OPERATION);
if (operation == null) {
throw new EISException("'" + OPERATION + "' property must be set on the query's interation.");
}
if (operation instanceof String) {
operation = OracleNoSQLOperation.valueOf((String) operation);
}
noSqlSpec.setOperation((OracleNoSQLOperation) operation);
// Allows setting of consistency as a property.
Object consistency = interaction.getProperty(CONSISTENCY);
if (consistency == null) {
// Default to session property.
consistency = interaction.getQuery().getSession().getProperty(CONSISTENCY);
}
if (consistency instanceof Consistency) {
noSqlSpec.setConsistency((Consistency) consistency);
} else if (consistency instanceof String) {
String constant = (String) consistency;
if (constant.equals("ABSOLUTE")) {
noSqlSpec.setConsistency(Consistency.ABSOLUTE);
} else if (constant.equals("NONE_REQUIRED")) {
noSqlSpec.setConsistency(Consistency.NONE_REQUIRED);
} else {
throw new EISException("Invalid consistency property value: " + constant);
}
}
// Allows setting of durability as a property.
Object durability = interaction.getProperty(DURABILITY);
if (durability == null) {
// Default to session property.
durability = interaction.getQuery().getSession().getProperty(DURABILITY);
}
if (durability instanceof Durability) {
noSqlSpec.setDurability((Durability) durability);
} else if (durability instanceof String) {
String constant = (String) durability;
if (constant.equals("COMMIT_NO_SYNC")) {
noSqlSpec.setDurability(Durability.COMMIT_NO_SYNC);
} else if (constant.equals("COMMIT_SYNC")) {
noSqlSpec.setDurability(Durability.COMMIT_SYNC);
} else if (constant.equals("COMMIT_WRITE_NO_SYNC")) {
noSqlSpec.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
} else {
throw new EISException("Invalid durability property value: " + constant);
}
}
// Allows setting of timeout as a property.
Object timeout = interaction.getProperty(TIMEOUT);
if (timeout == null) {
// Default to session property.
timeout = interaction.getQuery().getSession().getProperty(TIMEOUT);
}
if (timeout instanceof Number) {
noSqlSpec.setTimeout(((Number) timeout).longValue());
} else if (timeout instanceof String) {
noSqlSpec.setTimeout(Long.parseLong(((String) timeout)));
} else if (interaction.getQuery().getQueryTimeout() > 0) {
noSqlSpec.setTimeout(interaction.getQuery().getQueryTimeout());
}
// Allows setting of version as a property.
Object version = interaction.getProperty(VERSION);
if (version == null) {
// Default to session property.
version = interaction.getQuery().getSession().getProperty(VERSION);
}
if (version == null) {
if (interaction.getQuery().getDescriptor() != null) {
ClassDescriptor descriptor = interaction.getQuery().getDescriptor();
if (descriptor.usesOptimisticLocking() && descriptor.getOptimisticLockingPolicy() instanceof SelectedFieldsLockingPolicy) {
DatabaseField field = ((SelectedFieldsLockingPolicy) descriptor.getOptimisticLockingPolicy()).getLockFields().get(0);
if (interaction.getInputRow() != null) {
version = interaction.getInputRow().get(field);
}
}
}
}
if (version instanceof Version) {
noSqlSpec.setVersion((Version) version);
} else if (version instanceof byte[]) {
noSqlSpec.setVersion(Version.fromByteArray((byte[]) version));
}
spec = noSqlSpec;
}
return spec;
}
use of org.eclipse.persistence.eis.EISException in project eclipselink by eclipse-ee4j.
the class OracleNoSQLPlatform method setDOMInRecord.
/**
* Stores the XML DOM value into the record.
* XML is stored in Oracle NoSQL but storing the XML text, keyed on the object's {@literal "<dataTypeName>/<id>"}.
*/
@Override
public void setDOMInRecord(Element dom, jakarta.resource.cci.Record record, EISInteraction interaction, EISAccessor accessor) {
OracleNoSQLRecord noSqlRecord = (OracleNoSQLRecord) record;
org.eclipse.persistence.oxm.record.DOMRecord domRecord = new org.eclipse.persistence.oxm.record.DOMRecord(dom);
domRecord.setSession(interaction.getQuery().getSession());
// Create the key from the objects id.
ClassDescriptor descriptor = interaction.getQuery().getDescriptor();
if (descriptor == null) {
throw new EISException("XMLInteraction is only valid for object queries, use MappedIneraction for native queries: " + interaction);
}
Object key = createMajorKey(descriptor, domRecord, interaction, accessor);
noSqlRecord.put(key, domRecord.transformToXML().getBytes());
}
use of org.eclipse.persistence.eis.EISException in project eclipselink by eclipse-ee4j.
the class CciJMSInteraction method executeReceiveInteraction.
/**
* Execute the receive message interaction.
* Only text messages of XML content are supported.
*
* @param spec - the receive interaction spec
* @param input - the input record
* @param output - the output record
*/
protected void executeReceiveInteraction(CciJMSReceiveInteractionSpec spec, CciJMSRecord input, CciJMSRecord output) throws EISException {
try {
Queue queue;
QueueSession qSession = (QueueSession) connection.getSession();
if (spec.hasDestinationURL()) {
queue = (Queue) new InitialContext().lookup(spec.getDestinationURL());
} else {
queue = qSession.createQueue(spec.getDestination());
}
// create the receiver using a user-defined message selector, if one exists
QueueReceiver receiver;
if (spec.hasMessageSelector()) {
receiver = qSession.createReceiver(queue, spec.getFormattedMessageSelector());
} else {
receiver = qSession.createReceiver(queue);
}
Message msg = receiver.receive(spec.getTimeout());
// check for timeout
if (msg == null) {
throw EISException.timeoutOccurred();
}
output.add(msg);
} catch (Exception ex) {
throw EISException.createException(ex);
}
}
use of org.eclipse.persistence.eis.EISException in project eclipselink by eclipse-ee4j.
the class CciJMSInteraction method executeSendInteraction.
/**
* Execute the send message interaction.
* Only text messages of XML content are supported.
*
* @param spec - the send interaction spec
* @param input - the input record
* @param output - the output record
*/
protected void executeSendInteraction(CciJMSSendInteractionSpec spec, CciJMSRecord input, CciJMSRecord output) throws EISException {
// verify input record
if (input.size() != 1) {
throw EISException.invalidInput();
}
try {
Queue queue;
QueueSession qSession = (QueueSession) connection.getSession();
if (spec.hasDestinationURL()) {
queue = (Queue) new InitialContext().lookup(spec.getDestinationURL());
} else {
queue = qSession.createQueue(spec.getDestination());
}
Message msg = createMessage(input.get(0), qSession);
if (spec.hasMessageSelector()) {
msg.setJMSCorrelationID(spec.getMessageSelector());
}
if (spec.hasReplyToDestinationURL()) {
msg.setJMSReplyTo((Queue) new InitialContext().lookup(spec.getReplyToDestinationURL()));
} else {
msg.setJMSReplyTo(qSession.createQueue(spec.getReplyToDestination()));
}
qSession.createSender(queue).send(msg);
} catch (Exception ex) {
throw EISException.createException(ex);
}
}
use of org.eclipse.persistence.eis.EISException in project eclipselink by eclipse-ee4j.
the class MongoPlatform method appendExpressionToSortRow.
/**
* Append the order by expression to the sort row.
*/
protected void appendExpressionToSortRow(Expression expression, AbstractRecord row, DatabaseQuery query) {
if (expression.isFunctionExpression()) {
FunctionExpression function = (FunctionExpression) expression;
if (function.getOperator().getSelector() == ExpressionOperator.Ascending) {
Object field = extractValueFromExpression(function.getChildren().get(0), query);
row.put(field, 1);
} else if (function.getOperator().getSelector() == ExpressionOperator.Descending) {
Object field = extractValueFromExpression(function.getChildren().get(0), query);
row.put(field, -1);
} else {
throw new EISException("Query too complex for Mongo translation, order by [" + expression + "] not supported in query: " + query);
}
} else {
Object field = extractValueFromExpression(expression, query);
row.put(field, 1);
}
}
Aggregations