MCPcopy
hub / github.com/apache/casbin / applyUpdateOperationToDatabase

Method applyUpdateOperationToDatabase

transaction_commit.go:192–208  ·  view source on GitHub ↗

applyUpdateOperationToDatabase applies an update operation to the database.

(adapter persist.Adapter, op persist.PolicyOperation)

Source from the content-addressed store, hash-verified

190
191// applyUpdateOperationToDatabase applies an update operation to the database.
192func (tx *Transaction) applyUpdateOperationToDatabase(adapter persist.Adapter, op persist.PolicyOperation) error {
193 if updateAdapter, ok := adapter.(persist.UpdatableAdapter); ok {
194 // Use update operation if available.
195 return updateAdapter.UpdatePolicies(op.Section, op.PolicyType, op.OldRules, op.Rules)
196 }
197
198 // Fall back to remove + add.
199 for i, oldRule := range op.OldRules {
200 if err := adapter.RemovePolicy(op.Section, op.PolicyType, oldRule); err != nil {
201 return err
202 }
203 if err := adapter.AddPolicy(op.Section, op.PolicyType, op.Rules[i]); err != nil {
204 return err
205 }
206 }
207 return nil
208}
209
210// applyOperationsToModel applies all buffered operations to the in-memory model.
211func (tx *Transaction) applyOperationsToModel() error {

Callers 1

Calls 3

UpdatePoliciesMethod · 0.65
RemovePolicyMethod · 0.65
AddPolicyMethod · 0.65

Tested by

no test coverage detected