Examples of StoredProcedure


Examples of org.teiid.query.sql.lang.StoredProcedure

      String fullName = metadata.getFullName(group.getMetadataID());
      String queryName = group.getName();
     
      StoredProcedureInfo storedProcedureInfo = metadata.getStoredProcedureInfoForProcedure(fullName);

      StoredProcedure storedProcedureCommand = new StoredProcedure();
      storedProcedureCommand.setProcedureRelational(true);
      storedProcedureCommand.setProcedureName(fullName);
     
      List<SPParameter> metadataParams = storedProcedureInfo.getParameters();
     
      Query procQuery = new Query();
      From from = new From();
      from.addClause(new SubqueryFromClause("X", storedProcedureCommand)); //$NON-NLS-1$
      procQuery.setFrom(from);
      Select select = new Select();
      select.addSymbol(new AllInGroupSymbol("X.*")); //$NON-NLS-1$
      procQuery.setSelect(select);
     
      List<String> accessPatternElementNames = new LinkedList<String>();
     
      int paramIndex = 1;
     
      for (SPParameter metadataParameter : metadataParams) {
          SPParameter clonedParam = (SPParameter)metadataParameter.clone();
          if (clonedParam.getParameterType()==ParameterInfo.IN || metadataParameter.getParameterType()==ParameterInfo.INOUT) {
              ElementSymbol paramSymbol = clonedParam.getParameterSymbol();
              Reference ref = new Reference(paramSymbol);
              clonedParam.setExpression(ref);
              clonedParam.setIndex(paramIndex++);
              storedProcedureCommand.setParameter(clonedParam);
             
              String aliasName = paramSymbol.getShortName();
             
              if (metadataParameter.getParameterType()==ParameterInfo.INOUT) {
                  aliasName += "_IN"; //$NON-NLS-1$
              }
             
              SingleElementSymbol newSymbol = new AliasSymbol(aliasName, new ExpressionSymbol(paramSymbol.getShortName(), ref));
             
              select.addSymbol(newSymbol);
              accessPatternElementNames.add(queryName + ElementSymbol.SEPARATOR + aliasName);
          }
      }
     
      QueryResolver.resolveCommand(procQuery, metadata.getMetadata());
     
      List<SingleElementSymbol> projectedSymbols = procQuery.getProjectedSymbols();
     
      HashSet<String> foundNames = new HashSet<String>();
     
      for (SingleElementSymbol ses : projectedSymbols) {
          if (!foundNames.add(ses.getShortCanonicalName())) {
              throw new QueryResolverException(QueryPlugin.Util.getString("SimpleQueryResolver.Proc_Relational_Name_conflict", fullName)); //$NON-NLS-1$                           
          }
      }
     
      TempMetadataID id = metadata.getMetadataStore().getTempGroupID(queryName);

      if (id == null) {
          metadata.getMetadataStore().addTempGroup(queryName, projectedSymbols, true);
         
          id = metadata.getMetadataStore().getTempGroupID(queryName);
          id.setOriginalMetadataID(storedProcedureCommand.getProcedureID());
          if (!accessPatternElementNames.isEmpty()) {
            List<TempMetadataID> accessPatternIds = new LinkedList<TempMetadataID>();
           
            for (String name : accessPatternElementNames) {
                accessPatternIds.add(metadata.getMetadataStore().getTempElementID(name));
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

    case Command.TYPE_UPDATE_PROCEDURE:
      CreateUpdateProcedureCommand cupc = (CreateUpdateProcedureCommand)command;
      if (cupc.isUpdateProcedure()) {
        result = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, context);
      } else {
        StoredProcedure c = (StoredProcedure)cupc.getUserCommand();
        Object pid = cupc.getVirtualGroup().getMetadataID();
        if (c != null) {
          pid = c.getProcedureID();
        }
        String fullName = metadata.getFullName(pid);
        fullName = "procedure cache:" + fullName; //$NON-NLS-1$
        PreparedPlan pp = context.getPlan(fullName);
        if (pp == null) {
          Determinism determinismLevel = context.resetDeterminismLevel();
          CommandContext clone = context.clone();
          ProcessorPlan plan = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, clone);
          //note that this is not a full prepared plan.  It is not usable by user queries.
          if (pid instanceof Procedure) {
            clone.accessedPlanningObject(pid);
          }
          pp = new PreparedPlan();
          pp.setPlan(plan, clone);
          context.putPlan(fullName, pp, context.getDeterminismLevel());
          context.setDeterminismLevel(determinismLevel);
        }
        result = pp.getPlan().clone();
        for (Object id : pp.getAccessInfo().getObjectsAccessed()) {
          context.accessedPlanningObject(id);
        }
      }
          // propagate procedure parameters to the plan to allow runtime type checking
          ProcedureContainer container = (ProcedureContainer)cupc.getUserCommand();
          ProcedurePlan plan = (ProcedurePlan)result;
          if (container != null) {
            LinkedHashMap<ElementSymbol, Expression> params = container.getProcedureParameters();
            if (container instanceof StoredProcedure) {
              plan.setRequiresTransaction(container.getUpdateCount() > 0);
              StoredProcedure sp = (StoredProcedure)container;
              if (sp.returnParameters()) {
                List<ElementSymbol> outParams = new LinkedList<ElementSymbol>();
                for (SPParameter param : sp.getParameters()) {
              if (param.getParameterType() == SPParameter.RETURN_VALUE) {
                outParams.add(param.getParameterSymbol());
              }
            }
                for (SPParameter param : sp.getParameters()) {
              if (param.getParameterType() == SPParameter.INOUT ||
                  param.getParameterType() == SPParameter.OUT) {
                outParams.add(param.getParameterSymbol());
              }
            }
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

        }
          response.setWarnings(responseWarnings);
         
          // If it is stored procedure, set parameters
          if (originalCommand instanceof StoredProcedure) {
            StoredProcedure proc = (StoredProcedure)originalCommand;
            if (proc.returnParameters()) {
              response.setParameters(getParameterInfo(proc));
            }
          }
          /*
           * mark the results sent at this point.
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

        throws QueryMetadataException, QueryResolverException, TeiidComponentException {

        findCommandMetadata(command, metadata.getMetadataStore(), metadata);
       
        //Resolve expressions on input parameters
        StoredProcedure storedProcedureCommand = (StoredProcedure) command;
        GroupContext externalGroups = storedProcedureCommand.getExternalGroupContexts();
        for (SPParameter param : storedProcedureCommand.getParameters()) {
            Expression expr = param.getExpression();
            if(expr == null) {
              continue;
            }
            for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr)) {
                QueryResolver.setChildMetadata(container.getCommand(), command);
               
                QueryResolver.resolveCommand(container.getCommand(), metadata.getMetadata());
            }
            ResolverVisitor.resolveLanguageObject(expr, null, externalGroups, metadata);
            Class<?> paramType = param.getClassType();

            ResolverUtil.setDesiredType(expr, paramType, storedProcedureCommand);
           
            // Compare type of parameter expression against parameter type
            // and add implicit conversion if necessary
            Class<?> exprType = expr.getType();
            if(paramType == null || exprType == null) {
                throw new QueryResolverException("ERR.015.008.0061", QueryPlugin.Util.getString("ERR.015.008.0061", storedProcedureCommand.getProcedureName(), param.getName())); //$NON-NLS-1$ //$NON-NLS-2$
            }
            String tgtType = DataTypeManager.getDataTypeName(paramType);
            String srcType = DataTypeManager.getDataTypeName(exprType);
            Expression result = null;
                           
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

                Command subCommand = cmdStmt.getCommand();
               
                TempMetadataStore discoveredMetadata = resolveEmbeddedCommand(metadata, externalGroups, subCommand);
               
                if (subCommand instanceof StoredProcedure) {
                  StoredProcedure sp = (StoredProcedure)subCommand;
                  for (SPParameter param : sp.getParameters()) {
                  switch (param.getParameterType()) {
                      case ParameterInfo.OUT:
                      case ParameterInfo.RETURN_VALUE:
                        if (!isAssignable(metadata, param)) {
                              throw new QueryResolverException(QueryPlugin.Util.getString("UpdateProcedureResolver.only_variables", param.getExpression())); //$NON-NLS-1$
                        }
                        sp.setCallableStatement(true);
                        break;
                      case ParameterInfo.INOUT:
                        if (!isAssignable(metadata, param)) {
                          continue;
                        }
                        sp.setCallableStatement(true);
                        break;
                      }
          }
                }
               
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

                 "INSERT INTO m.g (a) VALUES (?)"//$NON-NLS-1$
                 insert);                    
    }
       
    @Test public void testStoredQueryWithNoParameter(){
      StoredProcedure storedQuery = new StoredProcedure();
      storedQuery.setProcedureName("proc1"); //$NON-NLS-1$
      helpTest("exec proc1()", "EXEC proc1()", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
      helpTest("execute proc1()", "EXEC proc1()", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
    }
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

      helpTest("exec proc1()", "EXEC proc1()", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
      helpTest("execute proc1()", "EXEC proc1()", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    @Test public void testStoredQueryWithNoParameter2(){
      StoredProcedure storedQuery = new StoredProcedure();
      storedQuery.setProcedureName("proc1"); //$NON-NLS-1$
     
        From from = new From();
        SubqueryFromClause sfc = new SubqueryFromClause("x", storedQuery); //$NON-NLS-1$
        from.addClause(sfc);
       
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

        query.setFrom(from);
      helpTest("SELECT X.A FROM (exec proc1()) AS X", "SELECT X.A FROM (EXEC proc1()) AS X", query); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    @Test public void testStoredQuery(){
      StoredProcedure storedQuery = new StoredProcedure();
      storedQuery.setProcedureName("proc1"); //$NON-NLS-1$
      SPParameter parameter = new SPParameter(1, new Constant("param1")); //$NON-NLS-1$
        parameter.setParameterType(ParameterInfo.IN);
      storedQuery.setParameter(parameter);
      helpTest("Exec proc1('param1')", "EXEC proc1('param1')", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
      helpTest("execute proc1('param1')", "EXEC proc1('param1')", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
    }
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

      helpTest("Exec proc1('param1')", "EXEC proc1('param1')", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
      helpTest("execute proc1('param1')", "EXEC proc1('param1')", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    @Test public void testStoredQuery2(){
      StoredProcedure storedQuery = new StoredProcedure();
      storedQuery.setProcedureName("proc1"); //$NON-NLS-1$
      SPParameter parameter = new SPParameter(1, new Constant("param1")); //$NON-NLS-1$
      storedQuery.setParameter(parameter);
      From from = new From();
        SubqueryFromClause sfc = new SubqueryFromClause("x", storedQuery); //$NON-NLS-1$
        from.addClause(sfc);
       
        Select select = new Select();
View Full Code Here

Examples of org.teiid.query.sql.lang.StoredProcedure

        query.setFrom(from);
      helpTest("SELECT X.A FROM (exec proc1('param1')) AS X", "SELECT X.A FROM (EXEC proc1('param1')) AS X", query); //$NON-NLS-1$ //$NON-NLS-2$
    }

    @Test public void testStoredQuery2SanityCheck(){
        StoredProcedure storedQuery = new StoredProcedure();
        storedQuery.setProcedureName("proc1"); //$NON-NLS-1$
        SPParameter parameter = new SPParameter(1, new Constant("param1")); //$NON-NLS-1$
        storedQuery.setParameter(parameter);
        From from = new From();
        SubqueryFromClause sfc = new SubqueryFromClause("x", storedQuery); //$NON-NLS-1$
        from.addClause(sfc);
       
        Select select = new Select();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.