diff --git a/ElementType.go b/ElementType.go index 13f3b7d..ac5e096 100644 --- a/ElementType.go +++ b/ElementType.go @@ -11,11 +11,11 @@ const ( Element_Select ElementType = "select" Element_Sql ElementType = "sql" - //root templete elements - Element_Insert_Templete ElementType = "insertTemplete" - Element_Delete_Templete ElementType = "deleteTemplete" - Element_Update_Templete ElementType = `updateTemplete` - Element_Select_Templete ElementType = "selectTemplete" + //root template elements + Element_Insert_Template ElementType = "insertTemplate" + Element_Delete_Template ElementType = "deleteTemplate" + Element_Update_Template ElementType = `updateTemplate` + Element_Select_Template ElementType = "selectTemplate" //child elements Element_bind ElementType = "bind" @@ -34,7 +34,7 @@ const ( func isMethodElement(tag ElementType) bool { switch tag { case Element_Insert, Element_Delete, Element_Update, Element_Select, - Element_Insert_Templete, Element_Delete_Templete, Element_Update_Templete, Element_Select_Templete: + Element_Insert_Template, Element_Delete_Template, Element_Update_Template, Element_Select_Template: return true } return false diff --git a/GoMybatis.go b/GoMybatis.go index cef6c4e..dd6f86a 100644 --- a/GoMybatis.go +++ b/GoMybatis.go @@ -52,7 +52,7 @@ func WriteMapperPtrByEngine(ptr interface{}, xml []byte, sessionEngine SessionEn func WriteMapper(bean reflect.Value, xml []byte, sessionEngine SessionEngine) { beanCheck(bean) var mapperTree = LoadMapperXml(xml) - var decodeErr = sessionEngine.TempleteDecoder().DecodeTree(mapperTree, bean.Type()) + var decodeErr = sessionEngine.TemplateDecoder().DecodeTree(mapperTree, bean.Type()) if decodeErr != nil { panic(decodeErr) } diff --git a/GoMybatisEngine.go b/GoMybatisEngine.go index 08a79c3..314e312 100644 --- a/GoMybatisEngine.go +++ b/GoMybatisEngine.go @@ -21,7 +21,7 @@ type GoMybatisEngine struct { expressionEngine ast.ExpressionEngine //表达式解析引擎 sqlBuilder SqlBuilder //sql 构建 sqlResultDecoder SqlResultDecoder //sql查询结果解析引擎 - templeteDecoder TempleteDecoder //模板解析引擎 + templateDecoder TemplateDecoder //模板解析引擎 goroutineSessionMap *GoroutineSessionMap //map[协程id]Session goroutineIDEnable bool //是否启用goroutineIDEnable(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷,单线程处理场景可以关闭此配置) } @@ -52,8 +52,8 @@ func (it GoMybatisEngine) New() GoMybatisEngine { if it.sqlResultDecoder == nil { it.sqlResultDecoder = GoMybatisSqlResultDecoder{} } - if it.templeteDecoder == nil { - it.SetTempleteDecoder(&GoMybatisTempleteDecoder{}) + if it.templateDecoder == nil { + it.SetTemplateDecoder(&GoMybatisTemplateDecoder{}) } if it.sqlBuilder == nil { @@ -198,13 +198,13 @@ func (it *GoMybatisEngine) Open(driverName, dataSourceLink string) (*sql.DB, err } //模板解析器 -func (it *GoMybatisEngine) TempleteDecoder() TempleteDecoder { - return it.templeteDecoder +func (it *GoMybatisEngine) TemplateDecoder() TemplateDecoder { + return it.templateDecoder } //设置模板解析器 -func (it *GoMybatisEngine) SetTempleteDecoder(decoder TempleteDecoder) { - it.templeteDecoder = decoder +func (it *GoMybatisEngine) SetTemplateDecoder(decoder TemplateDecoder) { + it.templateDecoder = decoder } func (it *GoMybatisEngine) GoroutineSessionMap() *GoroutineSessionMap { diff --git a/GoMybatisTempleteDecoder.go b/GoMybatisTempleteDecoder.go index a6d99a4..faca211 100644 --- a/GoMybatisTempleteDecoder.go +++ b/GoMybatisTempleteDecoder.go @@ -12,9 +12,9 @@ import ( var equalOperator = []string{"/", "+", "-", "*", "**", "|", "^", "&", "%", "<", ">", ">=", "<=", " in ", " not in ", " or ", "||", " and ", "&&", "==", "!="} /** -TODO sqlTemplete解析器,目前直接操作*etree.Element实现,后期应该改成操作xml,换取更好的维护性 +TODO sqlTemplate解析器,目前直接操作*etree.Element实现,后期应该改成操作xml,换取更好的维护性 */ -type GoMybatisTempleteDecoder struct { +type GoMybatisTemplateDecoder struct { print bool } @@ -34,13 +34,13 @@ type VersionData struct { LangType string } -func (it *GoMybatisTempleteDecoder) SetPrintElement(print bool) { +func (it *GoMybatisTemplateDecoder) SetPrintElement(print bool) { it.print = print } -func (it *GoMybatisTempleteDecoder) DecodeTree(tree map[string]etree.Token, beanType reflect.Type) error { +func (it *GoMybatisTemplateDecoder) DecodeTree(tree map[string]etree.Token, beanType reflect.Type) error { if tree == nil { - return utils.NewError("GoMybatisTempleteDecoder", "decode data map[string]*MapperXml cant be nil!") + return utils.NewError("GoMybatisTemplateDecoder", "decode data map[string]*MapperXml cant be nil!") } if beanType != nil { if beanType.Kind() == reflect.Ptr { @@ -78,7 +78,7 @@ func (it *GoMybatisTempleteDecoder) DecodeTree(tree map[string]etree.Token, bean beanName = beanType.String() } if it.print { - var s = "================DecoderTemplete " + beanName + "." + v.SelectAttrValue("id", "") + "============\n" + var s = "================DecoderTemplate " + beanName + "." + v.SelectAttrValue("id", "") + "============\n" printElement(v, &s) println(s) } @@ -109,16 +109,16 @@ func printElement(element *etree.Element, v *string) { *v += "\n" } -func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper *etree.Element, tree map[string]etree.Token) (bool, error) { +func (it *GoMybatisTemplateDecoder) Decode(method *reflect.StructField, mapper *etree.Element, tree map[string]etree.Token) (bool, error) { switch mapper.Tag { - case "selectTemplete": + case "selectTemplate": mapper.Tag = Element_Select var id = mapper.SelectAttrValue("id", "") if id == "" { - mapper.CreateAttr("id", "selectTemplete") + mapper.CreateAttr("id", "selectTemplate") } var tables = mapper.SelectAttrValue("tables", "") @@ -131,7 +131,7 @@ func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper * } var resultMapData = tree[resultMap].(*etree.Element) if resultMapData == nil { - panic(utils.NewError("GoMybatisTempleteDecoder", "resultMap not define! id = ", resultMap)) + panic(utils.NewError("GoMybatisTemplateDecoder", "resultMap not define! id = ", resultMap)) } checkTablesValue(mapper, &tables, resultMapData) @@ -154,12 +154,12 @@ func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper * it.DecodeWheres(wheres, mapper, logic, nil) } break - case "insertTemplete": //已支持批量 + case "insertTemplate": //已支持批量 mapper.Tag = Element_Insert var id = mapper.SelectAttrValue("id", "") if id == "" { - mapper.CreateAttr("id", "insertTemplete") + mapper.CreateAttr("id", "insertTemplate") } var tables = mapper.SelectAttrValue("tables", "") @@ -175,7 +175,7 @@ func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper * var resultMapData = tree[resultMap].(*etree.Element) if resultMapData == nil { - panic(utils.NewError("GoMybatisTempleteDecoder", "resultMap not define! id = ", resultMap)) + panic(utils.NewError("GoMybatisTemplateDecoder", "resultMap not define! id = ", resultMap)) } checkTablesValue(mapper, &tables, resultMapData) @@ -321,12 +321,12 @@ func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper * mapper.Child = append(mapper.Child, &tempElement) break - case "updateTemplete": + case "updateTemplate": mapper.Tag = Element_Update var id = mapper.SelectAttrValue("id", "") if id == "" { - mapper.CreateAttr("id", "updateTemplete") + mapper.CreateAttr("id", "updateTemplate") } var tables = mapper.SelectAttrValue("tables", "") @@ -340,7 +340,7 @@ func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper * var resultMapData = tree[resultMap].(*etree.Element) if resultMapData == nil { - panic(utils.NewError("GoMybatisTempleteDecoder", "resultMap not define! id = ", resultMap)) + panic(utils.NewError("GoMybatisTemplateDecoder", "resultMap not define! id = ", resultMap)) } checkTablesValue(mapper, &tables, resultMapData) @@ -384,12 +384,12 @@ func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper * it.DecodeWheres(wheres, mapper, logic, versionData) } break - case "deleteTemplete": + case "deleteTemplate": mapper.Tag = Element_Delete var id = mapper.SelectAttrValue("id", "") if id == "" { - mapper.CreateAttr("id", "deleteTemplete") + mapper.CreateAttr("id", "deleteTemplate") } var tables = mapper.SelectAttrValue("tables", "") @@ -402,7 +402,7 @@ func (it *GoMybatisTempleteDecoder) Decode(method *reflect.StructField, mapper * var resultMapData = tree[resultMap].(*etree.Element) if resultMapData == nil { - panic(utils.NewError("GoMybatisTempleteDecoder", "resultMap not define! id = ", resultMap)) + panic(utils.NewError("GoMybatisTemplateDecoder", "resultMap not define! id = ", resultMap)) } checkTablesValue(mapper, &tables, resultMapData) @@ -452,13 +452,13 @@ func checkTablesValue(mapper *etree.Element, tables *string, resultMapData *etre if *tables == "" { *tables = resultMapData.SelectAttrValue("tables", "") if *tables == "" { - panic("[GoMybatisTempleteDecoder] attribute 'tables' can not be empty! need define in or <" + mapper.Tag + "Templete>,mapper id=" + mapper.SelectAttrValue("id", "")) + panic("[GoMybatisTemplateDecoder] attribute 'tables' can not be empty! need define in or <" + mapper.Tag + "Template>,mapper id=" + mapper.SelectAttrValue("id", "")) } } } //解码逗号分隔的where -func (it *GoMybatisTempleteDecoder) DecodeWheres(arg string, mapper *etree.Element, logic LogicDeleteData, versionData *VersionData) { +func (it *GoMybatisTemplateDecoder) DecodeWheres(arg string, mapper *etree.Element, logic LogicDeleteData, versionData *VersionData) { var whereRoot = &etree.Element{ Tag: Element_where, Attr: []etree.Attr{}, @@ -516,7 +516,7 @@ func (it *GoMybatisTempleteDecoder) DecodeWheres(arg string, mapper *etree.Eleme mapper.Child = append(mapper.Child, whereRoot) } -func (it *GoMybatisTempleteDecoder) DecodeSets(arg string, mapper *etree.Element, logic LogicDeleteData, versionData *VersionData) { +func (it *GoMybatisTemplateDecoder) DecodeSets(arg string, mapper *etree.Element, logic LogicDeleteData, versionData *VersionData) { var sets = strings.Split(arg, ",") for index, v := range sets { if v == "" { @@ -569,7 +569,7 @@ func (it *GoMybatisTempleteDecoder) DecodeSets(arg string, mapper *etree.Element } } -func (it *GoMybatisTempleteDecoder) makeIfNotNull(arg string) string { +func (it *GoMybatisTemplateDecoder) makeIfNotNull(arg string) string { for _, v := range equalOperator { if v == "" { continue @@ -581,7 +581,7 @@ func (it *GoMybatisTempleteDecoder) makeIfNotNull(arg string) string { return arg + ` != nil` } -func (it *GoMybatisTempleteDecoder) decodeLogicDelete(xml *etree.Element) LogicDeleteData { +func (it *GoMybatisTemplateDecoder) decodeLogicDelete(xml *etree.Element) LogicDeleteData { if xml == nil || len(xml.Child) == 0 { return LogicDeleteData{} } @@ -596,13 +596,13 @@ func (it *GoMybatisTempleteDecoder) decodeLogicDelete(xml *etree.Element) LogicD logicData.LangType = v.SelectAttrValue("langType", "") //check if logicData.Deleted_value == "" { - panic(utils.NewError("GoMybatisTempleteDecoder", ` logic_deleted="" can't be empty !`)) + panic(utils.NewError("GoMybatisTemplateDecoder", ` logic_deleted="" can't be empty !`)) } if logicData.Undelete_value == "" { - panic(utils.NewError("GoMybatisTempleteDecoder", ` logic_undelete="" can't be empty !`)) + panic(utils.NewError("GoMybatisTemplateDecoder", ` logic_undelete="" can't be empty !`)) } if logicData.Undelete_value == logicData.Deleted_value { - panic(utils.NewError("GoMybatisTempleteDecoder", ` logic_deleted value can't be logic_undelete value!`)) + panic(utils.NewError("GoMybatisTemplateDecoder", ` logic_deleted value can't be logic_undelete value!`)) } break } @@ -610,7 +610,7 @@ func (it *GoMybatisTempleteDecoder) decodeLogicDelete(xml *etree.Element) LogicD return logicData } -func (it *GoMybatisTempleteDecoder) decodeVersionData(xml *etree.Element) *VersionData { +func (it *GoMybatisTemplateDecoder) decodeVersionData(xml *etree.Element) *VersionData { if xml == nil || len(xml.Child) == 0 { return nil } @@ -623,7 +623,7 @@ func (it *GoMybatisTempleteDecoder) decodeVersionData(xml *etree.Element) *Versi versionData.LangType = v.SelectAttrValue("langType", "") //check if !(strings.Contains(versionData.LangType, "int") || strings.Contains(versionData.LangType, "time.Time")) { - panic(utils.NewError("GoMybatisTempleteDecoder", `version_enable only support int...,time.Time... number type!`)) + panic(utils.NewError("GoMybatisTemplateDecoder", `version_enable only support int...,time.Time... number type!`)) } return &versionData } @@ -632,7 +632,7 @@ func (it *GoMybatisTempleteDecoder) decodeVersionData(xml *etree.Element) *Versi } //反射解码得到 集合名词 -func (it *GoMybatisTempleteDecoder) DecodeCollectionName(method *reflect.StructField) string { +func (it *GoMybatisTemplateDecoder) DecodeCollectionName(method *reflect.StructField) string { var collection string //check method arg type if method != nil { diff --git a/GoMybatisTempleteDecoder_test.go b/GoMybatisTempleteDecoder_test.go index 25aed4d..8d219b1 100644 --- a/GoMybatisTempleteDecoder_test.go +++ b/GoMybatisTempleteDecoder_test.go @@ -10,10 +10,10 @@ import ( ) type ExampleActivityMapper struct { - SelectTemplete func(name string, session Session) ([]example.Activity, error) `args:"name,session"` - InsertTemplete func(args []example.Activity, session Session) (int64, error) `args:"args,session"` - UpdateTemplete func(arg example.Activity, session Session) (int64, error) `args:"name,session"` - DeleteTemplete func(name string, session Session) (int64, error) `args:"name,session"` + SelectTemplate func(name string, session Session) ([]example.Activity, error) `args:"name,session"` + InsertTemplate func(args []example.Activity, session Session) (int64, error) `args:"args,session"` + UpdateTemplate func(arg example.Activity, session Session) (int64, error) `args:"name,session"` + DeleteTemplate func(name string, session Session) (int64, error) `args:"name,session"` } //初始化mapper文件和结构体 @@ -44,14 +44,14 @@ func initMapper() { - - - - - - - - + + + + + + + + `) @@ -62,7 +62,7 @@ func initMapper() { panic(`Test_Load_Xml fail,LoadMapperXml "example/Example_ActivityMapper.xml"`) } - var decoder = GoMybatisTempleteDecoder{} + var decoder = GoMybatisTemplateDecoder{} err = decoder.DecodeTree(xmlItems, nil) if err != nil { panic(err) @@ -78,14 +78,14 @@ func initMapper() { engine.WriteMapperPtr(&exampleActivityMapper, bytes) } -type TempleteSession struct { +type TemplateSession struct { Session } -func (it *TempleteSession) Id() string { +func (it *TemplateSession) Id() string { return "sadf" } -func (it *TempleteSession) Query(sqlorArgs string) ([]map[string][]byte, error) { +func (it *TemplateSession) Query(sqlorArgs string) ([]map[string][]byte, error) { resultsSlice := make([]map[string][]byte, 0) result := make(map[string][]byte) @@ -97,17 +97,17 @@ func (it *TempleteSession) Query(sqlorArgs string) ([]map[string][]byte, error) resultsSlice = append(resultsSlice, result) return resultsSlice, nil } -func (it *TempleteSession) Exec(sqlorArgs string) (*Result, error) { +func (it *TemplateSession) Exec(sqlorArgs string) (*Result, error) { var result = Result{ LastInsertId: 1, RowsAffected: 1, } return &result, nil } -func (it *TempleteSession) QueryPrepare(sqlorArgs string, args ...interface{}) ([]map[string][]byte, error) { +func (it *TemplateSession) QueryPrepare(sqlorArgs string, args ...interface{}) ([]map[string][]byte, error) { return nil, nil } -func (it *TempleteSession) ExecPrepare(sqlorArgs string, args ...interface{}) (*Result, error) { +func (it *TemplateSession) ExecPrepare(sqlorArgs string, args ...interface{}) (*Result, error) { var result = Result{ LastInsertId: 1, RowsAffected: 1, @@ -115,19 +115,19 @@ func (it *TempleteSession) ExecPrepare(sqlorArgs string, args ...interface{}) (* return &result, nil } -func (it *TempleteSession) Rollback() error { +func (it *TemplateSession) Rollback() error { return nil } -func (it *TempleteSession) Commit() error { +func (it *TemplateSession) Commit() error { return nil } -func (it *TempleteSession) Begin(p *tx.Propagation) error { +func (it *TemplateSession) Begin(p *tx.Propagation) error { return nil } -func (it *TempleteSession) Close() { +func (it *TemplateSession) Close() { } -func (it *TempleteSession) StmtConvert() (stmt.StmtIndexConvert, error) { +func (it *TemplateSession) StmtConvert() (stmt.StmtIndexConvert, error) { return stmt.BuildStmtConvert("mysql") } @@ -185,7 +185,7 @@ func Test_create_conf(t *testing.T) { fmt.Println(els[0].test) } -func TestGoMybatisTempleteDecoder_Create(t *testing.T) { +func TestGoMybatisTemplateDecoder_Create(t *testing.T) { var act = example.Activity{ Id: "123", Uuid: "uu", @@ -204,8 +204,8 @@ func TestGoMybatisTempleteDecoder_Create(t *testing.T) { act, act, } - var session = TempleteSession{} - n, err := getMapper().InsertTemplete(args, &session) + var session = TemplateSession{} + n, err := getMapper().InsertTemplate(args, &session) if err != nil { t.Fatal(err) } @@ -213,9 +213,9 @@ func TestGoMybatisTempleteDecoder_Create(t *testing.T) { time.Sleep(time.Second) } -func TestGoMybatisTempleteDecoder_Select(t *testing.T) { - var session = TempleteSession{} - n, err := getMapper().SelectTemplete("test", &session) +func TestGoMybatisTemplateDecoder_Select(t *testing.T) { + var session = TemplateSession{} + n, err := getMapper().SelectTemplate("test", &session) if err != nil { t.Fatal(err) } @@ -223,13 +223,13 @@ func TestGoMybatisTempleteDecoder_Select(t *testing.T) { time.Sleep(time.Second) } -func TestGoMybatisTempleteDecoder_Update(t *testing.T) { +func TestGoMybatisTemplateDecoder_Update(t *testing.T) { var act = example.Activity{ Id: "123", Name: "test", } - var session = TempleteSession{} - n, err := getMapper().UpdateTemplete(act, &session) + var session = TemplateSession{} + n, err := getMapper().UpdateTemplate(act, &session) if err != nil { t.Fatal(err) } @@ -237,9 +237,9 @@ func TestGoMybatisTempleteDecoder_Update(t *testing.T) { time.Sleep(time.Second) } -func TestGoMybatisTempleteDecoder_Delete(t *testing.T) { - var session = TempleteSession{} - n, err := getMapper().DeleteTemplete("test", &session) +func TestGoMybatisTemplateDecoder_Delete(t *testing.T) { + var session = TemplateSession{} + n, err := getMapper().DeleteTemplate("test", &session) if err != nil { t.Fatal(err) } @@ -271,14 +271,14 @@ func initMapperTest() { - - - - - - - - + + + + + + + + `) @@ -289,7 +289,7 @@ func initMapperTest() { panic(`Test_Load_Xml fail,LoadMapperXml "example/Example_ActivityMapper.xml"`) } - var decoder = GoMybatisTempleteDecoder{} + var decoder = GoMybatisTemplateDecoder{} err = decoder.DecodeTree(xmlItems, nil) if err != nil { panic(err) diff --git a/README-ch.md b/README-ch.md index ab0a998..a7c02e7 100644 --- a/README-ch.md +++ b/README-ch.md @@ -28,8 +28,8 @@ * 智能表达式可处理动态判断、计算任务(例如:`#{foo.Bar}#{arg+1}#{arg*1}#{arg/1}#{arg-1}`),例如写模糊查询`select * from table where phone like #{phone+'%'}`(注意后置百分号走索引)
* 动态数据源可自定义多数据源,动态切换多个数据库实例
* 模板标签(新)一行代码实现增删改查,逻辑删除,乐观锁,而且还保留完美的扩展性(标签体内可以继续扩展sql逻辑)
-* 乐观锁(新)``乐观锁,尽可能防止并发竞争修改记录
-* 逻辑删除(新)``逻辑删除,防止意外删除数据,数据恢复简单
+* 乐观锁(新)``乐观锁,尽可能防止并发竞争修改记录
+* 逻辑删除(新)``逻辑删除,防止意外删除数据,数据恢复简单
* RPC/MVC组件支持(新)让服务完美支持RPC(减少参数限制),动态代理,事务订阅,易于微服务集成和扩展 详情请点击链接https://github.com/zhuxiujia/easyrpc
* Wrapper插件免写sql支持,Page分页插件支持(预计在golang1.17版本(支持泛型)之后出现)
@@ -146,14 +146,14 @@ func main() { - - - - - - - - + + + + + + + + ``` xml对应以下定义的Mapper结构体方法,然后将生成对应的SQL语句 @@ -172,12 +172,12 @@ type Activity struct { } type ExampleActivityMapper struct { //调用即可生成sql(带有逻辑删除) select * from biz_activity where delete_flag = 1 and name = #{name} - SelectTemplete func(name string) ([]Activity, error) `args:"name"` - InsertTemplete func(arg Activity) (int64, error) - InsertTempleteBatch func(args []Activity) (int64, error) `args:"args"` + SelectTemplate func(name string) ([]Activity, error) `args:"name"` + InsertTemplate func(arg Activity) (int64, error) + InsertTemplateBatch func(args []Activity) (int64, error) `args:"args"` //生成sql(带有乐观锁.逻辑删除) update biz_activity set name = #{name},remark=#{remark},version=#{version+1} where delete_flag = 1 and id = #{id} and version = #{version} - UpdateTemplete func(arg Activity) (int64, error) `args:"name"` - DeleteTemplete func(name string) (int64, error) `args:"name"` + UpdateTemplate func(arg Activity) (int64, error) `args:"name"` + DeleteTemplate func(name string) (int64, error) `args:"name"` } ``` diff --git a/README.md b/README.md index 2130feb..ed7f8a3 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ *
Intelligent expressionProcessing dynamic judgment and computation tasks(such as:`#{foo.Bar}#{arg+1}#{arg*1}#{arg/1}#{arg-1}`),For example, write fuzzy queries `select * from table where phone like #{phone+'%'}`(Note the post-percentile query run in index)
* Dynamic Data SourceMultiple data sources can be customized to dynamically switch multiple database instances
* Template label(new)One line of code to achieve add, delete, modify, delete logic, optimistic lock, but also retain perfect scalability (tag body can continue to expand SQL logic)
-* Optimistic Lock(new)``Optimistic locks to prevent concurrent competition to modify records as much as possible
-* Logical deletion(new)``Logical deletion, prevent accidental deletion of data, data recovery is simple
+* Optimistic Lock(new)``Optimistic locks to prevent concurrent competition to modify records as much as possible
+* Logical deletion(new)``Logical deletion, prevent accidental deletion of data, data recovery is simple
* RPC/MVC Component Support(new)To make the service perfect for RPC (reducing parameter restrictions), dynamic proxy, transaction subscription, easy integration and extension of micro services, click on the link https://github.com/zhuxiujia/easyrpc
@@ -130,14 +130,14 @@ func main() { - - - - - - - - + + + + + + + + ``` XML corresponds to the Mapper structure method defined below @@ -154,11 +154,11 @@ type Activity struct { DeleteFlag int `json:"deleteFlag"` } type ExampleActivityMapper struct { - SelectTemplete func(name string) ([]Activity, error) `args:"name"` - InsertTemplete func(arg Activity) (int64, error) - InsertTempleteBatch func(args []Activity) (int64, error) `args:"args"` - UpdateTemplete func(arg Activity) (int64, error) `args:"name"` - DeleteTemplete func(name string) (int64, error) `args:"name"` + SelectTemplate func(name string) ([]Activity, error) `args:"name"` + InsertTemplate func(arg Activity) (int64, error) + InsertTemplateBatch func(args []Activity) (int64, error) `args:"args"` + UpdateTemplate func(arg Activity) (int64, error) `args:"name"` + DeleteTemplate func(name string) (int64, error) `args:"name"` } ``` diff --git a/SqlEngine.go b/SqlEngine.go index 8c76b28..818e649 100644 --- a/SqlEngine.go +++ b/SqlEngine.go @@ -83,10 +83,10 @@ type SessionEngine interface { SetSqlResultDecoder(decoder SqlResultDecoder) //模板解析器 - TempleteDecoder() TempleteDecoder + TemplateDecoder() TemplateDecoder //设置模板解析器 - SetTempleteDecoder(decoder TempleteDecoder) + SetTemplateDecoder(decoder TemplateDecoder) //(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷) GoroutineSessionMap() *GoroutineSessionMap diff --git a/TempleteDecoder.go b/TempleteDecoder.go index 3f7623f..a574840 100644 --- a/TempleteDecoder.go +++ b/TempleteDecoder.go @@ -5,7 +5,7 @@ import ( "reflect" ) -type TempleteDecoder interface { +type TemplateDecoder interface { SetPrintElement(print bool) DecodeTree(tree map[string]etree.Token, beanType reflect.Type) error } diff --git a/XmlLoader.go b/XmlLoader.go index 40fb40b..78e5fb2 100644 --- a/XmlLoader.go +++ b/XmlLoader.go @@ -24,10 +24,10 @@ func LoadMapperXml(bytes []byte) (items map[string]etree.Token) { s.Tag == Element_Select || s.Tag == Element_ResultMap || s.Tag == Element_Sql || - s.Tag == Element_Insert_Templete || - s.Tag == Element_Delete_Templete || - s.Tag == Element_Update_Templete || - s.Tag == Element_Select_Templete { + s.Tag == Element_Insert_Template || + s.Tag == Element_Delete_Template || + s.Tag == Element_Update_Template || + s.Tag == Element_Select_Template { var elementID = s.SelectAttrValue(ID, "") if elementID == "" { diff --git a/example/Example_ActivityMapper.xml b/example/Example_ActivityMapper.xml index b403b43..6ee4bdc 100644 --- a/example/Example_ActivityMapper.xml +++ b/example/Example_ActivityMapper.xml @@ -25,20 +25,20 @@ - - - - - - - - + + + + + + + + - - + + - + diff --git a/example/Example_test.go b/example/Example_test.go index 8329c5e..4ad2b36 100644 --- a/example/Example_test.go +++ b/example/Example_test.go @@ -23,12 +23,12 @@ type ExampleActivityMapper struct { NewSession func() (GoMybatis.Session, error) //session事务操作.写法2 ExampleActivityMapper.NewSession() //模板示例 - SelectTemplete func(name string) ([]Activity, error) `args:"name"` - SelectCountTemplete func(name string) (int64, error) `args:"name"` - InsertTemplete func(arg Activity) (int64, error) - InsertTempleteBatch func(args []Activity) (int64, error) `args:"args"` - UpdateTemplete func(arg Activity) (int64, error) `args:"name"` - DeleteTemplete func(name string) (int64, error) `args:"name"` + SelectTemplate func(name string) ([]Activity, error) `args:"name"` + SelectCountTemplate func(name string) (int64, error) `args:"name"` + InsertTemplate func(arg Activity) (int64, error) + InsertTemplateBatch func(args []Activity) (int64, error) `args:"args"` + UpdateTemplate func(arg Activity) (int64, error) `args:"name"` + DeleteTemplate func(name string) (int64, error) `args:"name"` //传统mybatis示例 SelectByIds func(ids []string) ([]Activity, error) `args:"ids"` @@ -70,7 +70,7 @@ func init() { engine = GoMybatis.GoMybatisEngine{}.New() //设置打印自动生成的xml 到控制台方便调试,false禁用 - engine.TempleteDecoder().SetPrintElement(false) + engine.TemplateDecoder().SetPrintElement(false) //设置是否打印警告(建议开启) engine.SetPrintWarning(false) @@ -283,39 +283,39 @@ func Test_include_sql(t *testing.T) { fmt.Println("result=", result) } -func TestSelectTemplete(t *testing.T) { +func TestSelectTemplate(t *testing.T) { if MysqlUri == "" || MysqlUri == "*" { fmt.Println("no database url define in Example_config.go , you must set the mysql link!") return } //使用mapper - var result, err = exampleActivityMapper.SelectTemplete("hello") + var result, err = exampleActivityMapper.SelectTemplate("hello") if err != nil { panic(err) } fmt.Println("result=", result) } -func TestSelectCountTemplete(t *testing.T) { +func TestSelectCountTemplate(t *testing.T) { if MysqlUri == "" || MysqlUri == "*" { fmt.Println("no database url define in Example_config.go , you must set the mysql link!") return } //使用mapper - var result, err = exampleActivityMapper.SelectCountTemplete("hello") + var result, err = exampleActivityMapper.SelectCountTemplate("hello") if err != nil { panic(err) } fmt.Println("result=", result) } -func TestInsertTemplete(t *testing.T) { +func TestInsertTemplate(t *testing.T) { if MysqlUri == "" || MysqlUri == "*" { fmt.Println("no database url define in Example_config.go , you must set the mysql link!") return } //使用mapper - var result, err = exampleActivityMapper.InsertTemplete(Activity{Id: "178", Name: "test_insret", CreateTime: time.Now(), Sort: 1, Status: 1, DeleteFlag: 1}) + var result, err = exampleActivityMapper.InsertTemplate(Activity{Id: "178", Name: "test_insret", CreateTime: time.Now(), Sort: 1, Status: 1, DeleteFlag: 1}) if err != nil { panic(err) } @@ -323,7 +323,7 @@ func TestInsertTemplete(t *testing.T) { } //批量插入模板 -func TestInsertTempleteBatch(t *testing.T) { +func TestInsertTemplateBatch(t *testing.T) { if MysqlUri == "" || MysqlUri == "*" { fmt.Println("no database url define in Example_config.go , you must set the mysql link!") return @@ -345,7 +345,7 @@ func TestInsertTempleteBatch(t *testing.T) { CreateTime: time.Now(), }, } - n, err := exampleActivityMapper.InsertTempleteBatch(args) + n, err := exampleActivityMapper.InsertTemplateBatch(args) if err != nil { t.Fatal(err) } @@ -354,7 +354,7 @@ func TestInsertTempleteBatch(t *testing.T) { } //修改模板默认支持逻辑删除和乐观锁 -func TestUpdateTemplete(t *testing.T) { +func TestUpdateTemplate(t *testing.T) { if MysqlUri == "" || MysqlUri == "*" { fmt.Println("no database url define in Example_config.go , you must set the mysql link!") return @@ -366,7 +366,7 @@ func TestUpdateTemplete(t *testing.T) { } //会自动生成乐观锁和逻辑删除字段 set version= * where version = * and delete_flag = * // update set name = 'rs168',version = 1 from biz_activity where name = 'rs168' and delete_flag = 1 and version = 0 - var updateNum, e = exampleActivityMapper.UpdateTemplete(activityBean) + var updateNum, e = exampleActivityMapper.UpdateTemplate(activityBean) fmt.Println("updateNum=", updateNum) if e != nil { panic(e) @@ -374,13 +374,13 @@ func TestUpdateTemplete(t *testing.T) { } //删除 -func TestDeleteTemplete(t *testing.T) { +func TestDeleteTemplate(t *testing.T) { if MysqlUri == "" || MysqlUri == "*" { fmt.Println("no database url define in Example_config.go , you must set the mysql link!") return } //模板默认支持逻辑删除 - var result, err = exampleActivityMapper.DeleteTemplete("rs168") + var result, err = exampleActivityMapper.DeleteTemplate("rs168") if err != nil { panic(err) } @@ -414,7 +414,7 @@ func initTestService() TestService { //TODO 此处可能会因为activitys长度为0 导致数组越界 painc,painc 为运行时异常 框架自动回滚事务 var activity = activitys[0] activity.Remark = remark - updateNum, err := testService.exampleActivityMapper.UpdateTemplete(activity) + updateNum, err := testService.exampleActivityMapper.UpdateTemplate(activity) if err != nil { panic(err) } @@ -431,7 +431,7 @@ func initTestService() TestService { } var activity = activitys[0] activity.Name = name - updateNum, err := testService.exampleActivityMapper.UpdateTemplete(activity) + updateNum, err := testService.exampleActivityMapper.UpdateTemplate(activity) if err != nil { panic(err) } diff --git a/mybatis-3-mapper.dtd b/mybatis-3-mapper.dtd index fab2a83..1774041 100644 --- a/mybatis-3-mapper.dtd +++ b/mybatis-3-mapper.dtd @@ -16,7 +16,7 @@ limitations under the License. --> - + @@ -64,8 +64,8 @@ lang CDATA #IMPLIED > - - + - - + - - + - - +