|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| SLSBEntityManagerTester00.java | 100% | 84% | 88.9% | 86.1% |
|
||||||||||||||
| 1 | /** | |
| 2 | * EasyBeans | |
| 3 | * Copyright (C) 2006 Bull S.A.S. | |
| 4 | * Contact: easybeans@objectweb.org | |
| 5 | * | |
| 6 | * This library is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU Lesser General Public | |
| 8 | * License as published by the Free Software Foundation; either | |
| 9 | * version 2.1 of the License, or any later version. | |
| 10 | * | |
| 11 | * This library is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | * Lesser General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU Lesser General Public | |
| 17 | * License along with this library; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
| 19 | * USA | |
| 20 | * | |
| 21 | * -------------------------------------------------------------------------- | |
| 22 | * $Id:$ | |
| 23 | * -------------------------------------------------------------------------- | |
| 24 | */ | |
| 25 | package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged; | |
| 26 | ||
| 27 | import javax.ejb.Remote; | |
| 28 | import javax.ejb.Stateless; | |
| 29 | import javax.persistence.EntityManager; | |
| 30 | import javax.persistence.PersistenceContext; | |
| 31 | import javax.persistence.PersistenceContextType; | |
| 32 | ||
| 33 | import org.objectweb.easybeans.tests.common.ejbs.entity.ebstore.EBStore; | |
| 34 | ||
| 35 | /** | |
| 36 | * Tests if the EntityManager is creating and deleting correctly the entity | |
| 37 | * beans when a persistence context transaction is used. | |
| 38 | * @author Gisele Pinheiro Souza | |
| 39 | * @author Eduardo Studzinski Estima de Castro | |
| 40 | */ | |
| 41 | @Stateless | |
| 42 | @Remote(ItfEntityManagerTester00.class) | |
| 43 | public class SLSBEntityManagerTester00 implements ItfEntityManagerTester00 { | |
| 44 | ||
| 45 | /** | |
| 46 | * The persistence context used during the test. | |
| 47 | */ | |
| 48 | @PersistenceContext(type = PersistenceContextType.TRANSACTION) | |
| 49 | private EntityManager em; | |
| 50 | ||
| 51 | /** | |
| 52 | * Completes the entity with the values. | |
| 53 | * @param id the entity primary key. | |
| 54 | * @param name the entity name. | |
| 55 | * @return the ebstore completed. | |
| 56 | */ | |
| 57 | 6 | private EBStore completeEBStore(final int id, final String name) { |
| 58 | 6 | EBStore ebstore = new EBStore(); |
| 59 | 6 | ebstore.setId(id); |
| 60 | 6 | ebstore.setName(name); |
| 61 | 6 | return ebstore; |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Finds the entity by primaryKey. | |
| 66 | * @param id the entity primary key. | |
| 67 | * @return the entity. | |
| 68 | */ | |
| 69 | 10 | public EBStore findEBStore(final int id) { |
| 70 | 10 | return em.find(EBStore.class, new Integer(id)); |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Removes the entity that is in the database. | |
| 75 | * @param id the entity primary key. | |
| 76 | */ | |
| 77 | 6 | public void removeEBStore(final int id) { |
| 78 | 6 | EBStore ebstore = findEBStore(id); |
| 79 | 6 | if(ebstore != null){ |
| 80 | 2 | em.remove(ebstore); |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * Creates an entity beans. | |
| 86 | * @param id the primary key. | |
| 87 | * @param name the entity name. | |
| 88 | */ | |
| 89 | 1 | public void createEBStoreNew(final int id, final String name) { |
| 90 | 1 | em.persist(completeEBStore(id, name)); |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Tries to persist the same bean twice. In the first persist, the entity | |
| 95 | * status is new, in the second persist, the bean status is managed. | |
| 96 | * @param id the primary key. | |
| 97 | * @param name the entity name. | |
| 98 | */ | |
| 99 | 1 | public void createEBStoreManaged(final int id, final String name) { |
| 100 | 1 | EBStore ebstore = completeEBStore(id, name); |
| 101 | 1 | em.persist(ebstore); |
| 102 | 1 | em.persist(ebstore); |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Creates the entity, removes it and after tries to insert other time the | |
| 107 | * removed entity. | |
| 108 | * @param id the primary key. | |
| 109 | * @param name the entity name. | |
| 110 | */ | |
| 111 | 1 | public void createEBStoreRemoved(final int id, final String name) { |
| 112 | 1 | EBStore ebstore = completeEBStore(id, name); |
| 113 | 1 | em.persist(ebstore); |
| 114 | 1 | em.remove(ebstore); |
| 115 | 1 | em.persist(ebstore); |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * Creates the entity and tries to remove twice the same entity. | |
| 120 | * @param id the primary key. | |
| 121 | * @param name the entity name. | |
| 122 | */ | |
| 123 | 0 | public void removeEBStoreRemoved(final int id, final String name) { |
| 124 | 0 | EBStore ebstore = completeEBStore(id, name); |
| 125 | 0 | em.persist(ebstore); |
| 126 | 0 | em.remove(ebstore); |
| 127 | 0 | em.remove(ebstore); |
| 128 | } | |
| 129 | ||
| 130 | /** | |
| 131 | * Creates the entity and , after that, tries remove the same entity. | |
| 132 | * @param id the primary key. | |
| 133 | * @param name the entity name. | |
| 134 | */ | |
| 135 | 2 | public void removeEBStoreManaged(final int id, final String name) { |
| 136 | 2 | EBStore ebstore = completeEBStore(id, name); |
| 137 | 2 | em.persist(ebstore); |
| 138 | 2 | em.remove(ebstore); |
| 139 | } | |
| 140 | ||
| 141 | /** | |
| 142 | * Tries remove the entity that is not persistent yet. | |
| 143 | * @param id the primary key. | |
| 144 | * @param name the entity name. | |
| 145 | */ | |
| 146 | 1 | public void removeEBStoreNew(final int id, final String name) { |
| 147 | 1 | EBStore ebstore = completeEBStore(id, name); |
| 148 | 1 | em.remove(ebstore); |
| 149 | } | |
| 150 | } |
|
||||||||||