de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java Source code

Java tutorial

Introduction

Here is the source code for de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package de.lava.marvin.whaosleaguepersistence.dao.impl;

import de.lava.marvin.whaosleaguebeans.League;
import de.lava.marvin.whaosleaguebeans.Match;
import de.lava.marvin.whaosleaguebeans.Player;
import de.lava.marvin.whaosleaguepersistence.dao.PlayerDao;
import java.util.List;
import javax.persistence.TypedQuery;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author mlava
 */
@Repository("playerDao")
@Transactional(propagation = Propagation.REQUIRED)
public class PlayerDaoImpl extends BaseDaoImpl<Player> implements PlayerDao {

    @Override
    public List<Player> getAllPlayers() {
        TypedQuery<Player> query = entityManager.createNamedQuery("allPlayers", Player.class);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllMatchesForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allMatchesForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllRankedMatchesForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allRankedMatchesForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllUnrankedMatchesForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allUnrankedMatchesForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllRankedWinsForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allRankedWinsForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllUnrankedWinsForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allUnrankedWinsForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllRankedLosesForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allRankedLosesForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllUnrankedLosesForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allUnrankedLosesForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllWinsForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allWinsForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public List<Match> getAllLosesForPlayer(Player p) {
        TypedQuery<Match> query = entityManager.createNamedQuery("allLosesForPlayer", Match.class);
        query.setParameter("player", p);
        return query.getResultList();
    }

    @Override
    public long getCountAllMatchesForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllMatchesForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllRankedMatchesForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedMatchesForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllUnrankedMatchesForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedMatchesForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllRankedWinsForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedWinsForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllUnrankedWinsForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedWinsForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllRankedLosesForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllRankedLosesForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllUnrankedLosesForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllUnrankedWinsForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllWinsForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllWinsForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllLosesForPlayer(Player p) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllLosesForPlayer", Long.class);
        query.setParameter("player", p);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllMatchesForPlayerInLeague(Player p, League l) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllMatchesForPlayerInLeague", Long.class);
        query.setParameter("player", p);
        query.setParameter("league", l);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllWinsForPlayerInLeague(Player p, League l) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllWinsForPlayerInLeague", Long.class);
        query.setParameter("player", p);
        query.setParameter("league", l);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllLosesForPlayerInLeague(Player p, League l) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllLosesForPlayerInLeague", Long.class);
        query.setParameter("player", p);
        query.setParameter("league", l);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllWinsForPlayerVersusPlayer(Player p, Player o) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllWinsForPlayerVersusPlayer", Long.class);
        query.setParameter("player", p);
        query.setParameter("opponent", o);
        return query.getSingleResult();
    }

    @Override
    public long getCountAllLosesForPlayerVersusPlayer(Player p, Player o) {
        TypedQuery<Long> query = entityManager.createNamedQuery("countAllLosesForPlayerVersusPlayer", Long.class);
        query.setParameter("player", p);
        query.setParameter("opponent", o);
        return query.getSingleResult();
    }

}