gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/datax/modifyx2/cachez-source.go (about)

     1  package modifyx
     2  
     3  import (
     4  	"gitee.com/zhongguo168a/gocodes/datax"
     5  	"gitee.com/zhongguo168a/gocodes/datax/mapx"
     6  )
     7  
     8  type M = map[string]interface{}
     9  type A = []interface{}
    10  
    11  // className = origin["_type"]
    12  func NewSource() *Source {
    13  	return NewSourceWith(datax.M{})
    14  }
    15  
    16  func NewSourceWith(origin datax.M) *Source {
    17  	return &Source{
    18  		origin:    origin,
    19  		className: mapx.String(origin, "_type"),
    20  	}
    21  }
    22  
    23  // 数据源
    24  // 通常加载后,数据源不可变,作为配置文件的映射
    25  // 采用数据源的目的是为了避免数据的克隆影响性能,毕竟需要修正的地方有限
    26  type Source struct {
    27  	// 数据
    28  	origin map[string]interface{}
    29  	//
    30  	id string
    31  	//
    32  	kind string
    33  	// 作为结构时的类名
    34  	className string
    35  
    36  	// 保证一个root对象唯一, 需要传递给新的对象
    37  	pools *PoolList
    38  }
    39  
    40  func (s *Source) GetPools() *PoolList {
    41  	if s.pools == nil {
    42  		s.pools = NewPoolList()
    43  	}
    44  
    45  	return s.pools
    46  }
    47  
    48  func (s *Source) ClassId() string {
    49  	return s.id
    50  }
    51  func (s *Source) SetClassId(val string) {
    52  	s.id = val
    53  }
    54  func (s *Source) ClassKey() string {
    55  	return s.kind + "/" + s.id
    56  }
    57  
    58  func (s *Source) ClassKind() string {
    59  	return s.kind
    60  }
    61  
    62  func (s *Source) ClassName() string {
    63  	return s.className
    64  }
    65  
    66  func (s *Source) Dispose() {
    67  	s.origin = nil
    68  }
    69  
    70  func (s *Source) Clone() (r *Source) {
    71  	r = NewSourceWith(mapx.CloneMap(s.origin))
    72  	return
    73  }