use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TestProcErrors method testExceptionAndWarning.
@Test
public void testExceptionAndWarning() throws Exception {
String ddl = "create virtual procedure vproc (x integer) returns integer as begin declare exception e = sqlexception 'hello'; raise sqlwarning e; raise sqlexception 'hello world' sqlstate 'abc', 1 chain e; end;";
TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
// $NON-NLS-1$
String sql = "call vproc(1)";
ProcessorPlan plan = getProcedurePlan(sql, tm);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
try {
helpTestProcess(plan, null, dataManager, tm);
fail();
} catch (TeiidProcessingException e) {
TeiidSQLException tsw = (TeiidSQLException) plan.getContext().getAndClearWarnings().get(0);
assertEquals("hello", tsw.getMessage());
assertEquals(e.getCause().getCause(), tsw);
TeiidSQLException tse = (TeiidSQLException) e.getCause();
assertEquals("hello world", tse.getMessage());
assertEquals("abc", tse.getSQLState());
assertEquals(1, tse.getErrorCode());
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TestJoinNode method testSortMergeWithDistinct.
@Test
public void testSortMergeWithDistinct() throws TeiidComponentException, TeiidProcessingException {
this.leftTuples = new List[] { Arrays.asList(1, 2), Arrays.asList(1, 3) };
this.rightTuples = new List[] { Arrays.asList(1, 4), Arrays.asList(1, 5) };
expected = new List[] { Arrays.asList(1, 2, 1, 4), Arrays.asList(1, 2, 1, 5), Arrays.asList(1, 3, 1, 4), Arrays.asList(1, 3, 1, 5) };
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("e2");
es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List leftElements = Arrays.asList(es1, es2);
leftNode = new BlockingFakeRelationalNode(1, leftTuples);
leftNode.setElements(leftElements);
// $NON-NLS-1$
ElementSymbol es3 = new ElementSymbol("e3");
es3.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es4 = new ElementSymbol("e4");
es4.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List rightElements = Arrays.asList(es3, es4);
rightNode = new BlockingFakeRelationalNode(2, rightTuples) {
@Override
public boolean hasBuffer() {
return false;
}
@Override
public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
fail();
throw new AssertionError();
}
};
rightNode.setElements(rightElements);
List joinElements = new ArrayList();
joinElements.addAll(leftElements);
joinElements.addAll(rightElements);
joinType = JoinType.JOIN_INNER;
joinStrategy = new MergeJoinStrategy(SortOption.SORT_DISTINCT, SortOption.SORT_DISTINCT, false);
join = new JoinNode(3);
join.setElements(joinElements);
join.setJoinType(joinType);
join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es3));
join.setJoinStrategy(joinStrategy);
helpTestJoinDirect(expected, 100, 100000);
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class ODataSQLBuilder method insert.
public Insert insert(EdmEntityType entityType, Entity entity, List<UriParameter> keys, boolean prepared) throws TeiidException {
Table entityTable = findTable(entityType.getName(), this.metadata);
DocumentNode resource = new DocumentNode(entityTable, new GroupSymbol(entityTable.getFullName()), entityType);
List<Reference> referenceValues = new ArrayList<Reference>();
List<Constant> constantValues = new ArrayList<Constant>();
Insert insert = new Insert();
insert.setGroup(resource.getGroupSymbol());
if (keys != null) {
for (UriParameter key : keys) {
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(key.getName());
Column column = entityTable.getColumnByName(edmProperty.getName());
Object propertyValue = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), key.getText());
Property existing = entity.getProperty(edmProperty.getName());
if (existing == null || (existing.getValue() == null && propertyValue != null) || (existing.getValue() != null && propertyValue == null) || (existing.getValue() != null && !existing.getValue().equals(propertyValue))) {
throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16048, edmProperty.getName()));
}
}
}
int i = 0;
for (Property prop : entity.getProperties()) {
EdmProperty edmProp = (EdmProperty) entityType.getProperty(prop.getName());
Column column = entityTable.getColumnByName(edmProp.getName());
insert.addVariable(new ElementSymbol(column.getName(), resource.getGroupSymbol()));
if (prepared) {
referenceValues.add(new Reference(i++));
this.params.add(asParam(edmProp, prop.getValue()));
} else {
constantValues.add(new Constant(asParam(edmProp, prop.getValue()).getValue()));
}
}
if (prepared) {
insert.setValues(referenceValues);
} else {
insert.setValues(constantValues);
}
return insert;
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class ODataSQLBuilder method processExpandOption.
private void processExpandOption(ExpandOption option, DocumentNode node, Query outerQuery, int expandLevel, Integer cyclicLevel) throws TeiidException {
checkExpandLevel(expandLevel);
int starLevels = 0;
HashSet<String> seen = new HashSet<String>();
for (ExpandItem ei : option.getExpandItems()) {
if (ei.getSearchOption() != null) {
throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16035, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16035));
}
Integer levels = null;
if (cyclicLevel != null) {
levels = cyclicLevel - 1;
} else if (ei.getLevelsOption() != null) {
if (ei.getLevelsOption().isMax()) {
levels = MAX_EXPAND_LEVEL - expandLevel + 1;
} else {
levels = ei.getLevelsOption().getValue();
checkExpandLevel(expandLevel + levels - 1);
}
}
ExpandSQLBuilder esb = new ExpandSQLBuilder(ei);
EdmNavigationProperty property = esb.getNavigationProperty();
if (property == null) {
if (ei.isStar()) {
if (starLevels > 0) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, // $NON-NLS-1$
ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, "*"));
}
if (levels != null) {
starLevels = levels;
} else {
starLevels = 1;
}
continue;
}
throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16057, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16057));
}
if (!seen.add(property.getName())) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, property.getName()));
}
// always pass in the root as the parent as that seems to be the definition of the current context
// if instead it should refer to the parent expands, then we would pass in the node instead
ExpandDocumentNode expandResource = ExpandDocumentNode.buildExpand(property, this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService, this.context);
node.addExpand(expandResource);
// process $filter
if (ei.getFilterOption() != null) {
Expression expandCriteria = processFilterOption(ei.getFilterOption(), expandResource);
expandResource.addCriteria(expandCriteria);
}
OrderBy expandOrder = null;
if (ei.getOrderByOption() != null) {
expandOrder = new OrderBy();
processOrderBy(expandOrder, ei.getOrderByOption().getOrders(), expandResource);
} else {
expandOrder = expandResource.addDefaultOrderBy();
}
// process $select
processSelectOption(ei.getSelectOption(), expandResource, this.reference);
if (ei.getSkipOption() != null) {
expandResource.setSkip(ei.getSkipOption().getValue());
}
if (ei.getTopOption() != null) {
expandResource.setTop(ei.getTopOption().getValue());
}
Query query = expandResource.buildQuery();
if (ei.getExpandOption() != null) {
processExpandOption(ei.getExpandOption(), expandResource, query, expandLevel + 1, null);
} else if (levels != null) {
// self reference check
if (!property.getType().getFullQualifiedName().equals(node.getEdmEntityType().getFullQualifiedName())) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16060, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16060, node.getEdmEntityType().getFullQualifiedName(), property.getType().getFullQualifiedName()));
}
if (levels > 1) {
ExpandOptionImpl eoi = new ExpandOptionImpl();
eoi.addExpandItem(ei);
processExpandOption(eoi, expandResource, query, expandLevel + 1, levels);
}
}
buildAggregateQuery(node, outerQuery, expandResource, expandOrder, query, property);
}
if (starLevels > 0) {
List<ExpandNode> starExpand = new ArrayList<TeiidServiceHandler.ExpandNode>();
EdmEntityType edmEntityType = node.getEdmEntityType();
buildExpandGraph(seen, starExpand, edmEntityType, starLevels - 1);
if (!starExpand.isEmpty()) {
processExpand(starExpand, node, outerQuery, expandLevel);
}
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class OperationResponseImpl method getComplexProperty.
private ComplexValue getComplexProperty(ResultSet rs) throws SQLException {
HashMap<Integer, Property> properties = new HashMap<Integer, Property>();
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
Object value = rs.getObject(i + 1);
String propName = rs.getMetaData().getColumnLabel(i + 1);
EdmElement element = ((EdmComplexType) this.procedureReturn.getReturnType().getType()).getProperty(propName);
if (!(element instanceof EdmProperty) && !((EdmProperty) element).isPrimitive()) {
throw new SQLException(new TeiidNotImplementedException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16024)));
}
EdmPropertyImpl edmProperty = (EdmPropertyImpl) element;
Property property;
try {
property = EntityCollectionResponse.buildPropery(propName, (SingletonPrimitiveType) edmProperty.getType(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isCollection(), value);
properties.put(i, property);
} catch (IOException e) {
throw new SQLException(e);
} catch (TeiidProcessingException e) {
throw new SQLException(e);
}
}
// filter those columns out.
return createComplex("result", properties.values());
}
Aggregations