Skip to content

Commit

Permalink
Merge pull request #103 from ba-st/102-Allow-indexed-search-for-insta…
Browse files Browse the repository at this point in the history
…nce-variables-in-GemStone

102 allow indexed search for instance variables in gem stone
  • Loading branch information
mtabacman authored Apr 4, 2024
2 parents 3246da7 + 6a3c5b6 commit 5bd82ae
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
25 changes: 25 additions & 0 deletions source/Sagan-Core-Tests/RepositoryBasedTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,31 @@ RepositoryBasedTest >> testWithOneMatchingSortedByDoElse [
else: [ self fail ]
]

{ #category : 'tests - querying' }
RepositoryBasedTest >> testWithOneWhereIsDoElse [

| found |

self extraterrestrials
store: self johnTravolta;
store: self johnLock;
store: self silvesterStallone.

found := self extraterrestrials
withOneWhere: #lastName
is: 'Stallone'
do: [ :extraterrestrial | extraterrestrial ]
else: [ self fail ].
self assert: found firstName equals: 'Silvester'.

found := self extraterrestrials
withOneWhere: #lastName
is: 'Silvester'
do: [ :extraterrestrial | self fail ]
else: [ 'Not found' ].
self assert: found equals: 'Not found'
]

{ #category : 'tests - management' }
RepositoryBasedTest >> updateExtraterrestrialMatching: aBlock with: aNewExtraterrestrial [

Expand Down
19 changes: 17 additions & 2 deletions source/Sagan-Core/InMemoryRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,26 @@ InMemoryRepository >> valueOf: aVariableName in: anObject [
{ #category : 'querying' }
InMemoryRepository >> withOneMatching: aCriteriaOrBlock do: foundBlock else: noneBlock [

^ contents detect: ( self asMatchingCriteria: aCriteriaOrBlock ) ifFound: foundBlock ifNone: noneBlock
^ contents
detect: ( self asMatchingCriteria: aCriteriaOrBlock )
ifFound: foundBlock
ifNone: noneBlock
]

{ #category : 'querying' }
InMemoryRepository >> withOneMatching: aCriteriaOrBlock sortedBy: aSortFunction do: foundBlock else: noneBlock [

^ ( contents sorted: aSortFunction ) detect: ( self asMatchingCriteria: aCriteriaOrBlock ) ifFound: foundBlock ifNone: noneBlock
^ ( contents sorted: aSortFunction )
detect: ( self asMatchingCriteria: aCriteriaOrBlock )
ifFound: foundBlock
ifNone: noneBlock
]

{ #category : 'querying' }
InMemoryRepository >> withOneWhere: aVariableName is: anExpectedValue do: foundBlock else: noneBlock [

^ self
withOneMatching: [ :element | ( self valueOf: aVariableName in: element ) = anExpectedValue ]
do: foundBlock
else: noneBlock
]
6 changes: 6 additions & 0 deletions source/Sagan-Core/RepositoryBehavior.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,9 @@ RepositoryBehavior >> withOneMatching: aCriteria sortedBy: aSortCriteria do: fou

^ self subclassResponsibility
]

{ #category : 'querying' }
RepositoryBehavior >> withOneWhere: aVariableName is: anExpectedValue do: foundBlock else: noneBlock [

^ self subclassResponsibility
]
13 changes: 13 additions & 0 deletions source/Sagan-GemStone/GemStoneRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ GemStoneRepository >> withOneMatching: aCriteriaOrBlock sortedBy: aSortFunction
ifNone: noneBlock
]

{ #category : 'querying' }
GemStoneRepository >> withOneWhere: aVariableName is: anExpectedValue do: foundBlock else: noneBlock [

^ self
withQueryFrom: ( 'each.<1s> = target' expandMacrosWith: aVariableName asString )
do: [ :query |
query bind: 'target' to: anExpectedValue.
query isEmpty
ifTrue: noneBlock
ifFalse: [ foundBlock value: query any ]
]
]

{ #category : 'querying' }
GemStoneRepository >> withQueryFrom: aQueryString do: aBlock [

Expand Down
9 changes: 9 additions & 0 deletions source/Sagan-RDBMS/RDBMSRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ RDBMSRepository >> withOneMatching: aCriteriaOrBlock sortedBy: aSortFunction do:
^ ( self executeQuery: query ) ifNil: noneBlock ifNotNil: foundBlock
]

{ #category : 'querying' }
RDBMSRepository >> withOneWhere: anAttributeName is: anExpectedValue do: foundBlock else: noneBlock [

^ self
withOneMatching: [ :element | ( element perform: anAttributeName asSymbol ) = anExpectedValue ]
do: foundBlock
else: noneBlock
]

{ #category : 'private - accessing' }
RDBMSRepository >> withReadSessionDo: aBlock [

Expand Down

0 comments on commit 5bd82ae

Please sign in to comment.