public virtual Differences VisitQueryTransact(QueryTransact qt1, QueryTransact qt2){
      Differences differences = new Differences(qt1, qt2);
      if (qt1 == null || qt2 == null){
        if (qt1 != qt2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryTransact changes = (QueryTransact)qt2.Clone();
      QueryTransact deletions = (QueryTransact)qt2.Clone();
      QueryTransact insertions = (QueryTransact)qt2.Clone();

      //      qt1.Body;
      //      qt1.CommitBody;
      //      qt1.Isolation;
      //      qt1.RollbackBody;
      //      qt1.Transaction;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
 public virtual Node VisitQueryTransact(QueryTransact qt, QueryTransact changes, QueryTransact deletions, QueryTransact insertions){
   this.UpdateSourceContext(qt, changes);
   if (qt == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return qt;
 }
Exemple #3
0
 public override Node VisitQueryTransact(QueryTransact qt) {
   if (qt == null) return null;
   if (this.currentTransaction != null) {
     this.HandleError(qt, Error.QueryNoNestedTransaction);
     return null;
   }
   this.currentTransaction = qt;
   base.VisitQueryTransact(qt);
   this.currentTransaction = null;
   if (qt.Source == null || qt.Source.Type == null) return null;
   if (!this.typeSystem.ImplicitCoercionFromTo(qt.Source.Type, SystemTypes.IDbConnection, this.TypeViewer) &&
     !this.typeSystem.ImplicitCoercionFromTo(qt.Source.Type, SystemTypes.IDbTransactable, this.TypeViewer)) {
     this.HandleError(qt.Source, Error.QueryNotTransactable, this.GetTypeName(qt.Source.Type));
     return null;
   }
   if (qt.Isolation != null) {
     if (qt.Isolation.Type == null) return null;
     if (!this.typeSystem.ImplicitCoercionFromTo(qt.Isolation.Type, SystemTypes.IsolationLevel, this.TypeViewer)) {
       this.typeSystem.ImplicitCoercion(qt.Isolation, SystemTypes.IsolationLevel, this.TypeViewer);
       return null;
     }
   }
   return qt;
 }
 public virtual Node VisitQueryTransact(QueryTransact qt){
   if (qt == null) return null;
   qt.Source = this.VisitExpression(qt.Source);
   qt.Body = this.VisitBlock(qt.Body);
   qt.CommitBody = this.VisitBlock(qt.CommitBody);
   qt.RollbackBody = this.VisitBlock(qt.RollbackBody);
   return qt;
 }
Exemple #5
0
 public virtual void VisitQueryTransact(QueryTransact qt){
   if (qt == null) return;
   this.VisitExpression(qt.Source);
   this.VisitBlock(qt.Body);
   this.VisitBlock(qt.CommitBody);
   this.VisitBlock(qt.RollbackBody);
 }
Exemple #6
0
 public override Node VisitQueryTransact(QueryTransact qt){
   if (qt == null) return null;
   return base.VisitQueryTransact((QueryTransact)qt.Clone());
 }
 public virtual Node VisitQueryTransact(QueryTransact qt1, QueryTransact qt2){
   if (qt1 == null) return null;
   if (qt2 == null){
     qt1.Source = this.VisitExpression(qt1.Source, null);
     qt1.Body = this.VisitBlock(qt1.Body, null);
     qt1.CommitBody = this.VisitBlock(qt1.CommitBody, null);
     qt1.RollbackBody = this.VisitBlock(qt1.RollbackBody, null);
   }else{
     qt1.Source = this.VisitExpression(qt1.Source, qt2.Source);
     qt1.Body = this.VisitBlock(qt1.Body, qt2.Body);
     qt1.CommitBody = this.VisitBlock(qt1.CommitBody, qt2.CommitBody);
     qt1.RollbackBody = this.VisitBlock(qt1.RollbackBody, qt2.RollbackBody);
   }
   return qt1;
 }
Exemple #8
0
    public override Node VisitQueryTransact(QueryTransact qt) {
      if (qt == null || qt.Source == null || qt.Source.Type == null) return null;
      Block block = new Block(new StatementList(10));
      qt.Transaction = this.NewClosureLocal(SystemTypes.IDbTransaction, this.currentMethod.Body.Scope);
      Expression locCommit = this.NewClosureLocal(SystemTypes.Boolean, this.currentMethod.Body.Scope);
      TypeNode txType = null;
      if (this.GetTypeView(qt.Source.Type).IsAssignableTo(SystemTypes.IDbConnection)) {
        txType = SystemTypes.IDbConnection;
      }
      else if (this.GetTypeView(qt.Source.Type).IsAssignableTo(SystemTypes.IDbTransactable)) {
        txType = SystemTypes.IDbTransactable;
      }
      Expression source = this.typeSystem.ExplicitCoercion(qt.Source, txType, this.TypeViewer);
      if (qt.Isolation != null) {
        Method mBegin = this.GetTypeView(txType).GetMethod(idBeginTransaction, SystemTypes.IsolationLevel);
        MethodCall mcBegin = new MethodCall(new MemberBinding(source, mBegin), new ExpressionList(qt.Isolation));
        mcBegin.Type = mBegin.ReturnType;
        mcBegin.NodeType = NodeType.Callvirt;
        block.Statements.Add(new AssignmentStatement(qt.Transaction, mcBegin));
      }
      else {
        Method mBegin = this.GetTypeView(txType).GetMethod(idBeginTransaction);
        MethodCall mcBegin = new MethodCall(new MemberBinding(source, mBegin), null);
        mcBegin.Type = mBegin.ReturnType;
        mcBegin.NodeType = NodeType.Callvirt;
        block.Statements.Add(new AssignmentStatement(qt.Transaction, mcBegin));
      }
      block.Statements.Add(new AssignmentStatement(locCommit, Literal.True));

      // prepare finally block
      Block finBlock = new Block(new StatementList(10));
      Method mRollback = SystemTypes.IDbTransaction.GetMethod(idRollback);
      MethodCall mcRollback = new MethodCall(new MemberBinding(qt.Transaction, mRollback), null);
      mcRollback.Type = mRollback.ReturnType;
      mcRollback.NodeType = NodeType.Callvirt;
      Method mCommit = SystemTypes.IDbTransaction.GetMethod(idCommit);
      MethodCall mcCommit = new MethodCall(new MemberBinding(qt.Transaction, mCommit), null);
      mcCommit.Type = mCommit.ReturnType;
      mcCommit.NodeType = NodeType.Callvirt;
      Method mDispose = SystemTypes.IDisposable.GetMethod(StandardIds.Dispose);
      MethodCall mcDispose = new MethodCall(new MemberBinding(qt.Transaction, mDispose), null);
      mcDispose.Type = mDispose.ReturnType;
      mcDispose.NodeType = NodeType.Callvirt;
      Block bCommitStart = new Block();
      Block bCommitBody = new Block(qt.CommitBody.Statements);
      Block bRollbackBody = new Block(qt.RollbackBody.Statements);
      Block finExit = new Block();
      finBlock.Statements.Add(new Branch(locCommit, bCommitStart));
      finBlock.Statements.Add(new ExpressionStatement(mcRollback));
      finBlock.Statements.Add(bRollbackBody);
      finBlock.Statements.Add(new Branch(null, finExit));
      finBlock.Statements.Add(bCommitStart);
      finBlock.Statements.Add(new ExpressionStatement(mcCommit));
      finBlock.Statements.Add(bCommitBody);
      finBlock.Statements.Add(finExit);
      finBlock.Statements.Add(new ExpressionStatement(mcDispose));
      finBlock.Statements.Add(new AssignmentStatement(qt.Transaction, Literal.Null));

      // prepare catcher
      Local locEx = new Local(SystemTypes.Object);
      Block catchBlock = new Block(new StatementList(2));
      catchBlock.Statements.Add(new AssignmentStatement(locCommit, Literal.False));
      Throw _throw = new Throw(locEx);
      _throw.NodeType = NodeType.Rethrow;
      catchBlock.Statements.Add(_throw);
      CatchList catchers = new CatchList(1);
      catchers.Add(new Catch(catchBlock, locEx, SystemTypes.Object));

      // prepare try block
      Block tryBlock = new Block(new StatementList(4));
      qt.CommitBody.Statements = null;;
      qt.RollbackBody.Statements = null;
      tryBlock.Statements.Add(qt.Body);
      tryBlock.Statements.Add(new Branch(null, qt.CommitBody));
      tryBlock.Statements.Add(qt.RollbackBody);
      tryBlock.Statements.Add(new AssignmentStatement(locCommit, Literal.False));
      tryBlock.Statements.Add(qt.CommitBody);
      this.exceptionBlockFor[qt.CommitBody.UniqueKey] = tryBlock;
      this.exceptionBlockFor[qt.RollbackBody.UniqueKey] = tryBlock;

      // add try-finally to block      
      block.Statements.Add(new Try(tryBlock, catchers, null, null, new Finally(finBlock)));
      this.currentTransaction = qt;
      Node result = this.VisitBlock(block);
      this.currentTransaction = null;
      return result;
    }
 public EventingVisitor(Action<QueryTransact> visitQueryTransact) { VisitedQueryTransact += visitQueryTransact; } public event Action<QueryTransact> VisitedQueryTransact; public override Node VisitQueryTransact(QueryTransact qt) { if (VisitedQueryTransact != null) VisitedQueryTransact(qt); return base.VisitQueryTransact(qt); }