public void visit(Call obj) { visitNodes(obj.getArguments()); }
@Override public ProcedureExecution createProcedureExecution(Call command, ExecutionContext executionContext, RuntimeMetadata metadata, LdapContext connection) throws TranslatorException { String nativeQuery = command.getMetadataObject().getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false); if (nativeQuery != null) { if (nativeQuery.startsWith("search;")) { //$NON-NLS-1$ return new LDAPDirectSearchQueryExecution(command.getArguments(), this, executionContext, connection, nativeQuery, false); } return new LDAPDirectCreateUpdateDeleteQueryExecution(command.getArguments(), this, executionContext, connection, nativeQuery, false); } throw new TranslatorException("Missing native-query extension metadata."); //$NON-NLS-1$ }
private boolean setOutCursorType(Call call) { boolean set = false; for (Argument arg : call.getArguments()) { if (arg.getDirection() == Direction.OUT) { ProcedureParameter param = arg.getMetadataObject(); if (param != null && REF_CURSOR.equalsIgnoreCase(param.getNativeType())) { arg.setType(RefCursorType.class); set = true; } } } return set; }
public ProcedureBatchHandler(Call proc, ProcedureExecution procExec) { this.proc = proc; this.procExec = procExec; List<Argument> params = proc.getArguments(); resultSetCols = proc.getResultSetColumnTypes().length; if (proc.getReturnType() != null) { paramCols++; } if(params != null && !params.isEmpty()){ for (Argument param : params) { if(param.getDirection() == Direction.OUT || param.getDirection() == Direction.INOUT){ paramCols += 1; } } } if (paramCols > 0) { filler = Collections.nCopies(paramCols, null); } }
public ProcedureBatchHandler(Call proc, ProcedureExecution procExec) { this.proc = proc; this.procExec = procExec; List<Argument> params = proc.getArguments(); resultSetCols = proc.getResultSetColumnTypes().length; if (proc.getReturnType() != null) { paramCols++; } if(params != null && !params.isEmpty()){ for (Argument param : params) { if(param.getDirection() == Direction.OUT || param.getDirection() == Direction.INOUT){ paramCols += 1; } } } if (paramCols > 0) { filler = Collections.nCopies(paramCols, null); } }
public static Argument example(int index) throws Exception { Call procImpl = TestProcedureImpl.example(); return procImpl.getArguments().get(index); }
@Override public void execute(ProcedureExecutionParent procedureExecutionParent) throws TranslatorException { Call command = parent.getCommand(); List<Argument> params = command.getArguments(); Argument object = params.get(OBJECT); String objectName = (String) object.getArgumentValue().getValue(); Argument start = params.get(STARTDATE); Timestamp startTime = (Timestamp) start.getArgumentValue().getValue(); GregorianCalendar startCalendar = (GregorianCalendar) GregorianCalendar.getInstance(); startCalendar.setTime(startTime); Argument end = params.get(ENDDATE); Timestamp endTime = (Timestamp) end.getArgumentValue().getValue(); GregorianCalendar endCalendar = (GregorianCalendar) GregorianCalendar.getInstance(); endCalendar.setTime(endTime); deletedResult = parent.getConnection().getDeleted(objectName, startCalendar, endCalendar); }
public ProcedureBatchHandler(Call proc, ProcedureExecution procExec) { this.proc = proc; this.procExec = procExec; List<Argument> params = proc.getArguments(); resultSetCols = proc.getResultSetColumnTypes().length; if (proc.getReturnType() != null) { paramCols++; } if(params != null && !params.isEmpty()){ for (Argument param : params) { if(param.getDirection() == Direction.OUT || param.getDirection() == Direction.INOUT){ paramCols += 1; } } } if (paramCols > 0) { filler = Collections.nCopies(paramCols, null); } }
@Override public void execute(ProcedureExecutionParent procedureExecutionParent) throws TranslatorException { Call command = parent.getCommand(); List<Argument> params = command.getArguments(); Argument object = params.get(OBJECT); String objectName = (String) object.getArgumentValue().getValue(); Argument start = params.get(STARTDATE); Timestamp startTime = (Timestamp) start.getArgumentValue().getValue(); GregorianCalendar startCalendar = (GregorianCalendar) GregorianCalendar.getInstance(); startCalendar.setTime(startTime); Argument end = params.get(ENDDATE); Timestamp endTime = (Timestamp) end.getArgumentValue().getValue(); GregorianCalendar endCalendar = (GregorianCalendar) GregorianCalendar.getInstance(); endCalendar.setTime(endTime); updatedResult = parent.getConnection().getUpdated(objectName, startCalendar, endCalendar); }
public void visit(Call obj) { appendCallStart(obj); if(obj.getMetadataObject() != null) { buffer.append(getName(obj.getMetadataObject())); } else { buffer.append(obj.getProcedureName()); } buffer.append(Tokens.LPAREN); final List<Argument> params = obj.getArguments(); if (params != null && params.size() != 0) { Argument param = null; for (int i = 0; i < params.size(); i++) { param = params.get(i); if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) { if (i != 0) { buffer.append(Tokens.COMMA) .append(Tokens.SPACE); } append(param); } } } buffer.append(Tokens.RPAREN); }
public void testGetParameters() throws Exception { Call exec = example(); assertNotNull(exec.getArguments()); assertEquals(2, exec.getArguments().size()); }
@Override public ProcedureExecution createProcedureExecution(Call command,ExecutionContext executionContext, RuntimeMetadata metadata, SalesforceConnection connection) throws TranslatorException { Procedure metadataObject = command.getMetadataObject(); String nativeQuery = metadataObject.getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false); if (nativeQuery != null) { return new DirectQueryExecution(command.getArguments(), command, connection, metadata, executionContext, nativeQuery, false); } return new ProcedureExecutionParentImpl(command, connection, metadata, executionContext); }
@Override public ProcedureExecution createProcedureExecution(Call command, ExecutionContext executionContext, RuntimeMetadata metadata, GoogleSpreadsheetConnection connection) throws TranslatorException { String nativeQuery = command.getMetadataObject().getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false); if (nativeQuery != null) { return new DirectSpreadsheetQueryExecution(nativeQuery, command.getArguments(), executionContext, connection, false); } throw new TranslatorException("Missing native-query extension metadata."); //$NON-NLS-1$ }
@Override public ProcedureExecution createProcedureExecution(Call command, ExecutionContext executionContext, RuntimeMetadata metadata, EntityManager connection) throws TranslatorException { String nativeQuery = command.getMetadataObject().getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false); if (nativeQuery != null) { return new JPQLDirectQueryExecution(command.getArguments(), command, executionContext, metadata, connection, nativeQuery, false); } throw new TranslatorException("Missing native-query extension metadata."); //$NON-NLS-1$ }
static String getQueryParameters(Call obj) throws EdmPrimitiveTypeException { StringBuilder sb = new StringBuilder(); final List<Argument> params = obj.getArguments(); if (params != null && params.size() != 0) { Argument param = null; for (int i = 0; i < params.size(); i++) { param = params.get(i); if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) { if (i != 0) { sb.append("&"); //$NON-NLS-1$ } sb.append(WSUtil.httpURLEncode(param.getMetadataObject().getName())); sb.append(Tokens.EQ); sb.append(WSUtil.httpURLEncode(ODataTypeManager.convertToODataURIValue(param.getArgumentValue().getValue(), ODataTypeManager.odataType(param.getType()).getFullQualifiedName() .getFullQualifiedNameAsString()))); } } } return sb.toString(); }
@Override public ProcedureExecution createProcedureExecution(Call command, ExecutionContext executionContext, RuntimeMetadata metadata, Connection connection) throws TranslatorException { String nativeQuery = command.getMetadataObject().getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false); if (nativeQuery != null) { return new OlapQueryExecution(command.getArguments(), command, unwrap(connection), executionContext, this, nativeQuery, false); } throw new TranslatorException("Missing native-query extension metadata."); //$NON-NLS-1$ }
@Override public ProcedureExecution createProcedureExecution(Call command, ExecutionContext executionContext, RuntimeMetadata metadata, MongoDBConnection connection) throws TranslatorException { String nativeQuery = command.getMetadataObject().getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false); if (nativeQuery != null) { return new MongoDBDirectQueryExecution(command.getArguments(), command, executionContext, metadata, connection, nativeQuery, false, this); } throw new TranslatorException(MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18011)); }
/** * Create an execution object for the specified command * @param command the command * @param executionContext Provides information about the context that this command is * executing within, such as the identifiers for the command being executed * @param metadata Access to runtime metadata if needed to translate the command * @param connection connection factory object to the data source * @return An execution object that can use to execute the command */ public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, C connection) throws TranslatorException { if (command instanceof Call) { Call obj = (Call)command; //TODO: our extension property support in designer makes ad-hoc properties impossible, so //we just match based upon name. it would be better to have the metadatarepository/tooling add a teiid property //to explicitly set this proc as direct. //the other approach would be to addd a native system stored procedure, but that would require //special security semantics, whereas this proc can be secured on a schema basis if (supportsDirectQueryProcedure() && obj.getMetadataObject().getName().equals(getDirectQueryProcedureName())) { List<Argument> arguments = obj.getArguments(); return createDirectExecution(arguments, command, executionContext, metadata, connection); } } if (command instanceof QueryExpression) { return createResultSetExecution((QueryExpression)command, executionContext, metadata, connection); } if (command instanceof Call) { return createProcedureExecution((Call)command, executionContext, metadata, connection); } return createUpdateExecution(command, executionContext, metadata, connection); }
@Override public List<?> getOutputParameterValues() throws TranslatorException { try { Call proc = (Call)this.command; List<Object> result = new ArrayList<Object>(); int paramIndex = 1; if (proc.getReturnType() != null) { if (proc.getReturnParameter() != null) { addParameterValue(result, paramIndex, proc.getReturnType()); } paramIndex++; } for (Argument parameter : proc.getArguments()) { switch (parameter.getDirection()) { case IN: paramIndex++; break; case INOUT: case OUT: addParameterValue(result, paramIndex++, parameter.getType()); break; } } return result; } catch (SQLException e) { throw new TranslatorException(JDBCPlugin.Event.TEIID11005, e); } }
@Test public void testVarArgs1() throws Exception { String ddl = "create foreign procedure proc (VARIADIC z integer) returns (x string);\n"; TransformationMetadata tm = createMetadata(ddl); String sql = "call proc ()"; //$NON-NLS-1$ StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm); assertEquals("EXEC proc()", sp.toString()); assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(1).getExpression()); sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm); LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm); Call call = (Call)lbf.translate(sp); assertEquals("EXEC proc()", call.toString()); //we pass to the translator level flattened, so no argument assertEquals(0, call.getArguments().size()); }