@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$ }
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 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 visit(Call call) { if (oracleSuppliedDriver && call.getResultSetColumnTypes().length > 0 && call.getMetadataObject() != null) { if (call.getReturnType() == null && call.getMetadataObject().getProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, false) == null) { //assume stored function handling if (!setOutCursorType(call)) { call.setReturnType(RefCursorType.class); } } else { //TODO we only will allow a single out cursor if (call.getMetadataObject() != null) { ProcedureParameter param = call.getReturnParameter(); if (param != null && REF_CURSOR.equalsIgnoreCase(param.getNativeType())) { call.setReturnType(RefCursorType.class); } } setOutCursorType(call); } } super.visit(call); }
prepareCallBuffer.append("{"); //$NON-NLS-1$ List<Argument> params = exec.getArguments(); boolean needQuestionMark = exec.getReturnType() != null; prepareCallBuffer.append(exec.getMetadataObject() != null ? getName(exec.getMetadataObject()) : exec.getProcedureName()); prepareCallBuffer.append("("); //$NON-NLS-1$
public void visit(Call obj) { visitNodes(obj.getArguments()); }
protected void appendCallStart(Call call) { if (!isTVF(call.getMetadataObject())) { buffer.append(EXEC) .append(Tokens.SPACE); } }
/** * @see org.teiid.language.visitor.SQLStringVisitor#visit(org.teiid.language.Call) */ public void visit(Call obj) { usingBinding = true; Procedure p = obj.getMetadataObject(); if (p != null) { String nativeQuery = p.getProperty(TEIID_NATIVE_QUERY, false); if (nativeQuery != null) { this.prepared = !Boolean.valueOf(p.getProperty(TEIID_NON_PREPARED, false)); if (this.prepared) { this.preparedValues = new ArrayList<Object>(); } parseNativeQueryParts(nativeQuery, obj.getArguments(), buffer, this); return; } } if (obj.isTableReference()) { usingBinding = false; super.visit(obj); return; } this.prepared = true; /* * preparedValues is now a list of procedure params instead of just values */ this.preparedValues = obj.getArguments(); buffer.append(generateSqlForStoredProcedure(obj)); }
@Override public void execute() throws TranslatorException { String name = getCommand().getMetadataObject().getSourceName(); if (name == null) { name = getCommand().getProcedureName(); } if(GET_UPDATED.equalsIgnoreCase(name)) { execution = new GetUpdatedExecutionImpl(this); } else if(GET_DELETED.equalsIgnoreCase(name)) { execution = new GetDeletedExecutionImpl(this); } else { throw new TeiidRuntimeException("Unknown procedure " + getCommand().getProcedureName() + " with name in source " + name); //$NON-NLS-1$ //$NON-NLS-2$ } execution.execute(this); }
@Override public void execute() throws TranslatorException { String filePath = (String)command.getArguments().get(0).getArgumentValue().getValue(); if(this.command.getProcedureName().equalsIgnoreCase(SAVEFILE)){ Object file = command.getArguments().get(1).getArgumentValue().getValue(); if (file == null || filePath == null) { throw new TranslatorException(UTIL.getString("non_null")); //$NON-NLS-1$ throw new TranslatorException(e, UTIL.getString("error_writing")); //$NON-NLS-1$ } else if(this.command.getProcedureName().equalsIgnoreCase(DELETEFILE)) { if (filePath == null) { throw new TranslatorException(UTIL.getString("non_null")); //$NON-NLS-1$ this.files = VirtualFileConnection.Util.getFiles(filePath, this.conn, exceptionIfFileNotFound); LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Getting", files != null ? files.length : 0, "file(s)"); //$NON-NLS-1$ //$NON-NLS-2$ String name = command.getProcedureName(); if(name.equalsIgnoreCase(GETTEXTFILES)) { this.isText = true;
@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()); }
public ODataProcedureExecution(Call command, ODataExecutionFactory translator, ExecutionContext executionContext, RuntimeMetadata metadata, WSConnection connection) throws TranslatorException { super(translator, executionContext, metadata, connection); this.command = command; this.expectedColumnTypes = command.getResultSetColumnTypes(); }
Call call = new Call(removeSchemaName(sp.getProcedureName()), translatedParameters, proc); call.setReturnType(returnType); return call;
private String buildFunctionURL(Call obj, String parameters) { StringBuilder sb = new StringBuilder(); sb.append(obj.getProcedureName()); if (parameters != null && !parameters.isEmpty()) { sb.append("?"); sb.append(parameters); } return sb.toString(); }
@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)); } }
public Call createCall(String name, List<Argument> parameters, Procedure metadataReference) { return new Call(name, parameters, metadataReference); }
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; }
private ProcedureParameter getReturnParameter() { for (ProcedureParameter pp : this.command.getMetadataObject().getParameters()) { if (pp.getType() == ProcedureParameter.Type.ReturnValue) { return pp; } } return null; }
@Override public void execute() throws TranslatorException { try { String parameters = getQueryParameters(this.command); InputStream response = null; Procedure procedure = this.command.getMetadataObject(); if (isFunction(procedure)) { String URI = buildFunctionURL(this.command, parameters); response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK }); handleResponse(procedure, URI, response); } else { String URI = this.command.getProcedureName(); response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK }); handleResponse(procedure, URI, response); } } catch (ODataDeserializerException e) { throw new TranslatorException(e); } catch (EdmPrimitiveTypeException e) { throw new TranslatorException(e); } }