Package org.teiid.query.sql.lang

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


        ElementSymbol a1 = new ElementSymbol("a1"); //$NON-NLS-1$
        a1.setType(DataTypeManager.DefaultDataClasses.STRING);
        symbols.add(a1)
       
        DynamicCommand sqlCmd = new DynamicCommand();
        Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5"); //$NON-NLS-1$
       
        sqlCmd.setSql(sql);
        sqlCmd.setAsColumns(symbols);
        sqlCmd.setAsClauseSet(true);
       
        sqlCmd.setIntoGroup(new GroupSymbol("#g")); //$NON-NLS-1$
       
        CommandStatement cmdStmt = new CommandStatement(sqlCmd);
  
        helpStmtTest("exec string 'SELECT a1 FROM g WHERE a2 = 5' as a1 string into #g;", "EXECUTE 'SELECT a1 FROM g WHERE a2 = 5' AS a1 string INTO #g;", //$NON-NLS-1$ //$NON-NLS-2$
        cmdStmt);      
View Full Code Here


       
        ElementSymbol a2 = new ElementSymbol("a2"); //$NON-NLS-1$
        a1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
        symbols.add(a2)
       
        DynamicCommand sqlCmd = new DynamicCommand();
        Expression sql = new ElementSymbol("z"); //$NON-NLS-1$
       
        sqlCmd.setSql(sql);
        sqlCmd.setAsColumns(symbols);
        sqlCmd.setAsClauseSet(true);
       
        sqlCmd.setIntoGroup(new GroupSymbol("#g")); //$NON-NLS-1$
       
        sqlCmd.setUpdatingModelCount(1);
       
        CommandStatement cmdStmt = new CommandStatement(sqlCmd);
  
        helpStmtTest("execute string z as a1 string, a2 integer into #g update 1;", "EXECUTE z AS a1 string, a2 integer INTO #g UPDATE 1;", //$NON-NLS-1$ //$NON-NLS-2$
        cmdStmt);      
View Full Code Here

        SetClauseList using = new SetClauseList();
       
        ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
        using.addClause(a, new ElementSymbol("b"))//$NON-NLS-1$
               
        DynamicCommand sqlCmd = new DynamicCommand();
        Expression sql = new ElementSymbol("z"); //$NON-NLS-1$
       
        sqlCmd.setSql(sql);
        sqlCmd.setUsing(using);
       
        CommandStatement cmdStmt = new CommandStatement(sqlCmd);
  
        helpStmtTest("execute immediate z using a=b;", "EXECUTE z USING a = b;", //$NON-NLS-1$ //$NON-NLS-2$
        cmdStmt);      
View Full Code Here

     * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
     */
    public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals)
        throws QueryMetadataException, QueryResolverException, TeiidComponentException {

        DynamicCommand dynamicCmd = (DynamicCommand)command;
       
        Iterator columns = dynamicCmd.getAsColumns().iterator();

        Set groups = new HashSet();
       
        //if there is no into group, just create temp metadata ids
        if (dynamicCmd.getIntoGroup() == null) {
            while (columns.hasNext()) {
                ElementSymbol column = (ElementSymbol)columns.next();
                column.setMetadataID(new TempMetadataID(column.getShortCanonicalName(), column.getType()));
            }
        } else if (dynamicCmd.getIntoGroup().isTempGroupSymbol()) {
            while (columns.hasNext()) {
                ElementSymbol column = (ElementSymbol)columns.next();
                column.setGroupSymbol(new GroupSymbol(dynamicCmd.getIntoGroup().getCanonicalName()));
            }
        }
       
        ResolverVisitor.resolveLanguageObject(dynamicCmd, groups, dynamicCmd.getExternalGroupContexts(), metadata);
       
        String sqlType = DataTypeManager.getDataTypeName(dynamicCmd.getSql().getType());
        String targetType = DataTypeManager.DefaultDataTypes.STRING;
       
        if (!targetType.equals(sqlType) && !DataTypeManager.isImplicitConversion(sqlType, targetType)) {
            throw new QueryResolverException(QueryPlugin.Util.getString("DynamicCommandResolver.SQL_String", sqlType)); //$NON-NLS-1$
        }
       
        if (dynamicCmd.getUsing() != null && !dynamicCmd.getUsing().isEmpty()) {
            for (SetClause clause : dynamicCmd.getUsing().getClauses()) {
                ElementSymbol id = clause.getSymbol();
                id.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.DVARS));
                id.setType(clause.getValue().getType());
                id.setMetadataID(new TempMetadataID(id.getCanonicalName(), id.getType()));
            }
        }
       
        GroupSymbol intoSymbol = dynamicCmd.getIntoGroup();
        if (intoSymbol != null) {
            if (!intoSymbol.isImplicitTempGroupSymbol()) {
                ResolverUtil.resolveGroup(intoSymbol, metadata);
            } else {
                List symbols = dynamicCmd.getAsColumns();
                ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols);
            }
        }
    }
View Full Code Here

                    metadata.getMetadataStore().getData().putAll(discoveredMetadata.getData());
                }
               
                //dynamic commands need to be updated as to their implicitly expected projected symbols
                if (subCommand instanceof DynamicCommand) {
                    DynamicCommand dynCommand = (DynamicCommand)subCommand;
                   
                    if(dynCommand.getIntoGroup() == null && !command.isUpdateProcedure()
                        && !dynCommand.isAsClauseSet() && !command.getProjectedSymbols().isEmpty()) {
                        dynCommand.setAsColumns(command.getProjectedSymbols());
                    }
                }
               
                if(!command.isUpdateProcedure()){
                    //don't bother using the metadata when it doesn't matter
                    if (command.getResultsCommand() != null && command.getResultsCommand().getType() == Command.TYPE_DYNAMIC) {
                        DynamicCommand dynamicCommand = (DynamicCommand)command.getResultsCommand();
                        if (!dynamicCommand.isAsClauseSet()) {
                            dynamicCommand.setAsColumns(Collections.EMPTY_LIST);
                        }
                    }
                   
                    if (subCommand.returnsResultSet()) {
                      //this could be the last select statement, set the projected symbol
View Full Code Here

 
      ElementSymbol a1 = new ElementSymbol("a1"); //$NON-NLS-1$
      a1.setType(DataTypeManager.DefaultDataClasses.STRING);
      symbols.add(a1)
     
      DynamicCommand obj = new DynamicCommand();
      Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5"); //$NON-NLS-1$
     
      obj.setSql(sql);
      obj.setAsColumns(symbols);
      obj.setAsClauseSet(true);     
      obj.setIntoGroup(new GroupSymbol("#g")); //$NON-NLS-1$
     
      helpTest(obj, "EXECUTE 'SELECT a1 FROM g WHERE a2 = 5' AS a1 string INTO #g"); //$NON-NLS-1$
    }
View Full Code Here

        ElementSymbol a1 = new ElementSymbol("a1"); //$NON-NLS-1$
        a1.setType(DataTypeManager.DefaultDataClasses.STRING);
        symbols.add(a1)
       
        DynamicCommand sqlCmd = new DynamicCommand();
        Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5"); //$NON-NLS-1$
       
        sqlCmd.setSql(sql);
        sqlCmd.setAsColumns(symbols);
        sqlCmd.setAsClauseSet(true);
       
        sqlCmd.setIntoGroup(new GroupSymbol("#g")); //$NON-NLS-1$
       
        UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());       
    }
View Full Code Here

        Expression sql = new Constant("SELECT * FROM g"); //$NON-NLS-1$
       
        SetClauseList using = new SetClauseList();
        using.addClause(a1, a1);       
       
        DynamicCommand sqlCmd = new DynamicCommand(sql, symbols, new GroupSymbol("#g"), using); //$NON-NLS-1$
       
        UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());    
    }
View Full Code Here

        ElementSymbol a1 = new ElementSymbol("a1"); //$NON-NLS-1$
        a1.setType(DataTypeManager.DefaultDataClasses.STRING);
        symbols.add(a1)
       
        DynamicCommand sqlCmd = new DynamicCommand();
        Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5"); //$NON-NLS-1$
       
        sqlCmd.setSql(sql);
        sqlCmd.setAsColumns(symbols);
        sqlCmd.setAsClauseSet(true);
       
        sqlCmd.setIntoGroup(new GroupSymbol("#g")); //$NON-NLS-1$
       
        List projectedSymbols = sqlCmd.getProjectedSymbols();
       
        UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
        assertEquals(projectedSymbols, ((DynamicCommand)sqlCmd.clone()).getProjectedSymbols());
    }
View Full Code Here

        UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
        assertEquals(projectedSymbols, ((DynamicCommand)sqlCmd.clone()).getProjectedSymbols());
    }
   
    public void testUpdatingModelCount() {
        DynamicCommand sqlCmd = new DynamicCommand();
       
        sqlCmd.setUpdatingModelCount(1);
        assertEquals(1, sqlCmd.getUpdatingModelCount());
       
        sqlCmd.setUpdatingModelCount(3);
        assertEquals(2, sqlCmd.getUpdatingModelCount());
       
        sqlCmd.setUpdatingModelCount(-1);
        assertEquals(0, sqlCmd.getUpdatingModelCount());
    }
View Full Code Here

TOP

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

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.