"organization.trade.obligor_standard_and_poors_credit_rating");
final long docId = nextId("org_organisation_seq");
final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId);
final UniqueId organizationUid = createUniqueId(docOid, docId);
final ManageableOrganization organization = document.getOrganization();
// the arguments for inserting into the organization table
final DbMapSqlParameterSource docArgs = new DbMapSqlParameterSource()
.addValue("doc_id", docId)
.addValue("doc_oid", docOid)
.addTimestamp("ver_from_instant", document.getVersionFromInstant())
.addTimestampNullFuture("ver_to_instant", document.getVersionToInstant())
.addTimestamp("corr_from_instant", document.getCorrectionFromInstant())
.addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant())
.addValue("provider_scheme",
document.getProviderId() != null ? document.getProviderId().getScheme().getName() : null,
Types.VARCHAR)
.addValue("provider_value",
document.getProviderId() != null ? document.getProviderId().getValue() : null,
Types.VARCHAR)
.addValue("obligor_short_name", organization.getObligor().getObligorShortName(), Types.VARCHAR)
.addValue("obligor_red_code", organization.getObligor().getObligorREDCode(), Types.VARCHAR)
.addValue("obligor_ticker", organization.getObligor().getObligorTicker(), Types.VARCHAR)
.addValue("obligor_composite_rating", organization.getObligor().getCompositeRating().name(), Types.VARCHAR)
.addValue("obligor_country", organization.getObligor().getCountry(), Types.VARCHAR)
.addValue("obligor_fitch_credit_rating", organization.getObligor().getFitchCreditRating().name(), Types.VARCHAR)
.addValue("obligor_implied_rating", organization.getObligor().getImpliedRating().name(), Types.VARCHAR)
.addValue("obligor_moodys_credit_rating",
organization.getObligor().getMoodysCreditRating().name(),
Types.VARCHAR)
.addValue("obligor_region", organization.getObligor().getRegion().name(), Types.VARCHAR)
.addValue("obligor_sector", organization.getObligor().getSector().name(), Types.VARCHAR)
.addValue("obligor_standard_and_poors_credit_rating",
organization.getObligor().getStandardAndPoorsCreditRating().name(),
Types.VARCHAR)
.addValue("obligor_has_defaulted",
organization.getObligor().isHasDefaulted() ? 1 : 0,
Types.TINYINT);
final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs);
getJdbcTemplate().update(sqlDoc, docArgs);
// set the uniqueId
organization.setUniqueId(organizationUid);
document.setUniqueId(organizationUid);
return document;
}