Examples of DbMapSqlParameterSource


Examples of com.opengamma.util.db.DbMapSqlParameterSource

        ExternalIdSearch.canMatch(exchangeSearch) == false) {
      result.setPaging(Paging.of(request.getPagingRequest(), 0));
      return result;
    }
   
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addTimestamp("version_as_of_instant", vc.getVersionAsOf())
      .addTimestamp("corrected_to_instant", vc.getCorrectedTo())
      .addValueNullIgnored("name", getDialect().sqlWildcardAdjustValue(request.getName()))
      .addValueNullIgnored("hol_type", request.getType() != null ? request.getType().name() : null)
      .addValueNullIgnored("currency_iso", currencyISO);
    if (request.getProviderId() != null) {
      args.addValue("provider_scheme", request.getProviderId().getScheme().getName());
      args.addValue("provider_value", request.getProviderId().getValue());
    }
    if (regionSearch != null) {
      if (regionSearch.getSearchType() != ExternalIdSearchType.ANY) {
        throw new IllegalArgumentException("Unsupported search type: " + regionSearch.getSearchType());
      }
      int i = 0;
      for (ExternalId idKey : regionSearch.getExternalIds()) {
        args.addValue("region_scheme" + i, idKey.getScheme().getName());
        args.addValue("region_value" + i, idKey.getValue());
        i++;
      }
      args.addValue("sql_search_region_ids", sqlSelectIdKeys(request.getRegionExternalIdSearch(), "region"));
    }
    if (exchangeSearch != null) {
      if (exchangeSearch.getSearchType() != ExternalIdSearchType.ANY) {
        throw new IllegalArgumentException("Unsupported search type: " + exchangeSearch.getSearchType());
      }
      int i = 0;
      for (ExternalId idKey : exchangeSearch.getExternalIds()) {
        args.addValue("exchange_scheme" + i, idKey.getScheme().getName());
        args.addValue("exchange_value" + i, idKey.getValue());
        i++;
      }
      args.addValue("sql_search_exchange_ids", sqlSelectIdKeys(request.getExchangeExternalIdSearch(), "exchange"));
    }
    if (request.getHolidayObjectIds() != null) {
      StringBuilder buf = new StringBuilder(request.getHolidayObjectIds().size() * 10);
      for (ObjectId objectId : request.getHolidayObjectIds()) {
        checkScheme(objectId);
        buf.append(extractOid(objectId)).append(", ");
      }
      buf.setLength(buf.length() - 2);
      args.addValue("sql_search_object_ids", buf.toString());
    }
    args.addValue("sort_order", ORDER_BY_MAP.get(request.getSortOrder()));
    args.addValue("paging_offset", request.getPagingRequest().getFirstItem());
    args.addValue("paging_fetch", request.getPagingRequest().getPagingSize());
   
    final String[] sql = {getElSqlBundle().getSql("Search", args), getElSqlBundle().getSql("SearchCount", args)};
    doSearch(request.getPagingRequest(), sql, args, new HolidayDocumentExtractor(), result);
    return result;
  }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    _timeSource = timeSource;
  }

  //-------------------------------------------------------------------------
  public int getSchemaVersion() {
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource().addValue("version_key", "schema_patch");
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetSchemaVersion", args);
    String version = namedJdbc.queryForObject(sql, args, String.class);
    return Integer.parseInt(version);
  }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

  public FunctionCostsDocument load(final String configuration, final String functionId, Instant versionAsOf) {
    s_logger.debug("load: {} {}", configuration, functionId);
    if (versionAsOf == null) {
      versionAsOf = Instant.now(getClock());
    }
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("configuration", configuration.trim())
      .addValue("function", functionId.trim())
      .addTimestamp("version_instant", versionAsOf)
      .addValue("paging_offset", 0)
      .addValue("paging_fetch", 1);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    ArgumentChecker.notNull(costs, "costs");
    ArgumentChecker.notNull(costs.getConfigurationName(), "costs.configurationName");
    ArgumentChecker.notNull(costs.getFunctionId(), "costs.functionId");
    costs.setVersion(Instant.now(getClock()));
   
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("configuration", costs.getConfigurationName().trim())
      .addValue("function", costs.getFunctionId().trim())
      .addTimestamp("version_instant", costs.getVersion())
      .addValue("invocation_cost", costs.getInvocationCost())
      .addValue("data_input_cost", costs.getDataInputCost())
      .addValue("data_output_cost", costs.getDataOutputCost());
    final String sql = getElSqlBundle().getSql("InsertCosts", args);
    getDbConnector().getJdbcTemplate().update(sql, args);
   
    // delete older data
    final DbMapSqlParameterSource deleteArgs = new DbMapSqlParameterSource()
      .addValue("configuration", costs.getConfigurationName().trim())
      .addValue("function", costs.getFunctionId().trim())
      .addValue("offset_zero", 0)
      .addValue("keep_rows", 20);
    final String deleteSql = getElSqlBundle().getSql("DeleteOld", deleteArgs);
View Full Code Here

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()
      .addTimestamp("version_as_of_instant", vc.getVersionAsOf())
      .addTimestamp("corrected_to_instant", vc.getCorrectedTo())
      .addValueNullIgnored("name", getDialect().sqlWildcardAdjustValue(request.getName()));
    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("sort_order", ORDER_BY_MAP.get(request.getSortOrder()));
    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 ExchangeDocumentExtractor(), result);
    return result;
  }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    exchange.setUniqueId(uniqueId);
    document.setUniqueId(uniqueId);
    // the arguments for inserting into the exchange table
    FudgeMsgEnvelope env = FUDGE_CONTEXT.toFudgeMsg(exchange);
    byte[] bytes = FUDGE_CONTEXT.toByteArray(env.getMessage());
    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", document.getName())
      .addValue("time_zone", exchange.getTimeZone() != null ? exchange.getTimeZone().getId() : null, Types.VARCHAR)
      .addValue("detail", new SqlLobValue(bytes, getDialect().getLobHandler()), Types.BLOB);
    // 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 (ExternalId id : exchange.getExternalIdBundle()) {
      final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource()
        .addValue("doc_id", docId)
        .addValue("key_scheme", id.getScheme().getName())
        .addValue("key_value", id.getValue());
      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("exg_idkey_seq");
        final DbMapSqlParameterSource idkeyArgs = new DbMapSqlParameterSource()
          .addValue("idkey_id", idKeyId)
          .addValue("key_scheme", id.getScheme().getName())
          .addValue("key_value", id.getValue());
        idKeyList.add(idkeyArgs);
      }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

        (ExternalIdSearch.canMatch(securityIdSearch) == false)) {
      result.setPaging(Paging.of(request.getPagingRequest(), 0));
      return result;
    }

    final DbMapSqlParameterSource args = new DbMapSqlParameterSource().addTimestamp("version_as_of_instant", vc.getVersionAsOf()).addTimestamp("corrected_to_instant", vc.getCorrectedTo())
        .addValueNullIgnored("min_quantity", request.getMinQuantity()).addValueNullIgnored("max_quantity", request.getMaxQuantity())
        .addValueNullIgnored("security_id_value", getDialect().sqlWildcardAdjustValue(request.getSecurityIdValue()));
    if (request.getPositionProviderId() != null) {
      args.addValue("pos_provider_scheme", request.getPositionProviderId().getScheme().getName());
      args.addValue("pos_provider_value", request.getPositionProviderId().getValue());
    }
    if (request.getTradeProviderId() != null) {
      args.addValue("trade_provider_scheme", request.getTradeProviderId().getScheme().getName());
      args.addValue("trade_provider_value", request.getTradeProviderId().getValue());
    }
    if (securityIdSearch != null && securityIdSearch.alwaysMatches() == false) {
      int i = 0;
      for (final ExternalId id : securityIdSearch) {
        args.addValue("key_scheme" + i, id.getScheme().getName());
        args.addValue("key_value" + i, id.getValue());
        i++;
      }
      args.addValue("sql_search_security_ids_type", securityIdSearch.getSearchType());
      args.addValue("sql_search_security_ids", sqlSelectIdKeys(securityIdSearch));
      args.addValue("security_id_search_size", securityIdSearch.getExternalIds().size());
    }
    if (positionObjectIds != null) {
      final StringBuilder buf = new StringBuilder(positionObjectIds.size() * 10);
      for (final ObjectId objectId : positionObjectIds) {
        checkScheme(objectId);
        buf.append(extractOid(objectId)).append(", ");
      }
      buf.setLength(buf.length() - 2);
      args.addValue("sql_search_position_ids", buf.toString());
    }
    if (tradeObjectIds != null) {
      final StringBuilder buf = new StringBuilder(tradeObjectIds.size() * 10);
      for (final ObjectId objectId : tradeObjectIds) {
        checkScheme(objectId);
        buf.append(extractOid(objectId)).append(", ");
      }
      buf.setLength(buf.length() - 2);
      args.addValue("sql_search_trade_ids", buf.toString());
    }
    args.addValue("paging_offset", request.getPagingRequest().getFirstItem());
    args.addValue("paging_fetch", request.getPagingRequest().getPagingSize());

    final String[] sql = {getElSqlBundle().getSql("Search", args), getElSqlBundle().getSql("SearchCount", args) };
    doSearch(request.getPagingRequest(), sql, args, new PositionDocumentExtractor(), result);
    return result;
  }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

      final long positionOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : positionId);
      final UniqueId positionUid = createUniqueId(positionOid, positionId);
      final ManageablePosition position = document.getPosition();
     
      // the arguments for inserting into the position table
      final DbMapSqlParameterSource docArgs = new DbMapSqlParameterSource().addValue("position_id", positionId).addValue("position_oid", positionOid)
          .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("quantity", position.getQuantity(), Types.DECIMAL)
          .addValue("provider_scheme",
              position.getProviderId() != null ? position.getProviderId().getScheme().getName() : null, Types.VARCHAR)
          .addValue("provider_value",
              position.getProviderId() != null ? position.getProviderId().getValue() : null, Types.VARCHAR);
     
      // the arguments for inserting into the pos_attribute table
      final List<DbMapSqlParameterSource> posAttrList = Lists.newArrayList();
      for (final Entry<String, String> entry : position.getAttributes().entrySet()) {
        final long posAttrId = nextId("pos_trade_attr_seq");
        final DbMapSqlParameterSource posAttrArgs = new DbMapSqlParameterSource().addValue("attr_id", posAttrId)
            .addValue("pos_id", positionId)
            .addValue("pos_oid", positionOid)
            .addValue("key", entry.getKey())
            .addValue("value", entry.getValue());
        posAttrList.add(posAttrArgs);
      }
     
      // the arguments for inserting into the idkey tables
      final List<DbMapSqlParameterSource> posAssocList = new ArrayList<DbMapSqlParameterSource>();
      final Set<Pair<String, String>> schemeValueSet = Sets.newHashSet();
      for (final ExternalId id : position.getSecurityLink().getAllExternalIds()) {
        final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource().addValue("position_id", positionId)
            .addValue("key_scheme", id.getScheme().getName())
            .addValue("key_value", id.getValue());
        posAssocList.add(assocArgs);
        schemeValueSet.add(Pair.of(id.getScheme().getName(), id.getValue()));
      }
     
      // the arguments for inserting into the trade table
      final List<DbMapSqlParameterSource> tradeList = Lists.newArrayList();
      final List<DbMapSqlParameterSource> tradeAssocList = Lists.newArrayList();
      final List<DbMapSqlParameterSource> tradeAttributeList = Lists.newArrayList();
      for (final ManageableTrade trade : position.getTrades()) {
        final long tradeId = nextId("pos_master_seq");
        final long tradeOid = (trade.getUniqueId() != null ? extractOid(trade.getUniqueId()) : tradeId);
        final ExternalId counterpartyId = trade.getCounterpartyExternalId();
       
        final DbMapSqlParameterSource tradeArgs = new DbMapSqlParameterSource().addValue("trade_id", tradeId)
            .addValue("trade_oid", tradeOid)
            .addValue("position_id", positionId)
            .addValue("position_oid", positionOid)
            .addValue("quantity", trade.getQuantity())
            .addDate("trade_date", trade.getTradeDate())
            .addTimeAllowNull("trade_time", trade.getTradeTime() != null ? trade.getTradeTime().toLocalTime() : null)
            .addValue("zone_offset",
                trade.getTradeTime() != null ? trade.getTradeTime().getOffset().getTotalSeconds() : null, Types.INTEGER)
            .addValue("cparty_scheme", counterpartyId.getScheme().getName())
            .addValue("cparty_value", counterpartyId.getValue())
            .addValue("provider_scheme",
                position.getProviderId() != null ? position.getProviderId().getScheme().getName() : null, Types.VARCHAR)
            .addValue("provider_value",
                position.getProviderId() != null ? position.getProviderId().getValue() : null, Types.VARCHAR)
            .addValue("premium_value", trade.getPremium(), Types.DOUBLE)
            .addValue("premium_currency",
                trade.getPremiumCurrency() != null ? trade.getPremiumCurrency().getCode() : null, Types.VARCHAR)
            .addDateAllowNull("premium_date", trade.getPremiumDate())
            .addTimeAllowNull("premium_time", (trade.getPremiumTime() != null ? trade.getPremiumTime().toLocalTime() : null))
            .addValue("premium_zone_offset",
                trade.getPremiumTime() != null ? trade.getPremiumTime().getOffset().getTotalSeconds() : null, Types.INTEGER);
        tradeList.add(tradeArgs);
       
        // trade attributes
        final Map<String, String> attributes = new HashMap<String, String>(trade.getAttributes());
        for (final Entry<String, String> entry : attributes.entrySet()) {
          final long tradeAttrId = nextId("pos_trade_attr_seq");
          final DbMapSqlParameterSource tradeAttributeArgs = new DbMapSqlParameterSource().addValue("attr_id", tradeAttrId)
              .addValue("trade_id", tradeId)
              .addValue("trade_oid", tradeOid)
              .addValue("key", entry.getKey())
              .addValue("value", entry.getValue());
          tradeAttributeList.add(tradeAttributeArgs);
        }
       
        // set the trade uniqueId
        final UniqueId tradeUid = createUniqueId(tradeOid, tradeId);
        IdUtils.setInto(trade, tradeUid);
        trade.setParentPositionId(positionUid);
        for (final ExternalId id : trade.getSecurityLink().getAllExternalIds()) {
          final DbMapSqlParameterSource assocArgs = new DbMapSqlParameterSource().addValue("trade_id", tradeId)
              .addValue("key_scheme", id.getScheme().getName())
              .addValue("key_value", id.getValue());
          tradeAssocList.add(assocArgs);
          schemeValueSet.add(Pair.of(id.getScheme().getName(), id.getValue()));
        }
      }
     
      final List<DbMapSqlParameterSource> idKeyList = new ArrayList<DbMapSqlParameterSource>();
      final String sqlSelectIdKey = getElSqlBundle().getSql("SelectIdKey");
      for (final Pair<String, String> pair : schemeValueSet) {
        final DbMapSqlParameterSource idkeyArgs = new DbMapSqlParameterSource().addValue("key_scheme", pair.getFirst())
            .addValue("key_value", pair.getSecond());
        if (getJdbcTemplate().queryForList(sqlSelectIdKey, idkeyArgs).isEmpty()) {
          // select avoids creating unecessary id, but id may still not be used
          final long idKeyId = nextId("pos_idkey_seq");
          idkeyArgs.addValue("idkey_id", idKeyId);
          idKeyList.add(idkeyArgs);
        }
      }
     
      final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   * @return the trade, null if not found
   */
  protected ManageableTrade getTradeByInstants(final UniqueId uniqueId, final Instant versionAsOf, final Instant correctedTo) {
    s_logger.debug("getTradeByLatest {}", uniqueId);
    final Instant now = now();
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource().addValue("trade_oid", extractOid(uniqueId))
        .addTimestamp("version_as_of_instant", Objects.firstNonNull(versionAsOf, now))
        .addTimestamp("corrected_to_instant", Objects.firstNonNull(correctedTo, now));
    final PositionDocumentExtractor extractor = new PositionDocumentExtractor();
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetTradeByOidInstants", args);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   * @param uniqueId the unique identifier, not null
   * @return the trade, null if not found
   */
  protected ManageableTrade getTradeById(final UniqueId uniqueId) {
    s_logger.debug("getTradeById {}", uniqueId);
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource().addValue("trade_id", extractRowId(uniqueId));
    final PositionDocumentExtractor extractor = new PositionDocumentExtractor();
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetTradeById", args);
    final List<PositionDocument> docs = namedJdbc.query(sql, args, extractor);
    if (docs.isEmpty()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.