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 TypeMethodDescriptionvoiddeleteBySymbolAlias(SymbolAlias symbolAlias) Deletes aMarketPriceby itsSymbolAlias.findMarketPriceByDateAndIntervalAndSymbolAlias(LocalDateTime date, MarketTimeInterval interval, SymbolAlias symbolAlias) Returns theMarketPricematching its database identity.findMarketPricesBySymbolAlias(SymbolAlias symbolAlias) Returns aListofMarketPrices for the given symbol alias.findMarketPricesWithinTimespan(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end) Returns aListofMarketPrices for the given symbol alias, within the time span.voidmigrateSymbolAlias(SymbolAlias oldAlias, SymbolAlias newAlias, LocalDateTime modifiedAt) intupsertMarketPrice(LocalDateTime date, String interval, double open, double high, double low, double close, Double adjustedClose, long volume, long symbolAliasId) Inserts or updates an existingMarketPrice.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
count, count, delete, delete, exists, exists, findAll, findAll, findAll, findAll, findAll, findBy, findBy, findOne, findOne, updateMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods 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 aListofMarketPrices for the given symbol alias, within the time span.- Parameters:
symbolAlias-SymbolAliastimeInterval-MarketTimeIntervalstart-LocalDateTimeend-LocalDateTime- Returns:
ListofMarketPrice
-
findMarketPricesBySymbolAlias
Returns aListofMarketPrices for the given symbol alias.- Parameters:
symbolAlias-SymbolAlias- Returns:
ListofMarketPrice
-
findMarketPriceByDateAndIntervalAndSymbolAlias
MarketPrice findMarketPriceByDateAndIntervalAndSymbolAlias(LocalDateTime date, MarketTimeInterval interval, SymbolAlias symbolAlias) Returns theMarketPricematching its database identity.- Parameters:
date- date and timeinterval-MarketTimeIntervalsymbolAlias-SymbolAlias- Returns:
- nullable
MarketPrice
-
deleteBySymbolAlias
@Modifying @Query("DELETE FROM MarketPrice mp WHERE mp.symbolAlias = :symbolAlias") void deleteBySymbolAlias(@Param("symbolAlias") SymbolAlias symbolAlias) Deletes aMarketPriceby itsSymbolAlias.- 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) - Parameters:
oldAlias- previousSymbolAliasnewAlias- newSymbolAliasmodifiedAt- 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 existingMarketPrice.- Parameters:
date- date and timeinterval-MarketTimeIntervalopen- open price of periodhigh- high price of periodlow- low price of periodclose- close price of periodadjustedClose- adjusted close price of periodvolume- volume of periodsymbolAliasId- symbol alias id- Returns:
- number of entities inserted/updated
-