Skip to content

Commit

Permalink
edit name
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Mar 25, 2021
1 parent 5fe13a8 commit 9aae641
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 167 deletions.
12 changes: 6 additions & 6 deletions ElementType.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion GoMybatis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions GoMybatisEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,有一定性能消耗,换取最大的事务定义便捷,单线程处理场景可以关闭此配置)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
60 changes: 30 additions & 30 deletions GoMybatisTempleteDecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -109,16 +109,16 @@ func printElement(element *etree.Element, v *string) {
*v += "</" + element.Tag + ">\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", "")
Expand All @@ -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)

Expand All @@ -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", "")
Expand All @@ -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)

Expand Down Expand Up @@ -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", "")
Expand All @@ -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)

Expand Down Expand Up @@ -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", "")
Expand All @@ -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)

Expand Down Expand Up @@ -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 <resultMap> or <" + mapper.Tag + "Templete>,mapper id=" + mapper.SelectAttrValue("id", ""))
panic("[GoMybatisTemplateDecoder] attribute 'tables' can not be empty! need define in <resultMap> 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{},
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
Expand All @@ -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{}
}
Expand All @@ -596,21 +596,21 @@ func (it *GoMybatisTempleteDecoder) decodeLogicDelete(xml *etree.Element) LogicD
logicData.LangType = v.SelectAttrValue("langType", "")
//check
if logicData.Deleted_value == "" {
panic(utils.NewError("GoMybatisTempleteDecoder", `<resultMap> logic_deleted="" can't be empty !`))
panic(utils.NewError("GoMybatisTemplateDecoder", `<resultMap> logic_deleted="" can't be empty !`))
}
if logicData.Undelete_value == "" {
panic(utils.NewError("GoMybatisTempleteDecoder", `<resultMap> logic_undelete="" can't be empty !`))
panic(utils.NewError("GoMybatisTemplateDecoder", `<resultMap> logic_undelete="" can't be empty !`))
}
if logicData.Undelete_value == logicData.Deleted_value {
panic(utils.NewError("GoMybatisTempleteDecoder", `<resultMap> logic_deleted value can't be logic_undelete value!`))
panic(utils.NewError("GoMybatisTemplateDecoder", `<resultMap> logic_deleted value can't be logic_undelete value!`))
}
break
}
}
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
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 9aae641

Please sign in to comment.