Package com.opengamma.util.db

Examples of com.opengamma.util.db.DbMapSqlParameterSource


    List<DbMapSqlParameterSource> updates = newArrayList();

    for (ComputationTargetSpecification target : targets) {
      Long computationTargetId = _computationTargets.get(target);

      DbMapSqlParameterSource params = new DbMapSqlParameterSource();

      // this assumes that _searchKey2StatusEntry has already been populated
      // in getStatus()
      Pair<Long, Long> key = Pair.of(calcConfId, computationTargetId);
      StatusEntry statusEntry = statusCache.get(key);
      if (statusEntry != null) {
        statusEntry.setStatus(status);
        params.addValue("id", statusEntry.getId());
        params.addValue("run_id", runId);
        params.addValue("status", statusEntry.getStatus().ordinal());
        updates.add(params);
      } else {
        final long statusId = nextId(RSK_SEQUENCE_NAME);

        final DbMapSqlParameterSource insertArgs = new DbMapSqlParameterSource();
        insertArgs.addValue("ID", statusId);
        statusEntry = new StatusEntry();
        statusEntry.setId(statusId);
        statusEntry.setRunId(runId);
        statusEntry.setStatus(status);
        statusEntry.setCalculationConfigurationId(calcConfId);
View Full Code Here


    if (snapshotIds != null && snapshotIds.size() == 0) {
      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.addValue("details", request.isIncludeData());
    if (snapshotIds != null) {
      StringBuilder buf = new StringBuilder(snapshotIds.size() * 10);
      for (ObjectId snapshotId : snapshotIds) {
        checkScheme(snapshotId);
        buf.append(extractOid(snapshotId)).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 MarketDataSnapshotDocumentExtractor(request.isIncludeData()), result);
    return result;
  }
View Full Code Here

    return doHistory(request, new MarketDataSnapshotHistoryResult(), new MarketDataSnapshotDocumentExtractor(request.isIncludeData()));
  }

  @Override
  protected DbMapSqlParameterSource argsHistory(AbstractHistoryRequest request) {
    DbMapSqlParameterSource args = super.argsHistory(request);
    args.addValue("details", ((MarketDataSnapshotHistoryRequest) request).isIncludeData());
    return args;
  }
View Full Code Here

    document.setUniqueId(uniqueId);
   
    // the arguments for inserting into the marketDataSnaphshot table
    FudgeMsgEnvelope env = FUDGE_CONTEXT.toFudgeMsg(marketDataSnaphshot);
    byte[] bytes = FUDGE_CONTEXT.toByteArray(env.getMessage());
    final DbMapSqlParameterSource marketDataSnaphshotArgs = 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())
View Full Code Here

        (nodeObjectIds != null && nodeObjectIds.size() == 0)) {
      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 (request.getDepth() >= 0) {
      args.addValue("depth", request.getDepth());
    }
    if (portfolioObjectIds != null) {
      StringBuilder buf = new StringBuilder(portfolioObjectIds.size() * 10);
      for (ObjectId objectId : portfolioObjectIds) {
        checkScheme(objectId);
        buf.append(extractOid(objectId)).append(", ");
      }
      buf.setLength(buf.length() - 2);
      args.addValue("sql_search_portfolio_ids", buf.toString());
    }
    if (nodeObjectIds != null) {
      StringBuilder buf = new StringBuilder(nodeObjectIds.size() * 10);
      for (ObjectId objectId : nodeObjectIds) {
        checkScheme(objectId);
        buf.append(extractOid(objectId)).append(", ");
      }
      buf.setLength(buf.length() - 2);
      args.addValue("sql_search_node_ids", buf.toString());
    }
    args.addValue("visibility", request.getVisibility().getVisibilityLevel());
    args.addValue("sort_order", ORDER_BY_MAP.get(request.getSortOrder()));
    args.addValue("paging_offset", request.getPagingRequest().getFirstItem());
    args.addValue("paging_fetch", request.getPagingRequest().getPagingSize());

    if (request.isIncludePositions()) {
      String[] sql = {getElSqlBundle().getSql("Search", args), getElSqlBundle().getSql("SearchCount", args) };
      doSearch(request.getPagingRequest(), sql, args, new PortfolioDocumentExtractor(true, true), result);
    } else {
View Full Code Here

    return doHistory(request, new PortfolioHistoryResult(), new PortfolioDocumentExtractor(true, true));
  }

  @Override
  protected DbMapSqlParameterSource argsHistory(AbstractHistoryRequest request) {
    DbMapSqlParameterSource args = super.argsHistory(request);
    int depth = ((PortfolioHistoryRequest) request).getDepth();
    if (depth >= 0) {
      args.addValue("depth", depth);
    }
    return args;
  }
View Full Code Here

    final Long portfolioId = nextId("prt_master_seq");
    final Long portfolioOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : portfolioId);
    final UniqueId portfolioUid = createUniqueId(portfolioOid, portfolioId);

    // the arguments for inserting into the portfolio table
    final DbMapSqlParameterSource docArgs = new DbMapSqlParameterSource()
        .addValue("portfolio_id", portfolioId)
        .addValue("portfolio_oid", portfolioOid)
        .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", StringUtils.defaultString(document.getPortfolio().getName()))
        .addValue("visibility", document.getVisibility().getVisibilityLevel());

    // the arguments for inserting into the node table
    final List<DbMapSqlParameterSource> nodeList = new ArrayList<DbMapSqlParameterSource>(256);
    final List<DbMapSqlParameterSource> posList = new ArrayList<DbMapSqlParameterSource>(256);
    insertBuildArgs(portfolioUid, null, document.getPortfolio().getRootNode(), document.getUniqueId() != null,
        portfolioId, portfolioOid, null, null,
        new AtomicInteger(1), 0, nodeList, posList);

    // the arguments for inserting into the portifolio_attribute table
    final List<DbMapSqlParameterSource> prtAttrList = Lists.newArrayList();
    for (Entry<String, String> entry : document.getPortfolio().getAttributes().entrySet()) {
      final long prtAttrId = nextId("prt_portfolio_attr_seq");
      final DbMapSqlParameterSource posAttrArgs = new DbMapSqlParameterSource()
          .addValue("attr_id", prtAttrId)
          .addValue("portfolio_id", portfolioId)
          .addValue("portfolio_oid", portfolioOid)
          .addValue("key", entry.getKey())
          .addValue("value", entry.getValue());
View Full Code Here

    final Long nodeOid = (update && node.getUniqueId() != null ? extractOid(node.getUniqueId()) : nodeId);
    UniqueId nodeUid = createUniqueId(nodeOid, nodeId);
    node.setUniqueId(nodeUid);
    node.setParentNodeId(parentNodeUid);
    node.setPortfolioId(portfolioUid);
    final DbMapSqlParameterSource treeArgs = new DbMapSqlParameterSource()
        .addValue("node_id", nodeId)
        .addValue("node_oid", nodeOid)
        .addValue("portfolio_id", portfolioId)
        .addValue("portfolio_oid", portfolioOid)
        .addValue("parent_node_id", parentNodeId, Types.BIGINT)
        .addValue("parent_node_oid", parentNodeOid, Types.BIGINT)
        .addValue("depth", depth)
        .addValue("name", StringUtils.defaultString(node.getName()));
    argsList.add(treeArgs);

    // store position links
    Set<ObjectId> positionIds = new LinkedHashSet<ObjectId>(node.getPositionIds());
    node.getPositionIds().clear();
    node.getPositionIds().addAll(positionIds);
    for (ObjectId positionId : positionIds) {
      final DbMapSqlParameterSource posArgs = new DbMapSqlParameterSource()
          .addValue("node_id", nodeId)
          .addValue("key_scheme", positionId.getScheme())
          .addValue("key_value", positionId.getValue());
      posList.add(posArgs);
    }
View Full Code Here

   * @return the node, null if not found
   */
  protected ManageablePortfolioNode getNodeByInstants(final UniqueId uniqueId, final Instant versionAsOf, final Instant correctedTo) {
    s_logger.debug("getNodeByLatest {}", uniqueId);
    final Instant now = now();
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
        .addValue("node_oid", extractOid(uniqueId))
        .addTimestamp("version_as_of_instant", Objects.firstNonNull(versionAsOf, now))
        .addTimestamp("corrected_to_instant", Objects.firstNonNull(correctedTo, now));
    final PortfolioDocumentExtractor extractor = new PortfolioDocumentExtractor(true, false);
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
View Full Code Here

   * @param uniqueId the unique identifier, not null
   * @return the node, null if not found
   */
  protected ManageablePortfolioNode getNodeById(final UniqueId uniqueId) {
    s_logger.debug("getNodeById {}", uniqueId);
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
        .addValue("node_id", extractRowId(uniqueId));
    final PortfolioDocumentExtractor extractor = new PortfolioDocumentExtractor(true, false);
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetNodeById", args);
    final List<PortfolioDocument> docs = namedJdbc.query(sql, args, extractor);
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.