use of org.teiid.core.TeiidException in project teiid by teiid.
the class TestProcessor method helpProcessException.
private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
TupleBuffer tsId = null;
BufferManager bufferMgr = null;
try {
bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("0", "test", null, null, 1);
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
tsId = collector.collectTuples();
// $NON-NLS-1$
fail("Expected error during processing, but got none.");
} catch (TeiidException e) {
// ignore - this is expected
if (expectedErrorMessage != null) {
assertEquals(expectedErrorMessage, e.getMessage());
}
} finally {
if (tsId != null) {
tsId.remove();
}
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class JPQLUpdateExecution method handleInsert.
private Object handleInsert(Insert insert) throws TranslatorException {
try {
String entityClassName = insert.getTable().getMetadataObject().getProperty(JPAMetadataProcessor.ENTITYCLASS, false);
Object entity = ReflectionHelper.create(entityClassName, null, this.executionContext.getCommandContext().getVDBClassLoader());
List<ColumnReference> columns = insert.getColumns();
List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
if (columns.size() != values.size()) {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14007));
}
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i).getMetadataObject();
Object value = values.get(i);
// do not add the derived columns
String name = column.getProperty(JPAMetadataProcessor.KEY_ASSOSIATED_WITH_FOREIGN_TABLE, false);
if (name == null) {
if (value instanceof Literal) {
Literal literalValue = (Literal) value;
PropertiesUtils.setBeanProperty(entity, column.getName(), literalValue.getValue());
} else {
PropertiesUtils.setBeanProperty(entity, column.getName(), value);
}
}
}
return entity;
} catch (TeiidException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TestCriteriaCapabilityValidatorVisitor method helpTestVisitorWithCommand.
// Assume there is a wrapped command - this will allow subqueries to be properly resolved
public void helpTestVisitorWithCommand(String sql, Object modelID, TransformationMetadata metadata, CapabilitiesFinder capFinder, boolean isValid, boolean expectException) {
try {
Command command = QueryParser.getQueryParser().parseCommand(sql);
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
assertEquals("Got incorrect isValid flag", isValid, CriteriaCapabilityValidatorVisitor.canPushLanguageObject(command, modelID, metadata, capFinder, null));
} catch (QueryMetadataException e) {
if (!expectException) {
throw new RuntimeException(e);
}
} catch (TeiidException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class ValidationVisitor method validateUpdate.
protected void validateUpdate(Update update) {
try {
UpdateInfo info = update.getUpdateInfo();
// list of elements that are being updated
for (SetClause entry : update.getChangeList().getClauses()) {
ElementSymbol elementID = entry.getSymbol();
// Check that left side element is updatable
if (!getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.UPDATE)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0059", elementID), elementID);
}
Object metadataID = elementID.getMetadataID();
if (getMetadata().isMultiSourceElement(metadataID)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("multi_source_update_not_allowed", elementID), elementID);
}
// Check that right expression is a constant and is non-null
Expression value = entry.getValue();
if (EvaluatableVisitor.isFullyEvaluatable(value, true)) {
try {
value = new Constant(Evaluator.evaluate(value));
} catch (ExpressionEvaluationException err) {
}
}
if (value instanceof Constant) {
// If value is null, check that element supports this as a nullable column
if (((Constant) value).isNull() && !getMetadata().elementSupports(elementID.getMetadataID(), SupportConstants.Element.NULL)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0060", SQLStringVisitor.getSQLString(elementID)), elementID);
}
// end of if
}
}
if (info != null && info.isInherentUpdate()) {
validateUpdate(update, Command.TYPE_UPDATE, info);
Set<ElementSymbol> updateCols = update.getChangeList().getClauseMap().keySet();
if (!info.hasValidUpdateMapping(updateCols)) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30376, updateCols), update);
}
}
} catch (TeiidException e) {
handleException(e, update);
}
validateSetClauseList(update.getChangeList());
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class CommandContext method getConnection.
@Override
public TeiidConnection getConnection() throws TeiidSQLException {
LocalProfile ep = getDQPWorkContext().getConnectionProfile();
// TODO: this is problematic as the client properties are not conveyed
Properties info = new Properties();
info.put(LocalProfile.DQP_WORK_CONTEXT, getDQPWorkContext());
// $NON-NLS-1$ //$NON-NLS-2$
String url = "jdbc:teiid:" + getVdbName() + "." + getVdbVersion();
ServerConnection sc;
try {
sc = ep.createServerConnection(info);
} catch (TeiidException e) {
throw TeiidSQLException.create(e);
}
return new ConnectionImpl(sc, info, url) {
@Override
public void close() throws SQLException {
// just ignore
}
@Override
public void rollback() throws SQLException {
// just ignore
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
// TODO: detect if attempted set conflicts with current txn state
throw new TeiidSQLException();
}
@Override
public void commit() throws SQLException {
throw new TeiidSQLException();
}
@Override
public void changeUser(String userName, String newPassword) throws SQLException {
throw new TeiidSQLException();
}
@Override
protected synchronized long nextRequestID() {
// need to choose ids that won't conflict with the user connection
return -(long) (Math.random() * Long.MAX_VALUE);
}
};
}
Aggregations