Interface MarketPriceRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<MarketPrice, Long>, org.springframework.data.jpa.repository.JpaRepository<MarketPrice, Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<MarketPrice>, org.springframework.data.repository.ListCrudRepository<MarketPrice, Long>, org.springframework.data.repository.ListPagingAndSortingRepository<MarketPrice, Long>, org.springframework.data.repository.PagingAndSortingRepository<MarketPrice, Long>, org.springframework.data.repository.query.QueryByExampleExecutor<MarketPrice>, org.springframework.data.repository.Repository<MarketPrice, Long>

@Repository public interface MarketPriceRepository extends org.springframework.data.jpa.repository.JpaRepository<MarketPrice, Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<MarketPrice>
Data-access layer for MarketPrice.
Version:
3.0.6
Author:
Stephen Prizio
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor

    org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<T>
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes a MarketPrice by its SymbolAlias.
    Returns the MarketPrice matching its database identity.
    Returns a List of MarketPrices for the given symbol alias.
    Returns a List of MarketPrices for the given symbol alias, within the time span.
    void
    migrateSymbolAlias(SymbolAlias oldAlias, SymbolAlias newAlias, LocalDateTime modifiedAt)
    Migrates MarketPrices with the given SymbolAlias to a new SymbolAlias.
    int
    upsertMarketPrice(LocalDateTime date, String interval, double open, double high, double low, double close, Double adjustedClose, long volume, long symbolAliasId)
    Inserts or updates an existing MarketPrice.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor

    count, count, delete, delete, exists, exists, findAll, findAll, findAll, findAll, findAll, findBy, findBy, findOne, findOne, update

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findMarketPricesWithinTimespan

      @Query(" SELECT mp\n FROM MarketPrice mp\n WHERE mp.symbolAlias = ?1 AND mp.interval = ?2 AND mp.date >= ?3 AND mp.date < ?4\n ORDER BY mp.date ASC\n") List<MarketPrice> findMarketPricesWithinTimespan(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end)
      Returns a List of MarketPrices for the given symbol alias, within the time span.
      Parameters:
      symbolAlias - SymbolAlias
      timeInterval - MarketTimeInterval
      start - LocalDateTime
      end - LocalDateTime
      Returns:
      List of MarketPrice
    • findMarketPricesBySymbolAlias

      List<MarketPrice> findMarketPricesBySymbolAlias(SymbolAlias symbolAlias)
      Returns a List of MarketPrices for the given symbol alias.
      Parameters:
      symbolAlias - SymbolAlias
      Returns:
      List of MarketPrice
    • findMarketPriceByDateAndIntervalAndSymbolAlias

      MarketPrice findMarketPriceByDateAndIntervalAndSymbolAlias(LocalDateTime date, MarketTimeInterval interval, SymbolAlias symbolAlias)
      Returns the MarketPrice matching its database identity.
      Parameters:
      date - date and time
      interval - MarketTimeInterval
      symbolAlias - SymbolAlias
      Returns:
      nullable MarketPrice
    • deleteBySymbolAlias

      @Modifying @Query("DELETE FROM MarketPrice mp WHERE mp.symbolAlias = :symbolAlias") void deleteBySymbolAlias(@Param("symbolAlias") SymbolAlias symbolAlias)
      Deletes a MarketPrice by its SymbolAlias.
      Parameters:
      symbolAlias - SymbolAlias
    • migrateSymbolAlias

      @Modifying @Query("UPDATE MarketPrice mp\nSET mp.symbolAlias = :newAlias,\n mp.modifiedAt = CASE\n WHEN mp.createdAt > :modifiedAt THEN mp.createdAt\n ELSE :modifiedAt\n END\nWHERE mp.symbolAlias = :oldAlias\n") void migrateSymbolAlias(@Param("oldAlias") SymbolAlias oldAlias, @Param("newAlias") SymbolAlias newAlias, @Param("modifiedAt") LocalDateTime modifiedAt)
      Migrates MarketPrices with the given SymbolAlias to a new SymbolAlias.
      Parameters:
      oldAlias - previous SymbolAlias
      newAlias - new SymbolAlias
      modifiedAt - modification timestamp
    • upsertMarketPrice

      @Modifying(flushAutomatically=true) @Transactional @Query(value=" INSERT INTO market_prices (\n price_date,\n market_price_time_interval,\n open,\n high,\n low,\n close,\n adjusted_close,\n volume,\n symbol_alias_id\n )\n VALUES (\n :date,\n :interval,\n :open,\n :high,\n :low,\n :close,\n :adjustedClose,\n :volume,\n :symbolAliasId\n )\n ON CONFLICT (price_date, market_price_time_interval, symbol_alias_id)\n DO UPDATE SET\n open = EXCLUDED.open,\n high = EXCLUDED.high,\n low = EXCLUDED.low,\n close = EXCLUDED.close,\n adjusted_close = EXCLUDED.adjusted_close,\n volume = EXCLUDED.volume,\n modified_at = GREATEST(\n market_prices.created_at,\n clock_timestamp() AT TIME ZONE 'UTC'\n )\n WHERE\n market_prices.open IS DISTINCT FROM EXCLUDED.open\n OR market_prices.high IS DISTINCT FROM EXCLUDED.high\n OR market_prices.low IS DISTINCT FROM EXCLUDED.low\n OR market_prices.close IS DISTINCT FROM EXCLUDED.close\n OR market_prices.adjusted_close IS DISTINCT FROM EXCLUDED.adjusted_close\n OR market_prices.volume IS DISTINCT FROM EXCLUDED.volume\n", nativeQuery=true) int upsertMarketPrice(@Param("date") LocalDateTime date, @Param("interval") String interval, @Param("open") double open, @Param("high") double high, @Param("low") double low, @Param("close") double close, @Param("adjustedClose") Double adjustedClose, @Param("volume") long volume, @Param("symbolAliasId") long symbolAliasId)
      Inserts or updates an existing MarketPrice.
      Parameters:
      date - date and time
      interval - MarketTimeInterval
      open - open price of period
      high - high price of period
      low - low price of period
      close - close price of period
      adjustedClose - adjusted close price of period
      volume - volume of period
      symbolAliasId - symbol alias id
      Returns:
      number of entities inserted/updated