Package org.teiid.query.sql.lang

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


        proc.setParameter(param);
        helpTest(proc, "EXEC myproc(p1 => ?)"); //$NON-NLS-1$
    }

    public void testExecNamedParams() {
        StoredProcedure proc = new StoredProcedure();
        proc.setDisplayNamedParameters(true);
        proc.setProcedureName("myproc"); //$NON-NLS-1$
        SPParameter param = new SPParameter(1, new Reference(0));
        param.setName("p1");//$NON-NLS-1$
        proc.setParameter(param);
        SPParameter param2 = new SPParameter(2, new Reference(0));
        param2.setName("p2");//$NON-NLS-1$
        proc.setParameter(param2);
        helpTest(proc, "EXEC myproc(p1 => ?, p2 => ?)"); //$NON-NLS-1$
    }
View Full Code Here


     * multiple period-delimited name components.)
     *
     * @since 4.3
     */
    public void testExecNamedParamsReservedWord() {
        StoredProcedure proc = new StoredProcedure();
        proc.setDisplayNamedParameters(true);
        proc.setProcedureName("myproc"); //$NON-NLS-1$
        SPParameter param = new SPParameter(1, new Reference(0));
        param.setName("in");//$NON-NLS-1$
        proc.setParameter(param);
        SPParameter param2 = new SPParameter(2, new Reference(0));
        param2.setName("in2");//$NON-NLS-1$
        proc.setParameter(param2);
        helpTest(proc, "EXEC myproc(\"in\" => ?, in2 => ?)"); //$NON-NLS-1$
    }   
View Full Code Here

     */
  private void handleCallableStatement(Command command) {
    if (!this.requestMsg.isCallableStatement() || !(command instanceof StoredProcedure)) {
        return;
      }
    StoredProcedure proc = (StoredProcedure)command;
    if (!proc.isCallableStatement()) {
      return;
    }
    List<?> values = requestMsg.getParameterValues();
    List<SPParameter> spParams = proc.getParameters();
    proc.clearParameters();
    int inParameterCount = values.size();
    if (this.requestMsg.isBatchedUpdate() && values.size() > 0) {
      inParameterCount = ((List)values.get(0)).size();
    }
    int index = 1;
    for (Iterator<SPParameter> params = spParams.iterator(); params.hasNext();) {
      SPParameter param = params.next();
      if (param.getParameterType() == SPParameter.RETURN_VALUE) {
        inParameterCount++;
      } else if (param.getExpression() instanceof Reference && index > inParameterCount) {
        //assume it's an output parameter
        this.prepPlan.getReferences().remove(param.getExpression());
        continue;
      }
      param.setIndex(index++);
      proc.setParameter(param);         
    }
  }
View Full Code Here

    }
   
    public void testProjectedSymbols() {
      CreateUpdateProcedureCommand cupc = new CreateUpdateProcedureCommand();
      cupc.setUpdateProcedure(false);
      StoredProcedure sp = (StoredProcedure)TestResolver.helpResolve("call TEIIDSP9(p1=>1, p2=>?)", RealMetadataFactory.exampleBQTCached());
      sp.setCallableStatement(true);
      cupc.setResultsCommand(sp);
      assertEquals(1, cupc.getProjectedSymbols().size());
    }
View Full Code Here

         
          // Create the execution based on mode
          final Execution exec = connector.createExecution(this.translatedCommand, this.securityContext, rmd, (unwrapped == null) ? this.connection:unwrapped);
          if (this.translatedCommand instanceof Call) {
            this.execution = Assertion.isInstanceOf(exec, ProcedureExecution.class, "Call Executions are expected to be ProcedureExecutions"); //$NON-NLS-1$
            StoredProcedure proc = (StoredProcedure)command;
            if (proc.returnParameters()) {
              this.procedureBatchHandler = new ProcedureBatchHandler((Call)this.translatedCommand, (ProcedureExecution)exec);
            }
          } else if (this.translatedCommand instanceof QueryExpression){
            this.execution = Assertion.isInstanceOf(exec, ResultSetExecution.class, "QueryExpression Executions are expected to be ResultSetExecutions"); //$NON-NLS-1$
          } else {
View Full Code Here

          }
        }
        break;
      }
    } else {         
      StoredProcedure proc = (StoredProcedure)command;   
      if (StringUtil.startsWithIgnoreCase(proc.getProcedureCallableName(), CoreConstants.SYSTEM_ADMIN_MODEL)) {
        final SystemAdminProcs sysProc = SystemAdminProcs.valueOf(proc.getProcedureCallableName().substring(CoreConstants.SYSTEM_ADMIN_MODEL.length() + 1).toUpperCase());
        switch (sysProc) {
        case SETPROPERTY:
          try {
            String uuid = (String)((Constant)proc.getParameter(2).getExpression()).getValue();
            String key = (String)((Constant)proc.getParameter(3).getExpression()).getValue();
            Clob value = (Clob)((Constant)proc.getParameter(4).getExpression()).getValue();
            String strVal = null;
            String result = null;
            if (value != null) {
              if (value.length() > MAX_VALUE_LENGTH) {
                throw new TeiidProcessingException(QueryPlugin.Util.getString("DataTierManagerImpl.max_value_length", MAX_VALUE_LENGTH)); //$NON-NLS-1$
              }
              strVal = ObjectConverterUtil.convertToString(value.getCharacterStream());
            }
            AbstractMetadataRecord target = getByUuid(metadata, uuid);
            if (target == null) {
              throw new TeiidProcessingException(QueryPlugin.Util.getString("DataTierManagerImpl.unknown_uuid", uuid)); //$NON-NLS-1$
            }
            if (this.metadataRepository != null) {
              this.metadataRepository.setProperty(vdbName, vdbVersion, target, key, strVal);
            }
            result = target.setProperty(key, strVal);
            if (eventDistributor != null) {
              eventDistributor.setProperty(vdbName, vdbVersion, uuid, key, strVal);
            }
            if (result == null) {
              rows.add(Arrays.asList((Clob)null));
            } else {
              rows.add(Arrays.asList(new ClobType(new SerialClob(result.toCharArray()))));
            }
            return new CollectionTupleSource(rows.iterator());
          } catch (SQLException e) {
            throw new TeiidProcessingException(e);
          } catch (IOException e) {
            throw new TeiidProcessingException(e);
          }
        }
        Table table = indexMetadata.getGroupID((String)((Constant)proc.getParameter(1).getExpression()).getValue());
        switch (sysProc) {
        case SETCOLUMNSTATS:
          String columnName = (String)((Constant)proc.getParameter(2).getExpression()).getValue();
          Column c = null;
          for (Column col : table.getColumns()) {
            if (col.getName().equalsIgnoreCase(columnName)) {
              c = col;
              break;
            }
          }
          if (c == null) {
            throw new TeiidProcessingException(columnName + TransformationMetadata.NOT_EXISTS_MESSAGE);
          }
          Integer distinctVals = (Integer)((Constant)proc.getParameter(3).getExpression()).getValue();
          Integer nullVals = (Integer)((Constant)proc.getParameter(4).getExpression()).getValue();
          String max = (String) ((Constant)proc.getParameter(5).getExpression()).getValue();
          String min = (String) ((Constant)proc.getParameter(6).getExpression()).getValue();
          ColumnStats columnStats = new ColumnStats();
          columnStats.setDistinctValues(distinctVals);
          columnStats.setNullValues(nullVals);
          columnStats.setMaximumValue(max);
          columnStats.setMinimumValue(min);
          if (this.metadataRepository != null) {
            this.metadataRepository.setColumnStats(vdbName, vdbVersion, c, columnStats);
          }
          c.setColumnStats(columnStats);
          if (eventDistributor != null) {
            eventDistributor.setColumnStats(vdbName, vdbVersion, table.getParent().getName(), table.getName(), columnName, columnStats);
          }
          break;
        case SETTABLESTATS:
          Constant val = (Constant)proc.getParameter(2).getExpression();
          int cardinality = (Integer)val.getValue();
          TableStats tableStats = new TableStats();
          tableStats.setCardinality(cardinality);
          if (this.metadataRepository != null) {
            this.metadataRepository.setTableStats(vdbName, vdbVersion, table, tableStats);
          }
          table.setCardinality(cardinality);
          if (eventDistributor != null) {
            eventDistributor.setTableStats(vdbName, vdbVersion, table.getParent().getName(), table.getName(), tableStats);
          }
          break;
        }
        table.setLastModified(System.currentTimeMillis());
        return new CollectionTupleSource(rows.iterator());
      }
      final SystemProcs sysTable = SystemProcs.valueOf(proc.getProcedureCallableName().substring(CoreConstants.SYSTEM_MODEL.length() + 1).toUpperCase());
      switch (sysTable) {
      case GETXMLSCHEMAS:
        try {
          Object groupID = indexMetadata.getGroupID((String)((Constant)proc.getParameter(1).getExpression()).getValue());
          List<SQLXMLImpl> schemas = indexMetadata.getXMLSchemas(groupID);
          for (SQLXMLImpl schema : schemas) {
            rows.add(Arrays.asList(new XMLType(schema)));
          }
        } catch (QueryMetadataException e) {
View Full Code Here

                //user may have not entered any query yet
                return Collections.EMPTY_LIST;
            }
            List<? extends SingleElementSymbol> symbols = this.resultsCommand.getProjectedSymbols();
            if (this.resultsCommand instanceof StoredProcedure) {
              StoredProcedure sp = (StoredProcedure)this.resultsCommand;
              if (sp.isCallableStatement()) {
                symbols = sp.getResultSetColumns();
              }
            }
            setProjectedSymbols(symbols);
            return this.projectedSymbols;
        }
View Full Code Here

    // Check name of all in group symbol
    assertEquals("AllInGroupSymbol name did not get mapped correctly: ", "NEWG0.*", aigs.getName()); //$NON-NLS-1$ //$NON-NLS-2$
   }
   
    public void testExecName() {
        StoredProcedure exec = new StoredProcedure();
        exec.setProcedureName(exampleGroup(true, 1).getName());
        exec.setProcedureID("proc"); //$NON-NLS-1$

        // Run symbol mapper
        StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
        DeepPreOrderNavigator.doVisit(exec, visitor);

        // Check that group got mapped
        assertEquals("Procedure name did not get mapped correctly: ", exampleGroup(false, 1).getName(), exec.getProcedureName()); //$NON-NLS-1$

    }   
View Full Code Here

        assertEquals("Procedure name did not get mapped correctly: ", exampleGroup(false, 1).getName(), exec.getProcedureName()); //$NON-NLS-1$

    }   
   
    public void testExecParamElement() {
        StoredProcedure exec = new StoredProcedure();
        exec.setProcedureName("pm1.proc1"); //$NON-NLS-1$
        exec.setProcedureID("proc"); //$NON-NLS-1$
        SPParameter param1 = new SPParameter(1, exampleElement(true, 1));
        exec.setParameter(param1);
       
        // Run symbol mapper
        StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
        DeepPreOrderNavigator.doVisit(exec, visitor);
       
View Full Code Here

        // Check that element got switched
        assertEquals("Stored proc param did not get mapped correctly: ", exampleElement(false, 1), param1.getExpression());    //$NON-NLS-1$
    }

    public void testExecParamFunction() {
        StoredProcedure exec = new StoredProcedure();
        exec.setProcedureName("pm1.proc1"); //$NON-NLS-1$
        exec.setProcedureID("proc"); //$NON-NLS-1$
        Function f = new Function("length", new Expression[] { exampleElement(true, 1) }); //$NON-NLS-1$
       
        SPParameter param1 = new SPParameter(1, f);
        exec.setParameter(param1);

        // Run symbol mapper
        StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
        DeepPreOrderNavigator.doVisit(exec, visitor);
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.lang.StoredProcedure

Copyright © 2018 www.massapicom. 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.