001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.interceptors;
023:
024: import javax.ejb.EJB;
025: import javax.annotation.Resource;
026: import javax.transaction.TransactionManager;
027: import javax.sql.DataSource;
028: import javax.persistence.PersistenceContext;
029: import javax.persistence.EntityManager;
030: import javax.persistence.PersistenceUnit;
031: import javax.persistence.EntityManagerFactory;
032: import javax.interceptor.AroundInvoke;
033: import javax.interceptor.InvocationContext;
034:
035: import org.jboss.annotation.JndiInject;
036: import org.hibernate.Session;
037: import org.hibernate.SessionFactory;
038:
039: /**
040: * Comment
041: *
042: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
043: * @version $Revision: 60233 $
044: */
045: public class MyInterceptor extends MyBaseInterceptor {
046: @EJB
047: MySession2 session2;
048: @JndiInject(jndiName="java:/TransactionManager")
049: TransactionManager tm;
050: @Resource(name="DefaultDS",mappedName="java:DefaultDS")
051: DataSource ds;
052: @PersistenceContext(unitName="interceptors-test")
053: EntityManager em;
054: @PersistenceContext(unitName="interceptors-test")
055: Session session;
056: @PersistenceUnit(unitName="interceptors-test")
057: EntityManagerFactory factory;
058: @PersistenceUnit(unitName="interceptors-test")
059: SessionFactory sessionFactory;
060:
061: MySession2 session2Method;
062: TransactionManager tmMethod;
063: DataSource dsMethod;
064: EntityManager emMethod;
065: Session sessionMethod;
066: EntityManagerFactory factoryMethod;
067: SessionFactory sessionFactoryMethod;
068:
069: @EJB
070: public void setSession2Method(MySession2 session2Method) {
071: this .session2Method = session2Method;
072: }
073:
074: @JndiInject(jndiName="java:/TransactionManager")
075: public void setTmMethod(TransactionManager tmMethod) {
076: this .tmMethod = tmMethod;
077: }
078:
079: @Resource(name="DefaultDS",mappedName="java:DefaultDS")
080: public void setDsMethod(DataSource dsMethod) {
081: this .dsMethod = dsMethod;
082: }
083:
084: @PersistenceContext(unitName="interceptors-test")
085: public void setEmMethod(EntityManager emMethod) {
086: this .emMethod = emMethod;
087: }
088:
089: @PersistenceContext(unitName="interceptors-test")
090: public void setSessionMethod(Session sessionMethod) {
091: this .sessionMethod = sessionMethod;
092: }
093:
094: @PersistenceUnit(unitName="interceptors-test")
095: public void setFactoryMethod(EntityManagerFactory factoryMethod) {
096: this .factoryMethod = factoryMethod;
097: }
098:
099: @PersistenceUnit(unitName="interceptors-test")
100: public void setSessionFactoryMethod(
101: SessionFactory sessionFactoryMethod) {
102: this .sessionFactoryMethod = sessionFactoryMethod;
103: }
104:
105: @AroundInvoke
106: public Object invoke(InvocationContext ctx) throws Exception {
107: session2.doit();
108: if (tm == null)
109: throw new RuntimeException("tm was null");
110: if (ds == null)
111: throw new RuntimeException("ds was null");
112: if (em == null)
113: throw new RuntimeException("em was null");
114: if (session == null)
115: throw new RuntimeException("session was null");
116: if (factory == null)
117: throw new RuntimeException("factory was null");
118: if (sessionFactory == null)
119: throw new RuntimeException("sessionFactory was null");
120:
121: session2Method.doit();
122: if (tmMethod == null)
123: throw new RuntimeException("tm was null");
124: if (dsMethod == null)
125: throw new RuntimeException("ds was null");
126: if (emMethod == null)
127: throw new RuntimeException("em was null");
128: if (sessionMethod == null)
129: throw new RuntimeException("session was null");
130: if (factoryMethod == null)
131: throw new RuntimeException("factory was null");
132: if (sessionFactoryMethod == null)
133: throw new RuntimeException("sessionFactory was null");
134: return ctx.proceed();
135: }
136: }
|