use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class InfinispanUpdateExecution method insertRow.
private void insertRow(RemoteCache<Object, Object> cache, Object rowKey, InfinispanDocument row, boolean upsert) throws TranslatorException {
// this is always single row; putIfAbsent is not working correctly.
InfinispanDocument previous = (InfinispanDocument) cache.get(rowKey);
if (previous != null && !upsert) {
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25005, previous.getName(), rowKey));
}
if (upsert && previous != null) {
previous.merge(row);
previous = (InfinispanDocument) cache.replace(rowKey, previous);
} else {
previous = row;
previous = (InfinispanDocument) cache.put(rowKey, previous);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class JDBCProcedureExecution method execute.
@Override
public void execute() throws TranslatorException {
Call procedure = (Call) command;
columnDataTypes = procedure.getResultSetColumnTypes();
// translate command
TranslatedCommand translatedComm = translateCommand(procedure);
// create statement or CallableStatement and execute
String sql = translatedComm.getSql();
try {
// create parameter index map
CallableStatement cstmt = getCallableStatement(sql);
this.results = this.executionFactory.executeStoredProcedure(cstmt, translatedComm.getPreparedValues(), procedure.getReturnType());
addStatementWarnings();
} catch (SQLException e) {
throw new TranslatorException(JDBCPlugin.Event.TEIID11004, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11004, sql));
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class JDBCQueryExecution method next.
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
try {
if (results.next()) {
// New row for result set
List<Object> vals = new ArrayList<Object>(columnDataTypes.length);
for (int i = 0; i < columnDataTypes.length; i++) {
// Convert from 0-based to 1-based
Object value = this.executionFactory.retrieveValue(results, i + 1, columnDataTypes[i]);
vals.add(value);
}
return vals;
}
} catch (SQLException e) {
throw new TranslatorException(e, // $NON-NLS-1$
JDBCPlugin.Util.getString("JDBCTranslator.Unexpected_exception_translating_results___8", e.getMessage()));
}
return null;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class JDBCUpdateExecution method execute.
public int[] execute(BatchedUpdates batchedCommand) throws TranslatorException {
boolean succeeded = false;
boolean commitType = false;
if (batchedCommand.isSingleResult()) {
commitType = getAutoCommit(null);
}
Command[] commands = batchedCommand.getUpdateCommands().toArray(new Command[batchedCommand.getUpdateCommands().size()]);
result = new int[commands.length];
TranslatedCommand tCommand = null;
int batchStart = 0;
int i = 0;
try {
// before at the end of the command execution.
if (commitType) {
connection.setAutoCommit(false);
}
List<TranslatedCommand> executedCmds = new ArrayList<TranslatedCommand>();
TranslatedCommand previousCommand = null;
for (; i < commands.length; i++) {
tCommand = translateCommand(commands[i]);
if (tCommand.isPrepared()) {
PreparedStatement pstmt = null;
if (previousCommand != null && previousCommand.isPrepared() && previousCommand.getSql().equals(tCommand.getSql())) {
pstmt = (PreparedStatement) statement;
} else {
if (!executedCmds.isEmpty()) {
executeBatch(i, result, executedCmds);
batchStart = i;
}
pstmt = getPreparedStatement(tCommand.getSql());
}
bind(pstmt, tCommand.getPreparedValues(), null);
pstmt.addBatch();
} else {
if (previousCommand != null && previousCommand.isPrepared()) {
executeBatch(i, result, executedCmds);
batchStart = i;
getStatement();
}
if (statement == null) {
getStatement();
}
statement.addBatch(tCommand.getSql());
}
executedCmds.add(tCommand);
previousCommand = tCommand;
}
if (!executedCmds.isEmpty()) {
executeBatch(commands.length, result, executedCmds);
}
succeeded = true;
} catch (TranslatorException e) {
if (batchedCommand.isSingleResult()) {
throw e;
}
int size = i + 1;
// if there is a BatchUpdateException, there are more update counts to accumulate
if (e.getCause() instanceof BatchUpdateException) {
BatchUpdateException bue = (BatchUpdateException) e.getCause();
int[] batchResults = bue.getUpdateCounts();
for (int j = 0; j < batchResults.length; j++) {
result[batchStart + j] = batchResults[j];
}
size = batchStart + batchResults.length;
} else {
size = batchStart;
}
// resize the result and throw exception
throw new TranslatorBatchException(e, Arrays.copyOf(result, size));
} catch (SQLException e) {
if (batchedCommand.isSingleResult()) {
throw new JDBCExecutionException(JDBCPlugin.Event.TEIID11011, e, tCommand);
}
// resize the result and throw exception
throw new TranslatorBatchException(e, Arrays.copyOf(result, batchStart));
} finally {
if (commitType) {
restoreAutoCommit(!succeeded, null);
}
}
return result;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class TestEmbeddedServer method testImportExcept.
@Ignore("limit to/exclude not yet implemented")
@Test
public void testImportExcept() throws Exception {
es.start(new EmbeddedConfiguration());
es.addMetadataRepository("x", new MetadataRepository() {
@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory, String text) throws TranslatorException {
assertEquals("helloworld1,other", factory.getModelProperties().get("importer.excludeTables"));
Table t = factory.addTable("helloworld");
t.setVirtual(true);
factory.addColumn("col", "string", t);
t.setSelectTransformation("select 'HELLO WORLD'");
}
});
String externalDDL = "CREATE DATABASE test VERSION '1';" + "USE DATABASE test VERSION '1';" + "CREATE VIRTUAL SCHEMA test2;" + "IMPORT FOREIGN SCHEMA public except (helloworld1, other) FROM REPOSITORY x INTO test2;";
es.deployVDB(new ByteArrayInputStream(externalDDL.getBytes(Charset.forName("UTF-8"))), true);
ResultSet rs = es.getDriver().connect("jdbc:teiid:test", null).createStatement().executeQuery("select * from helloworld");
rs.next();
assertEquals("HELLO WORLD", rs.getString(1));
}
Aggregations