-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #1922 - implement whole-system search in new query builder
Signed-off-by: Mike Schroeder <mschroed@us.ibm.com>
- Loading branch information
1 parent
6c18b9b
commit aab551b
Showing
39 changed files
with
658 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/cache/IdNameCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2021 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.persistence.jdbc.cache; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import com.ibm.fhir.persistence.jdbc.dao.api.IIdNameCache; | ||
|
||
|
||
/** | ||
* @param <T> the type of the key value held by the cache | ||
*/ | ||
public class IdNameCache<T> implements IIdNameCache<T> { | ||
|
||
// We use LinkedHashMap for the local map because we also need to maintain order | ||
// of insertion to make sure we have correct LRU behavior when updating the shared cache | ||
private final ThreadLocal<Map<T,String>> local = new ThreadLocal<>(); | ||
|
||
// The cache shared at the server level | ||
private final ConcurrentHashMap<T,String> shared = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* Public constructor | ||
*/ | ||
public IdNameCache() { | ||
} | ||
|
||
@Override | ||
public void updateSharedMaps() { | ||
|
||
Map<T,String> localMap = local.get(); | ||
if (localMap != null) { | ||
// no need to synchronize because we can use a ConcurrentHashMap | ||
shared.putAll(localMap); | ||
localMap.clear(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName(T key) { | ||
String result = null; | ||
Map<T,String> localMap = local.get(); | ||
if (localMap != null) { | ||
result = localMap.get(key); | ||
} | ||
|
||
if (result == null) { | ||
result = shared.get(key); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void addEntry(T id, String name) { | ||
Map<T,String> localMap = local.get(); | ||
if (localMap == null) { | ||
localMap = new HashMap<>(); | ||
local.set(localMap); | ||
} | ||
localMap.put(id, name); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
local.remove(); | ||
shared.clear(); | ||
} | ||
|
||
@Override | ||
public void clearLocalMaps() { | ||
Map<T,String> map = local.get(); | ||
if (map != null) { | ||
map.clear(); | ||
} | ||
} | ||
|
||
@Override | ||
public void prefill(Map<T,String> content) { | ||
// as the given content is supposed to be already committed in the database, | ||
// we can add it directly to the shared map | ||
this.shared.putAll(content); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/dao/api/IIdNameCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2021 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.persistence.jdbc.dao.api; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Interface to a cache mapping an id of type T to a string. Supports | ||
* thread-local caching to support temporary staging of values pending | ||
* successful completion of a transaction. | ||
* @param<T> | ||
*/ | ||
public interface IIdNameCache<T> { | ||
|
||
/** | ||
* Get the name for the given id | ||
* @param id | ||
* @return | ||
*/ | ||
String getName(T id); | ||
|
||
/** | ||
* Add the entry to the local cache | ||
* @param id | ||
* @param name | ||
*/ | ||
void addEntry(T id, String name); | ||
|
||
/** | ||
* Called after a transaction commit() to transfer all the staged (thread-local) data | ||
* over to the shared cache. | ||
*/ | ||
void updateSharedMaps(); | ||
|
||
/** | ||
* Clear both local shared caches - useful for unit tests | ||
*/ | ||
void reset(); | ||
|
||
/** | ||
* Clear anything cached in thread-local (after transaction rollback, for example) | ||
*/ | ||
void clearLocalMaps(); | ||
|
||
/** | ||
* Prefill the shared map with the given content (must come data already | ||
* committed in the database) | ||
* @param content | ||
*/ | ||
void prefill(Map<T,String> content); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.