Package com.opengamma.util.db

Examples of com.opengamma.util.db.DbMapSqlParameterSource


      (ExternalIdSearch.canMatch(externalIdSearch) == false)) {
      result.setPaging(Paging.of(request.getPagingRequest(), 0));
      return result;
    }
   
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource();
    args.addTimestamp("version_as_of_instant", vc.getVersionAsOf());
    args.addTimestamp("corrected_to_instant", vc.getCorrectedTo());
    args.addValueNullIgnored("name", getDialect().sqlWildcardAdjustValue(request.getName()));
    args.addValueNullIgnored("data_field", getDialect().sqlWildcardAdjustValue(request.getDataField()));
    args.addValueNullIgnored("data_source", getDialect().sqlWildcardAdjustValue(request.getDataSource()));
    args.addValueNullIgnored("data_provider", getDialect().sqlWildcardAdjustValue(request.getDataProvider()));
    args.addValueNullIgnored("observation_time", getDialect().sqlWildcardAdjustValue(request.getObservationTime()));
    args.addDateNullIgnored("id_validity_date", request.getValidityDate());
    args.addValueNullIgnored("external_id_value", getDialect().sqlWildcardAdjustValue(request.getExternalIdValue()));
    if (externalIdSearch != null) {
      int i = 0;
      for (ExternalId id : externalIdSearch) {
        args.addValue("key_scheme" + i, id.getScheme().getName());
        args.addValue("key_value" + i, id.getValue());
        i++;
      }
    }
    if (externalIdSearch != null && externalIdSearch.alwaysMatches() == false) {
      int i = 0;
      for (ExternalId id : externalIdSearch) {
        args.addValue("key_scheme" + i, id.getScheme().getName());
        args.addValue("key_value" + i, id.getValue());
        i++;
      }
      args.addValue("sql_search_external_ids_type", externalIdSearch.getSearchType());
      args.addValue("sql_search_external_ids", sqlSelectIdKeys(externalIdSearch));
      args.addValue("id_search_size", externalIdSearch.getExternalIds().size());
    }
    if (objectIds != null) {
      StringBuilder buf = new StringBuilder(objectIds.size() * 10);
      for (ObjectId objectId : objectIds) {
        checkScheme(objectId);
        buf.append(extractOid(objectId)).append(", ");
      }
      buf.setLength(buf.length() - 2);
      args.addValue("sql_search_object_ids", buf.toString());
    }
    args.addValue("paging_offset", request.getPagingRequest().getFirstItem());
    args.addValue("paging_fetch", request.getPagingRequest().getPagingSize());
    String[] sql = {getElSqlBundle().getSql("Search", args), getElSqlBundle().getSql("SearchCount", args)};
    doSearch(request.getPagingRequest(), sql, args, new HistoricalTimeSeriesDocumentExtractor(), result);
    return result;
  }
View Full Code Here


    try (Timer.Context context = _insertTimer.time()) {
      final long docId = nextId("hts_master_seq");
      final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId);
      // the arguments for inserting into the table
      final ManageableHistoricalTimeSeriesInfo info = document.getInfo();
      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("name_id", getNameTable().ensure(info.getName()))
        .addValue("data_field_id", getDataFieldTable().ensure(info.getDataField()))
        .addValue("data_source_id", getDataSourceTable().ensure(info.getDataSource()))
        .addValue("data_provider_id", getDataProviderTable().ensure(info.getDataProvider()))
        .addValue("observation_time_id", getObservationTimeTable().ensure(info.getObservationTime()));
      // the arguments for inserting into the idkey tables
      final List<DbMapSqlParameterSource> assocList = new ArrayList<DbMapSqlParameterSource>();
      final List<DbMapSqlParameterSource> idKeyList = new ArrayList<DbMapSqlParameterSource>();
      final String sqlSelectIdKey = getElSqlBundle().getSql("SelectIdKey");
      for (ExternalIdWithDates id : info.getExternalIdBundle()) {
        final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource()
          .addValue("doc_id", docId)
          .addValue("key_scheme", id.getExternalId().getScheme().getName())
          .addValue("key_value", id.getExternalId().getValue())
          .addValue("valid_from", DbDateUtils.toSqlDateNullFarPast(id.getValidFrom()))
          .addValue("valid_to", DbDateUtils.toSqlDateNullFarFuture(id.getValidTo()));
        assocList.add(assocArgs);
        if (getJdbcTemplate().queryForList(sqlSelectIdKey, assocArgs).isEmpty()) {
          // select avoids creating unecessary id, but id may still not be used
          final long idKeyId = nextId("hts_idkey_seq");
          final DbMapSqlParameterSource idkeyArgs = new DbMapSqlParameterSource()
            .addValue("idkey_id", idKeyId)
            .addValue("key_scheme", id.getExternalId().getScheme().getName())
            .addValue("key_value", id.getExternalId().getValue());
          idKeyList.add(idkeyArgs);
        }
View Full Code Here

    s_logger.debug("getByOidInstants {}", objectId);

    Timer.Context context = _getByOidInstantsTimer.time();
    try {
      final VersionCorrection vc = (versionCorrection.containsLatest() ? versionCorrection.withLatestFixed(now()) : versionCorrection);
      final DbMapSqlParameterSource args = argsGetByOidInstants(objectId, vc);
      final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
      final String sql = getElSqlBundle().getSql("GetByOidInstants", args);
      final List<D> docs = namedJdbc.query(sql, args, extractor);
      if (docs.isEmpty()) {
        throw new DataNotFoundException(masterName + " not found: " + objectId);
View Full Code Here

   * @param versionCorrection  the version-correction locator with instants fixed, not null
   * @return the SQL arguments, not null
   */
  protected DbMapSqlParameterSource argsGetByOidInstants(final ObjectIdentifiable objectId, final VersionCorrection versionCorrection) {
    final long docOid = extractOid(objectId);
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("doc_oid", docOid)
      .addTimestamp("version_as_of", versionCorrection.getVersionAsOf())
      .addTimestamp("corrected_to", versionCorrection.getCorrectedTo());
    return args;
  }
View Full Code Here

    ArgumentChecker.notNull(extractor, "extractor");
    s_logger.debug("getById {}", uniqueId);

    Timer.Context context = _getByIdTimer.time();
    try {
      final DbMapSqlParameterSource args = argsGetById(uniqueId);
      final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
      final String sql = getElSqlBundle().getSql("GetById", args);
      final List<D> docs = namedJdbc.query(sql, args, extractor);
      if (docs.isEmpty()) {
        throw new DataNotFoundException(masterName + " not found: " + uniqueId);
View Full Code Here

   *
   * @param uniqueId  the versioned unique identifier, not null
   * @return the SQL arguments, not null
   */
  protected DbMapSqlParameterSource argsGetById(final UniqueId uniqueId) {
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("doc_oid", extractOid(uniqueId))
      .addValue("doc_id", extractRowId(uniqueId));
    return args;
  }
View Full Code Here

    checkScheme(request.getObjectId());
    s_logger.debug("history {}", request);
   
    Timer.Context context = _historyTimer.time();
    try {
      final DbMapSqlParameterSource args = argsHistory(request);
      final String[] sql = {getElSqlBundle().getSql("History", args), getElSqlBundle().getSql("HistoryCount", args)};
      searchWithPaging(request.getPagingRequest(), sql, args, extractor, result);
      return result;
    } finally {
      context.stop();
View Full Code Here

   *
   * @param request  the request, not null
   * @return the SQL arguments, not null
   */
  protected DbMapSqlParameterSource argsHistory(final AbstractHistoryRequest request) {
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("doc_oid", extractOid(request.getObjectId()))
      .addTimestampNullIgnored("versions_from_instant", request.getVersionsFromInstant())
      .addTimestampNullIgnored("versions_to_instant", request.getVersionsToInstant())
      .addTimestampNullIgnored("corrections_from_instant", request.getCorrectionsFromInstant())
      .addTimestampNullIgnored("corrections_to_instant", request.getCorrectionsToInstant());
    if (request.getVersionsFromInstant() != null && request.getVersionsFromInstant().equals(request.getVersionsToInstant())) {
      args.addValue("sql_history_versions", "Point");
    } else {
      args.addValue("sql_history_versions", "Range");
    }
    if (request.getCorrectionsFromInstant() != null && request.getCorrectionsFromInstant().equals(request.getCorrectionsToInstant())) {
      args.addValue("sql_history_corrections", "Point");
    } else {
      args.addValue("sql_history_corrections", "Range");
    }
    args.addValue("paging_offset", request.getPagingRequest().getFirstItem());
    args.addValue("paging_fetch", request.getPagingRequest().getPagingSize());
    return args;
  }
View Full Code Here

   * Updates the document row to mark the version as ended.
   *
   * @param document  the document to update, not null
   */
  protected void updateVersionToInstant(final D document) {
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("doc_id", extractRowId(document.getUniqueId()))
      .addTimestamp("ver_to_instant", document.getVersionToInstant())
      .addValue("max_instant", DbDateUtils.MAX_SQL_TIMESTAMP);
    final String sql = getElSqlBundle().getSql("UpdateVersionToInstant", args);
    final int rowsUpdated = getJdbcTemplate().update(sql, args);
View Full Code Here

   * Updates the document row to mark the correction as ended.
   *
   * @param document  the document to update, not null
   */
  protected void updateCorrectionToInstant(final AbstractDocument document) {
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("doc_id", extractRowId(document.getUniqueId()))
      .addTimestamp("corr_to_instant", document.getCorrectionToInstant())
      .addValue("max_instant", DbDateUtils.MAX_SQL_TIMESTAMP);
    final String sql = getElSqlBundle().getSql("UpdateCorrectionToInstant", args);
    final int rowsUpdated = getJdbcTemplate().update(sql, args);
View Full Code Here

TOP

Related Classes of com.opengamma.util.db.DbMapSqlParameterSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.