Java源码示例:org.jdbi.v3.core.mapper.RowMapper

示例1
/** Returns a JDBI row mapper used to convert a ResultSet into an instance of this bean object. */
public static RowMapper<PlayerApiKeyLookupRecord> buildResultMapper() {
  return (rs, ctx) -> {
    final var apiKeyLookupRecord =
        PlayerApiKeyLookupRecord.builder()
            .apiKeyId(rs.getInt("api_key_id"))
            .userId(rs.getInt("user_id"))
            .playerChatId(Preconditions.checkNotNull(rs.getString("player_chat_id")))
            .role(Preconditions.checkNotNull(rs.getString("user_role")))
            .username(rs.getString("username"))
            .build();

    verifyState(apiKeyLookupRecord);
    return apiKeyLookupRecord;
  };
}
 
示例2
@Override
public Optional<RowMapper<?>> build(Type type, ConfigRegistry configRegistry) {
    if (acceptsPredicate.test(type, configRegistry)) {
        RowMapper<?> rowMapper = cache.get(type);
        if (rowMapper == null) {
            ContextualSourceMapper<ResultSet, ?> resultSetMapper = mapperFactory.newInstance(type);
            rowMapper = toRowMapper(resultSetMapper);
            RowMapper<?> cachedMapper = cache.putIfAbsent(type, rowMapper);
            if (cachedMapper != null) {
                rowMapper = cachedMapper;
            }
        }
        return Optional.of(rowMapper);
    }

    return Optional.empty();
}
 
示例3
/**
 * @see io.apicurio.hub.core.storage.IStorage#lookupEditingSessionUuid(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public long lookupEditingSessionUuid(String uuid, String designId, String userId, String hash)
        throws StorageException {
    logger.debug("Looking up an editing session UUID: {}", uuid);
    long now = System.currentTimeMillis();
    try {
        return this.jdbi.withHandle( handle -> {
            String statement = sqlStatements.selectEditingSessionUuid();
            Long contentVersion = handle.createQuery(statement)
                    .bind(0, uuid)
                    .bind(1, Long.valueOf(designId))
                    .bind(2, hash)
                    .bind(3, now)
                    .map(new RowMapper<Long>() {
                        @Override
                        public Long map(ResultSet rs, StatementContext ctx) throws SQLException {
                            return rs.getLong("version");
                        }
                    })
                    .one();
            return contentVersion;
        });
    } catch (Exception e) {
        throw new StorageException("Error getting Editing Session UUID.", e);
    }
}
 
示例4
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<PlayerAliasRecord> buildResultMapper() {
  return (rs, ctx) ->
      PlayerAliasRecord.builder()
          .username(rs.getString("name"))
          .ip(rs.getString("ip"))
          .systemId(rs.getString("systemId"))
          .date(TimestampMapper.map(rs, "accessTime"))
          .build();
}
 
示例5
public static RowMapper<PlayerBanRecord> buildResultMapper() {
  return (rs, ctx) ->
      PlayerBanRecord.builder()
          .username(rs.getString("name"))
          .ip(rs.getString("ip"))
          .systemId(rs.getString("systemId"))
          .banStart(TimestampMapper.map(rs, "banStart"))
          .banEnd(TimestampMapper.map(rs, "banEnd"))
          .build();
}
 
示例6
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<ModeratorAuditHistoryRecord> buildResultMapper() {
  return (rs, ctx) ->
      ModeratorAuditHistoryRecord.builder()
          .dateCreated(TimestampMapper.map(rs, "date_created"))
          .username(rs.getString("username"))
          .actionName(rs.getString("action_name"))
          .actionTarget(rs.getString("action_target"))
          .build();
}
 
示例7
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<ChatHistoryRecord> buildResultMapper() {
  return (rs, ctx) ->
      ChatHistoryRecord.builder()
          .date(TimestampMapper.map(rs, "date"))
          .username(rs.getString("username"))
          .message(rs.getString("message"))
          .build();
}
 
示例8
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<ModeratorUserDaoData> buildResultMapper() {
  return (rs, ctx) ->
      ModeratorUserDaoData.builder()
          .username(rs.getString("username"))
          .lastLogin(TimestampMapper.map(rs, "access_time"))
          .build();
}
 
示例9
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<UsernameBanRecord> buildResultMapper() {
  return (rs, ctx) ->
      UsernameBanRecord.builder()
          .username(rs.getString("username"))
          .dateCreated(TimestampMapper.map(rs, "date_created"))
          .build();
}
 
示例10
public static RowMapper<PlayerIdentifiersByApiKeyLookup> buildResultMapper() {
  return (rs, ctx) ->
      PlayerIdentifiersByApiKeyLookup.builder()
          .userName(UserName.of(rs.getString("username")))
          .systemId(SystemId.of(rs.getString("system_id")))
          .ip(rs.getString("ip"))
          .build();
}
 
示例11
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<UserRoleLookup> buildResultMapper() {
  return (rs, ctx) -> {
    final UserRoleLookup roleLookup =
        UserRoleLookup.builder()
            .userId(rs.getInt("id"))
            .userRoleId(rs.getInt("user_role_id"))
            .build();
    Postconditions.assertState(roleLookup.userId != 0);
    Postconditions.assertState(roleLookup.userRoleId != 0);
    return roleLookup;
  };
}
 
示例12
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<BanLookupRecord> buildResultMapper() {
  return (rs, ctx) ->
      BanLookupRecord.builder()
          .publicBanId(rs.getString("public_id"))
          .banExpiry(TimestampMapper.map(rs, "ban_expiry"))
          .build();
}
 
示例13
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<UserBanRecord> buildResultMapper() {
  return (rs, ctx) ->
      UserBanRecord.builder()
          .publicBanId(rs.getString("public_id"))
          .username(rs.getString("username"))
          .systemId(rs.getString("system_id"))
          .ip(rs.getString("ip"))
          .dateCreated(TimestampMapper.map(rs, "date_created"))
          .banExpiry(TimestampMapper.map(rs, "ban_expiry"))
          .build();
}
 
示例14
/** Returns a JDBI row mapper used to convert results into an instance of this bean object. */
public static RowMapper<AccessLogRecord> buildResultMapper() {
  return (rs, ctx) ->
      AccessLogRecord.builder()
          .accessTime(TimestampMapper.map(rs, "access_time"))
          .username(rs.getString("username"))
          .ip(rs.getString("ip"))
          .systemId(rs.getString("system_id"))
          .registered(rs.getBoolean("registered"))
          .build();
}
 
示例15
private <T> RowMapper<T> toRowMapper(ContextualSourceMapper<ResultSet, T> resultSetMapper) {
    RowMapper<T> mapper;
    if (resultSetMapper instanceof DynamicJdbcMapper) {
        mapper = new DynamicRowMapper<T>((DynamicJdbcMapper<T>) resultSetMapper);
    } else {
        mapper = new StaticRowMapper<T>(resultSetMapper);
    }
    return mapper;
}
 
示例16
@Override
public Optional<RowMapper<?>> build(Type type, ConfigRegistry config) {
  if (accepts(type, config)) {
    return Optional.of((rs, ctx) -> {
      ObjectMapper objectMapper = ctx.getConfig(RosettaObjectMapper.class).getObjectMapper();
      String tableName = SqlTableNameExtractor.extractTableName(ctx.getParsedSql().getSql());
      final RosettaMapper mapper = new RosettaMapper(type, objectMapper, tableName);

      return mapper.mapRow(rs);
    });
  } else {
    return Optional.empty();
  }
}
 
示例17
@Inject(optional = true)
void setMappers(
  Set<RowMapper<?>> rowMappers,
  Set<ColumnMapper<?>> columnMappers,
  @Singularity ObjectMapper objectMapper
) {
  checkNotNull(rowMappers, "resultSetMappers is null");
  this.rowMappers = ImmutableSet.copyOf(rowMappers);
  this.columnMappers = ImmutableSet.copyOf(columnMappers);
  this.objectMapper = objectMapper;
}
 
示例18
public static RowMapper<PlayerHistoryRecord> buildResultMapper() {
  return (rs, ctx) ->
      PlayerHistoryRecord.builder()
          .registrationDate(TimestampMapper.map(rs, "date_registered").toEpochMilli())
          .build();
}
 
示例19
@Override
public RowMapper<T> specialize(ResultSet rs, StatementContext ctx) throws SQLException {
    return new StaticRowMapper<T>(dynamicMapper.getMapper(rs.getMetaData()));
}
 
示例20
@Override
public void configure() {
  Multibinder<RowMapper<?>> rowMappers = Multibinder.newSetBinder(
    binder(),
    new TypeLiteral<RowMapper<?>>() {}
  );
  rowMappers
    .addBinding()
    .to(SingularityMappers.SingularityRequestHistoryMapper.class)
    .in(Scopes.SINGLETON);
  rowMappers
    .addBinding()
    .to(SingularityMappers.SingularityTaskIdHistoryMapper.class)
    .in(Scopes.SINGLETON);
  rowMappers
    .addBinding()
    .to(SingularityMappers.SingularityDeployHistoryLiteMapper.class)
    .in(Scopes.SINGLETON);
  rowMappers
    .addBinding()
    .to(SingularityMappers.SingularityRequestIdCountMapper.class)
    .in(Scopes.SINGLETON);
  rowMappers
    .addBinding()
    .to(SingularityMappers.SingularityTaskUsageMapper.class)
    .in(Scopes.SINGLETON);
  rowMappers
    .addBinding()
    .to(SingularityMappers.SingularityRequestWithTimeMapper.class)
    .in(Scopes.SINGLETON);

  Multibinder<ColumnMapper<?>> columnMappers = Multibinder.newSetBinder(
    binder(),
    new TypeLiteral<ColumnMapper<?>>() {}
  );
  columnMappers
    .addBinding()
    .to(SingularityMappers.SingularityBytesMapper.class)
    .in(Scopes.SINGLETON);
  columnMappers.addBinding().to(SingularityIdMapper.class).in(Scopes.SINGLETON);
  columnMappers.addBinding().to(SingularityJsonStringMapper.class).in(Scopes.SINGLETON);
  columnMappers
    .addBinding()
    .to(SingularityMappers.DateMapper.class)
    .in(Scopes.SINGLETON);
  columnMappers
    .addBinding()
    .to(SingularityMappers.SingularityTimestampMapper.class)
    .in(Scopes.SINGLETON);

  bind(TaskHistoryHelper.class).in(Scopes.SINGLETON);
  bind(RequestHistoryHelper.class).in(Scopes.SINGLETON);
  bind(DeployHistoryHelper.class).in(Scopes.SINGLETON);
  bind(DeployTaskHistoryHelper.class).in(Scopes.SINGLETON);
  bind(SingularityRequestHistoryPersister.class).in(Scopes.SINGLETON);
  bind(SingularityDeployHistoryPersister.class).in(Scopes.SINGLETON);
  bind(SingularityTaskHistoryPersister.class).in(Scopes.SINGLETON);
}