com.github.carlomicieli.service.hibernate.PlayerServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.github.carlomicieli.service.hibernate.PlayerServiceImpl.java

Source

/*
 * Copyright 2012 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.carlomicieli.service.hibernate;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.carlomicieli.model.Player;
import com.github.carlomicieli.service.PlayerDAO;
import com.github.carlomicieli.service.PlayerService;

@Service("playerService")
@Transactional(readOnly = true)
public class PlayerServiceImpl implements PlayerService {

    private @Autowired PlayerDAO playerDAO;

    public PlayerServiceImpl() {
        // default constructor required by GCLIB
    }

    public PlayerDAO getDAO() {
        return playerDAO;
    }

    /**
     * Add a new player.
     * @param player the player.
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void addPlayer(Player player) {
        getDAO().addPlayer(player);
    }

    /**
     * Update a player.
     * @param player the player.
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void updatePlayer(Player player) {
        getDAO().updatePlayer(player);
    }

    /**
     * Delete a player.
     * @param player the player.
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void deletePlayer(Player player) {
        getDAO().deletePlayer(player);
    }

    /**
     * Return a player for his id.
     * @return the player.
     */
    @Override
    public Player getPlayerById(long id) {
        return getDAO().getPlayerById(id);
    }

    /**
     * Return the players list.
     * @return the list of player.
     */
    @Override
    public List<Player> getPlayers() {
        return getDAO().getPlayers();
    }

    /**
     * Return the players list for a team.
     * @param teamId the team unique id.
     * @return the list of player.
     */
    @Override
    public List<Player> findByTeamId(long teamId) {
        return getDAO().findByTeamId(teamId);
    }
}