This is an automated email from the ASF dual-hosted git repository.

xjlgod pushed a commit to branch feature/saga
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/feature/saga by this push:
     new 6c148cfb feat: Supplement the statelog_repository section in Database 
persistence for Saga state machine (#800)
6c148cfb is described below

commit 6c148cfb219f56475395d3bac695dc29c8234e26
Author: 1kasa <134709672+1k...@users.noreply.github.com>
AuthorDate: Mon Mar 31 21:50:50 2025 +0800

    feat: Supplement the statelog_repository section in Database persistence 
for Saga state machine (#800)
    
    * fix: Wrong commit
    
    * feat:add state_log_repository
    
    * fix: conflicts and wrong commit
    
    * fix: delete Remove redundant singleton patterns
---
 .../store/repository/state_log_repository.go       | 123 +++++++++++++++++++++
 1 file changed, 123 insertions(+)

diff --git a/pkg/saga/statemachine/store/repository/state_log_repository.go 
b/pkg/saga/statemachine/store/repository/state_log_repository.go
index a00f57bf..a9d970cc 100644
--- a/pkg/saga/statemachine/store/repository/state_log_repository.go
+++ b/pkg/saga/statemachine/store/repository/state_log_repository.go
@@ -16,3 +16,126 @@
  */
 
 package repository
+
+import (
+       "context"
+       "database/sql"
+       "github.com/pkg/errors"
+
+       "github.com/seata/seata-go/pkg/saga/statemachine/engine/core"
+       "github.com/seata/seata-go/pkg/saga/statemachine/statelang"
+       "github.com/seata/seata-go/pkg/saga/statemachine/store/db"
+)
+
+var (
+       stateLogRepositoryImpl *StateLogRepositoryImpl
+)
+
+type StateLogRepositoryImpl struct {
+       stateLogStore *db.StateLogStore
+}
+
+func NewStateLogRepositoryImpl(hsqldb *sql.DB, tablePrefix string) 
*StateLogRepositoryImpl {
+       if stateLogRepositoryImpl == nil {
+               stateLogRepositoryImpl = &StateLogRepositoryImpl{
+                       stateLogStore: db.NewStateLogStore(hsqldb, tablePrefix),
+               }
+       }
+
+       return stateLogRepositoryImpl
+}
+
+func (s *StateLogRepositoryImpl) RecordStateMachineStarted(
+       ctx context.Context,
+       machineInstance statelang.StateMachineInstance,
+       processContext core.ProcessContext,
+) error {
+       if s.stateLogStore == nil {
+               return errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.RecordStateMachineStarted(ctx, machineInstance, 
processContext)
+}
+
+func (s *StateLogRepositoryImpl) RecordStateMachineFinished(
+       ctx context.Context,
+       machineInstance statelang.StateMachineInstance,
+       processContext core.ProcessContext,
+) error {
+       if s.stateLogStore == nil {
+               return errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.RecordStateMachineFinished(ctx, machineInstance, 
processContext)
+}
+
+func (s *StateLogRepositoryImpl) RecordStateMachineRestarted(
+       ctx context.Context,
+       machineInstance statelang.StateMachineInstance,
+       processContext core.ProcessContext,
+) error {
+       if s.stateLogStore == nil {
+               return errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.RecordStateMachineRestarted(ctx, 
machineInstance, processContext)
+}
+
+func (s *StateLogRepositoryImpl) RecordStateStarted(
+       ctx context.Context,
+       stateInstance statelang.StateInstance,
+       processContext core.ProcessContext,
+) error {
+       if s.stateLogStore == nil {
+               return errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.RecordStateStarted(ctx, stateInstance, 
processContext)
+}
+
+func (s *StateLogRepositoryImpl) RecordStateFinished(
+       ctx context.Context,
+       stateInstance statelang.StateInstance,
+       processContext core.ProcessContext,
+) error {
+       if s.stateLogStore == nil {
+               return errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.RecordStateFinished(ctx, stateInstance, 
processContext)
+}
+
+func (s *StateLogRepositoryImpl) 
GetStateMachineInstance(stateMachineInstanceId string) 
(statelang.StateMachineInstance, error) {
+       if s.stateLogStore == nil {
+               return nil, errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.GetStateMachineInstance(stateMachineInstanceId)
+}
+
+func (s *StateLogRepositoryImpl) 
GetStateMachineInstanceByBusinessKey(businessKey, tenantId string) 
(statelang.StateMachineInstance, error) {
+       if s.stateLogStore == nil {
+               return nil, errors.New("stateLogStore is not initialized")
+       }
+       return 
s.stateLogStore.GetStateMachineInstanceByBusinessKey(businessKey, tenantId)
+}
+
+func (s *StateLogRepositoryImpl) QueryStateMachineInstanceByParentId(parentId 
string) ([]statelang.StateMachineInstance, error) {
+       if s.stateLogStore == nil {
+               return nil, errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.GetStateMachineInstanceByParentId(parentId)
+}
+
+func (s *StateLogRepositoryImpl) GetStateInstance(stateInstanceId, 
machineInstId string) (statelang.StateInstance, error) {
+       if s.stateLogStore == nil {
+               return nil, errors.New("stateLogStore is not initialized")
+       }
+       return s.stateLogStore.GetStateInstance(stateInstanceId, machineInstId)
+}
+
+func (s *StateLogRepositoryImpl) 
QueryStateInstanceListByMachineInstanceId(stateMachineInstanceId string) 
([]statelang.StateInstance, error) {
+       if s.stateLogStore == nil {
+               return nil, errors.New("stateLogStore is not initialized")
+       }
+       return 
s.stateLogStore.GetStateInstanceListByMachineInstanceId(stateMachineInstanceId)
+
+}
+
+func (s *StateLogRepositoryImpl) SetStateLogStore(stateLogStore 
*db.StateLogStore) {
+       s.stateLogStore = stateLogStore
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to