Package org.springframework.jdbc.core.namedparam

Examples of org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations


      .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;
    }

    // Get the actual data points and attach to the Manageable HTS
    if (filter.getLatestDate() == null || filter.getEarliestDate() == null || !filter.getLatestDate().isBefore(filter.getEarliestDate())) {
      final String sqlPoints = getElSqlBundle().getSql("SelectDataPoints", args);
      final LocalDateDoubleTimeSeries series = namedJdbc.query(sqlPoints, args, new DataPointsExtractor());
      result.setTimeSeries(series);
    } else {
      //TODO: this is a hack, most of the places that call with this condition want some kind of metadata, which it would be cheaper for us to expose specifically
      result.setTimeSeries(ImmutableLocalDateDoubleTimeSeries.EMPTY_SERIES);
    }
View Full Code Here


    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);
      }
      return docs.get(0);
    } finally {
View Full Code Here

    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);
      }
      return docs.get(0);
    } finally {
View Full Code Here

  protected <T extends AbstractDocument> void searchWithPaging(
      final PagingRequest pagingRequest, final String[] sql, final DbMapSqlParameterSource args,
      final ResultSetExtractor<List<T>> extractor, final AbstractDocumentsResult<T> result) {
    s_logger.debug("with args {}", args);
   
    final NamedParameterJdbcOperations namedJdbc = getJdbcTemplate();
    if (pagingRequest.equals(PagingRequest.ALL)) {
      result.getDocuments().addAll(namedJdbc.query(sql[0], args, extractor));
      result.setPaging(Paging.of(pagingRequest, result.getDocuments()));
    } else {
      s_logger.debug("executing sql {}", sql[1]);
      final int count = namedJdbc.queryForObject(sql[1], args, Integer.class);
      result.setPaging(Paging.of(pagingRequest, count));
      if (count > 0 && pagingRequest.equals(PagingRequest.NONE) == false) {
        s_logger.debug("executing sql {}", sql[0]);
        result.getDocuments().addAll(namedJdbc.query(sql[0], args, extractor));
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations

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.