use of org.teiid.client.RequestMessage in project teiid by teiid.
the class StatementImpl method executeSql.
@SuppressWarnings("unchecked")
protected ResultsFuture<Boolean> executeSql(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode, boolean synch, RequestOptions options, boolean autoGenerateKeys) throws SQLException {
checkStatement();
resetExecutionState();
if (options != null) {
if (options.isContinuous()) {
if (!this.driverConnection.getServerConnection().supportsContinuous()) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("JDBC.continuous"));
}
if (this.getResultSetType() != ResultSet.TYPE_FORWARD_ONLY) {
// $NON-NLS-1$
String msg = JDBCPlugin.Util.getString("JDBC.forward_only_resultset");
throw new TeiidSQLException(msg);
}
if (resultsMode == ResultsMode.EITHER) {
resultsMode = ResultsMode.RESULTSET;
} else if (resultsMode == ResultsMode.UPDATECOUNT) {
// $NON-NLS-1$
String msg = JDBCPlugin.Util.getString("JDBC.forward_only_resultset");
throw new TeiidSQLException(msg);
}
}
}
if (logger.isLoggable(Level.FINER)) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
logger.finer("Executing: requestID " + getCurrentRequestID() + " commands: " + Arrays.toString(commands) + " expecting: " + resultsMode);
}
if (commands.length == 1) {
Matcher match = SET_STATEMENT.matcher(commands[0]);
if (match.matches()) {
if (resultsMode == ResultsMode.RESULTSET) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("StatementImpl.set_result_set"));
}
String val = match.group(2);
String key = unescapeId(val);
String value = match.group(3);
if (value != null && value.startsWith("\'") && value.endsWith("\'")) {
// $NON-NLS-1$ //$NON-NLS-2$
value = value.substring(1, value.length() - 1);
// $NON-NLS-1$ //$NON-NLS-2$
value = StringUtil.replaceAll(value, "''", "'");
}
if (match.group(1) != null) {
// payload case
Properties p = this.getMMConnection().getPayload();
if (p == null) {
p = new Properties();
this.getMMConnection().setPayload(p);
}
p.setProperty(key, value);
} else if (val == key && "SESSION AUTHORIZATION".equalsIgnoreCase(key)) {
// $NON-NLS-1$
this.getMMConnection().changeUser(value, this.getMMConnection().getPassword());
} else if (key.equalsIgnoreCase(TeiidURL.CONNECTION.PASSWORD)) {
this.getMMConnection().setPassword(value);
} else if (ExecutionProperties.NEWINSTANCE.equalsIgnoreCase(key)) {
if (Boolean.valueOf(value)) {
this.getMMConnection().getServerConnection().cleanUp();
}
} else {
this.driverConnection.setExecutionProperty(key, value);
}
this.updateCounts = new int[] { 0 };
return booleanFuture(false);
}
match = SET_CHARACTERISTIC_STATEMENT.matcher(commands[0]);
if (match.matches()) {
String value = match.group(1);
if (StringUtil.endsWithIgnoreCase(value, "uncommitted")) {
// $NON-NLS-1$
this.getMMConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
} else if (StringUtil.endsWithIgnoreCase(value, "committed")) {
// $NON-NLS-1$
this.getMMConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
} else if (StringUtil.startsWithIgnoreCase(value, "repeatable")) {
// $NON-NLS-1$
this.getMMConnection().setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
} else if ("serializable".equalsIgnoreCase(value)) {
// $NON-NLS-1$
this.getMMConnection().setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
}
this.updateCounts = new int[] { 0 };
return booleanFuture(false);
}
match = TRANSACTION_STATEMENT.matcher(commands[0]);
if (match.matches()) {
// $NON-NLS-1$
logger.finer("Executing as transaction statement");
if (resultsMode == ResultsMode.RESULTSET) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("StatementImpl.set_result_set"));
}
String command = match.group(1);
Boolean commit = null;
if (StringUtil.startsWithIgnoreCase(command, "start")) {
// $NON-NLS-1$
// TODO: this should force a start and through an exception if we're already in a txn
this.getConnection().setAutoCommit(false);
} else if (command.equalsIgnoreCase("commit")) {
// $NON-NLS-1$
commit = true;
if (synch) {
this.getConnection().setAutoCommit(true);
}
} else if (command.equalsIgnoreCase("rollback")) {
// $NON-NLS-1$
commit = false;
if (synch || !this.getConnection().isInLocalTxn()) {
this.getConnection().rollback(false);
}
}
this.updateCounts = new int[] { 0 };
if (commit != null && !synch) {
ResultsFuture<?> pending = this.getConnection().submitSetAutoCommitTrue(commit);
final ResultsFuture<Boolean> result = new ResultsFuture<Boolean>();
pending.addCompletionListener(new ResultsFuture.CompletionListener() {
@Override
public void onCompletion(ResultsFuture future) {
try {
future.get();
result.getResultsReceiver().receiveResults(false);
} catch (Throwable t) {
result.getResultsReceiver().exceptionOccurred(t);
}
}
});
return result;
}
return booleanFuture(false);
}
match = SHOW_STATEMENT.matcher(commands[0]);
if (match.matches()) {
// $NON-NLS-1$
logger.finer("Executing as show statement");
if (resultsMode == ResultsMode.UPDATECOUNT) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("StatementImpl.show_update_count"));
}
return executeShow(match);
}
}
final RequestMessage reqMessage = createRequestMessage(commands, isBatchedCommand, resultsMode);
reqMessage.setReturnAutoGeneratedKeys(autoGenerateKeys);
reqMessage.setRequestOptions(options);
ResultsFuture<ResultsMessage> pendingResult = execute(reqMessage, synch);
final ResultsFuture<Boolean> result = new ResultsFuture<Boolean>();
pendingResult.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {
@Override
public void onCompletion(ResultsFuture<ResultsMessage> future) {
try {
postReceiveResults(reqMessage, future.get());
result.getResultsReceiver().receiveResults(hasResultSet());
} catch (Throwable t) {
result.getResultsReceiver().exceptionOccurred(t);
}
}
});
if (synch) {
try {
pendingResult.get(queryTimeoutMS == 0 ? Integer.MAX_VALUE : queryTimeoutMS, TimeUnit.MILLISECONDS);
// throw an exception if needed
result.get();
return result;
} catch (ExecutionException e) {
if (e.getCause() instanceof SQLException) {
throw (SQLException) e.getCause();
}
if (e.getCause() != null) {
throw TeiidSQLException.create(e.getCause());
}
throw TeiidSQLException.create(e);
} catch (InterruptedException e) {
timeoutOccurred();
} catch (TimeoutException e) {
timeoutOccurred();
}
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("MMStatement.Timeout_before_complete"));
}
return result;
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class CallableStatementImpl method createRequestMessage.
@Override
protected RequestMessage createRequestMessage(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode) {
RequestMessage message = super.createRequestMessage(commands, isBatchedCommand, resultsMode);
message.setStatementType(StatementType.CALLABLE);
return message;
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class PreparedStatementImpl method createRequestMessage.
@Override
protected RequestMessage createRequestMessage(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode) {
RequestMessage message = super.createRequestMessage(commands, false, resultsMode);
message.setStatementType(StatementType.PREPARED);
message.setParameterValues(isBatchedCommand ? getParameterValuesList() : getParameterValues());
message.setBatchedUpdate(isBatchedCommand);
message.setCommand(this.command);
return message;
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class DataTierManagerImpl method createRequest.
private AtomicRequestMessage createRequest(RequestWorkItem workItem, Command command, String modelName, String connectorBindingId, int nodeID) throws TeiidComponentException {
RequestMessage request = workItem.requestMsg;
// build the atomic request based on original request + context info
AtomicRequestMessage aqr = new AtomicRequestMessage(request, workItem.getDqpWorkContext(), nodeID);
aqr.setCommand(command);
aqr.setModelName(modelName);
aqr.setMaxResultRows(requestMgr.getMaxSourceRows());
aqr.setExceptionOnMaxRows(requestMgr.isExceptionOnMaxSourceRows());
aqr.setPartialResults(request.supportsPartialResults());
aqr.setSerial(requestMgr.getUserRequestSourceConcurrency() == 1);
aqr.setTransactionContext(workItem.getTransactionContext());
aqr.setBufferManager(this.getBufferManager());
if (connectorBindingId == null) {
VDBMetaData vdb = workItem.getDqpWorkContext().getVDB();
ModelMetaData model = vdb.getModel(modelName);
List<String> bindings = model.getSourceNames();
if (bindings == null || bindings.size() != 1) {
// this should not happen, but it did occur when setting up the SystemAdmin models
throw new TeiidComponentException(QueryPlugin.Event.TEIID30554, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30554, modelName, workItem.getDqpWorkContext().getVdbName(), workItem.getDqpWorkContext().getVdbVersion()));
}
connectorBindingId = bindings.get(0);
// $NON-NLS-1$
Assertion.isNotNull(connectorBindingId, "could not obtain connector id");
}
aqr.setConnectorName(connectorBindingId);
return aqr;
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class TestConnectorWorkItem method createNewAtomicRequestMessage.
static AtomicRequestMessage createNewAtomicRequestMessage(int requestid, int nodeid) throws Exception {
RequestMessage rm = new RequestMessage();
DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(EXAMPLE_BQT, RealMetadataFactory.exampleBQTVDB());
workContext.getSession().setSessionId(String.valueOf(1));
// $NON-NLS-1$
workContext.getSession().setUserName("foo");
AtomicRequestMessage request = new AtomicRequestMessage(rm, workContext, nodeid);
// $NON-NLS-1$
request.setCommand(helpGetCommand("SELECT BQT1.SmallA.INTKEY FROM BQT1.SmallA", EXAMPLE_BQT));
request.setRequestID(new RequestID(requestid));
// $NON-NLS-1$
request.setConnectorName("testing");
request.setFetchSize(5);
request.setCommandContext(new CommandContext());
return request;
}
Aggregations