Examples of DbMapSqlParameterSource


Examples of com.opengamma.util.db.DbMapSqlParameterSource

    try (Timer.Context context = _insertTimer.time()) {
      final long docId = nextId("hol_holiday_seq");
      final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId);
      // the arguments for inserting into the holiday table
      final ManageableHoliday holiday = document.getHoliday();
      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("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("hol_type", holiday.getType().name())
        .addValue("region_scheme",
            holiday.getRegionExternalId() != null ? holiday.getRegionExternalId().getScheme().getName() : null,
            Types.VARCHAR)
        .addValue("region_value",
            holiday.getRegionExternalId() != null ? holiday.getRegionExternalId().getValue() : null,
            Types.VARCHAR)
        .addValue("exchange_scheme",
            holiday.getExchangeExternalId() != null ? holiday.getExchangeExternalId().getScheme().getName() : null,
            Types.VARCHAR)
        .addValue("exchange_value",
            holiday.getExchangeExternalId() != null ? holiday.getExchangeExternalId().getValue() : null,
            Types.VARCHAR)
        .addValue("currency_iso",
            holiday.getCurrency() != null ? holiday.getCurrency().getCode() : null,
            Types.VARCHAR);
      // the arguments for inserting into the date table
      final List<DbMapSqlParameterSource> dateList = new ArrayList<DbMapSqlParameterSource>();
      for (LocalDate date : holiday.getHolidayDates()) {
        final DbMapSqlParameterSource dateArgs = new DbMapSqlParameterSource()
          .addValue("doc_id", docId)
          .addDate("hol_date", date);
        dateList.add(dateArgs);
      }
      final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

  
   * @return the schema version, or null if not found
   */
  public Integer getSchemaVersion() {
    try {
      final DbMapSqlParameterSource args = new DbMapSqlParameterSource().addValue("version_key", "schema_patch");
      final String sql = getElSqlBundle().getSql("GetSchemaVersion", args);
      String version = getJdbcTemplate().queryForObject(sql, args, String.class);
      return Integer.parseInt(version);
    } catch (Exception e) {
      s_logger.debug("Error reading schema version from database", e);
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("userid", getDialect().sqlWildcardAdjustValue(request.getUserId()))
      .addValueNullIgnored("name", getDialect().sqlWildcardAdjustValue(request.getName()))
      .addValueNullIgnored("time_zone", getDialect().sqlWildcardAdjustValue(request.getTimeZone()))
      .addValueNullIgnored("email_address", getDialect().sqlWildcardAdjustValue(request.getEmailAddress()))
      .addValueNullIgnored("external_id_scheme", getDialect().sqlWildcardAdjustValue(request.getExternalIdScheme()))
      .addValueNullIgnored("external_id_value", getDialect().sqlWildcardAdjustValue(request.getExternalIdValue()));
    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 UserDocumentExtractor(), result);
    return result;
  }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

        (ExternalIdSearch.canMatch(request.getExternalIdSearch()) == 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("sec_type", request.getSecurityType())
      .addValueNullIgnored("external_id_scheme", getDialect().sqlWildcardAdjustValue(request.getExternalIdScheme()))
      .addValueNullIgnored("external_id_value", getDialect().sqlWildcardAdjustValue(request.getExternalIdValue()));
    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());
   
    final SecurityMasterDetailProvider detailProvider = getDetailProvider()// lock against change
    if (detailProvider != null) {
      detailProvider.extendSearch(request, args);
    }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    final ManageableOGUser user = document.getUser();
    user.setUniqueId(uniqueId);
    document.setUniqueId(uniqueId);
   
    // the arguments for inserting into the user 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("userid", user.getUserId())
      .addValue("password", user.getPasswordHash())
      .addValue("name", user.getName())
      .addValue("time_zone", user.getTimeZone().getId())
      .addValue("email_address", user.getEmailAddress());
   
    // 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 : user.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("usr_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);
      }
    }
   
    final List<DbMapSqlParameterSource> entitlementList = new ArrayList<DbMapSqlParameterSource>();
    int iEntitlement = 0;
    for (String entitlement : user.getEntitlements()) {
      entitlementList.add(new DbMapSqlParameterSource()
        .addValue("oguser_id", docId)
        .addValue("entitlement_index", iEntitlement)
        .addValue("entitlement_pattern", entitlement));
      iEntitlement++;
    }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    Timer.Context context = _insertTimer.time();
    try {
      final long docId = nextId("sec_security_seq");
      final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId);
      // the arguments for inserting into the security 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("name", document.getSecurity().getName())
        .addValue("sec_type", document.getSecurity().getSecurityType());
      if (document.getSecurity() instanceof RawSecurity) {
        docArgs.addValue("detail_type", "R");
      } else if (document.getSecurity().getClass() == ManageableSecurity.class) {
        docArgs.addValue("detail_type", "M");
      } else {
        docArgs.addValue("detail_type", "D");
      }
      // 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 : document.getSecurity().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 unnecessary id, but id may still not be used
          final long idKeyId = nextId("sec_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);
        }
      }
      final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs);
      final String sqlIdKey = getElSqlBundle().getSql("InsertIdKey");
      final String sqlDoc2IdKey = getElSqlBundle().getSql("InsertDoc2IdKey");
      getJdbcTemplate().update(sqlDoc, docArgs);
      getJdbcTemplate().batchUpdate(sqlIdKey, idKeyList.toArray(new DbMapSqlParameterSource[idKeyList.size()]));
      getJdbcTemplate().batchUpdate(sqlDoc2IdKey, assocList.toArray(new DbMapSqlParameterSource[assocList.size()]));
      // set the uniqueId
      final UniqueId uniqueId = createUniqueId(docOid, docId);
      document.getSecurity().setUniqueId(uniqueId);
      document.setUniqueId(uniqueId);
     
      // store the detail
      if (document.getSecurity() instanceof RawSecurity) {
        storeRawSecurityDetail((RawSecurity) document.getSecurity());
      } else {
        final SecurityMasterDetailProvider detailProvider = getDetailProvider();
        if (detailProvider != null) {
          detailProvider.storeSecurityDetail(document.getSecurity());
        }
      }
     
      // store attributes
      Map<String, String> attributes = new HashMap<String, String>(document.getSecurity().getAttributes());
      final List<DbMapSqlParameterSource> securityAttributeList = Lists.newArrayList();
      for (Map.Entry<String, String> entry : attributes.entrySet()) {
        final long securityAttrId = nextId("sec_security_attr_seq");
        final DbMapSqlParameterSource attributeArgs = new DbMapSqlParameterSource()
                .addValue("attr_id", securityAttrId)
                .addValue("security_id", docId)
                .addValue("security_oid", docOid)
                .addValue("key", entry.getKey())
                .addValue("value", entry.getValue());
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    }

  }

  private void storeRawSecurityDetail(RawSecurity security) {
    final DbMapSqlParameterSource rawArgs = new DbMapSqlParameterSource()
      .addValue("security_id", extractRowId(security.getUniqueId()))
      .addValue("raw_data", new SqlLobValue(security.getRawData(), getDialect().getLobHandler()), Types.BLOB);
    final String sqlRaw = getElSqlBundle().getSql("InsertRaw", rawArgs);
    getJdbcTemplate().update(sqlRaw, rawArgs);
  }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

      }

      byte[] bytes = serializeToFudge(value);

      // the arguments for inserting into the config 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())
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

      if (objectIds != null && objectIds.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.getType().isInstance(Object.class)) {
        args.addValue("config_type", request.getType().getName());
      }
      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) };

      final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
      ConfigDocumentExtractor configDocumentExtractor = new ConfigDocumentExtractor();
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    checkScheme(request.getObjectId());
    s_logger.debug("history {}", request);

    ConfigHistoryResult<T> result = new ConfigHistoryResult<T>();
    ConfigDocumentExtractor extractor = new ConfigDocumentExtractor();
    final DbMapSqlParameterSource args = argsHistory(request);
    final String[] sql = {getElSqlBundle().getSql("History", args), getElSqlBundle().getSql("HistoryCount", args) };

    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    if (request.getPagingRequest().equals(PagingRequest.ALL)) {
      List<ConfigDocument> queryResult = namedJdbc.query(sql[0], args, extractor);
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.