github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/state/interface.go (about) 1 /* 2 * 3 * Copyright (c) 2021-present unTill Pro, Ltd. 4 * 5 * @author Michael Saigachenko 6 * 7 */ 8 9 package state 10 11 import ( 12 "github.com/voedger/voedger/pkg/appdef" 13 "github.com/voedger/voedger/pkg/istructs" 14 ) 15 16 type IStateStorage interface { 17 NewKeyBuilder(entity appdef.QName, existingKeyBuilder istructs.IStateKeyBuilder) (newKeyBuilder istructs.IStateKeyBuilder) 18 } 19 type IWithGet interface { 20 // Get reads item from storage 21 // Nil value returned when item not found 22 Get(key istructs.IStateKeyBuilder) (value istructs.IStateValue, err error) 23 } 24 type IWithGetBatch interface { 25 // GetBatch reads items from storage 26 GetBatch(items []GetBatchItem) (err error) 27 } 28 type IWithRead interface { 29 // Read reads items with callback. Can return many more than 1 item for the same get 30 Read(key istructs.IStateKeyBuilder, callback istructs.ValueCallback) (err error) 31 } 32 type IWithApplyBatch interface { 33 // Validate validates batch before store 34 Validate(items []ApplyBatchItem) (err error) 35 // ApplyBatch applies batch to storage 36 ApplyBatch(items []ApplyBatchItem) (err error) 37 } 38 type IWithInsert interface { 39 IWithApplyBatch 40 41 // ProvideValueBuilder provides value builder. ExistingBuilder can be null 42 ProvideValueBuilder(key istructs.IStateKeyBuilder, existingBuilder istructs.IStateValueBuilder) (istructs.IStateValueBuilder, error) 43 } 44 45 type IWithUpdate interface { 46 IWithApplyBatch 47 48 // ProvideValueBuilderForUpdate provides value builder to update the value. ExistingBuilder can be null 49 ProvideValueBuilderForUpdate(key istructs.IStateKeyBuilder, existingValue istructs.IStateValue, existingBuilder istructs.IStateValueBuilder) (istructs.IStateValueBuilder, error) 50 } 51 52 type IState interface { 53 istructs.IState 54 istructs.IIntents 55 istructs.IPkgNameResolver 56 } 57 58 type IHostState interface { 59 IState 60 61 // ValidateIntents validates intents 62 ValidateIntents() (err error) 63 // ApplyIntents applies intents to underlying storage 64 ApplyIntents() (err error) 65 // ClearIntents clears intents 66 ClearIntents() 67 } 68 69 // IBundledHostState buffers changes in "bundles" when ApplyIntents is called. 70 // Further Read- and *Exist operations see these changes. 71 type IBundledHostState interface { 72 IState 73 74 // ApplyIntents validates and stores intents to bundles 75 ApplyIntents() (readyToFlushBundle bool, err error) 76 77 // FlushBundles flushes bundles to underlying storage and resets the bundles 78 FlushBundles() (err error) 79 }