private void buildTrade(final ResultSet rs, final long tradeId) throws SQLException {
_lastTradeId = tradeId;
final long tradeOid = rs.getLong("TRADE_OID");
final BigDecimal tradeQuantity = extractBigDecimal(rs, "TRADE_QUANTITY");
final LocalDate tradeDate = DbDateUtils.fromSqlDate(rs.getDate("TRADE_DATE"));
final LocalTime tradeTime = rs.getTimestamp("TRADE_TIME") != null ? DbDateUtils.fromSqlTime(rs.getTimestamp("TRADE_TIME")) : null;
final int zoneOffset = rs.getInt("ZONE_OFFSET");
final String cpartyScheme = rs.getString("CPARTY_SCHEME");
final String cpartyValue = rs.getString("CPARTY_VALUE");
final String providerScheme = rs.getString("TRADE_PROVIDER_SCHEME");
final String providerValue = rs.getString("TRADE_PROVIDER_VALUE");
OffsetTime tradeOffsetTime = null;
if (tradeTime != null) {
tradeOffsetTime = OffsetTime.of(tradeTime, ZoneOffset.ofTotalSeconds(zoneOffset));
}
ExternalId counterpartyId = null;
if (cpartyScheme != null && cpartyValue != null) {
counterpartyId = ExternalId.of(cpartyScheme, cpartyValue);
}
_trade = new ManageableTrade(tradeQuantity, ExternalIdBundle.EMPTY, tradeDate, tradeOffsetTime, counterpartyId);
_trade.setUniqueId(createUniqueId(tradeOid, tradeId));
if (providerScheme != null && providerValue != null) {
_trade.setProviderId(ExternalId.of(providerScheme, providerValue));
}
//set premium
final Object premiumValue = rs.getObject("PREMIUM_VALUE");
if (premiumValue != null) {
_trade.setPremium((Double) premiumValue);
}
final String currencyCode = rs.getString("PREMIUM_CURRENCY");
if (currencyCode != null) {
_trade.setPremiumCurrency(Currency.of(currencyCode));
}
final Date premiumDate = rs.getDate("PREMIUM_DATE");
if (premiumDate != null) {
_trade.setPremiumDate(DbDateUtils.fromSqlDate(premiumDate));
}
_trade.setParentPositionId(_position.getUniqueId());
final LocalTime premiumTime = rs.getTimestamp("PREMIUM_TIME") != null ? DbDateUtils.fromSqlTime(rs.getTimestamp("PREMIUM_TIME")) : null;
final int premiumZoneOffset = rs.getInt("PREMIUM_ZONE_OFFSET");
if (premiumTime != null) {
_trade.setPremiumTime(OffsetTime.of(premiumTime, ZoneOffset.ofTotalSeconds(premiumZoneOffset)));
}
_position.getTrades().add(_trade);