Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Makes SecretContentMapper type safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
alokmenghrajani committed Apr 23, 2015
1 parent 1c30fa8 commit 7078f3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Expand Up @@ -70,21 +70,21 @@ public Optional<SecretContent> getSecretContentById(long id) {
SecretsContentRecord r = dslContext.fetchOne(SECRETS_CONTENT,
SECRETS_CONTENT.ID.eq(Math.toIntExact(id)));
return Optional.ofNullable(r).map(
(rec) -> rec.map(new SecretContentMapper(mapper)));
rec -> new SecretContentMapper(mapper).map(rec));
}

public Optional<SecretContent> getSecretContentBySecretIdAndVersion(long secretId,
String version) {
SecretsContentRecord r = dslContext.fetchOne(SECRETS_CONTENT,
SECRETS_CONTENT.SECRETID.eq(Math.toIntExact(secretId))
.and(SECRETS_CONTENT.VERSION.eq(version)));
return Optional.ofNullable(r).map((rec) -> rec.map(new SecretContentMapper(mapper)));
return Optional.ofNullable(r).map(
rec -> new SecretContentMapper(mapper).map(rec));
}

public ImmutableList<SecretContent> getSecretContentsBySecretId(long secretId) {
List<SecretContent> r = dslContext
.select()
.from(SECRETS_CONTENT)
.selectFrom(SECRETS_CONTENT)
.where(SECRETS_CONTENT.SECRETID.eq(Math.toIntExact(secretId)))
.fetch()
.map(new SecretContentMapper(mapper));
Expand Down
Expand Up @@ -23,10 +23,9 @@
import java.util.Map;
import keywhiz.api.model.SecretContent;
import keywhiz.jooq.tables.records.SecretsContentRecord;
import org.jooq.Record;
import org.jooq.RecordMapper;

class SecretContentMapper implements RecordMapper<Record, SecretContent> {
class SecretContentMapper implements RecordMapper<SecretsContentRecord, SecretContent> {
private static final TypeReference MAP_STRING_STRING_TYPE =
new TypeReference<Map<String, String>>() {};
private final ObjectMapper mapper;
Expand All @@ -35,9 +34,7 @@ class SecretContentMapper implements RecordMapper<Record, SecretContent> {
this.mapper = mapper;
}

public SecretContent map(Record record) {
SecretsContentRecord r = (SecretsContentRecord) record;

public SecretContent map(SecretsContentRecord r) {
return SecretContent.of(
r.getId(),
r.getSecretid(),
Expand Down

0 comments on commit 7078f3f

Please sign in to comment.