package com.bd.movie.serviceimpl;

import com.bd.framework.util.HibernateUtil;

import com.bd.movie.domain.Library;
import com.bd.movie.domain.LibraryRepository;
import com.bd.movie.domain.Media;
import com.bd.movie.domain.Person;
import com.bd.movie.domain.PersonRepository;

import com.bd.movie.serviceapi.LibraryService;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 <!-- begin-user-doc -->
 * Service implementation for '<em><b>LibraryService</b></em>'.
 <!-- end-user-doc -->
 *
 * @generated
 */
public class LibraryServiceImpl implements LibraryService {

    private static final Log LOG = LogFactory.getLog(LibraryServiceImpl.class);

    /** @generated */
    private LibraryRepository libraryRepository = new LibraryRepository();
    /** @generated */
    private PersonRepository personRepository = new PersonRepository();

    /**
     <!-- begin-user-doc -->
     <!-- end-user-doc -->
     * @generated
     */
     public Library findLibraryByName(String name) {
        try 
            return libraryRepository.findLibraryByName(name);
         catch (RuntimeException e) {
            LOG.error(e.getMessage(), e);
            throw e;
        finally {
            HibernateUtil.closeSession();
        }
     }
     
    /**
     <!-- begin-user-doc -->
     <!-- end-user-doc -->
     * @generated
     */
     public void createLibrary(Library newLibrary) {
        try 
            libraryRepository.create(newLibrary);
         catch (RuntimeException e) {
            LOG.error(e.getMessage(), e);
            throw e;
        finally {
            HibernateUtil.closeSession();
        }
     }
     
    /**
     <!-- begin-user-doc -->
     <!-- end-user-doc -->
     * @generated
     */
     public List<Media> findMediaByName(int libraryId, String name) {
        try 
            return libraryRepository.findMediaByName(libraryId, name);
         catch (RuntimeException e) {
            LOG.error(e.getMessage(), e);
            throw e;
        finally {
            HibernateUtil.closeSession();
        }
     }
     
    /**
     <!-- begin-user-doc -->
     <!-- end-user-doc -->
     * @generated
     */
     public List<Media> findMediaByCharacter(int libraryId, String characterName) {
        try 
            return libraryRepository.findMediaByCharacter(libraryId, characterName);
         catch (RuntimeException e) {
            LOG.error(e.getMessage(), e);
            throw e;
        finally {
            HibernateUtil.closeSession();
        }
     }
     
    /**
     <!-- begin-user-doc -->
     <!-- end-user-doc -->
     * @generated
     */
     public Person findPersonByName(String name) {
        try 
            return personRepository.findPersonByName(name);
         catch (RuntimeException e) {
            LOG.error(e.getMessage(), e);
            throw e;
        finally {
            HibernateUtil.closeSession();
        }
     }