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 java.util.ArrayList;
025:
026: import javax.ejb.EJB;
027: import javax.annotation.Resource;
028: import javax.interceptor.AroundInvoke;
029: import javax.interceptor.InvocationContext;
030: import javax.persistence.EntityManager;
031: import javax.persistence.EntityManagerFactory;
032: import javax.persistence.PersistenceContext;
033: import javax.persistence.PersistenceUnit;
034: import javax.sql.DataSource;
035: import javax.transaction.TransactionManager;
036:
037: import org.hibernate.Session;
038: import org.hibernate.SessionFactory;
039: import org.jboss.annotation.JndiInject;
040:
041: /**
042: *
043: * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
044: * @version $Revision: 60233 $
045: */
046: public class MyBaseInterceptor {
047: @EJB
048: MySession2 baseSession2;
049: @JndiInject(jndiName="java:/TransactionManager")
050: TransactionManager baseTm;
051: @Resource(name="DefaultDS",mappedName="java:DefaultDS")
052: DataSource baseDs;
053: @PersistenceContext(unitName="interceptors-test")
054: EntityManager baseEm;
055: @PersistenceContext(unitName="interceptors-test")
056: Session baseSession;
057: @PersistenceUnit(unitName="interceptors-test")
058: EntityManagerFactory baseFactory;
059: @PersistenceUnit(unitName="interceptors-test")
060: SessionFactory baseSessionFactory;
061:
062: MySession2 baseSession2Method;
063: TransactionManager baseTmMethod;
064: DataSource baseDsMethod;
065: EntityManager baseEmMethod;
066: Session baseSessionMethod;
067: EntityManagerFactory baseFactoryMethod;
068: SessionFactory baseSessionFactoryMethod;
069:
070: @EJB
071: public void setBaseSession2Method(MySession2 session2Method) {
072: this .baseSession2Method = session2Method;
073: }
074:
075: @JndiInject(jndiName="java:/TransactionManager")
076: public void setBaseTmMethod(TransactionManager tmMethod) {
077: this .baseTmMethod = tmMethod;
078: }
079:
080: @Resource(name="DefaultDS",mappedName="java:DefaultDS")
081: public void setBaseDsMethod(DataSource dsMethod) {
082: this .baseDsMethod = dsMethod;
083: }
084:
085: @PersistenceContext(unitName="interceptors-test")
086: public void setBaseEmMethod(EntityManager emMethod) {
087: this .baseEmMethod = emMethod;
088: }
089:
090: @PersistenceContext(unitName="interceptors-test")
091: public void setBaseSessionMethod(Session sessionMethod) {
092: this .baseSessionMethod = sessionMethod;
093: }
094:
095: @PersistenceUnit(unitName="interceptors-test")
096: public void setBaseFactoryMethod(EntityManagerFactory factoryMethod) {
097: this .baseFactoryMethod = factoryMethod;
098: }
099:
100: @PersistenceUnit(unitName="interceptors-test")
101: public void setBaseSessionFactoryMethod(
102: SessionFactory sessionFactoryMethod) {
103: this .baseSessionFactoryMethod = sessionFactoryMethod;
104: }
105:
106: @AroundInvoke
107: public Object baseInvoke(InvocationContext ctx) throws Exception {
108: baseSession2.doit();
109: if (baseTm == null)
110: throw new RuntimeException("tm was null");
111: if (baseDs == null)
112: throw new RuntimeException("ds was null");
113: if (baseEm == null)
114: throw new RuntimeException("em was null");
115: if (baseSession == null)
116: throw new RuntimeException("session was null");
117: if (baseFactory == null)
118: throw new RuntimeException("factory was null");
119: if (baseSessionFactory == null)
120: throw new RuntimeException("sessionFactory was null");
121:
122: baseSession2Method.doit();
123: if (baseTmMethod == null)
124: throw new RuntimeException("tm was null");
125: if (baseDsMethod == null)
126: throw new RuntimeException("ds was null");
127: if (baseEmMethod == null)
128: throw new RuntimeException("em was null");
129: if (baseSessionMethod == null)
130: throw new RuntimeException("session was null");
131: if (baseFactoryMethod == null)
132: throw new RuntimeException("factory was null");
133: if (baseSessionFactoryMethod == null)
134: throw new RuntimeException("sessionFactory was null");
135: ArrayList list = (ArrayList) ctx.proceed();
136: list.add(0, "MyBaseInterceptor");
137: return list;
138: }
139:
140: }
|