Skip to content

πŸ’£ Method Breakdown

πŸ’£ Method Breakdown

Let’s break down each method in RaveRepository, ensuring you know how to keep your data rave lit!

Query Methods

Purpose: Retrieve lists of objects from the database based on your SQL queries.

query(Class<T> type, Object... keyValues)

  • Description: Executes a SQL query linked via @SqlPath, using key-value pairs as parameters.

  • Example:

    @SqlPath("sql/getTracksByGenre.sql")
    public List<Track> getTracksByGenre(String genre) {
    return raveRepository.query(Track.class, "genre", genre);
    }

query(Class<T> type, Object params)

  • Description: Executes a SQL query with a parameter object.

  • Example:

    @SqlPath("sql/getRaversByGenreAndCity.sql")
    public List<Raver> getRaversByGenreAndCity(RaverFilter filter) {
    return raveRepository.query(Raver.class, filter);
    }

query(Class<T> type)

  • Description: Executes a SQL query without any parameters.

  • Example:

    @SqlPath("sql/getAllTracks.sql")
    public List<Track> getAllTracks() {
    return raveRepository.query(Track.class);
    }

Raw Query Methods

Purpose: Execute raw SQL queries by specifying the SQL path directly, giving you full control over the data flow.

rawQuery(String sqlPath, Class<T> type, Object... keyValues)

  • Description: Executes a raw SQL query with key-value pairs.

  • Example:

    public List<Track> getTracksByGenre(String genre) {
    return raveRepository.rawQuery("sql/getTracksBySpeedcoreBPM.sql", Track.class, "genre", genre);
    }

rawQuery(String sqlPath, Class<T> type, Object params)

  • Description: Executes a raw SQL query with a parameter object.

  • Example:

    public List<Track> searchTracksByArtist(Artist artist) {
    return raveRepository.rawQuery("sql/searchRavers.sql", Track.class, artist);
    }

rawQuery(String sqlPath, Class<T> type)

  • Description: Executes a raw SQL query without any parameters.

  • Example:

    public List<Track> getPopularTracks() {
    return raveRepository.rawQuery("sql/getPopularTracks.sql", Track.class);
    }

Query for Single Object

Purpose: Retrieve a single object from the database that matches the query parameters.

queryForObject(Class<T> type, Object... keyValues)

  • Description: Executes a SQL query to fetch a single object using key-value pairs.

  • Example:

    @SqlPath("sql/getTrackById.sql")
    public Raver getTrackById(int id) {
    return raveRepository.queryForObject(Track.class, "id", id);
    }

queryForObject(Class<T> type, Object params)

  • Description: Executes a SQL query to fetch a single object with a parameter object.

  • Example:

    @SqlPath("sql/getFestivalByCity.sql")
    public Festival getFestivalByCity(City city) {
    return raveRepository.queryForObject(Festival.class, city);
    }

queryForObject(Class<T> type)

  • Description: Executes a SQL query to fetch a single object without any parameters.

  • Example:

    @SqlPath("sql/getFeaturedRave.sql")
    public Raver getFeaturedRave() {
    return raveRepository.queryForObject(Rave.class);
    }

Raw Query for Single Object

Purpose: Execute raw SQL queries to retrieve a single object, offering precise control over data selection.

rawQueryForObject(String sqlPath, Class<T> type, Object... keyValues)

  • Description: Executes a raw SQL query to fetch a single object using key-value pairs.

  • Example:

    public Raver getRaverByEmail(String email) {
    return raveRepository.rawQueryForObject("sql/getRaverByEmail.sql", Raver.class, "email", email);
    }

rawQueryForObject(String sqlPath, Class<T> type, Object params)

  • Description: Executes a raw SQL query to fetch a single object with a parameter object.

  • Example:

    public Raver getRaverBySocialMediaHandle(SocialMediaHandle handle) {
    return raveRepository.rawQueryForObject("sql/getRaverBySocialMediaHandle.sql", Raver.class, handle);
    }

rawQueryForObject(String sqlPath, Class<T> type)

  • Description: Executes a raw SQL query to fetch a single object without any parameters.

  • Example:

    public Raver getRaveAmbassador() {
    return raveRepository.rawQueryForObject("sql/getRaveAmbassador.sql", Raver.class);
    }

Update Methods

Purpose: Perform update operations on the database, modifying records to keep your data rave synchronized.

update(Object... keyValues)

  • Description: Executes an update operation using key-value pairs.

  • Example:

    @SqlPath("sql/updateTrackBPM.sql")
    public int updateTrackBPM(int trackId, int newBPM) {
    return raveRepository.update("trackId", trackId, "newBPM", newBPM);
    }

update(Object params)

  • Description: Executes an update operation with a parameter object.

  • Example:

    @SqlPath("sql/updateRaveInfo.sql")
    public int updateRaverInfo(RaveInfoUpdate raveInfo) {
    return raveRepository.update(raveInfo);
    }

update()

  • Description: Executes an update operation without any parameters.

  • Example:

    @SqlPath("sql/resetDailyMusicStats.sql")
    public int resetDailyMusicStats() {
    return raveRepository.update();
    }

Raw Update Methods

Purpose: Execute raw update operations by specifying the SQL path directly, offering full control over data modifications.

rawUpdate(String sqlPath, Object... keyValues)

  • Description: Executes a raw update operation using key-value pairs.

  • Example:

    public int deactivateRaver(int raverId) {
    return raveRepository.rawUpdate("sql/deactivateRaver.sql", "raverId", raverId);
    }

rawUpdate(String sqlPath, Object params)

  • Description: Executes a raw update operation with a parameter object.

  • Example:

    public int updateTrackDetails(TrackUpdate trackUpdate) {
    return raveRepository.rawUpdate("sql/updateTrackDetails.sql", trackUpdate);
    }

rawUpdate(String sqlPath)

  • Description: Executes a raw update operation without any parameters.

  • Example:

    public int archiveOldTracks() {
    return raveRepository.rawUpdate("sql/archiveOldTracks.sql");
    }

Batch Update

Purpose: Perform batch updates to modify multiple records in one synchronized drop, keeping the rave energy high.

batchUpdate(List<?> paramObjects)

  • Description: Executes a batch update using a list of parameter objects.

  • Example:

    @SqlPath("sql/updateMultipleRavers.sql")
    public int[] updateAllTracks(List<TrackUpdate> updates) {
    return raveRepository.batchUpdate(updates);
    }

Raw Batch Update

Purpose: Execute raw batch updates with precise control over each data modification.

rawBatchUpdate(String sqlPath, List<?> paramObjects)

  • Description: Executes a raw batch update using a list of parameter objects.

  • Example:

    public int[] deactivateMultipleTracks(List<Integer> trackIds) {
    return raveRepository.rawBatchUpdate("sql/deactivateTracks.sql", trackIds);
    }

Preload SQL Queries

Purpose: Preload a list of SQL queries into the cache, ensuring your favorite tracks are always ready to drop without delay.

preloadSqlQueries(List<String> sqlPaths)

  • Description: Loads multiple SQL scripts into the cache.

  • Example:

    public void preloadFestivalSql() {
    List<String> sqlTracks = Arrays.asList(
    "sql/getAllRavers.sql",
    "sql/getAllTracks.sql",
    "sql/getAllEvents.sql"
    );
    raveRepository.preloadSqlQueries(sqlTracks);
    }

Clear SQL Cache

Purpose: Clears the SQL cache, allowing you to refresh your playlist and ensure the latest queries are always in sync with your application’s needs.

clearSqlCache()

  • Description: Empties the SQL cache.

  • Example:

    public void refreshSqlCache() {
    raveRepository.clearSqlCache();
    }