diff --git a/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st b/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st index a788605..ac3babe 100644 --- a/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st +++ b/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st @@ -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 ] @@ -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 [ @@ -340,54 +315,55 @@ 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 ] ] @@ -395,8 +371,7 @@ GemStoneRepositoryProviderTest >> testTransactionLevelWithUnhandledException [ on: ZeroDivide do: [ :ex | ex return ]. - self assert: System transactionLevel equals: initialLevel - + self assert: System transactionLevel equals: baseLevel ] { #category : 'utility' } diff --git a/source/Sagan-GemStone/GemStoneRepository.class.st b/source/Sagan-GemStone/GemStoneRepository.class.st index 4559fb6..47e8e69 100644 --- a/source/Sagan-GemStone/GemStoneRepository.class.st +++ b/source/Sagan-GemStone/GemStoneRepository.class.st @@ -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' } @@ -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' } @@ -120,8 +126,10 @@ GemStoneRepository >> saganGemStoneIndexOptions [ { #category : 'private - management' } GemStoneRepository >> storeAfterCheckingConflicts: aDomainObject [ - contents add: aDomainObject. - ^ aDomainObject + ^ self transact: [ + contents add: aDomainObject. + aDomainObject + ] ] { #category : 'management' } @@ -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' } diff --git a/source/Sagan-GemStone/GemStoneTransaction.class.st b/source/Sagan-GemStone/GemStoneTransaction.class.st index ed97bd2..32b9b8f 100644 --- a/source/Sagan-GemStone/GemStoneTransaction.class.st +++ b/source/Sagan-GemStone/GemStoneTransaction.class.st @@ -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 + ] ]