use of org.teiid.query.parser.QueryParser in project teiid by teiid.
the class TestAuthorizationValidationVisitor method helpTest.
private void helpTest(String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb, DataPolicyMetadata... roles) throws QueryParserException, QueryResolverException, TeiidComponentException {
QueryParser parser = QueryParser.getQueryParser();
Command command = parser.parseCommand(sql);
QueryResolver.resolveCommand(command, metadata);
DataRolePolicyDecider dataRolePolicyDecider = createPolicyDecider(metadata, vdb, roles);
// $NON-NLS-1$
AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(dataRolePolicyDecider, context);
ValidatorReport report = Validator.validate(command, metadata, visitor);
if (report.hasItems()) {
ValidatorFailure firstFailure = report.getItems().iterator().next();
// strings
Set<String> expected = new HashSet<String>(Arrays.asList(expectedInaccesible));
// elements
Set<String> actual = new HashSet<String>();
for (LanguageObject obj : firstFailure.getInvalidObjects()) {
if (obj instanceof ElementSymbol) {
actual.add(((ElementSymbol) obj).getName());
} else {
actual.add(obj.toString());
}
}
assertEquals(expected, actual);
} else if (expectedInaccesible.length > 0) {
// $NON-NLS-1$
fail("Expected inaccessible objects, but got none.");
}
}
use of org.teiid.query.parser.QueryParser in project teiid by teiid.
the class TestProcedureImpl method example.
public static Call example() throws Exception {
// $NON-NLS-1$
String sql = "EXEC pm1.sq3('x', 1)";
Command command = new QueryParser().parseCommand(sql);
QueryResolver.resolveCommand(command, TstLanguageBridgeFactory.metadata);
return TstLanguageBridgeFactory.factory.translate((StoredProcedure) command);
}
use of org.teiid.query.parser.QueryParser in project teiid by teiid.
the class TestValidator method testDefect9917.
@Test
public void testDefect9917() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
// $NON-NLS-1$
String sql = "SELECT lookup('pm1.g1', 'e1a', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
Command command = new QueryParser().parseCommand(sql);
try {
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
fail("Did not get exception");
} catch (QueryResolverException e) {
// expected
}
// $NON-NLS-1$
sql = "SELECT lookup('pm1.g1a', 'e1', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
command = new QueryParser().parseCommand(sql);
try {
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
fail("Did not get exception");
} catch (QueryResolverException e) {
// expected
}
}
use of org.teiid.query.parser.QueryParser in project teiid by teiid.
the class TestQueryRewriter method testStoredProcedure_9822.
// defect 9822
@Test
public void testStoredProcedure_9822() throws Exception {
QueryParser parser = new QueryParser();
// $NON-NLS-1$
Command command = parser.parseCommand("exec pm1.sp4(5)");
// resolve
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
QueryResolver.resolveCommand(command, metadata);
// rewrite
Command rewriteCommand = QueryRewriter.rewrite(command, metadata, null);
Collection<SPParameter> parameters = ((StoredProcedure) rewriteCommand).getParameters();
for (SPParameter param : parameters) {
if (param.getParameterType() == ParameterInfo.IN || param.getParameterType() == ParameterInfo.INOUT) {
assertTrue(param.getExpression() instanceof Constant);
}
}
}
use of org.teiid.query.parser.QueryParser in project teiid by teiid.
the class Request method parseCommand.
private Command parseCommand() throws QueryParserException {
if (requestMsg.getCommand() != null) {
return (Command) requestMsg.getCommand();
}
String[] commands = requestMsg.getCommands();
ParseInfo parseInfo = createParseInfo(this.requestMsg, this.workContext.getSession());
QueryParser queryParser = QueryParser.getQueryParser();
if (requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || !requestMsg.isBatchedUpdate()) {
String commandStr = commands[0];
if (preParser != null) {
commandStr = preParser.preParse(commandStr, this.context);
}
return queryParser.parseCommand(commandStr, parseInfo);
}
List<Command> parsedCommands = new ArrayList<Command>(commands.length);
for (int i = 0; i < commands.length; i++) {
String updateCommand = commands[i];
if (preParser != null) {
updateCommand = preParser.preParse(updateCommand, this.context);
}
parsedCommands.add(queryParser.parseCommand(updateCommand, parseInfo));
}
return new BatchedUpdateCommand(parsedCommands);
}
Aggregations