<file_sep>package ua.nure.tvshowmusic.db.dao.vote;

import org.springframework.stereotype.Repository;
import ua.nure.tvshowmusic.db.dao.AbstractCrudDao;
import ua.nure.tvshowmusic.model.Vote;

@Repository
public class DefaultVoteDao extends AbstractCrudDao<Vote> {

    public DefaultVoteDao() {
        super("vote");
    }

}<file_sep>package ua.nure.tvshowmusic.db.dao.episode;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import ua.nure.tvshowmusic.annotation.DefaultRowMapperQualifier;
import ua.nure.tvshowmusic.model.Episode;
import ua.nure.tvshowmusic.model.TvShow;

import java.sql.ResultSet;
import java.sql.SQLException;

@Component
@DefaultRowMapperQualifier
public class EpisodeRowMapper implements RowMapper<Episode> {

    @Override
    public Episode mapRow(ResultSet resultSet, int i) throws SQLException {
        Episode episode = new Episode();
        episode.setId(resultSet.getLong("id"));
        TvShow tvShow = new TvShow();
        tvShow.setId(resultSet.getLong("tv_show_id"));
        episode.setTvShow(tvShow);
        episode.setName(resultSet.getString("name"));
        episode.setSeason(resultSet.getInt("season"));
        episode.setNumber(resultSet.getInt("number"));
        episode.setDate(resultSet.getDate("date"));
        episode.setDescription(resultSet.getString("description"));
        return episode;
    }

}<file_sep>package ua.nure.tvshowmusic.exception;

public class SqlEntryExtractorException extends RuntimeException {

    public SqlEntryExtractorException() {
    }

    public SqlEntryExtractorException(String message) {
        super(message);
    }

    public SqlEntryExtractorException(String message, Throwable cause) {
        super(message, cause);
    }

    public SqlEntryExtractorException(Throwable cause) {
        super(cause);
    }

}<file_sep>package ua.nure.tvshowmusic.db.entry.extractor;

import ua.nure.tvshowmusic.db.entry.SqlEntry;
import ua.nure.tvshowmusic.model.Model;

import java.util.List;

public interface DefaultSqlEntryExtractor<T> {

    List<SqlEntry> extractSqlEntries(Model<T> model);

}<file_sep>db.driverClassName=com.mysql.cj.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/tvshowmusic?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
db.username=root
db.password=<PASSWORD><file_sep>package ua.nure.tvshowmusic.db.dao.user;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import ua.nure.tvshowmusic.annotation.DefaultRowMapperQualifier;
import ua.nure.tvshowmusic.model.User;

import java.sql.ResultSet;
import java.sql.SQLException;

@Component
@DefaultRowMapperQualifier
public class UserRowMapper implements RowMapper<User> {

    @Override
    public User mapRow(ResultSet resultSet, int i) throws SQLException {
        User user = new User();
        user.setId(resultSet.getLong("id"));
        user.setName(resultSet.getString("name"));
        user.setEmail(resultSet.getString("email"));
        user.setPassword(resultSet.getString("password"));
        user.setAvatar(resultSet.getString("avatar"));
        return user;
    }

}<file_sep>package ua.nure.tvshowmusic.model;

import org.apache.commons.lang3.builder.ToStringBuilder;
import ua.nure.tvshowmusic.annotation.ManyToOne;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;

import static java.util.Objects.hash;

public class SubComment extends Model<Long> implements Serializable {

    @ManyToOne
    private User user;

    @ManyToOne
    private Comment comment;

    private Timestamp date;

    private String text;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Comment getComment() {
        return comment;
    }

    public void setComment(Comment comment) {
        this.comment = comment;
    }

    public Timestamp getDate() {
        return date;
    }

    public void setDate(Timestamp date) {
        this.date = date;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SubComment that = (SubComment) o;
        return Objects.equals(getId(), that.getId()) &&
                Objects.equals(user, that.user) &&
                Objects.equals(comment, that.comment) &&
                Objects.equals(date, that.date) &&
                Objects.equals(text, that.text);
    }

    @Override
    public int hashCode() {
        return hash(getId(), user, comment, date, text);
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("id", getId())
                .append("user", user)
                .append("comment", comment)
                .append("date", date)
                .append("text", text)
                .toString();
    }

}<file_sep>package ua.nure.tvshowmusic.model;

import org.apache.commons.lang3.builder.ToStringBuilder;
import ua.nure.tvshowmusic.annotation.ManyToOne;
import ua.nure.tvshowmusic.annotation.OneToMany;

import java.io.Serializable;
import java.sql.Date;
import java.util.List;
import java.util.Objects;

import static java.util.Objects.hash;

public class Episode extends Model<Long> implements Serializable {

    @ManyToOne
    private TvShow tvShow;

    @OneToMany
    private List<Appearance> appearances;

    @OneToMany
    private List<Comment> comments;

    private String name;

    private int season;

    private int number;

    private Date date;

    private String description;

    public TvShow getTvShow() {
        return tvShow;
    }

    public void setTvShow(TvShow tvShow) {
        this.tvShow = tvShow;
    }

    public List<Appearance> getAppearances() {
        return appearances;
    }

    public void setAppearances(List<Appearance> appearances) {
        this.appearances = appearances;
    }

    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSeason() {
        return season;
    }

    public void setSeason(int season) {
        this.season = season;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Episode episode = (Episode) o;
        return Objects.equals(getId(), episode.getId()) &&
                season == episode.season &&
                number == episode.number &&
                Objects.equals(tvShow, episode.tvShow) &&
                Objects.equals(appearances, episode.appearances) &&
                Objects.equals(comments, episode.comments) &&
                Objects.equals(name, episode.name) &&
                Objects.equals(date, episode.date) &&
                Objects.equals(description, episode.description);
    }

    @Override
    public int hashCode() {
        return hash(getId(), tvShow, appearances, comments, name, season, number, date, description);
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("id", getId())
                .append("tvShow", tvShow)
                .append("appearances", appearances)
                .append("comments", comments)
                .append("name", name)
                .append("season", season)
                .append("number", number)
                .append("date", date)
                .append("description", description)
                .toString();
    }

}<file_sep>package ua.nure.tvshowmusic.db.dao.song;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import ua.nure.tvshowmusic.annotation.DefaultRowMapperQualifier;
import ua.nure.tvshowmusic.model.Artist;
import ua.nure.tvshowmusic.model.Song;

import java.sql.ResultSet;
import java.sql.SQLException;

@Component
@DefaultRowMapperQualifier
public class SongRowMapper implements RowMapper<Song> {

    @Override
    public Song mapRow(ResultSet resultSet, int i) throws SQLException {
        Song song = new Song();
        song.setId(resultSet.getLong("id"));
        Artist artist = new Artist();
        artist.setId(resultSet.getLong("artist_id"));
        song.setArtist(artist);
        song.setName(resultSet.getString("name"));
        song.setAlbum(resultSet.getString("album"));
        song.setTime(resultSet.getInt("time"));
        song.setArtworkUrl(resultSet.getString("artwork_url"));
        song.setItunesUrl(resultSet.getString("itunes_url"));
        song.setPreviewUrl(resultSet.getString("preview_url"));
        return song;
    }

}<file_sep>package ua.nure.tvshowmusic.db.dao.vote;

import ua.nure.tvshowmusic.db.dao.CrudDao;
import ua.nure.tvshowmusic.model.Vote;

public interface VoteDao extends CrudDao<Long, Vote> {
}<file_sep>package ua.nure.tvshowmusic.db.dao.appearance;

import org.springframework.stereotype.Repository;
import ua.nure.tvshowmusic.db.dao.AbstractCrudDao;
import ua.nure.tvshowmusic.model.Appearance;

@Repository
public class DefaultAppearanceDao extends AbstractCrudDao<Appearance> {

    public DefaultAppearanceDao() {
        super("appearance");
    }

}<file_sep>package ua.nure.tvshowmusic.model;

import org.apache.commons.lang3.builder.ToStringBuilder;
import ua.nure.tvshowmusic.annotation.ManyToOne;
import ua.nure.tvshowmusic.annotation.OneToMany;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import static java.util.Objects.hash;

public class Song extends Model<Long> implements Serializable {

    @ManyToOne
    private Artist artist;

    @OneToMany
    private List<Appearance> appearances;

    private String name;

    private String album;

    private int time;

    private String artworkUrl;

    private String itunesUrl;

    private String previewUrl;

    public Artist getArtist() {
        return artist;
    }

    public void setArtist(Artist artist) {
        this.artist = artist;
    }

    public List<Appearance> getAppearances() {
        return appearances;
    }

    public void setAppearances(List<Appearance> appearances) {
        this.appearances = appearances;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAlbum() {
        return album;
    }

    public void setAlbum(String album) {
        this.album = album;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public String getArtworkUrl() {
        return artworkUrl;
    }

    public void setArtworkUrl(String artworkUrl) {
        this.artworkUrl = artworkUrl;
    }

    public String getItunesUrl() {
        return itunesUrl;
    }

    public void setItunesUrl(String itunesUrl) {
        this.itunesUrl = itunesUrl;
    }

    public String getPreviewUrl() {
        return previewUrl;
    }

    public void setPreviewUrl(String previewUrl) {
        this.previewUrl = previewUrl;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Song song = (Song) o;
        return Objects.equals(getId(), song.getId()) &&
                time == song.time &&
                Objects.equals(artist, song.artist) &&
                Objects.equals(appearances, song.appearances) &&
                Objects.equals(name, song.name) &&
                Objects.equals(album, song.album) &&
                Objects.equals(artworkUrl, song.artworkUrl) &&
                Objects.equals(itunesUrl, song.itunesUrl) &&
                Objects.equals(previewUrl, song.previewUrl);
    }

    @Override
    public int hashCode() {
        return hash(getId(), artist, appearances, name, album, time, artworkUrl, itunesUrl, previewUrl);
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("id", getId())
                .append("artist", artist)
                .append("appearances", appearances)
                .append("name", name)
                .append("album", album)
                .append("time", time)
                .append("artworkUrl", artworkUrl)
                .append("itunesUrl", itunesUrl)
                .append("previewUrl", previewUrl)
                .toString();
    }

}<file_sep>package ua.nure.tvshowmusic.db.dao.comment;

import org.springframework.stereotype.Repository;
import ua.nure.tvshowmusic.db.dao.AbstractCrudDao;
import ua.nure.tvshowmusic.model.Comment;

@Repository
public class DefaultCommentDao extends AbstractCrudDao<Comment> {

    public DefaultCommentDao() {
        super("comment");
    }

}<file_sep>package ua.nure.tvshowmusic.db.jdbc.template;

import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowMapper;

public interface ExtendedJdbcOperations extends JdbcOperations {

    <T> T queryForObject(String sql, RowMapper<T> rowMapper, Object... args);

}<file_sep>package ua.nure.tvshowmusic.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

@Controller
@RequestMapping("/logIn")
public class LogInController {

    @RequestMapping(method = GET)
    public String logIn() {
        return "logIn";
    }

}<file_sep>package ua.nure.tvshowmusic.db.dao.user;

import ua.nure.tvshowmusic.db.dao.CrudDao;
import ua.nure.tvshowmusic.model.User;

public interface UserDao extends CrudDao<Long, User> {

    User read(String email);

}<file_sep>package ua.nure.tvshowmusic.db.dao.appearance;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import ua.nure.tvshowmusic.annotation.DefaultRowMapperQualifier;
import ua.nure.tvshowmusic.model.Appearance;
import ua.nure.tvshowmusic.model.Episode;
import ua.nure.tvshowmusic.model.Song;

import java.sql.ResultSet;
import java.sql.SQLException;

import static ua.nure.tvshowmusic.model.Appearance.AppearanceStatus.valueOf;

@Component
@DefaultRowMapperQualifier
public class AppearanceRowMapper implements RowMapper<Appearance> {

    @Override
    public Appearance mapRow(ResultSet resultSet, int i) throws SQLException {
        Appearance appearance = new Appearance();
        appearance.setId(resultSet.getLong("id"));
        Song song = new Song();
        song.setId(resultSet.getLong("song_id"));
        appearance.setSong(song);
        Episode episode = new Episode();
        episode.setId(resultSet.getLong("episode_id"));
        appearance.setEpisode(episode);
        appearance.setStatus(valueOf(resultSet.getString("status")));
        appearance.setDescription(resultSet.getString("description"));
        return appearance;
    }

}<file_sep>package ua.nure.tvshowmusic.db.dao.artist;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import ua.nure.tvshowmusic.annotation.DefaultRowMapperQualifier;
import ua.nure.tvshowmusic.model.Artist;

import java.sql.ResultSet;
import java.sql.SQLException;

@Component
@DefaultRowMapperQualifier
public class ArtistRowMapper implements RowMapper<Artist> {

    @Override
    public Artist mapRow(ResultSet resultSet, int i) throws SQLException {
        Artist artist = new Artist();
        artist.setId(resultSet.getLong("id"));
        artist.setName(resultSet.getString("name"));
        return artist;
    }

}