Examples of StatementContext


Examples of com.bacoder.parser.java.JavaParser.StatementContext

        return processContinueStatement(context);
      case JavaParser.Identifier: {
        if (context.children.size() > 1
            && context.children.get(1) instanceof TerminalNode
            && ((TerminalNode) context.children.get(1)).getSymbol().getType() == JavaParser.COLON) {
          StatementContext statementContext = getChild(context, StatementContext.class);
          if (statementContext != null) {
            Statement statement = adapt(statementContext);
            statement.setLabel(getAdapter(IdentifierAdapter.class).adapt(firstTerminal));
            setNodeAttributes(statement, firstTerminal, statementContext);
            return statement;
View Full Code Here

Examples of com.espertech.esper.core.service.StatementContext

    public ViewableActivationResult activate(AgentInstanceContext agentInstanceContext, boolean isSubselect, boolean isRecoveringResilient) {
        PatternAgentInstanceContext patternAgentInstanceContext = agentInstanceContext.getStatementContext().getPatternContextFactory().createPatternAgentContext(patternContext, agentInstanceContext, hasConsumingFilter);
        EvalRootNode rootNode = EvalNodeUtil.makeRootNodeFromFactory(rootFactoryNode, patternAgentInstanceContext);

        final EventStream sourceEventStream = new ZeroDepthStream(eventType);
        final StatementContext statementContext = patternContext.getStatementContext();
        final PatternMatchCallback callback = new PatternMatchCallback() {
            public void matchFound(Map<String, Object> matchEvent)
            {
                EventBean compositeEvent = statementContext.getEventAdapterService().adapterForTypedMap(matchEvent, eventType);
                sourceEventStream.insert(compositeEvent);
            }
        };

        EvalRootState rootState = rootNode.start(callback, patternContext, isRecoveringResilient);
View Full Code Here

Examples of com.salesforce.phoenix.compile.StatementContext

                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(3L))),
                new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(2L))),
            };

        PhoenixConnection pconn = DriverManager.getConnection(getUrl(), TEST_PROPERTIES).unwrap(PhoenixConnection.class);
        StatementContext context = new StatementContext(new PhoenixStatement(pconn), null, Collections.emptyList(), new Scan());
        AggregationManager aggregationManager = context.getAggregationManager();
        SumAggregateFunction func = new SumAggregateFunction(Arrays.<Expression>asList(new KeyValueColumnExpression(new PLongColumn() {
            @Override
            public PName getName() {
                return SINGLE_COLUMN_NAME;
            }
View Full Code Here

Examples of org.apache.derby.iapi.sql.conn.StatementContext

    {
      if (! isTopResultSet)
      {
        /* This is simply for RunTimeStats */
        /* We first need to get the subquery tracking array via the StatementContext */
        StatementContext sc = activation.getLanguageConnectionContext().getStatementContext();
        subqueryTrackingArray = sc.getSubqueryTrackingArray();
      }
      nextTime += getElapsedMillis(beginTime);
    }
      return result;
  }
View Full Code Here

Examples of org.apache.derby.iapi.sql.conn.StatementContext

    long        bindTime = 0;
    long        optimizeTime = 0;
    long        generateTime = 0;
    Timestamp      beginTimestamp = null;
    Timestamp      endTimestamp = null;
    StatementContext  statementContext = null;

    // verify it isn't already prepared...
    // if it is, and is valid, simply return that tree.
    // if it is invalid, we will recompile now.
    if (preparedStmt != null) {
      if (preparedStmt.upToDate())
        return preparedStmt;
    }

    // Clear the optimizer trace from the last statement
    if (lcc.getOptimizerTrace())
      lcc.setOptimizerTraceOutput(getSource() + "\n");

    beginTime = getCurrentTimeMillis(lcc);
    /* beginTimestamp only meaningful if beginTime is meaningful.
     * beginTime is meaningful if STATISTICS TIMING is ON.
     */
    if (beginTime != 0)
    {
      beginTimestamp = new Timestamp(beginTime);
    }

    /** set the prepare Isolaton from the LanguageConnectionContext now as
     * we need to consider it in caching decisions
     */
    prepareIsolationLevel = lcc.getPrepareIsolationLevel();

    /* a note on statement caching:
     *
     * A GenericPreparedStatement (GPS) is only added it to the cache if the
     * parameter cacheMe is set to TRUE when the GPS is created.
     *
     * Earlier only CacheStatement (CS) looked in the statement cache for a
     * prepared statement when prepare was called. Now the functionality
     * of CS has been folded into GenericStatement (GS). So we search the
     * cache for an existing PreparedStatement only when cacheMe is TRUE.
     * i.e if the user calls prepare with cacheMe set to TRUE:
     * then we
     *         a) look for the prepared statement in the cache.
     *         b) add the prepared statement to the cache.
     *
     * In cases where the statement cache has been disabled (by setting the
     * relevant Derby property) then the value of cacheMe is irrelevant.
     */
    boolean foundInCache = false;
    if (preparedStmt == null)
    {
      if (cacheMe)
        preparedStmt = (GenericPreparedStatement)((GenericLanguageConnectionContext)lcc).lookupStatement(this);

      if (preparedStmt == null)
      {
        preparedStmt = new GenericPreparedStatement(this);
      }
      else
      {
        foundInCache = true;
      }
    }

    // if anyone else also has this prepared statement,
    // we don't want them trying to compile with it while
    // we are.  So, we synchronize on it and re-check
    // its validity first.
    // this is a no-op if and until there is a central
    // cache of prepared statement objects...
    synchronized (preparedStmt)
    {

      for (;;) {

        if (foundInCache) {
          if (preparedStmt.referencesSessionSchema()) {
            // cannot use this state since it is private to a connection.
            // switch to a new statement.
            foundInCache = false;
            preparedStmt = new GenericPreparedStatement(this);
            break;
          }
        }

        // did it get updated while we waited for the lock on it?
        if (preparedStmt.upToDate()) {
          return preparedStmt;
        }

        if (!preparedStmt.compilingStatement) {
          break;
        }

        try {
          preparedStmt.wait();
        } catch (InterruptedException ie) {
                    InterruptStatus.setInterrupted();
        }
      }

      preparedStmt.compilingStatement = true;
      preparedStmt.setActivationClass(null);
    }

    try {

      HeaderPrintWriter istream = lcc.getLogStatementText() ? Monitor.getStream() : null;

      /*
      ** For stored prepared statements, we want all
      ** errors, etc in the context of the underlying
      ** EXECUTE STATEMENT statement, so don't push/pop
      ** another statement context unless we don't have
      ** one.  We won't have one if it is an internal
      ** SPS (e.g. jdbcmetadata).
      */
      if (!preparedStmt.isStorable() || lcc.getStatementDepth() == 0)
      {
        // since this is for compilation only, set atomic
        // param to true and timeout param to 0
        statementContext = lcc.pushStatementContext(true, isForReadOnly, getSource(),
                                                            null, false, 0L);
      }



      /*
      ** RESOLVE: we may ultimately wish to pass in
      ** whether we are a jdbc metadata query or not to
      ** get the CompilerContext to make the createDependency()
      ** call a noop.
      */
      CompilerContext cc = lcc.pushCompilerContext(compilationSchema);
     
      if (prepareIsolationLevel !=
        ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL)
      {
        cc.setScanIsolationLevel(prepareIsolationLevel);
      }


      // Look for stored statements that are in a system schema
      // and with a match compilation schema. If so, allow them
      // to compile using internal SQL constructs.

      if (internalSQL ||
        (spsSchema != null) && (spsSchema.isSystemSchema()) &&
          (spsSchema.equals(compilationSchema))) {
            cc.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);
      }

      try
      {
        // Statement logging if lcc.getLogStatementText() is true
        if (istream != null)
        {
          String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
          istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                        xactId +
                        "), " +
                        LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                        "), " +
                        LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                        "), " +
                        LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                        "), Begin compiling prepared statement: " +
                        getSource() +
                        " :End prepared statement");
        }

        Parser p = cc.getParser();

        cc.setCurrentDependent(preparedStmt);

        //Only top level statements go through here, nested statement
        //will invoke this method from other places
        StatementNode qt = p.parseStatement(statementText, paramDefaults);

        parseTime = getCurrentTimeMillis(lcc);

                // Call user-written tree-printer if it exists
                walkAST( lcc, qt, ASTVisitor.AFTER_PARSE);

        if (SanityManager.DEBUG)
        {
          if (SanityManager.DEBUG_ON("DumpParseTree"))
          {
            SanityManager.GET_DEBUG_STREAM().print(
              "\n\n============PARSE===========\n\n");
            qt.treePrint();
            lcc.getPrintedObjectsMap().clear();
          }

          if (SanityManager.DEBUG_ON("StopAfterParsing"))
          {
                        lcc.setLastQueryTree( qt );
                       
            throw StandardException.newException(SQLState.LANG_STOP_AFTER_PARSING);
          }
        }

        /*
        ** Tell the data dictionary that we are about to do
        ** a bunch of "get" operations that must be consistent with
        ** each other.
        */
       
        DataDictionary dataDictionary = lcc.getDataDictionary();

        int ddMode = dataDictionary == null ? 0 : dataDictionary.startReading(lcc);

        try
        {
          // start a nested transaction -- all locks acquired by bind
          // and optimize will be released when we end the nested
          // transaction.
          lcc.beginNestedTransaction(true);

          qt.bindStatement();
          bindTime = getCurrentTimeMillis(lcc);

                    // Call user-written tree-printer if it exists
                    walkAST( lcc, qt, ASTVisitor.AFTER_BIND);

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("DumpBindTree"))
            {
              SanityManager.GET_DEBUG_STREAM().print(
                "\n\n============BIND===========\n\n");
              qt.treePrint();
              lcc.getPrintedObjectsMap().clear();
            }

            if (SanityManager.DEBUG_ON("StopAfterBinding")) {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_BINDING);
            }
          }

          //Derby424 - In order to avoid caching select statements referencing
          // any SESSION schema objects (including statements referencing views
          // in SESSION schema), we need to do the SESSION schema object check
          // here. 
          //a specific eg for statement referencing a view in SESSION schema
          //CREATE TABLE t28A (c28 int)
          //INSERT INTO t28A VALUES (280),(281)
          //CREATE VIEW SESSION.t28v1 as select * from t28A
          //SELECT * from SESSION.t28v1 should show contents of view and we
          // should not cache this statement because a user can later define
          // a global temporary table with the same name as the view name.
          //Following demonstrates that
          //DECLARE GLOBAL TEMPORARY TABLE SESSION.t28v1(c21 int, c22 int) not
          //     logged
          //INSERT INTO SESSION.t28v1 VALUES (280,1),(281,2)
          //SELECT * from SESSION.t28v1 should show contents of global temporary
          //table and not the view.  Since this select statement was not cached
          // earlier, it will be compiled again and will go to global temporary
          // table to fetch data. This plan will not be cached either because
          // select statement is using SESSION schema object.
          //
          //Following if statement makes sure that if the statement is
          // referencing SESSION schema objects, then we do not want to cache it.
          // We will remove the entry that was made into the cache for
          //this statement at the beginning of the compile phase.
          //The reason we do this check here rather than later in the compile
          // phase is because for a view, later on, we loose the information that
          // it was referencing SESSION schema because the reference
          //view gets replaced with the actual view definition. Right after
          // binding, we still have the information on the view and that is why
          // we do the check here.
          if (preparedStmt.referencesSessionSchema(qt)) {
            if (foundInCache)
              ((GenericLanguageConnectionContext)lcc).removeStatement(this);
          }
         
          qt.optimizeStatement();

          optimizeTime = getCurrentTimeMillis(lcc);

                    // Call user-written tree-printer if it exists
                    walkAST( lcc, qt, ASTVisitor.AFTER_OPTIMIZE);

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), End compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
        }

        catch (StandardException se)
        {
          lcc.commitNestedTransaction();

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), Error compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
          throw se;
        }

        finally
        {
          /* Tell the data dictionary that we are done reading */
          if (dataDictionary != null)
          dataDictionary.doneReading(ddMode, lcc);
        }

        /* we need to move the commit of nested sub-transaction
         * after we mark PS valid, during compilation, we might need
         * to get some lock to synchronize with another thread's DDL
         * execution, in particular, the compilation of insert/update/
         * delete vs. create index/constraint (see Beetle 3976).  We
         * can't release such lock until after we mark the PS valid.
         * Otherwise we would just erase the DDL's invalidation when
         * we mark it valid.
         */
        try    // put in try block, commit sub-transaction if bad
        {
          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("DumpOptimizedTree"))
            {
              SanityManager.GET_DEBUG_STREAM().print(
                "\n\n============OPT===========\n\n");
              qt.treePrint();
              lcc.getPrintedObjectsMap().clear();
            }

            if (SanityManager.DEBUG_ON("StopAfterOptimizing"))
            {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_OPTIMIZING);
            }
          }

          GeneratedClass ac = qt.generate(preparedStmt.getByteCodeSaver());

          generateTime = getCurrentTimeMillis(lcc);
          /* endTimestamp only meaningful if generateTime is meaningful.
           * generateTime is meaningful if STATISTICS TIMING is ON.
           */
          if (generateTime != 0)
          {
            endTimestamp = new Timestamp(generateTime);
          }

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("StopAfterGenerating"))
            {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_GENERATING);
            }
          }

          /*
            copy over the compile-time created objects
            to the prepared statement.  This always happens
            at the end of a compile, so there is no need
            to erase the previous entries on a re-compile --
            this erases as it replaces.  Set the activation
            class in case it came from a StorablePreparedStatement
          */
          preparedStmt.setConstantAction( qt.makeConstantAction() );
          preparedStmt.setSavedObjects( cc.getSavedObjects() );
          preparedStmt.setRequiredPermissionsList(cc.getRequiredPermissionsList());
          preparedStmt.setActivationClass(ac);
          preparedStmt.setNeedsSavepoint(qt.needsSavepoint());
          preparedStmt.setCursorInfo((CursorInfo)cc.getCursorInfo());
          preparedStmt.setIsAtomic(qt.isAtomic());
          preparedStmt.setExecuteStatementNameAndSchema(
                        qt.executeStatementName(),
                        qt.executeSchemaName()
                        );
          preparedStmt.setSPSName(qt.getSPSName());
          preparedStmt.completeCompile(qt);
          preparedStmt.setCompileTimeWarnings(cc.getWarnings());

                    // Schedule updates of any stale index statistics we may
                    // have detected when creating the plan.
                    TableDescriptor[] tds = qt.updateIndexStatisticsFor();
                    if (tds.length > 0) {
                        IndexStatisticsDaemon isd = lcc.getDataDictionary().
                            getIndexStatsRefresher(true);
                        if (isd != null) {
                            for (int i=0; i < tds.length; i++) {
                                isd.schedule(tds[i]);
                            }
                        }
                    }
                }
        catch (StandardException e)   // hold it, throw it
        {
          lcc.commitNestedTransaction();
          throw e;
        }

        if (lcc.getRunTimeStatisticsMode())
        {
          preparedStmt.setCompileTimeMillis(
            parseTime - beginTime, //parse time
            bindTime - parseTime, //bind time
            optimizeTime - bindTime, //optimize time
            generateTime - optimizeTime, //generate time
            generateTime - beginTime, //total compile time
            beginTimestamp,
            endTimestamp);
        }

      }
      finally // for block introduced by pushCompilerContext()
      {
        lcc.popCompilerContext( cc );
      }
    }
    catch (StandardException se)
    {
      if (foundInCache)
        ((GenericLanguageConnectionContext)lcc).removeStatement(this);

            if (statementContext != null) {
                statementContext.cleanupOnError(se);
            }

      throw se;
    }
    finally
View Full Code Here

Examples of org.apache.derby.iapi.sql.conn.StatementContext

        ps.setSource(sps.getText());
        ps.setSPSAction();
      }

      // save the active statement context for exception handling purpose
      StatementContext active_sc = lcc.getStatementContext();
     
      /*
      ** Execute the activation.  If we have an error, we
      ** are going to go to some extra work to pop off
      ** our statement context.  This is because we are
      ** a nested statement (we have 2 activations), but
      ** we aren't a nested connection, so we have to
      ** pop off our statementcontext to get error handling 
      ** to work correctly.  This is normally a no-no, but
      ** we are an unusual case.
      */
      try
      {
                // This is a substatement; for now, we do not set any timeout
                // for it. We might change this behaviour later, by linking
                // timeout to its parent statement's timeout settings.
                ResultSet rs = ps.execute(spsActivation, false, 0L);
                if( rs.returnsRows())
                {
                    // Fetch all the data to ensure that functions in the select list or values statement will
                    // be evaluated and side effects will happen. Why else would the trigger action return
                    // rows, but for side effects?
                    // The result set was opened in ps.execute()
                    while( rs.getNextRow() != null)
                    {
                    }
                }
                rs.close();
      }
      catch (StandardException e)
      {
        /*
        ** When a trigger SPS action is executed and results in
        ** an exception, the system needs to clean up the active
        ** statement context(SC) and the trigger execution context
        ** (TEC) in language connection context(LCC) properly (e.g.: 
        ** "Maximum depth triggers exceeded" exception); otherwise,
        ** this will leave old TECs lingering and may result in
        ** subsequent statements within the same connection to throw
        ** the same exception again prematurely. 
        **   
        ** A new statement context will be created for the SPS before
        ** it is executed.  However, it is possible for some
        ** StandardException to be thrown before a new statement
        ** context is pushed down to the context stack; hence, the
        ** trigger executor needs to ensure that the current active SC
        ** is associated with the SPS, so that it is cleaning up the
        ** right statement context in LCC.
        **   
        ** When the active SC is cleaned up, the TEC will be removed
        ** from LCC and the SC object will be popped off from the LCC
        ** as part of cleanupOnError logic. 
         */
       
        /* retrieve the current active SC */
        StatementContext sc = lcc.getStatementContext();
       
        /* make sure that the cleanup is on the new SC */
        if (active_sc != sc)
        {
          sc.cleanupOnError(e);
        }
       
        /* Handle dynamic recompiles */
        if (e.getMessageId().equals(SQLState.LANG_STATEMENT_NEEDS_RECOMPILE))
        {
View Full Code Here

Examples of org.apache.derby.iapi.sql.conn.StatementContext

    {
      if (! isTopResultSet)
      {
        /* This is simply for RunTimeStats */
        /* We first need to get the subquery tracking array via the StatementContext */
        StatementContext sc = activation.getLanguageConnectionContext().getStatementContext();
        subqueryTrackingArray = sc.getSubqueryTrackingArray();
      }
      nextTime += getElapsedMillis(beginTime);
    }
      return result;
  }
View Full Code Here

Examples of org.apache.derby.iapi.sql.conn.StatementContext

      SanityManager.ASSERT(isClone, "Should only call method on a clone");

    getlcc();
    if (lcc != null)
    {
      StatementContext sc = lcc.getStatementContext();
      if (sc != null)
        return sc.getStatementText() ;
    }
    return null;

  }
View Full Code Here

Examples of org.apache.derby.iapi.sql.conn.StatementContext

        /* Push and pop a StatementContext around a next call
         * so that the ResultSet will get correctly closed down
         * on an error.
         * (Cache the LanguageConnectionContext)
         */
                StatementContext statementContext =
                    lcc.pushStatementContext(isAtomic,
               concurrencyOfThisResultSet==java.sql.ResultSet.CONCUR_READ_ONLY,
               getSQLText(),
               getParameterValueSet(),
                                             false, timeoutMillis);
View Full Code Here

Examples of org.apache.derby.iapi.sql.conn.StatementContext

  public void insertRow() throws SQLException {
        synchronized (getConnectionSynchronization()) {
            checksBeforeInsert();
            setupContextStack();
            LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
            StatementContext statementContext = null;
            try {
                /*
                 * construct the insert statement
                 *
                 * If no values have been supplied for a column, it will be set
                 * to the column's default value, if any.
                 * If no default value had been defined, the default value of a
                 * nullable column is set to NULL.
                 */

                boolean foundOneColumnAlready = false;
                StringBuffer insertSQL = new StringBuffer("INSERT INTO ");
                StringBuffer valuesSQL = new StringBuffer("VALUES (");
                CursorActivation activation = lcc.lookupCursorActivation(getCursorName());

                ExecCursorTableReference targetTable =
                        activation.getPreparedStatement().getTargetTable();
                // got the underlying (schema.)table name
                insertSQL.append(getFullBaseTableName(targetTable));
                ResultDescription rd = theResults.getResultDescription();

                insertSQL.append(" (");
                // in this for loop we are constructing list of column-names
                // and values (?) ,... part of the insert sql
                for (int i=1; i<=rd.getColumnCount(); i++) {
                    if (foundOneColumnAlready) {
                        insertSQL.append(",");
                        valuesSQL.append(",");
                    }
                    // using quotes around the column name
                    // to preserve case sensitivity
                    insertSQL.append(IdUtil.normalToDelimited(
                            rd.getColumnDescriptor(i).getName()));
                    if (columnGotUpdated[i-1]) {
                        valuesSQL.append("?");
                    } else {
                        valuesSQL.append("DEFAULT");
                    }
                    foundOneColumnAlready = true;
                }
                insertSQL.append(") ");
                valuesSQL.append(") ");
                insertSQL.append(valuesSQL);

                StatementContext currSC = lcc.getStatementContext();
                Activation parentAct = null;

                if (currSC != null) {
                    parentAct = currSC.getActivation();
                }

                // Context used for preparing, don't set any timeout (use 0)
                statementContext = lcc.pushStatementContext(
                        isAtomic,
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.