[seam-commits] Seam SVN: r13716 - in modules/persistence/trunk: api/src/main/java/org/jboss/seam/persistence and 3 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Sep 2 23:53:49 EDT 2010
Author: swd847
Date: 2010-09-02 23:53:49 -0400 (Thu, 02 Sep 2010)
New Revision: 13716
Added:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/hibernate/
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/hibernate/SeamManagedHibernateSessionCreated.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextProxyHandler.java
Modified:
modules/persistence/trunk/pom.xml
Log:
add start of managed hibernate managed sessions
Added: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/hibernate/SeamManagedHibernateSessionCreated.java
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/hibernate/SeamManagedHibernateSessionCreated.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/hibernate/SeamManagedHibernateSessionCreated.java 2010-09-03 03:53:49 UTC (rev 13716)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.hibernate;
+
+import org.hibernate.Session;
+
+/**
+ * event that is fired when the hibernate session is created. This allows you to
+ * configure the session before it is used, e.g. by enabling filters
+ *
+ * @author Stuart Douglas <stuart at baileyroberts.com.au>
+ *
+ */
+public class SeamManagedHibernateSessionCreated
+{
+ private final Session session;
+
+ public SeamManagedHibernateSessionCreated(Session session)
+ {
+ this.session = session;
+ }
+
+ public Session getSession()
+ {
+ return session;
+ }
+
+}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextBeanLifecycle.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextBeanLifecycle.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextBeanLifecycle.java 2010-09-03 03:53:49 UTC (rev 13716)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.hibernate;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.Set;
+
+import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.jboss.seam.persistence.HibernatePersistenceProvider;
+import org.jboss.seam.persistence.ManagedPersistenceContext;
+import org.jboss.seam.persistence.PersistenceContexts;
+import org.jboss.weld.extensions.bean.BeanLifecycle;
+import org.jboss.weld.extensions.literal.DefaultLiteral;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * lifecycle for seam managed hibernate sessions
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class HibernateManagedPersistenceContextBeanLifecycle implements BeanLifecycle<Session>
+{
+ private static final Logger log = LoggerFactory.getLogger(HibernateManagedPersistenceContextBeanLifecycle.class);
+
+ private final Class<?> proxyClass;
+
+ private final Constructor<?> proxyConstructor;
+
+ private HibernatePersistenceProvider persistenceProvider = new HibernatePersistenceProvider();
+
+ private PersistenceContexts persistenceContexts;
+
+ protected final Annotation[] qualifiers;
+
+ protected final BeanManager manager;
+
+ private SessionFactory sessionFactory;
+
+ public HibernateManagedPersistenceContextBeanLifecycle(Set<Annotation> qualifiers, ClassLoader loader, BeanManager manager)
+ {
+ this.manager = manager;
+ Set<Class<?>> additionalinterfaces = persistenceProvider.getAdditionalSessionInterfaces();
+ Class<?>[] interfaces = new Class[additionalinterfaces.size() + 3];
+ int count = 0;
+ for (Class<?> i : additionalinterfaces)
+ {
+ interfaces[count++] = i;
+ }
+
+ interfaces[count++] = Session.class;
+ interfaces[count++] = Serializable.class;
+ interfaces[count++] = ManagedPersistenceContext.class;
+ proxyClass = Proxy.getProxyClass(loader, interfaces);
+ try
+ {
+ proxyConstructor = proxyClass.getConstructor(InvocationHandler.class);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ this.qualifiers = new Annotation[qualifiers.size()];
+ int i = 0;
+ for (Annotation a : qualifiers)
+ {
+ this.qualifiers[i++] = a;
+ }
+ }
+
+ /**
+ * creates the proxy
+ */
+ public Session create(Bean<Session> bean, CreationalContext<Session> arg0)
+ {
+ try
+ {
+ SessionFactory sf = getSessionFactory();
+ Session session = sf.openSession();
+ session = (Session) persistenceProvider.proxyDelegate(session);
+ HibernateManagedPersistenceContextProxyHandler handler = new HibernateManagedPersistenceContextProxyHandler(session, manager, bean.getQualifiers(), getPersistenceContexts(), persistenceProvider);
+ Session proxy = (Session) proxyConstructor.newInstance(handler);
+ ((ManagedPersistenceContext) proxy).changeFlushMode(getPersistenceContexts().getFlushMode());
+ manager.fireEvent(new SeamManagedHibernateSessionCreated(proxy), qualifiers);
+
+ return proxy;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void destroy(Bean<Session> bean, Session session, CreationalContext<Session> arg1)
+ {
+ ((ManagedPersistenceContext) session).closeAfterTransaction();
+ arg1.release();
+ try
+ {
+ getPersistenceContexts().untouch((ManagedPersistenceContext) session);
+ }
+ catch (ContextNotActiveException e)
+ {
+ log.debug("Could not untouch PersistenceContext as conversation scope not active");
+ }
+ }
+
+ private PersistenceContexts getPersistenceContexts()
+ {
+ if (persistenceContexts == null)
+ {
+ Bean<PersistenceContexts> bean = (Bean) manager.resolve(manager.getBeans(PersistenceContexts.class, DefaultLiteral.INSTANCE));
+ if (bean == null)
+ {
+ throw new RuntimeException("Could not find PersistenceContexts bean");
+ }
+ CreationalContext<PersistenceContexts> ctx = manager.createCreationalContext(bean);
+ persistenceContexts = (PersistenceContexts) manager.getReference(bean, PersistenceContexts.class, ctx);
+ }
+ return persistenceContexts;
+ }
+
+ /**
+ * lazily resolve the relevant EMF
+ */
+ protected SessionFactory getSessionFactory()
+ {
+ if (sessionFactory == null)
+ {
+ Bean<SessionFactory> bean = (Bean) manager.resolve(manager.getBeans(SessionFactory.class, qualifiers));
+ if (bean == null)
+ {
+ throw new RuntimeException("Could not find SessionFactory bean with qualifiers" + qualifiers);
+ }
+ CreationalContext<SessionFactory> ctx = manager.createCreationalContext(bean);
+ sessionFactory = (SessionFactory) manager.getReference(bean, SessionFactory.class, ctx);
+ }
+ return sessionFactory;
+ }
+
+}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextExtension.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextExtension.java 2010-09-03 03:53:49 UTC (rev 13716)
@@ -0,0 +1,199 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.hibernate;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+
+import org.hibernate.Session;
+import org.jboss.seam.persistence.HibernatePersistenceProvider;
+import org.jboss.seam.persistence.ManagedPersistenceContext;
+import org.jboss.seam.persistence.SeamManaged;
+import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
+import org.jboss.weld.extensions.bean.BeanBuilder;
+import org.jboss.weld.extensions.literal.AnyLiteral;
+import org.jboss.weld.extensions.literal.ApplicationScopedLiteral;
+import org.jboss.weld.extensions.literal.DefaultLiteral;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Extension the wraps producer methods/fields that produce an entity manager to
+ * turn them into Seam Managed Persistence Contexts.
+ *
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class HibernateManagedPersistenceContextExtension implements Extension
+{
+
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+
+ private static final Logger log = LoggerFactory.getLogger(HibernateManagedPersistenceContextExtension.class);
+
+ private final HibernatePersistenceProvider provider = new HibernatePersistenceProvider();
+
+ /**
+ * loops through the fields on an AnnotatedType looking for a SessionFactory
+ * producer that is annotated {@link SeamManaged}. Then a corresponding smpc
+ * bean is created and registered. The producers scope will be changed to
+ * ApplicationScoped (or @Dependent if it is created using resource
+ * injection) to ensure that the SMPC is only created once
+ *
+ */
+ public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> event, BeanManager manager)
+ {
+ AnnotatedTypeBuilder<T> modifiedType = null;
+ for (AnnotatedField<? super T> f : event.getAnnotatedType().getFields())
+ {
+ // look for a seam managed persistence unit declaration on EE resource
+ // producer fields
+ if (f.isAnnotationPresent(SeamManaged.class) && f.isAnnotationPresent(PersistenceUnit.class) && f.isAnnotationPresent(Produces.class) && EntityManagerFactory.class.isAssignableFrom(f.getJavaMember().getType()))
+ {
+ if (modifiedType == null)
+ {
+ modifiedType = new AnnotatedTypeBuilder().readFromType(event.getAnnotatedType());
+ }
+ Set<Annotation> qualifiers = new HashSet<Annotation>();
+ Class<? extends Annotation> scope = Dependent.class;
+ // get the qualifier and scope for the new bean
+ for (Annotation a : f.getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ else if (manager.isScope(a.annotationType()))
+ {
+ scope = a.annotationType();
+ }
+ }
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(new DefaultLiteral());
+ }
+ qualifiers.add(AnyLiteral.INSTANCE);
+ // we need to remove the scope, they are not nessesarily supported
+ // on producer fields
+ if (scope != Dependent.class)
+ {
+ modifiedType.removeFromField(f.getJavaMember(), scope);
+ }
+ registerManagedPersistenceContext(qualifiers, scope, manager, event.getAnnotatedType().getJavaClass().getClassLoader());
+ }
+ // now look for producer methods that produce an EntityManagerFactory.
+ // This allows the user to manually configure an EntityManagerFactory
+ // and return it from a producer method
+ }
+ // now look for SMPC's that are configured programatically via a producer
+ // method. This looks for both EMF's and SessionFactories
+ // The producer method has its scope changes to application scoped
+ // this allows for programatic config of the SMPC
+ for (AnnotatedMethod<? super T> m : event.getAnnotatedType().getMethods())
+ {
+ if (m.isAnnotationPresent(SeamManaged.class) && m.isAnnotationPresent(Produces.class) && EntityManagerFactory.class.isAssignableFrom(m.getJavaMember().getReturnType()))
+ {
+ if (modifiedType == null)
+ {
+ modifiedType = new AnnotatedTypeBuilder().readFromType(event.getAnnotatedType());
+ }
+ Set<Annotation> qualifiers = new HashSet<Annotation>();
+ Class<? extends Annotation> scope = Dependent.class;
+ // get the qualifier and scope for the new bean
+ for (Annotation a : m.getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ else if (manager.isScope(a.annotationType()))
+ {
+ scope = a.annotationType();
+ }
+ }
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(new DefaultLiteral());
+ }
+ qualifiers.add(AnyLiteral.INSTANCE);
+ // we need to change the scope to application scoped
+ modifiedType.removeFromMethod(m.getJavaMember(), scope);
+ modifiedType.addToMethod(m.getJavaMember(), ApplicationScopedLiteral.INSTANCE);
+ registerManagedPersistenceContext(qualifiers, scope, manager, event.getAnnotatedType().getJavaClass().getClassLoader());
+ }
+ }
+
+ if (modifiedType != null)
+ {
+ event.setAnnotatedType(modifiedType.create());
+ }
+ }
+
+ private void registerManagedPersistenceContext(Set<Annotation> qualifiers, Class<? extends Annotation> scope, BeanManager manager, ClassLoader loader)
+ {
+ // we need to add all additional interfaces from our
+ // SeamPersistenceProvider to the bean as at this stage we have no way of
+ // knowing which persistence provider is actually in use this only time
+ // that this may cause slightly odd behavior is if two providers are on
+ // the class path, in which case the entity manager may be assignable to
+ // additional interfaces that it does not support.
+ Set<Class<?>> additionalInterfaces = new HashSet<Class<?>>();
+
+ additionalInterfaces.addAll(provider.getAdditionalEntityManagerInterfaces());
+
+ // create the new bean to be registered later
+ HibernateManagedPersistenceContextBeanLifecycle lifecycle = new HibernateManagedPersistenceContextBeanLifecycle(qualifiers, loader, manager);
+ AnnotatedTypeBuilder<Session> typeBuilder = new AnnotatedTypeBuilder().setJavaClass(Session.class);
+ BeanBuilder<Session> builder = new BeanBuilder<Session>(manager).defineBeanFromAnnotatedType(typeBuilder.create());
+ builder.setQualifiers(qualifiers);
+ builder.setScope(scope);
+ builder.getTypes().add(ManagedPersistenceContext.class);
+ builder.getTypes().addAll(additionalInterfaces);
+ builder.getTypes().add(Object.class);
+ builder.setBeanLifecycle(lifecycle);
+ beans.add(builder.create());
+ }
+
+ public void afterBeanDiscovery(@Observes AfterBeanDiscovery event)
+ {
+ for (Bean<?> i : beans)
+ {
+ event.addBean(i);
+ }
+ }
+
+}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextProxyHandler.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/hibernate/HibernateManagedPersistenceContextProxyHandler.java 2010-09-03 03:53:49 UTC (rev 13716)
@@ -0,0 +1,209 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.hibernate;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+import org.hibernate.FlushMode;
+import org.hibernate.Session;
+import org.jboss.seam.persistence.FlushModeType;
+import org.jboss.seam.persistence.ManagedPersistenceContext;
+import org.jboss.seam.persistence.PersistenceContexts;
+import org.jboss.seam.persistence.SeamPersistenceProvider;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
+import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
+import org.jboss.seam.persistence.util.InstanceResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Proxy handler for the seam managed Hibernate session. This handler makes sure
+ * that the EntityManager is enrolled in the current transaction before passing
+ * the call through to the delegate
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class HibernateManagedPersistenceContextProxyHandler implements InvocationHandler, Serializable, Synchronization
+{
+
+ private static final long serialVersionUID = -6539267789786229774L;
+
+ private final Session delegate;
+
+ private final Instance<SeamTransaction> userTransactionInstance;
+
+ private transient boolean synchronizationRegistered;
+
+ private final PersistenceContexts persistenceContexts;
+
+ private final Set<Annotation> qualifiers;
+
+ private final SeamPersistenceProvider provider;
+
+ private boolean persistenceContextsTouched = false;
+
+ private boolean closeOnTransactionCommit = false;
+
+ static final Logger log = LoggerFactory.getLogger(HibernateManagedPersistenceContextProxyHandler.class);
+
+ public HibernateManagedPersistenceContextProxyHandler(Session delegate, BeanManager beanManager, Set<Annotation> qualifiers, PersistenceContexts persistenceContexts, SeamPersistenceProvider provider)
+ {
+ this.qualifiers = qualifiers;
+ this.provider = provider;
+ this.delegate = delegate;
+ this.userTransactionInstance = InstanceResolver.getInstance(SeamTransaction.class, beanManager, DefaultTransactionLiteral.INSTANCE);
+ this.persistenceContexts = persistenceContexts;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ if (!synchronizationRegistered)
+ {
+ joinTransaction();
+ }
+ touch((ManagedPersistenceContext) proxy);
+ if ("changeFlushMode".equals(method.getName()) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(FlushModeType.class))
+ {
+ changeFushMode((FlushModeType) args[0]);
+ return null;
+ }
+ if ("getBeanType".equals(method.getName()) && method.getParameterTypes().length == 0)
+ {
+ return EntityManager.class;
+ }
+ if ("getQualifiers".equals(method.getName()) && method.getParameterTypes().length == 0)
+ {
+ return Collections.unmodifiableSet(qualifiers);
+ }
+ if ("getPersistenceProvider".equals(method.getName()) && method.getParameterTypes().length == 0)
+ {
+ return provider;
+ }
+ if ("closeAfterTransaction".equals(method.getName()) && method.getParameterTypes().length == 0)
+ {
+ closeAfterTransaction();
+ return null;
+ }
+ return method.invoke(delegate, args);
+ }
+
+ private void joinTransaction() throws SystemException
+ {
+ SeamTransaction transaction = userTransactionInstance.get();
+ if (transaction.isActive())
+ {
+ delegate.isOpen();
+ try
+ {
+ transaction.registerSynchronization(this);
+ synchronizationRegistered = true;
+ }
+ catch (Exception e)
+ {
+ // synchronizationRegistered =
+ // PersistenceProvider.instance().registerSynchronization(this,
+ // entityManager);
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ private void closeAfterTransaction() throws SystemException
+ {
+ SeamTransaction transaction = userTransactionInstance.get();
+ if (transaction.isActive())
+ {
+ closeOnTransactionCommit = true;
+ }
+ else
+ {
+ if (delegate.isOpen())
+ {
+ delegate.close();
+ }
+ }
+ }
+
+ private void changeFushMode(FlushModeType flushModeType)
+ {
+ switch (flushModeType)
+ {
+ case AUTO:
+ delegate.setFlushMode(FlushMode.AUTO);
+ break;
+ case MANUAL:
+ delegate.setFlushMode(FlushMode.MANUAL);
+ break;
+ case COMMIT:
+ delegate.setFlushMode(FlushMode.COMMIT);
+ break;
+ default:
+ throw new RuntimeException("Unkown flush mode: " + flushModeType);
+ }
+ }
+
+ void touch(ManagedPersistenceContext delegate)
+ {
+ if (!persistenceContextsTouched)
+ {
+ try
+ {
+ // we need to do this first to prevent an infinite loop
+ persistenceContextsTouched = true;
+ persistenceContexts.touch(delegate);
+ }
+ catch (ContextNotActiveException e)
+ {
+ persistenceContextsTouched = false;
+ log.debug("Not touching pc " + this + "as conversation scope not active");
+ }
+ }
+ }
+
+ public void afterCompletion(int status)
+ {
+ synchronizationRegistered = false;
+ if (closeOnTransactionCommit && delegate.isOpen())
+ {
+ delegate.close();
+ }
+ }
+
+ public void beforeCompletion()
+ {
+
+ }
+
+}
Modified: modules/persistence/trunk/pom.xml
===================================================================
--- modules/persistence/trunk/pom.xml 2010-09-03 01:01:19 UTC (rev 13715)
+++ modules/persistence/trunk/pom.xml 2010-09-03 03:53:49 UTC (rev 13716)
@@ -29,6 +29,7 @@
<module>api</module>
<module>impl</module>
<module>tests-base</module>
+ <module>tests-weld-se</module>
</modules>
<properties>
@@ -114,6 +115,13 @@
<artifactId>arquillian-jbossas-remote-6</artifactId>
<version>${arquillian.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-se-embedded-1</artifactId>
+ <version>${arquillian.version}</version>
+ </dependency>
+
<!-- Jboss dependencies -->
<dependency>
<groupId>org.jboss.jbossas</groupId>
@@ -128,7 +136,7 @@
<type>pom</type>
</dependency>
</dependencies>
-
+
</dependencyManagement>
<profiles>
More information about the seam-commits
mailing list