diff --git a/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st b/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st index 3f4b728..1648b10 100644 --- a/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st +++ b/source/Sagan-GemStone-Tests/GemStoneRepositoryProviderTest.class.st @@ -22,7 +22,7 @@ GemStoneRepositoryProviderTest >> setUpRepositoryWith: aConflictCheckingStrategy ] { #category : 'tests' } -GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLarge [ +GemStoneRepositoryProviderTest >> testQueryingWhenCollectionIsLargeAndIndexed [ 4 timesRepeat: [ 1000 timesRepeat: [ @@ -43,15 +43,20 @@ GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLarge [ ]. self should: [ - self - assert: ( self extraterrestrials findApplying: 'each.firstName = ''Silvester''' ) size - equals: 4 + self extraterrestrials withQueryFrom: 'each.firstName = ''Silvester''' do: [ :query | + self assert: query size equals: 4. + query do: [ :extraterrestrial | + self + assert: extraterrestrial firstName equals: 'Silvester'; + assert: extraterrestrial lastName equals: 'Stallone' + ] + ] ] notTakeMoreThanMilliseconds: 1 ] { #category : 'tests' } -GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLargeAndNotIndexed [ +GemStoneRepositoryProviderTest >> testQueryingWhenCollectionIsLargeButNotIndexed [ | notIndexed | @@ -76,9 +81,18 @@ GemStoneRepositoryProviderTest >> testFindApplyingWhenCollectionIsLargeAndNotInd store: self ellaTravolta ] ]. + self should: [ - self assert: ( notIndexed findApplying: 'each.firstName = ''Silvester''' ) size equals: 4 ] + notIndexed withQueryFrom: 'each.firstName = ''Silvester''' do: [ :query | + self assert: query size equals: 4. + query do: [ :extraterrestrial | + self + assert: extraterrestrial firstName equals: 'Silvester'; + assert: extraterrestrial lastName equals: 'Stallone' + ] + ] + ] notTakeMoreThanMilliseconds: 17 ] @@ -151,6 +165,27 @@ GemStoneRepositoryProviderTest >> testSpaceshipWhenUsingIdentityIndex [ ] ] +{ #category : 'tests' } +GemStoneRepositoryProviderTest >> testStreamQueryResults [ + + self extraterrestrials + store: self johnTravolta; + store: self johnLock; + store: self ellaTravolta; + store: self silvesterStallone. + + self extraterrestrials withQueryFrom: 'each.firstName = ''Silvester''' do: [ :query | + | stream extraterrestrial | + + stream := query readStream. + extraterrestrial := stream next. + self + assert: extraterrestrial firstName equals: 'Silvester'; + assert: extraterrestrial lastName equals: 'Stallone'. + self assert: stream atEnd + ] +] + { #category : 'private - accessing' } GemStoneRepositoryProviderTest >> timeLimitInMillisecondsWhenAdding [ diff --git a/source/Sagan-GemStone/GemStoneRepository.class.st b/source/Sagan-GemStone/GemStoneRepository.class.st index 80fe3bd..3924066 100644 --- a/source/Sagan-GemStone/GemStoneRepository.class.st +++ b/source/Sagan-GemStone/GemStoneRepository.class.st @@ -62,14 +62,6 @@ GemStoneRepository >> findAllMatching: aCriteriaOrBlock sortedBy: aSortFunction ^ ( self findAllMatching: aCriteriaOrBlock ) sorted: aSortFunction ] -{ #category : 'querying' } -GemStoneRepository >> findApplying: aQueryString [ - - ^ ( GsQuery fromString: aQueryString ) - on: contents; - queryResult -] - { #category : 'configuring' } GemStoneRepository >> indexByEquality: aPath typed: aType [ @@ -170,3 +162,11 @@ GemStoneRepository >> withOneMatching: aCriteriaOrBlock sortedBy: aSortFunction ifFound: foundBlock ifNone: noneBlock ] + +{ #category : 'querying' } +GemStoneRepository >> withQueryFrom: aQueryString do: aBlock [ + + ^ aBlock value: ( ( GsQuery fromString: aQueryString ) + on: contents; + yourself ) +]