Examples of DbMapSqlParameterSource


Examples of com.opengamma.util.db.DbMapSqlParameterSource

    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())
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   
    final long oid = extractOid(objectId);
    final VersionCorrection vc = versionCorrection.withLatestFixed(now());

    // Set up the basic query arguments
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("doc_oid", oid)
      .addTimestamp("version_as_of_instant", vc.getVersionAsOf())
      .addTimestamp("corrected_to_instant", vc.getCorrectedTo())
      .addValue("start_date", DbDateUtils.toSqlDateNullFarPast(filter.getEarliestDate()))
      .addValue("end_date", DbDateUtils.toSqlDateNullFarFuture(filter.getLatestDate()));
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
   
    // Get version metadata from the data-points and set up a Manageable HTS accordingly
    // While the HTS doc itself might have been deleted, the data-points can still be retrieved here
    final String sqlVersion = getElSqlBundle().getSql("SelectDataPointsVersion", args);
    ManageableHistoricalTimeSeries result = namedJdbc.query(sqlVersion, args, new ManageableHTSExtractor(oid));
    if (result == null) {
      // No data-points were found, check if the time-series doc exists or existed at some point
      final String sqlExists = getElSqlBundle().getSql("SelectExistential", args);
      result = namedJdbc.query(sqlExists, args, new ManageableHTSExtractor(oid));
      if (result != null) {
        // The time series doc exists or existed at some point, it's just that there are no data-points
        result.setTimeSeries(ImmutableLocalDateDoubleTimeSeries.EMPTY_SERIES);
        return result;
      } else {
        // The time series with the supplied id never existed
        throw new DataNotFoundException("Unable to find time-series: " + objectId);             
      }
    }

    // Set up query arguments to limit the number of points to return
    if (filter.getMaxPoints() == null) {
      // return all points (limit all)
      args.addValue("order", "ASC");
    } else if (filter.getMaxPoints() > 0) {
      // return first few points
      args.addValue("paging_fetch", filter.getMaxPoints());
      args.addValue("order", "ASC");
    } else if (filter.getMaxPoints() < 0) {
      // return last few points
      args.addValue("paging_fetch", -filter.getMaxPoints());
      args.addValue("order", "DESC");
    } else {
      // Zero datapoints requested
      result.setTimeSeries(ImmutableLocalDateDoubleTimeSeries.EMPTY_SERIES);
      return result;
    }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   * @param series  the time-series data points, not empty, not null
   */
  protected void insertDataPointsCheckMaxDate(final UniqueId uniqueId, final LocalDateDoubleTimeSeries series) {
    final Long docOid = extractOid(uniqueId);
    final VersionCorrection vc = getMaster().extractTimeSeriesInstants(uniqueId);
    final DbMapSqlParameterSource queryArgs = new DbMapSqlParameterSource()
      .addValue("doc_oid", docOid)
      .addTimestamp("ver_instant", vc.getVersionAsOf())
      .addTimestamp("corr_instant", vc.getCorrectedTo());
    final String sql = getElSqlBundle().getSql("SelectMaxPointDate", queryArgs);
    Date result = getDbConnector().getJdbcTemplate().queryForObject(sql, queryArgs, Date.class);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

      LocalDate date = entry.getKey();
      Double value = entry.getValue();
      if (date == null || value == null) {
        throw new IllegalArgumentException("Time-series must not contain a null value");
      }
      final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
        .addValue("doc_oid", docOid)
        .addDate("point_date", date)
        .addValue("ver_instant", nowTS)
        .addValue("corr_instant", nowTS)
        .addValue("point_value", value);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

      LocalDate date = entry.getKey();
      Double value = entry.getValue();
      if (date == null || value == null) {
        throw new IllegalArgumentException("Time-series must not contain a null value");
      }
      final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
        .addValue("doc_oid", docOid)
        .addDate("point_date", date)
        .addValue("corr_instant", nowTS)
        .addValue("point_value", value);
      argsList.add(args);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   * @return the unique identifier, not null
   */
  protected UniqueId removeDataPoints(UniqueId uniqueId, LocalDate fromDateInclusive, LocalDate toDateInclusive, Instant now) {
    final Long docOid = extractOid(uniqueId);
    // query dates to remove
    final DbMapSqlParameterSource queryArgs = new DbMapSqlParameterSource()
      .addValue("doc_oid", docOid)
      .addValue("start_date", DbDateUtils.toSqlDateNullFarPast(fromDateInclusive))
      .addValue("end_date", DbDateUtils.toSqlDateNullFarFuture(toDateInclusive));
    final String sqlRemove = getElSqlBundle().getSql("SelectRemoveDataPoints");
    final List<Map<String, Object>> dates = getJdbcTemplate().queryForList(sqlRemove, queryArgs);
    // insert new rows to remove them
    final Timestamp nowTS = DbDateUtils.toSqlTimestamp(now);
    final List<DbMapSqlParameterSource> argsList = new ArrayList<DbMapSqlParameterSource>();
    for (Map<String, Object> date : dates) {
      final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
        .addValue("doc_oid", docOid)
        .addValue("point_date", date.get("POINT_DATE"))
        .addValue("corr_instant", nowTS)
        .addValue("point_value", null, Types.DOUBLE);
      argsList.add(args);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

    ArgumentChecker.notNull(objectId, "objectId");
    ArgumentChecker.notNull(versionCorrection, "versionCorrection");
    checkScheme(objectId);
    final long oid = extractOid(objectId);
    versionCorrection = versionCorrection.withLatestFixed(now());
    final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue("doc_oid", oid)
      .addTimestamp("version_as_of_instant", versionCorrection.getVersionAsOf())
      .addTimestamp("corrected_to_instant", versionCorrection.getCorrectedTo());
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final UniqueIdExtractor extractor = new UniqueIdExtractor(oid);
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   * @param name  the name to lookup, not null
   * @return the id, null if not stored
   */
  public Long get(final String name) {
    String select = sqlSelectGet();
    DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue(getVariableName(), name);
    List<Map<String, Object>> result = getDbConnector().getJdbcTemplate().queryForList(select, args);
    if (result.size() == 1) {
      return (Long) result.get(0).get("dim_id");
    }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   * @param name  the name to lookup, not null
   * @return the id, null if not stored
   */
  public Long search(final String name) {
    String select = sqlSelectSearch(name);
    DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue(getVariableName(), getDialect().sqlWildcardAdjustValue(name));
    List<Map<String, Object>> result = getDbConnector().getJdbcTemplate().queryForList(select, args);
    if (result.isEmpty()) {
      return null;
    }
View Full Code Here

Examples of com.opengamma.util.db.DbMapSqlParameterSource

   * @param name  the name to ensure is present, not null
   * @return the id, null if not stored
   */
  public long ensure(final String name) {
    String select = sqlSelectGet();
    DbMapSqlParameterSource args = new DbMapSqlParameterSource()
      .addValue(getVariableName(), name);
    List<Map<String, Object>> result = getDbConnector().getJdbcTemplate().queryForList(select, args);
    if (result.size() == 1) {
      return (Long) result.get(0).get("dim_id");
    }
    final long id = nextId();
    args.addValue("dim_id", id);
    getDbConnector().getJdbcTemplate().update(sqlInsert(), args);
    s_logger.debug("Inserted new value into {} : {} = {}", new Object[] {getTableName(), id, name});
    return id;
  }
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.