-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FMWK-268 Store secondary indexes in metadata and make it cacheable
- Loading branch information
Showing
7 changed files
with
74 additions
and
15 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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/aerospike/jdbc/util/MetadataBuilder.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,32 @@ | ||
package com.aerospike.jdbc.util; | ||
|
||
import com.aerospike.client.IAerospikeClient; | ||
import com.aerospike.jdbc.AerospikeDatabaseMetadata; | ||
import com.aerospike.jdbc.model.DriverPolicy; | ||
import com.google.common.cache.Cache; | ||
import com.google.common.cache.CacheBuilder; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.time.Duration; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class MetadataBuilder { | ||
|
||
private final Cache<String, AerospikeDatabaseMetadata> metadataCache; | ||
|
||
public MetadataBuilder(DriverPolicy driverPolicy) { | ||
metadataCache = CacheBuilder.newBuilder() | ||
.expireAfterWrite(Duration.ofSeconds(driverPolicy.getMetadataCacheTtlSeconds())) | ||
.build(); | ||
} | ||
|
||
public AerospikeDatabaseMetadata build(String url, IAerospikeClient client, Connection connection) | ||
throws SQLException { | ||
try { | ||
return metadataCache.get(url, () -> new AerospikeDatabaseMetadata(url, client, connection)); | ||
} catch (ExecutionException e) { | ||
throw new SQLException(e); | ||
} | ||
} | ||
} |
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