KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateless > containermanaged > callbacklogger > SLSBListenerLoggerAccess


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: SLSBListenerLoggerAccess.java 562 2006-06-02 11:57:44Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger;
26
27 import java.util.List JavaDoc;
28
29 import javax.ejb.Remote JavaDoc;
30 import javax.ejb.Stateless JavaDoc;
31 import javax.persistence.EntityManager;
32 import javax.persistence.EntityManagerFactory;
33 import javax.persistence.PersistenceUnit;
34 import javax.persistence.Query;
35
36 import org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
37 import org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.ListenerLogger;
38
39 /**
40  * Accesses the entity bean that is responsible for registering the callback events.
41  * @author Gisele Pinheiro Souza
42  * @author Eduardo Studzinski Estima de Castro
43  *
44  */

45 @Stateless JavaDoc
46 @Remote JavaDoc(ItfListenerLoggerAccess.class)
47 public class SLSBListenerLoggerAccess extends CallbackLoggerAccessBase implements ItfListenerLoggerAccess{
48
49     /**
50      * The Entity Manager Factory used during the tests.
51      */

52     @PersistenceUnit
53     private EntityManagerFactory entityManagerFactory;
54
55
56     /**
57      * Creates an instance of ListenerLogger with the parameters and the current
58      * time.
59      * @param className the class for which the callback event was called.
60      * @param callbackEvent the callback event name.
61      * @param callbackClassName the name of the class that contains the callback
62      * method.
63      * @param entityId the identifier of the entity that the listenr methdos was
64      * called.
65      */

66     public void insertCallbackLogger(final String JavaDoc className, final CallbackType callbackEvent,
67             final String JavaDoc callbackClassName, final int entityId) {
68         EntityManager entityManager = entityManagerFactory.createEntityManager();
69
70         ListenerLogger logger = new ListenerLogger();
71         logger.setCallbackClassName(callbackClassName);
72         logger.setCallbackEvent(callbackEvent);
73         logger.setClassName(className);
74         logger.setInsertionDate(getTime());
75         logger.setEntityId(entityId);
76         entityManager.persist(logger);
77         entityManager.flush();
78     }
79
80     /**
81      * Finds a callback event that was called for the class in the className
82      * parameter and is defined in the class callbackClassName.
83      * @param className the class for each the callback was called.
84      * @param callbackEvent the callback method that was called.
85      * @param entityId the the entity for which the listener was called.
86      * @return the list of results.
87      */

88     public List JavaDoc findLifecycleEventByEntity(final String JavaDoc className, final CallbackType callbackEvent,
89             final int entityId) {
90         EntityManager entityManager = entityManagerFactory.createEntityManager();
91         Query query = entityManager.createQuery("SELECT e FROM ListenerManager "
92                 + "e WHERE e.className = :className AND e.callbackEvent= :event AND e.entityId = :entityId");
93         query.setParameter("className", className);
94         query.setParameter("event", callbackEvent);
95         query.setParameter("entityId", new Integer JavaDoc(entityId));
96         return query.getResultList();
97     }
98 }
99
Popular Tags