From ad71d92fbba50e31373e7606375068845908f5b0 Mon Sep 17 00:00:00 2001 From: zhuxiujia Date: Sat, 26 Jan 2019 22:50:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=A6=E5=90=88golint=20=E8=A7=84=E8=8C=83?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8it=E4=BB=A3=E6=9B=BFthis=20=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E6=8E=A5=E6=94=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ExpressionEngineExpr.go | 20 +++--- ExpressionEngineGovaluate.go | 14 ++-- ExpressionEngineJee.go | 18 ++--- ExpressionEngineLexerMapCache.go | 24 +++---- ExpressionEngineProxy.go | 40 +++++------ GoMybatisEngine.go | 4 +- GoMybatisEngine_test.go | 14 ++-- GoMybatisExpressionTypeConvert.go | 2 +- GoMybatisSqlArgTypeConvert.go | 8 +-- LICENSE | 34 +++++----- LocalSession.go | 76 ++++++++++----------- LogStandard.go | 8 +-- LogSystem.go | 34 +++++----- SessionFactory.go | 44 ++++++------- SessionFactorySession.go | 58 ++++++++-------- SqlBuilder.go | 106 +++++++++++++++--------------- SqlResultDecodeUtil.go | 54 +++++++-------- TransactionDefinition.go | 2 +- TransactionFactory.go | 26 ++++---- TransactionManager.go | 32 ++++----- TransactionManager_test.go | 6 +- TransactionStatus.go | 48 +++++++------- TransationRMClient.go | 50 +++++++------- TransationRMServer.go | 4 +- TransationRMServerSession.go | 52 +++++++-------- mybatis-3-mapper.dtd | 2 +- 26 files changed, 390 insertions(+), 390 deletions(-) diff --git a/ExpressionEngineExpr.go b/ExpressionEngineExpr.go index 196e88f..84cec28 100644 --- a/ExpressionEngineExpr.go +++ b/ExpressionEngineExpr.go @@ -10,15 +10,15 @@ type ExpressionEngineExpr struct { } //引擎名称 -func (this *ExpressionEngineExpr) Name() string { +func (it *ExpressionEngineExpr) Name() string { return "ExpressionEngineExpr" } //编译一个表达式 //参数:lexerArg 表达式内容 //返回:interface{} 编译结果,error 错误 -func (this *ExpressionEngineExpr) Lexer(expression string) (interface{}, error) { - expression = this.repleaceExpression(expression) +func (it *ExpressionEngineExpr) Lexer(expression string) (interface{}, error) { + expression = it.repleaceExpression(expression) var result, err = expr.Parse(expression) return result, err } @@ -26,13 +26,13 @@ func (this *ExpressionEngineExpr) Lexer(expression string) (interface{}, error) //执行一个表达式 //参数:lexerResult=编译结果,arg=参数 //返回:执行结果,错误 -func (this *ExpressionEngineExpr) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) { +func (it *ExpressionEngineExpr) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) { output, err := expr.Run(lexerResult.(expr.Node), arg) return output, err } //替换表达式中的值 and,or,参数 替换为实际值 -func (this *ExpressionEngineExpr) repleaceExpression(expression string) string { +func (it *ExpressionEngineExpr) repleaceExpression(expression string) string { if expression == "" { return expression } @@ -41,7 +41,7 @@ func (this *ExpressionEngineExpr) repleaceExpression(expression string) string { return expression } -func (this *ExpressionEngineExpr) split(str string) (stringItems []string) { +func (it *ExpressionEngineExpr) split(str string) (stringItems []string) { if str == "" { return nil } @@ -69,10 +69,10 @@ func (this *ExpressionEngineExpr) split(str string) (stringItems []string) { } //Lexer缓存,可不提供。 -func (this *ExpressionEngineExpr) LexerCache() ExpressionEngineLexerCache { - if this.mapCache == nil { +func (it *ExpressionEngineExpr) LexerCache() ExpressionEngineLexerCache { + if it.mapCache == nil { var cache = ExpressionEngineLexerMapCache{}.New() - this.mapCache = &cache + it.mapCache = &cache } - return this.mapCache + return it.mapCache } diff --git a/ExpressionEngineGovaluate.go b/ExpressionEngineGovaluate.go index 120f209..64e558a 100644 --- a/ExpressionEngineGovaluate.go +++ b/ExpressionEngineGovaluate.go @@ -8,27 +8,27 @@ import ( type ExpressionEngineGovaluate struct { } -func (this *ExpressionEngineGovaluate) Name() string { +func (it *ExpressionEngineGovaluate) Name() string { return "ExpressionEngineGovaluate" } //编译一个表达式 //参数:lexerArg 表达式内容 //返回:interface{} 编译结果,error 错误 -func (this *ExpressionEngineGovaluate) Lexer(expression string) (interface{}, error) { - expression = this.repleaceExpression(expression) +func (it *ExpressionEngineGovaluate) Lexer(expression string) (interface{}, error) { + expression = it.repleaceExpression(expression) return govaluate.NewEvaluableExpression(expression) } //执行一个表达式 //参数:lexerResult=编译结果,arg=参数 //返回:执行结果,错误 -func (this *ExpressionEngineGovaluate) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) { +func (it *ExpressionEngineGovaluate) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) { return compileResult.(*govaluate.EvaluableExpression).Evaluate(arg.(map[string]interface{})) } //替换表达式中的值 and,or,参数 替换为实际值 -func (this *ExpressionEngineGovaluate) repleaceExpression(expression string) string { +func (it *ExpressionEngineGovaluate) repleaceExpression(expression string) string { if expression == "" { return expression } @@ -37,7 +37,7 @@ func (this *ExpressionEngineGovaluate) repleaceExpression(expression string) str return expression } -func (this *ExpressionEngineGovaluate) split(str string) (stringItems []string) { +func (it *ExpressionEngineGovaluate) split(str string) (stringItems []string) { if str == "" { return nil } @@ -65,6 +65,6 @@ func (this *ExpressionEngineGovaluate) split(str string) (stringItems []string) } //Lexer缓存,可不提供。 -func (this *ExpressionEngineGovaluate) LexerCache() ExpressionEngineLexerCache { +func (it *ExpressionEngineGovaluate) LexerCache() ExpressionEngineLexerCache { return nil } diff --git a/ExpressionEngineJee.go b/ExpressionEngineJee.go index 8d7ae9d..a5041d7 100644 --- a/ExpressionEngineJee.go +++ b/ExpressionEngineJee.go @@ -19,15 +19,15 @@ const ( type ExpressionEngineJee struct { } -func (this *ExpressionEngineJee) Name() string { +func (it *ExpressionEngineJee) Name() string { return "ExpressionEngineJee" } //编译一个表达式 //参数:lexerArg 表达式内容 //返回:interface{} 编译结果,error 错误 -func (this *ExpressionEngineJee) Lexer(lexerArg string) (interface{}, error) { - tokenized, err := jee.Lexer(this.LexerAndOrSupport(lexerArg)) +func (it *ExpressionEngineJee) Lexer(lexerArg string) (interface{}, error) { + tokenized, err := jee.Lexer(it.LexerAndOrSupport(lexerArg)) if err != nil { return nil, utils.NewError("ExpressionEngineJee", err) } @@ -41,7 +41,7 @@ func (this *ExpressionEngineJee) Lexer(lexerArg string) (interface{}, error) { //执行一个表达式 //参数:lexerResult=编译结果,arg=参数 //返回:执行结果,错误 -func (this *ExpressionEngineJee) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) { +func (it *ExpressionEngineJee) Eval(compileResult interface{}, arg interface{}, operation int) (interface{}, error) { var jeeMsg jee.BMsg switch operation { case JeeOperation_Marshal_Map: @@ -73,16 +73,16 @@ func (this *ExpressionEngineJee) Eval(compileResult interface{}, arg interface{} } //编译后立即执行 -func (this *ExpressionEngineJee) LexerEval(lexerArg string, arg interface{}, operation int) (interface{}, error) { - var lexer, error = this.Lexer(lexerArg) +func (it *ExpressionEngineJee) LexerEval(lexerArg string, arg interface{}, operation int) (interface{}, error) { + var lexer, error = it.Lexer(lexerArg) if error != nil { return nil, error } - return this.Eval(lexer, arg, operation) + return it.Eval(lexer, arg, operation) } //添加and 和 or 语法支持 -func (this *ExpressionEngineJee) LexerAndOrSupport(lexerArg string) string { +func (it *ExpressionEngineJee) LexerAndOrSupport(lexerArg string) string { var buf bytes.Buffer strs := strings.Split(lexerArg, " or ") if len(strs) > 1 { @@ -118,6 +118,6 @@ func (this *ExpressionEngineJee) LexerAndOrSupport(lexerArg string) string { } //Lexer缓存,可不提供。 -func (this *ExpressionEngineJee) LexerCache() ExpressionEngineLexerCache { +func (it *ExpressionEngineJee) LexerCache() ExpressionEngineLexerCache { return nil } diff --git a/ExpressionEngineLexerMapCache.go b/ExpressionEngineLexerMapCache.go index cd1f4f5..2866bbb 100644 --- a/ExpressionEngineLexerMapCache.go +++ b/ExpressionEngineLexerMapCache.go @@ -10,26 +10,26 @@ type ExpressionEngineLexerMapCache struct { lock sync.RWMutex } -func (this ExpressionEngineLexerMapCache) New() ExpressionEngineLexerMapCache { - if this.mapCache == nil { - this.mapCache = make(map[string]interface{}) +func (it ExpressionEngineLexerMapCache) New() ExpressionEngineLexerMapCache { + if it.mapCache == nil { + it.mapCache = make(map[string]interface{}) } - return this + return it } -func (this *ExpressionEngineLexerMapCache) Set(expression string, lexer interface{}) error { +func (it *ExpressionEngineLexerMapCache) Set(expression string, lexer interface{}) error { if expression == "" { return utils.NewError("ExpressionEngineLexerMapCache", "set lexerMap chache key can not be ''!") } - this.lock.Lock() - defer this.lock.Unlock() - this.mapCache[expression] = lexer + it.lock.Lock() + defer it.lock.Unlock() + it.mapCache[expression] = lexer return nil } -func (this *ExpressionEngineLexerMapCache) Get(expression string) (interface{}, error) { +func (it *ExpressionEngineLexerMapCache) Get(expression string) (interface{}, error) { var result interface{} - this.lock.RLock() - defer this.lock.RUnlock() - result = this.mapCache[expression] + it.lock.RLock() + defer it.lock.RUnlock() + result = it.mapCache[expression] return result, nil } diff --git a/ExpressionEngineProxy.go b/ExpressionEngineProxy.go index 38ce894..41e91e3 100644 --- a/ExpressionEngineProxy.go +++ b/ExpressionEngineProxy.go @@ -16,23 +16,23 @@ func (ExpressionEngineProxy) New(engine ExpressionEngine, useLexerCache bool) Ex } //引擎名称 -func (this ExpressionEngineProxy) Name() string { - if this.expressionEngine == nil { +func (it ExpressionEngineProxy) Name() string { + if it.expressionEngine == nil { return "" } - return this.expressionEngine.Name() + return it.expressionEngine.Name() } //编译一个表达式 //参数:lexerArg 表达式内容 //返回:interface{} 编译结果,error 错误 -func (this *ExpressionEngineProxy) Lexer(expression string) (interface{}, error) { - if this.expressionEngine == nil { +func (it *ExpressionEngineProxy) Lexer(expression string) (interface{}, error) { + if it.expressionEngine == nil { return nil, utils.NewError("ExpressionEngineProxy", "ExpressionEngineProxy not init for ExpressionEngineProxy{}.New(...)") } - if this.expressionEngine.LexerCache() != nil && this.lexerCacheable { + if it.expressionEngine.LexerCache() != nil && it.lexerCacheable { //如果 提供缓存,则使用缓存 - cacheResult, cacheErr := this.expressionEngine.LexerCache().Get(expression) + cacheResult, cacheErr := it.expressionEngine.LexerCache().Get(expression) if cacheErr != nil { return nil, cacheErr } @@ -40,10 +40,10 @@ func (this *ExpressionEngineProxy) Lexer(expression string) (interface{}, error) return cacheResult, nil } } - var result, err = this.expressionEngine.Lexer(expression) - if this.expressionEngine.LexerCache() != nil && this.lexerCacheable { + var result, err = it.expressionEngine.Lexer(expression) + if it.expressionEngine.LexerCache() != nil && it.lexerCacheable { //如果 提供缓存,则使用缓存 - this.expressionEngine.LexerCache().Set(expression, result) + it.expressionEngine.LexerCache().Set(expression, result) } return result, err } @@ -51,24 +51,24 @@ func (this *ExpressionEngineProxy) Lexer(expression string) (interface{}, error) //执行一个表达式 //参数:lexerResult=编译结果,arg=参数 //返回:执行结果,错误 -func (this *ExpressionEngineProxy) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) { - if this.expressionEngine == nil { +func (it *ExpressionEngineProxy) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error) { + if it.expressionEngine == nil { return nil, utils.NewError("ExpressionEngineProxy", "ExpressionEngineProxy not init for ExpressionEngineProxy{}.New(...)") } - return this.expressionEngine.Eval(lexerResult, arg, operation) + return it.expressionEngine.Eval(lexerResult, arg, operation) } -func (this *ExpressionEngineProxy) LexerCache() ExpressionEngineLexerCache { - if this.expressionEngine == nil { +func (it *ExpressionEngineProxy) LexerCache() ExpressionEngineLexerCache { + if it.expressionEngine == nil { return nil } - return this.expressionEngine.LexerCache() + return it.expressionEngine.LexerCache() } -func (this *ExpressionEngineProxy) SetUseLexerCache(isUseCache bool) error { - this.lexerCacheable = isUseCache +func (it *ExpressionEngineProxy) SetUseLexerCache(isUseCache bool) error { + it.lexerCacheable = isUseCache return nil } -func (this *ExpressionEngineProxy) LexerCacheable() bool { - return this.lexerCacheable +func (it *ExpressionEngineProxy) LexerCacheable() bool { + return it.lexerCacheable } diff --git a/GoMybatisEngine.go b/GoMybatisEngine.go index 858a5f2..adf6d76 100644 --- a/GoMybatisEngine.go +++ b/GoMybatisEngine.go @@ -10,11 +10,11 @@ type GoMybatisEngine struct { DB *sql.DB } -func (this GoMybatisEngine) NewSession() Session { +func (it GoMybatisEngine) NewSession() Session { uuid := utils.CreateUUID() var mysqlLocalSession = LocalSession{ SessionId: uuid, - db: this.DB, + db: it.DB, } var session = Session(&mysqlLocalSession) return session diff --git a/GoMybatisEngine_test.go b/GoMybatisEngine_test.go index ae31784..b74da52 100644 --- a/GoMybatisEngine_test.go +++ b/GoMybatisEngine_test.go @@ -125,10 +125,10 @@ type TestSession struct { Session } -func (this *TestSession) Id() string { +func (it *TestSession) Id() string { return "sadf" } -func (this *TestSession) Query(sqlorArgs string) ([]map[string][]byte, error) { +func (it *TestSession) Query(sqlorArgs string) ([]map[string][]byte, error) { resultsSlice := make([]map[string][]byte, 0) result := make(map[string][]byte) @@ -140,19 +140,19 @@ func (this *TestSession) Query(sqlorArgs string) ([]map[string][]byte, error) { resultsSlice = append(resultsSlice, result) return resultsSlice, nil } -func (this *TestSession) Exec(sqlorArgs string) (*Result, error) { +func (it *TestSession) Exec(sqlorArgs string) (*Result, error) { return nil, nil } -func (this *TestSession) Rollback() error { +func (it *TestSession) Rollback() error { return nil } -func (this *TestSession) Commit() error { +func (it *TestSession) Commit() error { return nil } -func (this *TestSession) Begin() error { +func (it *TestSession) Begin() error { return nil } -func (this *TestSession) Close() { +func (it *TestSession) Close() { } diff --git a/GoMybatisExpressionTypeConvert.go b/GoMybatisExpressionTypeConvert.go index 8daaebb..0db2759 100644 --- a/GoMybatisExpressionTypeConvert.go +++ b/GoMybatisExpressionTypeConvert.go @@ -12,7 +12,7 @@ type GoMybatisExpressionTypeConvert struct { } //表达式类型转换器 -func (this GoMybatisExpressionTypeConvert) Convert(arg SqlArg) interface{} { +func (it GoMybatisExpressionTypeConvert) Convert(arg SqlArg) interface{} { if arg.Type.Kind() == reflect.Struct && arg.Type.String() == Adapter_DateType { return arg.Value.(time.Time).Nanosecond() } diff --git a/GoMybatisSqlArgTypeConvert.go b/GoMybatisSqlArgTypeConvert.go index ab780f3..062c83c 100644 --- a/GoMybatisSqlArgTypeConvert.go +++ b/GoMybatisSqlArgTypeConvert.go @@ -15,7 +15,7 @@ type GoMybatisSqlArgTypeConvert struct { } //Sql内容类型转换器 -func (this GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string { +func (it GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string { var argValue = arg.Value var argType = arg.Type if argValue == nil { @@ -32,7 +32,7 @@ func (this GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string { case reflect.String: var argStr bytes.Buffer argStr.WriteString(`'`) - argStr.WriteString(this.toString(&arg)) + argStr.WriteString(it.toString(&arg)) argStr.WriteString(`'`) return argStr.String() case reflect.Struct: @@ -45,10 +45,10 @@ func (this GoMybatisSqlArgTypeConvert) Convert(arg SqlArg) string { } break } - return this.toString(&arg) + return it.toString(&arg) } -func (this GoMybatisSqlArgTypeConvert) toString(value *SqlArg) string { +func (it GoMybatisSqlArgTypeConvert) toString(value *SqlArg) string { if value.Value == nil { return "" } diff --git a/LICENSE b/LICENSE index 261eeb9..bea135c 100644 --- a/LICENSE +++ b/LICENSE @@ -7,21 +7,21 @@ 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. + and distribution as defined by Sections 1 through 9 of it document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, + control with that entity. For the purposes of it definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. + exercising permissions granted by it License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation @@ -41,7 +41,7 @@ form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain + of it License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. @@ -50,7 +50,7 @@ to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" + the copyright owner. For the purposes of it definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, @@ -64,16 +64,16 @@ subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, + it License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, + it License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, + (except as stated in it section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their @@ -83,7 +83,7 @@ cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate + granted to You under it License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the @@ -92,7 +92,7 @@ meet the following conditions: (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and + Derivative Works a copy of it License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and @@ -125,17 +125,17 @@ for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. + the conditions stated in it License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. + it License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - 6. Trademarks. This License does not grant permission to use the trade + 6. Trademarks. it License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. @@ -148,7 +148,7 @@ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. + risks associated with Your exercise of permissions under it License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, @@ -156,7 +156,7 @@ negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the + result of it License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor @@ -165,7 +165,7 @@ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this + or other liability obligations and/or rights consistent with it License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, @@ -189,7 +189,7 @@ Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. + you may not use it file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 diff --git a/LocalSession.go b/LocalSession.go index 2789850..acc670d 100644 --- a/LocalSession.go +++ b/LocalSession.go @@ -15,18 +15,18 @@ type LocalSession struct { isClosed bool } -func (this *LocalSession) Id() string { - return this.SessionId +func (it *LocalSession) Id() string { + return it.SessionId } -func (this *LocalSession) Rollback() error { - if this.isClosed == true { +func (it *LocalSession) Rollback() error { + if it.isClosed == true { return utils.NewError("LocalSession", " can not Rollback() a Closed Session!") } - if this.tx != nil { - var err = this.tx.Rollback() + if it.tx != nil { + var err = it.tx.Rollback() if err == nil { - this.isCommitedOrRollbacked = true + it.isCommitedOrRollbacked = true } else { return err } @@ -34,27 +34,27 @@ func (this *LocalSession) Rollback() error { return nil } -func (this *LocalSession) Commit() error { - if this.isClosed == true { +func (it *LocalSession) Commit() error { + if it.isClosed == true { return utils.NewError("LocalSession", " can not Commit() a Closed Session!") } - if this.tx != nil { - var err = this.tx.Commit() + if it.tx != nil { + var err = it.tx.Commit() if err == nil { - this.isCommitedOrRollbacked = true + it.isCommitedOrRollbacked = true } } return nil } -func (this *LocalSession) Begin() error { - if this.isClosed == true { +func (it *LocalSession) Begin() error { + if it.isClosed == true { return utils.NewError("LocalSession", " can not Begin() a Closed Session!") } - if this.tx == nil { - var tx, err = this.db.Begin() + if it.tx == nil { + var tx, err = it.db.Begin() if err == nil { - this.tx = tx + it.tx = tx } else { return err } @@ -62,33 +62,33 @@ func (this *LocalSession) Begin() error { return nil } -func (this *LocalSession) Close() { - if this.db != nil { - if this.stmt != nil { - this.stmt.Close() +func (it *LocalSession) Close() { + if it.db != nil { + if it.stmt != nil { + it.stmt.Close() } // When Close be called, if session is a transaction and do not call // Commit or Rollback, then call Rollback. - if this.tx != nil && !this.isCommitedOrRollbacked { - this.tx.Rollback() + if it.tx != nil && !it.isCommitedOrRollbacked { + it.tx.Rollback() } - this.tx = nil - this.db = nil - this.stmt = nil - this.isClosed = true + it.tx = nil + it.db = nil + it.stmt = nil + it.isClosed = true } } -func (this *LocalSession) Query(sqlorArgs string) ([]map[string][]byte, error) { - if this.isClosed == true { +func (it *LocalSession) Query(sqlorArgs string) ([]map[string][]byte, error) { + if it.isClosed == true { return nil, utils.NewError("LocalSession", " can not Query() a Closed Session!") } var rows *sql.Rows var err error - if this.tx != nil { - rows, err = this.tx.Query(sqlorArgs) + if it.tx != nil { + rows, err = it.tx.Query(sqlorArgs) } else { - rows, err = this.db.Query(sqlorArgs) + rows, err = it.db.Query(sqlorArgs) } if err != nil { return nil, err @@ -99,19 +99,19 @@ func (this *LocalSession) Query(sqlorArgs string) ([]map[string][]byte, error) { return nil, nil } -func (this *LocalSession) Exec(sqlorArgs string) (*Result, error) { - if this.isClosed == true { +func (it *LocalSession) Exec(sqlorArgs string) (*Result, error) { + if it.isClosed == true { return nil, utils.NewError("LocalSession", " can not Exec() a Closed Session!") } var result sql.Result var err error - if this.tx != nil { - if this.isCommitedOrRollbacked { + if it.tx != nil { + if it.isCommitedOrRollbacked { return nil, utils.NewError("LocalSession", " Exec() sql fail!, session isCommitedOrRollbacked!") } - result, err = this.tx.Exec(sqlorArgs) + result, err = it.tx.Exec(sqlorArgs) } else { - result, err = this.db.Exec(sqlorArgs) + result, err = it.db.Exec(sqlorArgs) } if err != nil { return nil, err diff --git a/LogStandard.go b/LogStandard.go index e0346e2..759bfa3 100644 --- a/LogStandard.go +++ b/LogStandard.go @@ -7,15 +7,15 @@ type LogStandard struct { } //日志消息队列长度 -func (this *LogStandard) QueueLen() int { +func (it *LogStandard) QueueLen() int { //默认50万个日志消息缓存队列 return 500000 } //日志输出方法实现 -func (this *LogStandard) Println(v []byte) { - if this.PrintlnFunc != nil { - this.PrintlnFunc(v) +func (it *LogStandard) Println(v []byte) { + if it.PrintlnFunc != nil { + it.PrintlnFunc(v) } else { log.Println(string(v)) } diff --git a/LogSystem.go b/LogSystem.go index 4a896fc..de86ffe 100644 --- a/LogSystem.go +++ b/LogSystem.go @@ -12,46 +12,46 @@ type LogSystem struct { } //logImpl:日志实现类,queueLen:消息队列缓冲长度 -func (this LogSystem) New(logImpl Log, queueLen int) (LogSystem, error) { - if this.started == true { - return this, utils.NewError("LogSystem", "log system is started!") +func (it LogSystem) New(logImpl Log, queueLen int) (LogSystem, error) { + if it.started == true { + return it, utils.NewError("LogSystem", "log system is started!") } if logImpl == nil { logImpl = &LogStandard{} } - this.logChan = make(chan []byte, queueLen) - this.log = logImpl + it.logChan = make(chan []byte, queueLen) + it.log = logImpl //启动接受者 - go this.receiver() - this.started = true - return this, nil + go it.receiver() + it.started = true + return it, nil } //关闭日志系统和队列 -func (this *LogSystem) Close() error { - close(this.logChan) - this.started = false +func (it *LogSystem) Close() error { + close(it.logChan) + it.started = false return nil } //日志发送者 -func (this *LogSystem) SendLog(logs ...string) error { - if this.started == false { +func (it *LogSystem) SendLog(logs ...string) error { + if it.started == false { return utils.NewError("LogSystem", "no log Receiver! you must call go GoMybatis.LogSystem{}.New()") } var buf bytes.Buffer for _, v := range logs { buf.WriteString(v) } - this.logChan <- buf.Bytes() + it.logChan <- buf.Bytes() return nil } //日志接受者 -func (this *LogSystem) receiver() error { +func (it *LogSystem) receiver() error { for { - logs := <-this.logChan - this.log.Println(logs) + logs := <-it.logChan + it.log.Println(logs) } return nil } diff --git a/SessionFactory.go b/SessionFactory.go index b524f9f..62a4f65 100644 --- a/SessionFactory.go +++ b/SessionFactory.go @@ -5,28 +5,28 @@ type SessionFactory struct { SessionMap map[string]*Session } -func (this SessionFactory) New(Engine *SessionEngine) SessionFactory { - this.Engine = Engine - this.SessionMap = make(map[string]*Session) - return this +func (it SessionFactory) New(Engine *SessionEngine) SessionFactory { + it.Engine = Engine + it.SessionMap = make(map[string]*Session) + return it } -func (this *SessionFactory) NewSession(sessionType SessionType, config *TransationRMClientConfig) Session { - if this.SessionMap == nil || this.Engine == nil { +func (it *SessionFactory) NewSession(sessionType SessionType, config *TransationRMClientConfig) Session { + if it.SessionMap == nil || it.Engine == nil { panic("[GoMybatis] SessionFactory not init! you must call method SessionFactory.New(*)") } var newSession Session switch sessionType { case SessionType_Default: - var session = (*this.Engine).NewSession() + var session = (*it.Engine).NewSession() var factorySession = SessionFactorySession{ Session: session, - Factory: this, + Factory: it, } newSession = Session(&factorySession) break case SessionType_Local: - newSession = (*this.Engine).NewSession() + newSession = (*it.Engine).NewSession() break case SessionType_TransationRM: if config == nil { @@ -41,37 +41,37 @@ func (this *SessionFactory) NewSession(sessionType SessionType, config *Transati default: panic("[GoMybatis] newSession() must have a SessionType!") } - this.SessionMap[newSession.Id()] = &newSession + it.SessionMap[newSession.Id()] = &newSession return newSession } -func (this *SessionFactory) GetSession(id string) *Session { - return this.SessionMap[id] +func (it *SessionFactory) GetSession(id string) *Session { + return it.SessionMap[id] } -func (this *SessionFactory) SetSession(id string, session *Session) { - this.SessionMap[id] = session +func (it *SessionFactory) SetSession(id string, session *Session) { + it.SessionMap[id] = session } -func (this *SessionFactory) Close(id string) { - if this.SessionMap == nil { +func (it *SessionFactory) Close(id string) { + if it.SessionMap == nil { return } - var s = this.SessionMap[id] + var s = it.SessionMap[id] if s != nil { (*s).Close() - this.SessionMap[id] = nil + it.SessionMap[id] = nil } } -func (this *SessionFactory) CloseAll(id string) { - if this.SessionMap == nil { +func (it *SessionFactory) CloseAll(id string) { + if it.SessionMap == nil { return } - for _, v := range this.SessionMap { + for _, v := range it.SessionMap { if v != nil { (*v).Close() - this.SessionMap[id] = nil + it.SessionMap[id] = nil } } } diff --git a/SessionFactorySession.go b/SessionFactorySession.go index 3fa8f79..2ff99d7 100644 --- a/SessionFactorySession.go +++ b/SessionFactorySession.go @@ -9,49 +9,49 @@ type SessionFactorySession struct { Factory *SessionFactory } -func (this *SessionFactorySession) Id() string { - if this.Session == nil { +func (it *SessionFactorySession) Id() string { + if it.Session == nil { return "" } - return this.Session.Id() + return it.Session.Id() } -func (this *SessionFactorySession) Query(sqlorArgs string) ([]map[string][]byte, error) { - if this.Session == nil { - return nil, utils.NewError("SessionFactorySession", " can not run Id(),this.Session == nil") +func (it *SessionFactorySession) Query(sqlorArgs string) ([]map[string][]byte, error) { + if it.Session == nil { + return nil, utils.NewError("SessionFactorySession", " can not run Id(),it.Session == nil") } - return this.Session.Query(sqlorArgs) + return it.Session.Query(sqlorArgs) } -func (this *SessionFactorySession) Exec(sqlorArgs string) (*Result, error) { - if this.Session == nil { - return nil, utils.NewError("SessionFactorySession", " can not run Exec(),this.Session == nil") +func (it *SessionFactorySession) Exec(sqlorArgs string) (*Result, error) { + if it.Session == nil { + return nil, utils.NewError("SessionFactorySession", " can not run Exec(),it.Session == nil") } - return this.Session.Exec(sqlorArgs) + return it.Session.Exec(sqlorArgs) } -func (this *SessionFactorySession) Rollback() error { - if this.Session == nil { - return utils.NewError("SessionFactorySession", " can not run Rollback(),this.Session == nil") +func (it *SessionFactorySession) Rollback() error { + if it.Session == nil { + return utils.NewError("SessionFactorySession", " can not run Rollback(),it.Session == nil") } - return this.Session.Rollback() + return it.Session.Rollback() } -func (this *SessionFactorySession) Commit() error { - if this.Session == nil { - return utils.NewError("SessionFactorySession", " can not run Commit(),this.Session == nil") +func (it *SessionFactorySession) Commit() error { + if it.Session == nil { + return utils.NewError("SessionFactorySession", " can not run Commit(),it.Session == nil") } - return this.Session.Commit() + return it.Session.Commit() } -func (this *SessionFactorySession) Begin() error { - if this.Session == nil { - return utils.NewError("SessionFactorySession", " can not run Begin(),this.Session == nil") +func (it *SessionFactorySession) Begin() error { + if it.Session == nil { + return utils.NewError("SessionFactorySession", " can not run Begin(),it.Session == nil") } - return this.Session.Begin() + return it.Session.Begin() } -func (this *SessionFactorySession) Close() { - var id = this.Id() - var s = this.Factory.SessionMap[id] +func (it *SessionFactorySession) Close() { + var id = it.Id() + var s = it.Factory.SessionMap[id] if s != nil { - if this.Session != nil { - this.Session.Close() + if it.Session != nil { + it.Session.Close() } - this.Factory.SessionMap[id] = nil + it.Factory.SessionMap[id] = nil } } diff --git a/SqlBuilder.go b/SqlBuilder.go index 4a0118e..6a74ba9 100644 --- a/SqlBuilder.go +++ b/SqlBuilder.go @@ -25,52 +25,52 @@ type GoMybatisSqlBuilder struct { enableLog bool } -func (this GoMybatisSqlBuilder) ExpressionEngineProxy() ExpressionEngineProxy { - return this.expressionEngineProxy +func (it GoMybatisSqlBuilder) ExpressionEngineProxy() ExpressionEngineProxy { + return it.expressionEngineProxy } -func (this GoMybatisSqlBuilder) SqlArgTypeConvert() SqlArgTypeConvert { - return this.sqlArgTypeConvert +func (it GoMybatisSqlBuilder) SqlArgTypeConvert() SqlArgTypeConvert { + return it.sqlArgTypeConvert } -func (this GoMybatisSqlBuilder) ExpressionTypeConvert() ExpressionTypeConvert { - return this.expressionTypeConvert +func (it GoMybatisSqlBuilder) ExpressionTypeConvert() ExpressionTypeConvert { + return it.expressionTypeConvert } -func (this GoMybatisSqlBuilder) New(ExpressionTypeConvert ExpressionTypeConvert, SqlArgTypeConvert SqlArgTypeConvert, expressionEngine ExpressionEngineProxy, log Log, enableLog bool) GoMybatisSqlBuilder { - this.expressionTypeConvert = ExpressionTypeConvert - this.sqlArgTypeConvert = SqlArgTypeConvert - this.expressionEngineProxy = expressionEngine - this.enableLog = enableLog +func (it GoMybatisSqlBuilder) New(ExpressionTypeConvert ExpressionTypeConvert, SqlArgTypeConvert SqlArgTypeConvert, expressionEngine ExpressionEngineProxy, log Log, enableLog bool) GoMybatisSqlBuilder { + it.expressionTypeConvert = ExpressionTypeConvert + it.sqlArgTypeConvert = SqlArgTypeConvert + it.expressionEngineProxy = expressionEngine + it.enableLog = enableLog if enableLog { var logSystem, err = LogSystem{}.New(log, log.QueueLen()) if err != nil { panic(err) } - this.logSystem = &logSystem + it.logSystem = &logSystem } - return this + return it } -func (this GoMybatisSqlBuilder) BuildSql(paramMap map[string]SqlArg, mapperXml *MapperXml) (string, error) { +func (it GoMybatisSqlBuilder) BuildSql(paramMap map[string]SqlArg, mapperXml *MapperXml) (string, error) { var sql bytes.Buffer - err := this.createFromElement(mapperXml.ElementItems, &sql, paramMap) + err := it.createFromElement(mapperXml.ElementItems, &sql, paramMap) if err != nil { return "", err } var sqlStr = sql.String() sql.Reset() - if this.enableLog { + if it.enableLog { var now, _ = time.Now().MarshalText() - this.logSystem.SendLog("[GoMybatis] [", string(now), "] Preparing sql ==> ", sqlStr) + it.logSystem.SendLog("[GoMybatis] [", string(now), "] Preparing sql ==> ", sqlStr) } return sqlStr, nil } -func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql *bytes.Buffer, sqlArgMap map[string]SqlArg) error { - if this.sqlArgTypeConvert == nil || this.expressionTypeConvert == nil { +func (it *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql *bytes.Buffer, sqlArgMap map[string]SqlArg) error { + if it.sqlArgTypeConvert == nil || it.expressionTypeConvert == nil { panic("[GoMybatis] GoMybatisSqlBuilder.sqlArgTypeConvert and GoMybatisSqlBuilder.expressionTypeConvert can not be nil!") } //默认的map[string]interface{} - var defaultArgMap = this.makeArgInterfaceMap(sqlArgMap) + var defaultArgMap = it.makeArgInterfaceMap(sqlArgMap) //test表达式参数map var evaluateParameters map[string]interface{} for _, v := range itemTree { @@ -79,15 +79,15 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * switch v.ElementType { case Element_bind: //bind,param args change!need update - sqlArgMap = this.bindBindElementArg(sqlArgMap, v, this.sqlArgTypeConvert) - defaultArgMap = this.makeArgInterfaceMap(sqlArgMap) + sqlArgMap = it.bindBindElementArg(sqlArgMap, v, it.sqlArgTypeConvert) + defaultArgMap = it.makeArgInterfaceMap(sqlArgMap) if evaluateParameters != nil { - evaluateParameters = this.expressParamterMap(sqlArgMap, this.expressionTypeConvert) + evaluateParameters = it.expressParamterMap(sqlArgMap, it.expressionTypeConvert) } break case Element_String: //string element - var replaceSql, err = replaceArg(v.DataString, defaultArgMap, this.sqlArgTypeConvert, &this.expressionEngineProxy) + var replaceSql, err = replaceArg(v.DataString, defaultArgMap, it.sqlArgTypeConvert, &it.expressionEngineProxy) if err != nil { return err } @@ -96,13 +96,13 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * case Element_If: //if element var expression = v.Propertys[`test`] - var result, err = this.doIfElement(expression, sqlArgMap, evaluateParameters) + var result, err = it.doIfElement(expression, sqlArgMap, evaluateParameters) if err != nil { return err } if result { //test > true,write sql string - var replaceSql, err = replaceArg(v.DataString, defaultArgMap, this.sqlArgTypeConvert, &this.expressionEngineProxy) + var replaceSql, err = replaceArg(v.DataString, defaultArgMap, it.sqlArgTypeConvert, &it.expressionEngineProxy) if err != nil { return err } @@ -118,7 +118,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * var suffix = v.Propertys[`suffix`] var suffixOverrides = v.Propertys[`suffixOverrides`] var prefixOverrides = v.Propertys[`prefixOverrides`] - var err = this.elementTrim(&loopChildItem, v.ElementItems, sqlArgMap, prefix, suffix, prefixOverrides, suffixOverrides, sql) + var err = it.elementTrim(&loopChildItem, v.ElementItems, sqlArgMap, prefix, suffix, prefixOverrides, suffixOverrides, sql) if err != nil { return err } @@ -126,7 +126,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * case Element_Set: if loopChildItem && v.ElementItems != nil && len(v.ElementItems) > 0 { var trim bytes.Buffer - var err = this.createFromElement(v.ElementItems, &trim, sqlArgMap) + var err = it.createFromElement(v.ElementItems, &trim, sqlArgMap) if err != nil { return err } @@ -185,7 +185,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * Type: keyValue.Type(), } if loopChildItem && v.ElementItems != nil && len(v.ElementItems) > 0 { - var err = this.createFromElement(v.ElementItems, &tempSql, tempArgMap) + var err = it.createFromElement(v.ElementItems, &tempSql, tempArgMap) if err != nil { return err } @@ -213,7 +213,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * } } if loopChildItem && v.ElementItems != nil && len(v.ElementItems) > 0 { - var err = this.createFromElement(v.ElementItems, &tempSql, tempArgMap) + var err = it.createFromElement(v.ElementItems, &tempSql, tempArgMap) if err != nil { return err } @@ -235,7 +235,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * case Element_choose: //read when and otherwise var temp bytes.Buffer - var err = this.createFromElement(v.ElementItems, &temp, sqlArgMap) + var err = it.createFromElement(v.ElementItems, &temp, sqlArgMap) if err != nil { return err } @@ -245,19 +245,19 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * case Element_when: //if element var expression = v.Propertys[`test`] - var result, err = this.doIfElement(expression, sqlArgMap, evaluateParameters) + var result, err = it.doIfElement(expression, sqlArgMap, evaluateParameters) if err != nil { return err } if result { //test > true,write sql string - var replaceSql, err = replaceArg(v.DataString, defaultArgMap, this.sqlArgTypeConvert, &this.expressionEngineProxy) + var replaceSql, err = replaceArg(v.DataString, defaultArgMap, it.sqlArgTypeConvert, &it.expressionEngineProxy) if err != nil { return err } sql.WriteString(replaceSql) if loopChildItem && v.ElementItems != nil && len(v.ElementItems) > 0 { - var err = this.createFromElement(v.ElementItems, sql, sqlArgMap) + var err = it.createFromElement(v.ElementItems, sql, sqlArgMap) if err != nil { return err } @@ -271,7 +271,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * break case Element_otherwise: if loopChildItem && v.ElementItems != nil && len(v.ElementItems) > 0 { - var err = this.createFromElement(v.ElementItems, sql, sqlArgMap) + var err = it.createFromElement(v.ElementItems, sql, sqlArgMap) if err != nil { return err } @@ -279,7 +279,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * breakChildItem = true break case Element_where: - var err = this.elementTrim(&loopChildItem, v.ElementItems, sqlArgMap, DefaultWhereElement_Prefix, "", DefaultWhereElement_PrefixOverrides, "", sql) + var err = it.elementTrim(&loopChildItem, v.ElementItems, sqlArgMap, DefaultWhereElement_Prefix, "", DefaultWhereElement_PrefixOverrides, "", sql) if err != nil { return err } @@ -294,7 +294,7 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * break } if loopChildItem && v.ElementItems != nil && len(v.ElementItems) > 0 { - var err = this.createFromElement(v.ElementItems, sql, sqlArgMap) + var err = it.createFromElement(v.ElementItems, sql, sqlArgMap) if err != nil { return err } @@ -303,16 +303,16 @@ func (this *GoMybatisSqlBuilder) createFromElement(itemTree []ElementItem, sql * return nil } -func (this *GoMybatisSqlBuilder) doIfElement(expression string, param map[string]SqlArg, evaluateParameters map[string]interface{}) (bool, error) { - //this.repleaceExpression(expression, param) - ifElementevalExpression, err := this.expressionEngineProxy.Lexer(expression) +func (it *GoMybatisSqlBuilder) doIfElement(expression string, param map[string]SqlArg, evaluateParameters map[string]interface{}) (bool, error) { + //it.repleaceExpression(expression, param) + ifElementevalExpression, err := it.expressionEngineProxy.Lexer(expression) if err != nil { return false, err } if evaluateParameters == nil { - evaluateParameters = this.expressParamterMap(param, this.expressionTypeConvert) + evaluateParameters = it.expressParamterMap(param, it.expressionTypeConvert) } - result, err := this.expressionEngineProxy.Eval(ifElementevalExpression, evaluateParameters, 0) + result, err := it.expressionEngineProxy.Eval(ifElementevalExpression, evaluateParameters, 0) if err != nil { err = utils.NewError("SqlBuilder", "[GoMybatis] fail,`, err.Error()) return false, err @@ -320,7 +320,7 @@ func (this *GoMybatisSqlBuilder) doIfElement(expression string, param map[string return result.(bool), nil } -func (this *GoMybatisSqlBuilder) bindBindElementArg(args map[string]SqlArg, item ElementItem, typeConvert SqlArgTypeConvert) map[string]SqlArg { +func (it *GoMybatisSqlBuilder) bindBindElementArg(args map[string]SqlArg, item ElementItem, typeConvert SqlArgTypeConvert) map[string]SqlArg { var name = item.Propertys["name"] var value = item.Propertys["value"] if name == "" { @@ -333,12 +333,12 @@ func (this *GoMybatisSqlBuilder) bindBindElementArg(args map[string]SqlArg, item } return args } - bindEvalExpression, err := this.expressionEngineProxy.Lexer(value) + bindEvalExpression, err := it.expressionEngineProxy.Lexer(value) if err != nil { return args } - var evaluateParameters = this.expressParamterMap(args, this.expressionTypeConvert) - result, err := this.expressionEngineProxy.Eval(bindEvalExpression, evaluateParameters, 0) + var evaluateParameters = it.expressParamterMap(args, it.expressionTypeConvert) + result, err := it.expressionEngineProxy.Eval(bindEvalExpression, evaluateParameters, 0) if err != nil { //TODO send log bind fail return args @@ -351,7 +351,7 @@ func (this *GoMybatisSqlBuilder) bindBindElementArg(args map[string]SqlArg, item } //scan params -func (this *GoMybatisSqlBuilder) expressParamterMap(parameters map[string]SqlArg, typeConvert ExpressionTypeConvert) map[string]interface{} { +func (it *GoMybatisSqlBuilder) expressParamterMap(parameters map[string]SqlArg, typeConvert ExpressionTypeConvert) map[string]interface{} { var newMap = make(map[string]interface{}) for k, obj := range parameters { var value = obj.Value @@ -364,7 +364,7 @@ func (this *GoMybatisSqlBuilder) expressParamterMap(parameters map[string]SqlArg } //scan params -func (this *GoMybatisSqlBuilder) sqlParamterMap(parameters map[string]SqlArg, typeConvert SqlArgTypeConvert) map[string]string { +func (it *GoMybatisSqlBuilder) sqlParamterMap(parameters map[string]SqlArg, typeConvert SqlArgTypeConvert) map[string]string { var newMap = make(map[string]string) for k, obj := range parameters { var value = obj.Value @@ -377,10 +377,10 @@ func (this *GoMybatisSqlBuilder) sqlParamterMap(parameters map[string]SqlArg, ty } //trim处理element -func (this *GoMybatisSqlBuilder) elementTrim(loopChildItem *bool, items []ElementItem, param map[string]SqlArg, prefix string, suffix string, prefixOverrides string, suffixOverrides string, sql *bytes.Buffer) error { +func (it *GoMybatisSqlBuilder) elementTrim(loopChildItem *bool, items []ElementItem, param map[string]SqlArg, prefix string, suffix string, prefixOverrides string, suffixOverrides string, sql *bytes.Buffer) error { if *loopChildItem && items != nil && len(items) > 0 { var tempTrimSql bytes.Buffer - var err = this.createFromElement(items, &tempTrimSql, param) + var err = it.createFromElement(items, &tempTrimSql, param) if err != nil { return err } @@ -414,7 +414,7 @@ func (this *GoMybatisSqlBuilder) elementTrim(loopChildItem *bool, items []Elemen return nil } -func (this *GoMybatisSqlBuilder) makeArgInterfaceMap(args map[string]SqlArg) map[string]interface{} { +func (it *GoMybatisSqlBuilder) makeArgInterfaceMap(args map[string]SqlArg) map[string]interface{} { var m = make(map[string]interface{}) if args != nil { for k, v := range args { @@ -424,6 +424,6 @@ func (this *GoMybatisSqlBuilder) makeArgInterfaceMap(args map[string]SqlArg) map return m } -func (this GoMybatisSqlBuilder) LogSystem() *LogSystem { - return this.logSystem +func (it GoMybatisSqlBuilder) LogSystem() *LogSystem { + return it.logSystem } diff --git a/SqlResultDecodeUtil.go b/SqlResultDecodeUtil.go index 946cbca..85c56b7 100644 --- a/SqlResultDecodeUtil.go +++ b/SqlResultDecodeUtil.go @@ -20,7 +20,7 @@ type GoMybatisSqlResultDecoder struct { SqlResultDecoder } -func (this GoMybatisSqlResultDecoder) Decode(resultMap map[string]*ResultProperty, sqlResult []map[string][]byte, result interface{}) error { +func (it GoMybatisSqlResultDecoder) Decode(resultMap map[string]*ResultProperty, sqlResult []map[string][]byte, result interface{}) error { if sqlResult == nil || result == nil { return nil } @@ -33,16 +33,16 @@ func (this GoMybatisSqlResultDecoder) Decode(resultMap map[string]*ResultPropert } var sqlResultLen = len(sqlResult) - var renameMapArray = this.getRenameMapArray(sqlResult) + var renameMapArray = it.getRenameMapArray(sqlResult) - if this.isGoBasicType(resultV.Type()) { + if it.isGoBasicType(resultV.Type()) { //single basic type if sqlResultLen > 1 { return utils.NewError("SqlResultDecoder", " Decode one result,but find database result size find > 1 !") } else if sqlResultLen == 1 && len(sqlResult[0]) > 1 { return utils.NewError("SqlResultDecoder", " Decode one result,but find database result size find > 1 !") } - this.convertToBasicTypeCollection(sqlResult, &resultV, resultV.Type(), resultMap) + it.convertToBasicTypeCollection(sqlResult, &resultV, resultV.Type(), resultMap) } else { switch resultV.Kind() { case reflect.Struct: @@ -51,30 +51,30 @@ func (this GoMybatisSqlResultDecoder) Decode(resultMap map[string]*ResultPropert return utils.NewError("SqlResultDecoder", " Decode one result,but find database result size find > 1 !") } for index, sItemMap := range sqlResult { - var value = this.sqlStructConvert(resultMap, resultT.Elem(), sItemMap, renameMapArray[index]) + var value = it.sqlStructConvert(resultMap, resultT.Elem(), sItemMap, renameMapArray[index]) resultV.Set(value) } break case reflect.Slice: //slice var resultTItemType = resultT.Elem().Elem() - var isBasicTypeSlice = this.isGoBasicType(resultTItemType) + var isBasicTypeSlice = it.isGoBasicType(resultTItemType) if isBasicTypeSlice { - this.convertToBasicTypeCollection(sqlResult, &resultV, resultTItemType, resultMap) + it.convertToBasicTypeCollection(sqlResult, &resultV, resultTItemType, resultMap) } else { for index, sItemMap := range sqlResult { if resultTItemType.Kind() == reflect.Struct { - resultV = reflect.Append(resultV, this.sqlStructConvert(resultMap, resultTItemType, sItemMap, renameMapArray[index])) + resultV = reflect.Append(resultV, it.sqlStructConvert(resultMap, resultTItemType, sItemMap, renameMapArray[index])) } else if resultTItemType.Kind() == reflect.Map { var value = reflect.New(resultTItemType) var valueV = value.Elem() //map var resultTItemType = resultTItemType.Elem() //int,string,time.Time..... - var isBasicTypeSlice = this.isGoBasicType(resultTItemType) + var isBasicTypeSlice = it.isGoBasicType(resultTItemType) var isInterface = resultTItemType.String() == "interface {}" if isBasicTypeSlice && isInterface == false { - this.convertToBasicTypeCollection(sqlResult, &valueV, resultTItemType, resultMap) + it.convertToBasicTypeCollection(sqlResult, &valueV, resultTItemType, resultMap) resultV = reflect.Append(resultV, valueV) } else { panic("[GoMybatis] Decode result type not support " + resultTItemType.String() + "!") @@ -88,13 +88,13 @@ func (this GoMybatisSqlResultDecoder) Decode(resultMap map[string]*ResultPropert case reflect.Map: //map var resultTItemType = resultT.Elem().Elem() //int,string,time.Time..... - var isBasicTypeSlice = this.isGoBasicType(resultTItemType) + var isBasicTypeSlice = it.isGoBasicType(resultTItemType) var isInterface = resultTItemType.String() == "interface {}" if isBasicTypeSlice && isInterface == false { if sqlResultLen > 1 { return utils.NewError("SqlResultDecoder", " Decode one result,but find database result size find > 1!") } - this.convertToBasicTypeCollection(sqlResult, &resultV, resultTItemType, resultMap) + it.convertToBasicTypeCollection(sqlResult, &resultV, resultTItemType, resultMap) } else { panic("[GoMybatis] Decode result type not support map[string]interface{}!") } @@ -107,14 +107,14 @@ func (this GoMybatisSqlResultDecoder) Decode(resultMap map[string]*ResultPropert return nil } -func (this GoMybatisSqlResultDecoder) sqlStructConvert(resultMap map[string]*ResultProperty, resultTItemType reflect.Type, sItemMap map[string][]byte, renamedSItemMap map[string][]byte) reflect.Value { +func (it GoMybatisSqlResultDecoder) sqlStructConvert(resultMap map[string]*ResultProperty, resultTItemType reflect.Type, sItemMap map[string][]byte, renamedSItemMap map[string][]byte) reflect.Value { if resultTItemType.Kind() == reflect.Struct { var tItemTypeFieldTypeValue = reflect.New(resultTItemType) for i := 0; i < resultTItemType.NumField(); i++ { var tItemTypeFieldType = resultTItemType.Field(i) var repleaceName = tItemTypeFieldType.Name - if !this.isGoBasicType(tItemTypeFieldType.Type) { + if !it.isGoBasicType(tItemTypeFieldType.Type) { //not basic type,continue continue } @@ -129,7 +129,7 @@ func (this GoMybatisSqlResultDecoder) sqlStructConvert(resultMap map[string]*Res } } var fieldValue = tItemTypeFieldTypeValue.Elem().Field(i) - this.sqlBasicTypeConvert(repleaceName, resultMap, tItemTypeFieldType.Type, value, &fieldValue) + it.sqlBasicTypeConvert(repleaceName, resultMap, tItemTypeFieldType.Type, value, &fieldValue) } return tItemTypeFieldTypeValue.Elem() } else { @@ -137,7 +137,7 @@ func (this GoMybatisSqlResultDecoder) sqlStructConvert(resultMap map[string]*Res } } -func (this GoMybatisSqlResultDecoder) basicTypeConvert(tItemTypeFieldType reflect.Type, valueByte []byte, resultValue *reflect.Value) bool { +func (it GoMybatisSqlResultDecoder) basicTypeConvert(tItemTypeFieldType reflect.Type, valueByte []byte, resultValue *reflect.Value) bool { var value = string(valueByte) if tItemTypeFieldType.Kind() == reflect.String { resultValue.SetString(value) @@ -177,19 +177,19 @@ func (this GoMybatisSqlResultDecoder) basicTypeConvert(tItemTypeFieldType reflec return true } -func (this GoMybatisSqlResultDecoder) sqlBasicTypeConvert(clomnName string, resultMap map[string]*ResultProperty, tItemTypeFieldType reflect.Type, valueByte []byte, resultValue *reflect.Value) bool { +func (it GoMybatisSqlResultDecoder) sqlBasicTypeConvert(clomnName string, resultMap map[string]*ResultProperty, tItemTypeFieldType reflect.Type, valueByte []byte, resultValue *reflect.Value) bool { if tItemTypeFieldType.Kind() == reflect.String { - return this.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) + return it.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) } else if tItemTypeFieldType.Kind() == reflect.Bool { - return this.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) + return it.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) } else if tItemTypeFieldType.Kind() == reflect.Int || tItemTypeFieldType.Kind() == reflect.Int32 || tItemTypeFieldType.Kind() == reflect.Int64 { - return this.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) + return it.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) } else if tItemTypeFieldType.Kind() == reflect.Uint || tItemTypeFieldType.Kind() == reflect.Uint8 || tItemTypeFieldType.Kind() == reflect.Uint16 || tItemTypeFieldType.Kind() == reflect.Uint32 || tItemTypeFieldType.Kind() == reflect.Uint64 { - return this.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) + return it.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) } else if tItemTypeFieldType.Kind() == reflect.Float32 || tItemTypeFieldType.Kind() == reflect.Float64 { - return this.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) + return it.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) } else if tItemTypeFieldType.String() == "time.Time" { - return this.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) + return it.basicTypeConvert(tItemTypeFieldType, valueByte, resultValue) } else { if resultMap != nil { var v = resultMap[clomnName] @@ -216,7 +216,7 @@ func (this GoMybatisSqlResultDecoder) sqlBasicTypeConvert(clomnName string, resu } var newResultValue = reflect.New(tItemTypeFieldType) var newResultValueElem = newResultValue.Elem() - if this.basicTypeConvert(tItemTypeFieldType, valueByte, &newResultValueElem) { + if it.basicTypeConvert(tItemTypeFieldType, valueByte, &newResultValueElem) { resultValue.Set(newResultValue.Elem()) return true } else { @@ -229,7 +229,7 @@ func (this GoMybatisSqlResultDecoder) sqlBasicTypeConvert(clomnName string, resu return true } -func (this GoMybatisSqlResultDecoder) isGoBasicType(tItemTypeFieldType reflect.Type) bool { +func (it GoMybatisSqlResultDecoder) isGoBasicType(tItemTypeFieldType reflect.Type) bool { if tItemTypeFieldType.Kind() == reflect.Bool || tItemTypeFieldType.Kind() == reflect.Int || tItemTypeFieldType.Kind() == reflect.Int8 || @@ -252,7 +252,7 @@ func (this GoMybatisSqlResultDecoder) isGoBasicType(tItemTypeFieldType reflect.T return false } -func (this GoMybatisSqlResultDecoder) convertToBasicTypeCollection(sourceArray []map[string][]byte, resultV *reflect.Value, itemType reflect.Type, resultMap map[string]*ResultProperty) { +func (it GoMybatisSqlResultDecoder) convertToBasicTypeCollection(sourceArray []map[string][]byte, resultV *reflect.Value, itemType reflect.Type, resultMap map[string]*ResultProperty) { if resultV.Type().Kind() == reflect.Slice && resultV.IsValid() { *resultV = reflect.MakeSlice(resultV.Type(), 0, 0) } else if resultV.Type().Kind() == reflect.Map && resultV.IsValid() { @@ -267,7 +267,7 @@ func (this GoMybatisSqlResultDecoder) convertToBasicTypeCollection(sourceArray [ } var tItemTypeFieldTypeValue = reflect.New(itemType) var tItemTypeFieldTypeValueElem = tItemTypeFieldTypeValue.Elem() - var success = this.sqlBasicTypeConvert(key, resultMap, itemType, value, &tItemTypeFieldTypeValueElem) + var success = it.sqlBasicTypeConvert(key, resultMap, itemType, value, &tItemTypeFieldTypeValueElem) if success { if resultV.Type().Kind() == reflect.Slice { *resultV = reflect.Append(*resultV, tItemTypeFieldTypeValue.Elem()) diff --git a/TransactionDefinition.go b/TransactionDefinition.go index 9f6e60c..6b77eab 100644 --- a/TransactionDefinition.go +++ b/TransactionDefinition.go @@ -32,7 +32,7 @@ type TransactionDefinition struct { IsReadOnly bool } -func (this TransactionDefinition) Default() TransactionDefinition { +func (it TransactionDefinition) Default() TransactionDefinition { return TransactionDefinition{ PropagationBehavior: PROPAGATION_REQUIRED, IsolationLevel: ISOLATION_DEFAULT, diff --git a/TransactionFactory.go b/TransactionFactory.go index 9128911..f48011a 100644 --- a/TransactionFactory.go +++ b/TransactionFactory.go @@ -5,17 +5,17 @@ type TransactionFactory struct { SessionFactory *SessionFactory } -func (this TransactionFactory) New(SessionFactory *SessionFactory) TransactionFactory { - this.TransactionStatuss = make(map[string]*TransactionStatus) - this.SessionFactory = SessionFactory - return this +func (it TransactionFactory) New(SessionFactory *SessionFactory) TransactionFactory { + it.TransactionStatuss = make(map[string]*TransactionStatus) + it.SessionFactory = SessionFactory + return it } -func (this *TransactionFactory) GetTransactionStatus(transactionId string) (*TransactionStatus, error) { +func (it *TransactionFactory) GetTransactionStatus(transactionId string) (*TransactionStatus, error) { var Session Session - var result = this.TransactionStatuss[transactionId] + var result = it.TransactionStatuss[transactionId] if result == nil { - Session = this.SessionFactory.NewSession(SessionType_Default, nil) + Session = it.SessionFactory.NewSession(SessionType_Default, nil) var transaction = Transaction{ Id: transactionId, Session: Session, @@ -25,24 +25,24 @@ func (this *TransactionFactory) GetTransactionStatus(transactionId string) (*Tra Transaction: &transaction, } result = &transactionStatus - this.TransactionStatuss[transactionId] = result + it.TransactionStatuss[transactionId] = result } return result, nil } -func (this *TransactionFactory) SetTransactionStatus(transactionId string, transaction *TransactionStatus) { +func (it *TransactionFactory) SetTransactionStatus(transactionId string, transaction *TransactionStatus) { if transactionId == "" { return } - this.TransactionStatuss[transactionId] = transaction + it.TransactionStatuss[transactionId] = transaction } -func (this *TransactionFactory) Append(transactionId string, transaction TransactionStatus) { +func (it *TransactionFactory) Append(transactionId string, transaction TransactionStatus) { if transactionId == "" { return } - var old, _ = this.GetTransactionStatus(transactionId) + var old, _ = it.GetTransactionStatus(transactionId) if old != nil { - this.SetTransactionStatus(transactionId, old) + it.SetTransactionStatus(transactionId, old) } } diff --git a/TransactionManager.go b/TransactionManager.go index 02e802d..7de5a37 100644 --- a/TransactionManager.go +++ b/TransactionManager.go @@ -64,13 +64,13 @@ type DefaultTransationManager struct { TransactionFactory *TransactionFactory } -func (this DefaultTransationManager) New(SessionFactory *SessionFactory, TransactionFactory *TransactionFactory) DefaultTransationManager { - this.SessionFactory = SessionFactory - this.TransactionFactory = TransactionFactory - return this +func (it DefaultTransationManager) New(SessionFactory *SessionFactory, TransactionFactory *TransactionFactory) DefaultTransationManager { + it.SessionFactory = SessionFactory + it.TransactionFactory = TransactionFactory + return it } -func (this DefaultTransationManager) GetTransaction(def *TransactionDefinition, transactionId string, OwnerId string) (*TransactionStatus, error) { +func (it DefaultTransationManager) GetTransaction(def *TransactionDefinition, transactionId string, OwnerId string) (*TransactionStatus, error) { if transactionId == "" { return nil, utils.NewError("TransactionManager", " transactionId ="+transactionId+" transations is nil!") } @@ -78,7 +78,7 @@ func (this DefaultTransationManager) GetTransaction(def *TransactionDefinition, var d = TransactionDefinition{}.Default() def = &d } - var transationStatus, err = this.TransactionFactory.GetTransactionStatus(transactionId) + var transationStatus, err = it.TransactionFactory.GetTransactionStatus(transactionId) if err != nil { return nil, err } @@ -101,8 +101,8 @@ func (this DefaultTransationManager) GetTransaction(def *TransactionDefinition, return transationStatus, nil } -func (this DefaultTransationManager) Commit(transactionId string) error { - var transactions, err = this.TransactionFactory.GetTransactionStatus(transactionId) +func (it DefaultTransationManager) Commit(transactionId string) error { + var transactions, err = it.TransactionFactory.GetTransactionStatus(transactionId) if err != nil { log.Println(err) return err @@ -110,8 +110,8 @@ func (this DefaultTransationManager) Commit(transactionId string) error { return transactions.Commit() } -func (this DefaultTransationManager) Rollback(transactionId string) error { - var transactions, err = this.TransactionFactory.GetTransactionStatus(transactionId) +func (it DefaultTransationManager) Rollback(transactionId string) error { + var transactions, err = it.TransactionFactory.GetTransactionStatus(transactionId) if err != nil { log.Println(err) return err @@ -120,11 +120,11 @@ func (this DefaultTransationManager) Rollback(transactionId string) error { } //执行事务 -func (this DefaultTransationManager) DoTransaction(dto TransactionReqDTO) TransactionRspDTO { +func (it DefaultTransationManager) DoTransaction(dto TransactionReqDTO) TransactionRspDTO { var transcationStatus *TransactionStatus var err error - transcationStatus, err = this.GetTransaction(nil, dto.TransactionId, dto.OwnerId) + transcationStatus, err = it.GetTransaction(nil, dto.TransactionId, dto.OwnerId) if transcationStatus == nil || transcationStatus.Transaction == nil || transcationStatus.Transaction.Session == nil { return TransactionRspDTO{ TransactionId: dto.TransactionId, @@ -147,9 +147,9 @@ func (this DefaultTransationManager) DoTransaction(dto TransactionReqDTO) Transa if dto.Status == Transaction_Status_NO { defer transcationStatus.Flush() //关闭 - return this.DoAction(dto, transcationStatus) + return it.DoAction(dto, transcationStatus) } else if dto.Status == Transaction_Status_Prepare { - return this.DoAction(dto, transcationStatus) + return it.DoAction(dto, transcationStatus) } else if dto.Status == Transaction_Status_Commit { if transcationStatus.OwnerId == dto.OwnerId { //PROPAGATION_REQUIRED 情况下 子事务 不可提交 defer transcationStatus.Flush() //关闭 @@ -160,7 +160,7 @@ func (this DefaultTransationManager) DoTransaction(dto TransactionReqDTO) Transa Error: err.Error(), } } - var transaction, err = this.TransactionFactory.GetTransactionStatus(dto.TransactionId) + var transaction, err = it.TransactionFactory.GetTransactionStatus(dto.TransactionId) if err != nil { log.Println(err) } else { @@ -190,7 +190,7 @@ func (this DefaultTransationManager) DoTransaction(dto TransactionReqDTO) Transa } //执行数据库操作 -func (this DefaultTransationManager) DoAction(dto TransactionReqDTO, transcationStatus *TransactionStatus) TransactionRspDTO { +func (it DefaultTransationManager) DoAction(dto TransactionReqDTO, transcationStatus *TransactionStatus) TransactionRspDTO { if transcationStatus.IsCompleted { var TransactionRspDTO = TransactionRspDTO{ TransactionId: dto.TransactionId, diff --git a/TransactionManager_test.go b/TransactionManager_test.go index 9a3b0c0..9dfd4f3 100644 --- a/TransactionManager_test.go +++ b/TransactionManager_test.go @@ -89,7 +89,7 @@ type TestOrderService struct { } //嵌套事务 -func (this TestOrderService) Transform(transactionId string, outid string, inId string, amount int) error { +func (it TestOrderService) Transform(transactionId string, outid string, inId string, amount int) error { var OwnerId = utils.CreateUUID() var dto = TransactionReqDTO{ TransactionId: transactionId, @@ -103,7 +103,7 @@ func (this TestOrderService) Transform(transactionId string, outid string, inId return errors.New(rspDTO.Error) } //事务id=2018092d6172014a2a4c8a949f1004623,已存在的事务不可提交commit,只能提交状态rollback和Pause - var e1 = this.TestPropertyServiceB.Reduce(transactionId, outid, amount) + var e1 = it.TestPropertyServiceB.Reduce(transactionId, outid, amount) if e1 != nil { return e1 } @@ -114,7 +114,7 @@ func (this TestOrderService) Transform(transactionId string, outid string, inId return errors.New(rspDTO.Error) } //事务id=2018092d6172014a2a4c8a949f1004623,已存在的事务不可提交commit,只能提交状态rollback和Pause - var e = this.TestPropertyServiceA.Add(transactionId, inId, amount) + var e = it.TestPropertyServiceA.Add(transactionId, inId, amount) if e != nil { return e } diff --git a/TransactionStatus.go b/TransactionStatus.go index 32be24f..1d3a8d8 100644 --- a/TransactionStatus.go +++ b/TransactionStatus.go @@ -20,49 +20,49 @@ type Transaction struct { Session Session } -func (this *TransactionStatus) Rollback() error { - if this.IsCompleted == true { +func (it *TransactionStatus) Rollback() error { + if it.IsCompleted == true { return errors.New("[TransactionManager] can not Rollback() a completed Transaction!") } - this.IsCompleted = true - defer this.Flush() //close session - return this.Transaction.Session.Rollback() + it.IsCompleted = true + defer it.Flush() //close session + return it.Transaction.Session.Rollback() } -func (this *TransactionStatus) Commit() error { - if this.IsCompleted == true { +func (it *TransactionStatus) Commit() error { + if it.IsCompleted == true { return errors.New("[TransactionManager] can not Commit() a completed Transaction!") } - this.IsCompleted = true - defer this.Flush() //close session - return this.Transaction.Session.Commit() + it.IsCompleted = true + defer it.Flush() //close session + return it.Transaction.Session.Commit() } -func (this *TransactionStatus) Begin() error { - if this.IsNewTransaction == false { +func (it *TransactionStatus) Begin() error { + if it.IsNewTransaction == false { return errors.New("[TransactionManager] can not Begin() a old Transaction!") } - this.IsNewTransaction = false - return this.Transaction.Session.Begin() + it.IsNewTransaction = false + return it.Transaction.Session.Begin() } -func (this *TransactionStatus) Flush() { - if this.Transaction != nil && this.Transaction.Session != nil { - this.Transaction.Session.Close() - this.Transaction.Session = nil - this.Transaction = nil +func (it *TransactionStatus) Flush() { + if it.Transaction != nil && it.Transaction.Session != nil { + it.Transaction.Session.Close() + it.Transaction.Session = nil + it.Transaction = nil } } //延迟关闭 -func (this *TransactionStatus) DelayFlush(t time.Duration) { - if this.HasSetDelayClose == false { +func (it *TransactionStatus) DelayFlush(t time.Duration) { + if it.HasSetDelayClose == false { go func() { time.Sleep(t) - if this.IsCompleted == false { - this.Rollback() + if it.IsCompleted == false { + it.Rollback() } }() - this.HasSetDelayClose = true + it.HasSetDelayClose = true } } diff --git a/TransationRMClient.go b/TransationRMClient.go index 8bbe34a..a9624a2 100644 --- a/TransationRMClient.go +++ b/TransationRMClient.go @@ -21,13 +21,13 @@ type RemoteSessionEngine struct { Client *TransationRMClient } -func (this RemoteSessionEngine) New(Client *TransationRMClient) RemoteSessionEngine { - this.Client = Client - return this +func (it RemoteSessionEngine) New(Client *TransationRMClient) RemoteSessionEngine { + it.Client = Client + return it } -func (this *RemoteSessionEngine) NewSession() Session { - var TransationSession = TransationRMSession{Client: this.Client} +func (it *RemoteSessionEngine) NewSession() Session { + var TransationSession = TransationRMSession{Client: it.Client} var session = Session(&TransationSession) return session } @@ -38,39 +38,39 @@ type TransationRMClient struct { RetryTime int } -func (this *TransationRMClient) Link(addr string) (*rpc.Client, error) { - this.Addr = addr - var client, error = this.autoLink() +func (it *TransationRMClient) Link(addr string) (*rpc.Client, error) { + it.Addr = addr + var client, error = it.autoLink() if error != nil { return client, error } else { - this.Client = client + it.Client = client return client, nil } } -func (this *TransationRMClient) autoLink() (*rpc.Client, error) { - if this.Client != nil { - this.Client.Close() - this.Client = nil +func (it *TransationRMClient) autoLink() (*rpc.Client, error) { + if it.Client != nil { + it.Client.Close() + it.Client = nil } - return jsonrpc.Dial("tcp", this.Addr) + return jsonrpc.Dial("tcp", it.Addr) } -func (this *TransationRMClient) Call(arg TransactionReqDTO, result *TransactionRspDTO) error { +func (it *TransationRMClient) Call(arg TransactionReqDTO, result *TransactionRspDTO) error { var error error - if this.Client == nil { - if this.Addr != "" { - this.Link(this.Addr) + if it.Client == nil { + if it.Addr != "" { + it.Link(it.Addr) } else { error = utils.NewError("TransationRMClient", " link have no addr!") return error } } - error = this.Client.Call(CallMethod, arg, result) + error = it.Client.Call(CallMethod, arg, result) if error != nil && error.Error() == ConnectError { - for i := 0; i < this.RetryTime; i++ { - this.autoLink() - error = this.Client.Call(CallMethod, arg, result) + for i := 0; i < it.RetryTime; i++ { + it.autoLink() + error = it.Client.Call(CallMethod, arg, result) if error == nil { break } @@ -79,9 +79,9 @@ func (this *TransationRMClient) Call(arg TransactionReqDTO, result *TransactionR return error } -func (this *TransationRMClient) Close() error { - if this.Client != nil { - return this.Client.Close() +func (it *TransationRMClient) Close() error { + if it.Client != nil { + return it.Client.Close() } return nil } diff --git a/TransationRMServer.go b/TransationRMServer.go index 1fc60f4..136e850 100644 --- a/TransationRMServer.go +++ b/TransationRMServer.go @@ -11,13 +11,13 @@ type TransationRMServer struct { DefaultTransationManager *DefaultTransationManager } -func (this TransationRMServer) Msg(arg TransactionReqDTO, result *TransactionRspDTO) (err error) { +func (it TransationRMServer) Msg(arg TransactionReqDTO, result *TransactionRspDTO) (err error) { defer func() { if err := recover(); err != nil { log.Println("[TransationRMServer]work failed:", err) } }() - var rsp = this.DefaultTransationManager.DoTransaction(arg) + var rsp = it.DefaultTransationManager.DoTransaction(arg) *result = rsp return nil } diff --git a/TransationRMServerSession.go b/TransationRMServerSession.go index ccb90ee..89d4d45 100644 --- a/TransationRMServerSession.go +++ b/TransationRMServerSession.go @@ -11,61 +11,61 @@ type TransationRMSession struct { Status Transaction_Status //默认0,非事务 } -func (this TransationRMSession) New(TransactionId string, Client *TransationRMClient, Status Transaction_Status) *Session { - this.OwnerId = utils.CreateUUID() - this.TransactionId = TransactionId - this.Client = Client - this.Status = Status - var Session = Session(&this) +func (it TransationRMSession) New(TransactionId string, Client *TransationRMClient, Status Transaction_Status) *Session { + it.OwnerId = utils.CreateUUID() + it.TransactionId = TransactionId + it.Client = Client + it.Status = Status + var Session = Session(&it) return &Session } -func (this *TransationRMSession) Id() string { - return this.TransactionId +func (it *TransationRMSession) Id() string { + return it.TransactionId } -func (this *TransationRMSession) Query(sqlorArgs string) ([]map[string][]byte, error) { +func (it *TransationRMSession) Query(sqlorArgs string) ([]map[string][]byte, error) { var result TransactionRspDTO - var error = this.Client.Call(TransactionReqDTO{Status: this.Status, TransactionId: this.TransactionId, Sql: sqlorArgs, ActionType: ActionType_Query, OwnerId: this.OwnerId}, &result) + var error = it.Client.Call(TransactionReqDTO{Status: it.Status, TransactionId: it.TransactionId, Sql: sqlorArgs, ActionType: ActionType_Query, OwnerId: it.OwnerId}, &result) if error == nil && result.Error != "" { error = utils.NewError("TransationRMSession", result.Error) } return result.Query, error } -func (this *TransationRMSession) Exec(sqlorArgs string) (*Result, error) { +func (it *TransationRMSession) Exec(sqlorArgs string) (*Result, error) { var result TransactionRspDTO - var error = this.Client.Call(TransactionReqDTO{Status: this.Status, TransactionId: this.TransactionId, Sql: sqlorArgs, ActionType: ActionType_Exec, OwnerId: this.OwnerId}, &result) + var error = it.Client.Call(TransactionReqDTO{Status: it.Status, TransactionId: it.TransactionId, Sql: sqlorArgs, ActionType: ActionType_Exec, OwnerId: it.OwnerId}, &result) if error == nil && result.Error != "" { error = utils.NewError("TransationRMSession", result.Error) } return &result.Exec, error } -func (this *TransationRMSession) Rollback() error { - this.Status = Transaction_Status_Rollback +func (it *TransationRMSession) Rollback() error { + it.Status = Transaction_Status_Rollback var result TransactionRspDTO - return this.Client.Call(TransactionReqDTO{Status: this.Status, TransactionId: this.TransactionId, ActionType: ActionType_Exec, OwnerId: this.OwnerId}, &result) + return it.Client.Call(TransactionReqDTO{Status: it.Status, TransactionId: it.TransactionId, ActionType: ActionType_Exec, OwnerId: it.OwnerId}, &result) } -func (this *TransationRMSession) Commit() error { - this.Status = Transaction_Status_Commit +func (it *TransationRMSession) Commit() error { + it.Status = Transaction_Status_Commit var result TransactionRspDTO - return this.Client.Call(TransactionReqDTO{Status: this.Status, TransactionId: this.TransactionId, ActionType: ActionType_Exec, OwnerId: this.OwnerId}, &result) + return it.Client.Call(TransactionReqDTO{Status: it.Status, TransactionId: it.TransactionId, ActionType: ActionType_Exec, OwnerId: it.OwnerId}, &result) } -func (this *TransationRMSession) Begin() error { - this.Status = Transaction_Status_Prepare +func (it *TransationRMSession) Begin() error { + it.Status = Transaction_Status_Prepare var result TransactionRspDTO - var err = this.Client.Call(TransactionReqDTO{Status: this.Status, TransactionId: this.TransactionId, ActionType: ActionType_Exec, OwnerId: this.OwnerId}, &result) + var err = it.Client.Call(TransactionReqDTO{Status: it.Status, TransactionId: it.TransactionId, ActionType: ActionType_Exec, OwnerId: it.OwnerId}, &result) return err } -func (this *TransationRMSession) Close() { - if this.Status == Transaction_Status_Prepare { - this.Rollback() +func (it *TransationRMSession) Close() { + if it.Status == Transaction_Status_Prepare { + it.Rollback() } - if this.Client != nil { - this.Client.Close() + if it.Client != nil { + it.Client.Close() } } diff --git a/mybatis-3-mapper.dtd b/mybatis-3-mapper.dtd index 337ea77..87baf70 100644 --- a/mybatis-3-mapper.dtd +++ b/mybatis-3-mapper.dtd @@ -4,7 +4,7 @@ Copyright 2009-2017 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. + you may not use it file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0