| /******************************************************************************* |
| * Copyright (c) 2010-2012 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| * which accompanies this distribution. |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * dclarke - EclipseLink 2.4 - MySports Demo Bug 344608 |
| ******************************************************************************/ |
| package example.mysports.tests.admin; |
| |
| import java.io.InputStream; |
| import java.util.List; |
| |
| import javax.persistence.EntityManager; |
| import javax.persistence.EntityManagerFactory; |
| |
| import example.mysports.admin.model.HostedLeague; |
| import example.mysports.admin.services.HostedLeagueRepository; |
| import example.mysports.admin.services.HostedLeagueRepositoryBean; |
| |
| public class MockHostedLeagueRepository implements HostedLeagueRepository { |
| |
| private HostedLeagueRepositoryBean repositoryBean = new HostedLeagueRepositoryBean(); |
| |
| private EntityManagerFactory emf; |
| |
| public MockHostedLeagueRepository(EntityManagerFactory emf) { |
| super(); |
| this.emf = emf; |
| } |
| |
| public HostedLeagueRepositoryBean getRepositoryBean() { |
| return repositoryBean; |
| } |
| |
| public EntityManagerFactory getEmf() { |
| return emf; |
| } |
| |
| @Override |
| public List<HostedLeague> allLeagues() { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().allLeagues(); |
| } finally { |
| em.getTransaction().rollback(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| @Override |
| public List<HostedLeague> allSharedLeagues() { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().allSharedLeagues(); |
| } finally { |
| em.getTransaction().rollback(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| @Override |
| public HostedLeague getLeague(String leagueId) { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().getLeague(leagueId); |
| } finally { |
| em.getTransaction().rollback(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| @Override |
| public HostedLeague delete(String leagueId) { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().delete(leagueId); |
| } finally { |
| em.getTransaction().commit(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| @Override |
| public HostedLeague create(String id, String name, String scheme) { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().create(id, name, scheme); |
| } finally { |
| em.getTransaction().commit(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| @Override |
| public HostedLeague update(HostedLeague league) { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().update(league); |
| } finally { |
| em.getTransaction().commit(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| @Override |
| public String getORM(String leagueId) { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().getORM(leagueId); |
| } finally { |
| em.getTransaction().rollback(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| |
| @Override |
| public String getCSS(String leagueId) { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().getCSS(leagueId); |
| } finally { |
| em.getTransaction().rollback(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| } |
| |
| @Override |
| public InputStream getLogo(String leagueId) { |
| EntityManager em = getEmf().createEntityManager(); |
| |
| try { |
| getRepositoryBean().setEntityManager(em); |
| em.getTransaction().begin(); |
| return getRepositoryBean().getLogo(leagueId); |
| } finally { |
| em.getTransaction().rollback(); |
| em.close(); |
| getRepositoryBean().setEntityManager(null); |
| } |
| |
| } |
| |
| } |