[seam-commits] Seam SVN: r13665 - in modules/persistence/trunk/impl/src: test/java/org/jboss/seam/persistence/test and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Aug 30 05:35:25 EDT 2010
Author: swd847
Date: 2010-08-30 05:35:25 -0400 (Mon, 30 Aug 2010)
New Revision: 13665
Added:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamPersistenceProvider.java
Log:
add ability to set the default flush mode for the SMPC
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java 2010-08-30 08:54:49 UTC (rev 13664)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java 2010-08-30 09:35:25 UTC (rev 13665)
@@ -31,5 +31,11 @@
*/
public interface FlushModeManager
{
+ /**
+ *
+ * @return the default flush mode for all seam managed persistence contexts
+ */
public FlushModeType getFlushModeType();
+
+ public void setFlushModeType(FlushModeType flushModeType);
}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2010-08-30 08:54:49 UTC (rev 13664)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2010-08-30 09:35:25 UTC (rev 13665)
@@ -50,8 +50,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
- log.info("no Hibernate Search", e);
+ log.debug("no Hibernate Search", e);
}
if (version != null)
{
@@ -81,8 +80,7 @@
}
catch (Exception e)
{
- e.printStackTrace();
- log.info("no Hibernate Search", e);
+ log.debug("no Hibernate Search", e);
}
}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-08-30 08:54:49 UTC (rev 13664)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-08-30 09:35:25 UTC (rev 13665)
@@ -106,6 +106,7 @@
entityManager = getPersistenceProvider().proxyEntityManager(entityManager);
ManagedPersistenceContextProxyHandler handler = new ManagedPersistenceContextProxyHandler(entityManager, manager, bean.getQualifiers(), getPersistenceContexts());
EntityManager proxy = (EntityManager) proxyConstructor.newInstance(handler);
+ getPersistenceProvider().setFlushMode(proxy, getPersistenceContexts().getFlushMode());
return proxy;
}
catch (Exception e)
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-08-30 08:54:49 UTC (rev 13664)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-08-30 09:35:25 UTC (rev 13665)
@@ -40,6 +40,8 @@
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.BeanBuilder;
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
@@ -54,6 +56,8 @@
Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ private static final Logger log = LoggerFactory.getLogger(ManagedPersistenceContextExtension.class);
+
/**
* loops through the fields on an AnnotatedType looking for a @PersistnceUnit
* producer field that is annotated {@link SeamManaged}. Then a corresponding
@@ -126,6 +130,7 @@
catch (ClassNotFoundException e)
{
event.veto();
+ log.debug("Hibernate is not availbile", e);
}
}
}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamPersistenceProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamPersistenceProvider.java 2010-08-30 08:54:49 UTC (rev 13664)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamPersistenceProvider.java 2010-08-30 09:35:25 UTC (rev 13665)
@@ -106,8 +106,10 @@
break;
case COMMIT:
entityManager.setFlushMode(javax.persistence.FlushModeType.COMMIT);
+ break;
case MANUAL:
setFlushModeManual(entityManager);
+ break;
default:
throw new RuntimeException("Unkown flush mode: " + type);
}
Added: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextFlushModeTest.java 2010-08-30 09:35:25 UTC (rev 13665)
@@ -0,0 +1,89 @@
+/*
+ * 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.test;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import junit.framework.Assert;
+
+import org.hibernate.FlushMode;
+import org.hibernate.Session;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.FlushModeManager;
+import org.jboss.seam.persistence.PersistenceContextExtension;
+import org.jboss.seam.persistence.transaction.FlushModeType;
+import org.jboss.seam.persistence.transaction.TransactionExtension;
+import org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension;
+import org.jboss.seam.persistence.util.NamingUtils;
+import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.HelloService;
+import org.jboss.seam.transactions.test.util.Hotel;
+import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
+import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class ManagedPersistenceContextFlushModeTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
+ war.addPackage(TransactionExtension.class.getPackage());
+ war.addPackage(PersistenceContextExtension.class.getPackage());
+ war.addPackage(TransactionScopeExtension.class.getPackage());
+ war.addPackage(NamingUtils.class.getPackage());
+ war.addClasses(ManagedPersistenceContextFlushModeTest.class, Hotel.class, ManagedPersistenceContextProvider.class, HelloService.class);
+ war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
+ war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
+ return war;
+ }
+
+ @Inject
+ FlushModeManager manager;
+
+ @Inject
+ EntityManager em;
+
+ @Test
+ public void testPersistnceContextFlushMode() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
+ {
+ manager.setFlushModeType(FlushModeType.MANUAL);
+ Assert.assertEquals(FlushMode.MANUAL, ((Session) em.getDelegate()).getFlushMode());
+ }
+
+}
More information about the seam-commits
mailing list