Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

98 gem stone repository should transact on store purge and update #99

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: [ result := System abortTransaction ].
gcotelli marked this conversation as resolved.
Show resolved Hide resolved
result
]
]
Loading