Skip to content

Commit

Permalink
Merge pull request #99 from ba-st/98-GemStone-repository-should-trans…
Browse files Browse the repository at this point in the history
…act-on-store-purge-and-update

98 gem stone repository should transact on store purge and update
  • Loading branch information
gcotelli authored Feb 20, 2024
2 parents 435530a + 0228634 commit 1b6a558
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 80 deletions.
79 changes: 27 additions & 52 deletions source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ GemStoneRepositoryProviderTest >> testExceptionsAbortTransactionsUntilHandled [
self assert: self extraterrestrials findAll isEmpty.

self extraterrestrials transact: [
[
self extraterrestrials store: self silvesterStallone.
self assertTheOnlyOneInTheRepositoryIsSilvesterStallone.

[
self extraterrestrials transact: [
self extraterrestrials store: self johnTravolta.
1 / 0
]
1 / 0
]
on: ZeroDivide
do: [ :ex | ex return ]
Expand All @@ -56,27 +52,6 @@ GemStoneRepositoryProviderTest >> testExceptionsAbortTransactionsUntilHandled [
self assertTheOnlyOneInTheRepositoryIsSilvesterStallone
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testNestedTransactions [

self assert: self extraterrestrials findAll isEmpty.

self extraterrestrials transact: [
self extraterrestrials store: self silvesterStallone.
self assertTheOnlyOneInTheRepositoryIsSilvesterStallone.

System abortTransaction.
self assert: self extraterrestrials findAll isEmpty.
self extraterrestrials transact: [ self extraterrestrials store: self johnTravolta ]
].

self withTheOnlyOneIn: self extraterrestrials findAll do: [ :extraterrestrial |
self
assert: extraterrestrial firstName equals: 'John';
assert: extraterrestrial lastName equals: 'Travolta'
]
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testQueryReturningBeforeAllIndexedResultsAreRead [

Expand Down Expand Up @@ -340,63 +315,63 @@ GemStoneRepositoryProviderTest >> testStreamQueryResults [
{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testTransactionLevel [

| initialLevel |
| baseLevel |

initialLevel := System transactionLevel.
self assert: initialLevel >= 0.
baseLevel := System transactionLevel.

self extraterrestrials transact: [
self assert: System transactionLevel equals: initialLevel + 1.
self extraterrestrials transact: [ self assert: System transactionLevel equals: initialLevel + 2 ].
self assert: System transactionLevel equals: initialLevel + 1
].
self assert: System transactionLevel equals: initialLevel
| levelDuringTransaction |

levelDuringTransaction := System transactionLevel.
self extraterrestrials transact: [
self assert: System transactionLevel equals: levelDuringTransaction ].
self assert: System transactionLevel equals: levelDuringTransaction
].
self assert: System transactionLevel equals: baseLevel
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testTransactionLevelWithManualAbort [

| initialLevel |
| baseLevel |

initialLevel := System transactionLevel.
self assert: initialLevel >= 0.
baseLevel := System transactionLevel.

self extraterrestrials transact: [
self assert: System transactionLevel equals: initialLevel + 1.
| levelDuringTransaction |

levelDuringTransaction := System transactionLevel.
self extraterrestrials transact: [
self assert: System transactionLevel equals: initialLevel + 2.
self assert: System transactionLevel equals: levelDuringTransaction.
System abortTransaction.
self assert: System transactionLevel equals: initialLevel + 1
self assert: System transactionLevel equals: levelDuringTransaction
].
self assert: System transactionLevel equals: initialLevel.
self assert: System transactionLevel equals: levelDuringTransaction
].
self assert: System transactionLevel equals: initialLevel

self assert: System transactionLevel equals: baseLevel
]

{ #category : 'tests' }
GemStoneRepositoryProviderTest >> testTransactionLevelWithUnhandledException [

| initialLevel |

initialLevel := System transactionLevel.
self assert: initialLevel >= 0.
| baseLevel |

baseLevel := System transactionLevel.
[
| levelDuringTransaction |

self extraterrestrials transact: [
self assert: System transactionLevel equals: initialLevel + 1.
levelDuringTransaction := System transactionLevel.
self extraterrestrials transact: [
self assert: System transactionLevel equals: initialLevel + 2.
self assert: System transactionLevel equals: levelDuringTransaction.
1 / 0
]
]
]
on: ZeroDivide
do: [ :ex | ex return ].

self assert: System transactionLevel equals: initialLevel

self assert: System transactionLevel equals: baseLevel
]

{ #category : 'utility' }
Expand Down
44 changes: 26 additions & 18 deletions source/Sagan-GemStone/GemStoneRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,23 @@ GemStoneRepository >> findAllMatching: aCriteriaOrBlock sortedBy: aSortFunction
{ #category : 'configuring' }
GemStoneRepository >> indexByEquality: aPath typed: aType [

GsIndexSpec new
equalityIndex: ( 'each.<1s>' expandMacrosWith: aPath )
lastElementClass: aType
options: self saganGemStoneIndexOptions;
createIndexesOn: contents
self transact: [
GsIndexSpec new
equalityIndex: ( 'each.<1s>' expandMacrosWith: aPath )
lastElementClass: aType
options: self saganGemStoneIndexOptions;
createIndexesOn: contents
]
]

{ #category : 'configuring' }
GemStoneRepository >> indexByIdentity: aPath [

GsIndexSpec new
identityIndex: ( 'each.<1s>' expandMacrosWith: aPath ) options: self saganGemStoneIndexOptions;
createIndexesOn: contents
self transact: [
GsIndexSpec new
identityIndex: ( 'each.<1s>' expandMacrosWith: aPath ) options: self saganGemStoneIndexOptions;
createIndexesOn: contents
]
]

{ #category : 'initialization' }
Expand All @@ -96,18 +100,20 @@ GemStoneRepository >> matchingCriteriaBuilder [
{ #category : 'private - management' }
GemStoneRepository >> purgeAfterCheckingInclusion: aDomainObject [

contents remove: aDomainObject ifAbsent: [
DataInconsistencyFound signal:
( '<1p> was expected to be found in the contents, but it was not.' expandMacrosWith:
aDomainObject )
].
^ aDomainObject
^ self transact: [
contents remove: aDomainObject ifAbsent: [
DataInconsistencyFound signal:
( '<1p> was expected to be found in the contents, but it was not.' expandMacrosWith:
aDomainObject )
].
aDomainObject
]
]

{ #category : 'management' }
GemStoneRepository >> purgeAllMatching: aCriteriaOrBlock [

contents := contents reject: ( self asMatchingCriteria: aCriteriaOrBlock )
self transact: [ contents := contents reject: ( self asMatchingCriteria: aCriteriaOrBlock ) ]
]

{ #category : 'private - accessing' }
Expand All @@ -120,8 +126,10 @@ GemStoneRepository >> saganGemStoneIndexOptions [
{ #category : 'private - management' }
GemStoneRepository >> storeAfterCheckingConflicts: aDomainObject [

contents add: aDomainObject.
^ aDomainObject
^ self transact: [
contents add: aDomainObject.
aDomainObject
]
]

{ #category : 'management' }
Expand All @@ -133,7 +141,7 @@ GemStoneRepository >> transact: aBlock [
{ #category : 'management' }
GemStoneRepository >> update: aMutableDomainObject executing: aBlock [

aBlock value: aMutableDomainObject
self transact: [ aBlock value: aMutableDomainObject ]
]

{ #category : 'private - management' }
Expand Down
21 changes: 11 additions & 10 deletions source/Sagan-GemStone/GemStoneTransaction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ Class {
{ #category : 'processing' }
GemStoneTransaction >> transact: aBlock [

| result |
^ System inTransaction
ifTrue: aBlock
ifFalse: [
| result |

System inTransaction
ifTrue: [ System beginNestedTransaction ]
ifFalse: [ System beginTransaction ].
[
result := aBlock value.
System commitTransaction
] ifCurtailed: [ result := System abortTransaction ].

^ result
System beginTransaction.
[
result := aBlock value.
System commitTransaction
] ifCurtailed: [ System abortTransaction ].
result
]
]

0 comments on commit 1b6a558

Please sign in to comment.