arp

package
v0.0.0-...-1aa1ba8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(ctx context.Context)

func CopyEntity

func CopyEntity(typeFullname string, entity any) any

完整复制一个实体(深拷贝),这里约定,实体只能是一个struct,实体的field只能是基本类型或者实体或者集合(Array,Map,Slice),集合的元素只能是基本类型或者实体

func CopyEntityInProcess

func CopyEntityInProcess(ctx context.Context, entityType string, id any) any

func EntityAvailableInProcess

func EntityAvailableInProcess(ctx context.Context, entityType string, id any) bool

func Finish

func Finish(ctx context.Context) error

func GetFromOrPutEntityToProcessIfNotAvailable

func GetFromOrPutEntityToProcessIfNotAvailable(ctx context.Context, entityType string, id any, entity any) (actual any, get bool)

func Go

func Go(ctx context.Context, f func(ctx context.Context) error) (err error)

func PutNewEntityToProcess

func PutNewEntityToProcess(ctx context.Context, entityType string, id any, entity any)

func RemoveEntityInProcess

func RemoveEntityInProcess(ctx context.Context, entityType string, id any)

func Start

func Start(ctx context.Context) context.Context

func TakeEntityInProcess

func TakeEntityInProcess(ctx context.Context, entityType string, id any) (exists bool, entity any)

func TakenFromRepository

func TakenFromRepository(ctx context.Context, entityType string, id any, entity any)

func TakenFromSingletonRepository

func TakenFromSingletonRepository(ctx context.Context, entityType string)

Types

type CreatedInProcState

type CreatedInProcState struct {
}

在过程中新建的状态

type ErrorState

type ErrorState struct {
}

错误状态

type MockMutexes

type MockMutexes struct {
}

func NewMockMutexes

func NewMockMutexes() *MockMutexes

func (*MockMutexes) Lock

func (mutexes *MockMutexes) Lock(ctx context.Context, id any) (ok bool, absent bool, err error)

func (*MockMutexes) NewAndLock

func (mutexes *MockMutexes) NewAndLock(ctx context.Context, id any) (ok bool, err error)

func (*MockMutexes) UnlockAll

func (mutexes *MockMutexes) UnlockAll(ctx context.Context, ids []any)

type MockQueryFuncs

type MockQueryFuncs[T any] struct {
}

func (*MockQueryFuncs[T]) Count

func (qf *MockQueryFuncs[T]) Count(ctx context.Context) (uint64, error)

func (*MockQueryFuncs[T]) QueryAllByField

func (qf *MockQueryFuncs[T]) QueryAllByField(ctx context.Context, fieldName string, fieldValue any) ([]T, error)

func (*MockQueryFuncs[T]) QueryAllIds

func (qf *MockQueryFuncs[T]) QueryAllIds(ctx context.Context) (ids []any, err error)

type MockStore

type MockStore[T any] struct {
	// contains filtered or unexported fields
}

func NewMockStore

func NewMockStore[T any]() *MockStore[T]

func (*MockStore[T]) Load

func (store *MockStore[T]) Load(ctx context.Context, id any) (entity T, found bool, err error)

func (*MockStore[T]) RemoveAll

func (store *MockStore[T]) RemoveAll(ctx context.Context, ids []any) error

func (*MockStore[T]) Save

func (store *MockStore[T]) Save(ctx context.Context, id any, entity T) error

func (*MockStore[T]) SaveAll

func (store *MockStore[T]) SaveAll(ctx context.Context, entitiesToInsert map[any]any, entitiesToUpdate map[any]*ProcessEntity) error

type Mutexes

type Mutexes interface {
	Lock(ctx context.Context, id any) (ok bool, absent bool, err error)
	//返回ok不为true那就是已创建了
	NewAndLock(ctx context.Context, id any) (ok bool, err error)
	UnlockAll(ctx context.Context, ids []any)
}

type NewZeroEntity

type NewZeroEntity[T any] func() T

type ProcessContext

type ProcessContext struct {
	// contains filtered or unexported fields
}

收集,共享,输出一个过程中的数据。包括过程信息,过程中涉及到的实体的状态变化

type ProcessEntity

type ProcessEntity struct {
	// contains filtered or unexported fields
}

在当前过程当中的实体

func (*ProcessEntity) Entity

func (pe *ProcessEntity) Entity() any

func (*ProcessEntity) State

func (pe *ProcessEntity) State() ProcessEntityState

type ProcessEntityState

type ProcessEntityState interface {
	// contains filtered or unexported methods
}

过程当中的实体的可能的几种状态

type Repository

type Repository[T any] interface {
	Find(ctx context.Context, id any) (entity T, found bool)
	Take(ctx context.Context, id any) (entity T, found bool)
	Put(ctx context.Context, id any, entity T)
	PutIfAbsent(ctx context.Context, id any, entity T) (actual T, absent bool)
	Remove(ctx context.Context, id any) (removed T, exists bool)
	TakeOrPutIfAbsent(ctx context.Context, id any, newEntity T) T
}

仓库是存放聚合的地方,聚合只会通过它的id来获取。 仓库是一个接口,是为了清晰地罗列它的功能,除此之外没有其他特别的原因。 泛型类型T代表聚合的类型,仓库创建的时候决定T的实际类型, 例如: repoimpl.NewMemRepository(func() *Order { return &Order{} }) 这里创建了一个实际类型为“Order”的内存仓库 repoimpl.NewMemRepository(func() *Product { return &Product{} }) 这里创建了一个实际类型为“Product”的内存仓库

func NewMockRepository

func NewMockRepository[T any](newZeroEntityFunc NewZeroEntity[T]) Repository[T]

func NewRepository

func NewRepository[T any](store Store[T], mutexes Mutexes, newZeroEntityFunc NewZeroEntity[T]) Repository[T]

type RepositoryImpl

type RepositoryImpl[T any] struct {
	// contains filtered or unexported fields
}

func (*RepositoryImpl[T]) EntityType

func (repository *RepositoryImpl[T]) EntityType() string

func (*RepositoryImpl[T]) Find

func (repository *RepositoryImpl[T]) Find(ctx context.Context, id any) (entity T, found bool)

func (*RepositoryImpl[T]) FlushProcessEntities

func (repository *RepositoryImpl[T]) FlushProcessEntities(ctx context.Context, entitiesToInsert map[any]any, entitiesToUpdate map[any]*ProcessEntity, idsToRemoveEntity []any) error

func (*RepositoryImpl[T]) Put

func (repository *RepositoryImpl[T]) Put(ctx context.Context, id any, entity T)

func (*RepositoryImpl[T]) PutIfAbsent

func (repository *RepositoryImpl[T]) PutIfAbsent(ctx context.Context, id any, entity T) (actual T, absent bool)

func (*RepositoryImpl[T]) ReleaseProcessEntities

func (repository *RepositoryImpl[T]) ReleaseProcessEntities(ctx context.Context, ids []any)

func (*RepositoryImpl[T]) Remove

func (repository *RepositoryImpl[T]) Remove(ctx context.Context, id any) (removed T, exists bool)

func (*RepositoryImpl[T]) Take

func (repository *RepositoryImpl[T]) Take(ctx context.Context, id any) (entity T, found bool)

func (*RepositoryImpl[T]) TakeOrPutIfAbsent

func (repository *RepositoryImpl[T]) TakeOrPutIfAbsent(ctx context.Context, id any, newEntity T) T

type SingletonRepository

type SingletonRepository[T any] interface {
	Get(ctx context.Context) (*T, error)
	Take(ctx context.Context) (*T, error)
	Put(ctx context.Context, entity *T) error
}

保存的是一个不存在于某个集合当中的独立的实体。只在内存中,如需从数据库加载初始数据,则在系统启动时完成加载

func NewSingletonRepository

func NewSingletonRepository[T any](entity *T) SingletonRepository[T]

type SingletonRepositoryImpl

type SingletonRepositoryImpl[T any] struct {
	// contains filtered or unexported fields
}

func (*SingletonRepositoryImpl[T]) Get

func (repo *SingletonRepositoryImpl[T]) Get(ctx context.Context) (*T, error)

func (*SingletonRepositoryImpl[T]) Put

func (repo *SingletonRepositoryImpl[T]) Put(ctx context.Context, entity *T) error

func (*SingletonRepositoryImpl[T]) ReleaseProcessEntity

func (repo *SingletonRepositoryImpl[T]) ReleaseProcessEntity(ctx context.Context)

func (*SingletonRepositoryImpl[T]) Take

func (repo *SingletonRepositoryImpl[T]) Take(ctx context.Context) (*T, error)

type Store

type Store[T any] interface {
	//加载上来的是原始entity的一个副本(copy),基于数据库的store天然就是copy,而内存store需要实现copy而不能传递原始entity的指针
	Load(ctx context.Context, id any) (entity T, found bool, err error)
	Save(ctx context.Context, id any, entity T) error
	SaveAll(ctx context.Context, entitiesToInsert map[any]any, entitiesToUpdate map[any]*ProcessEntity) error
	RemoveAll(ctx context.Context, ids []any) error
}

type TakenFromRepoState

type TakenFromRepoState struct {
}

从仓库中取来的状态

type ToRemoveInRepoState

type ToRemoveInRepoState struct {
}

需要去仓库中删除的状态

type TransientInProcState

type TransientInProcState struct {
}

瞬时状态,就是在过程中创建之后又在过程中删除,和仓库没有关系

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL