github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/build_transation.go (about) 1 // Copyright 2021 - 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package plan 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/pb/plan" 19 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 20 ) 21 22 func buildBeginTransaction(stmt *tree.BeginTransaction, ctx CompilerContext) (*Plan, error) { 23 beginTransation := &plan.TransationBegin{} 24 switch stmt.Modes.RwMode { 25 case tree.READ_WRITE_MODE_NONE: 26 beginTransation.Mode = plan.TransationBegin_NONE 27 case tree.READ_WRITE_MODE_READ_ONLY: 28 beginTransation.Mode = plan.TransationBegin_READ_ONLY 29 case tree.READ_WRITE_MODE_READ_WRITE: 30 beginTransation.Mode = plan.TransationBegin_READ_WRITE 31 } 32 33 return &Plan{ 34 Plan: &plan.Plan_Tcl{ 35 Tcl: &plan.TransationControl{ 36 TclType: plan.TransationControl_BEGIN, 37 Action: &plan.TransationControl_Begin{ 38 Begin: beginTransation, 39 }, 40 }, 41 }, 42 }, nil 43 } 44 45 func buildCommitTransaction(stmt *tree.CommitTransaction, ctx CompilerContext) (*Plan, error) { 46 commitTransation := &plan.TransationCommit{} 47 switch stmt.Type { 48 case tree.COMPLETION_TYPE_CHAIN: 49 commitTransation.CompletionType = plan.TransationCompletionType_CHAIN 50 case tree.COMPLETION_TYPE_RELEASE: 51 commitTransation.CompletionType = plan.TransationCompletionType_RELEASE 52 case tree.COMPLETION_TYPE_NO_CHAIN: 53 commitTransation.CompletionType = plan.TransationCompletionType_NO_CHAIN 54 } 55 return &Plan{ 56 Plan: &plan.Plan_Tcl{ 57 Tcl: &plan.TransationControl{ 58 TclType: plan.TransationControl_COMMIT, 59 Action: &plan.TransationControl_Commit{ 60 Commit: commitTransation, 61 }, 62 }, 63 }, 64 }, nil 65 } 66 67 func buildRollbackTransaction(stmt *tree.RollbackTransaction, ctx CompilerContext) (*Plan, error) { 68 rollbackTransation := &plan.TransationRollback{} 69 switch stmt.Type { 70 case tree.COMPLETION_TYPE_CHAIN: 71 rollbackTransation.CompletionType = plan.TransationCompletionType_CHAIN 72 case tree.COMPLETION_TYPE_RELEASE: 73 rollbackTransation.CompletionType = plan.TransationCompletionType_RELEASE 74 case tree.COMPLETION_TYPE_NO_CHAIN: 75 rollbackTransation.CompletionType = plan.TransationCompletionType_NO_CHAIN 76 } 77 return &Plan{ 78 Plan: &plan.Plan_Tcl{ 79 Tcl: &plan.TransationControl{ 80 TclType: plan.TransationControl_ROLLBACK, 81 Action: &plan.TransationControl_Rollback{ 82 Rollback: rollbackTransation, 83 }, 84 }, 85 }, 86 }, nil 87 }