[jboss-cvs] JBossAS SVN: r62188 - in branches/Branch_4_2/ejb3/src: test/org/jboss/ejb3/test/clusteredentity and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 9 13:09:00 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-04-09 13:09:00 -0400 (Mon, 09 Apr 2007)
New Revision: 62188
Added:
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/OptimisticBulkOperationsUnitTestCase.java
Modified:
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/entity/TreeCacheProviderHook.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java
Log:
[EJBTHREE-940] Ensure bulk operations work properly
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/entity/TreeCacheProviderHook.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/entity/TreeCacheProviderHook.java 2007-04-09 15:03:37 UTC (rev 62187)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/entity/TreeCacheProviderHook.java 2007-04-09 17:09:00 UTC (rev 62188)
@@ -28,6 +28,7 @@
import org.hibernate.cache.Cache;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CacheProvider;
+import org.jboss.cache.TreeCache;
import org.jboss.cache.TreeCacheMBean;
import org.jboss.ejb3.tx.TxUtil;
import org.jboss.logging.Logger;
@@ -47,7 +48,9 @@
* @author Gavin King
* @author Brian Stansberry
*/
-public class TreeCacheProviderHook implements CacheProvider
+public class TreeCacheProviderHook
+ extends org.hibernate.cache.TreeCacheProvider
+ implements CacheProvider
{
/**
* Name of the Hibernate configuration property used to provide
@@ -144,4 +147,9 @@
return optimistic;
}
+ public TreeCache getUnderlyingCache()
+ {
+ return cache;
+ }
+
}
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java 2007-04-09 17:09:00 UTC (rev 62188)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.clusteredentity;
+
+import java.util.List;
+
+/**
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public interface BulkOperationsTest
+{
+ void createContacts();
+
+ int deleteContacts();
+
+ int updateContacts(String name, String newTLF);
+
+ List<Integer> getContactsByCustomer(String customerName);
+
+ List<Integer> getContactsByTLF(String tlf);
+
+ Contact getContact(Integer id);
+
+ void remove();
+}
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java 2007-04-09 17:09:00 UTC (rev 62188)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.clusteredentity;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.FlushModeType;
+import javax.persistence.PersistenceContext;
+
+/**
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+ at Stateless
+ at Remote(BulkOperationsTest.class)
+public class BulkOperationsTestBean implements BulkOperationsTest
+{
+ @PersistenceContext
+ private EntityManager manager;
+
+
+ public void createContacts()
+ {
+ for (int i = 0; i < 10; i++)
+ createCustomer(i);
+ }
+
+ public int deleteContacts()
+ {
+ String deleteHQL = "delete Contact where customer in ";
+ deleteHQL += " (select customer FROM Customer as customer ";
+ deleteHQL += " where customer.name = :cName)";
+
+ int rowsAffected = manager.createQuery(deleteHQL)
+ .setFlushMode(FlushModeType.AUTO)
+ .setParameter("cName", "Red Hat")
+ .executeUpdate();
+ return rowsAffected;
+ }
+
+ public List<Integer> getContactsByCustomer(String customerName)
+ {
+ String selectHQL = "select contact.id from Contact contact";
+ selectHQL += " where contact.customer.name = :cName";
+
+ List results = manager.createQuery(selectHQL)
+ .setFlushMode(FlushModeType.AUTO)
+ .setParameter("cName", customerName)
+ .getResultList();
+
+ return results;
+ }
+
+ public List<Integer> getContactsByTLF(String tlf)
+ {
+ String selectHQL = "select contact.id from Contact contact";
+ selectHQL += " where contact.tlf = :cTLF";
+
+ List results = manager.createQuery(selectHQL)
+ .setFlushMode(FlushModeType.AUTO)
+ .setParameter("cTLF", tlf)
+ .getResultList();
+
+ return results;
+ }
+
+ public int updateContacts(String name, String newTLF)
+ {
+ String updateHQL = "update Contact set tlf = :cNewTLF where name = :cName";
+
+ int rowsAffected = manager.createQuery(updateHQL)
+ .setFlushMode(FlushModeType.AUTO)
+ .setParameter("cNewTLF", newTLF)
+ .setParameter("cName", name)
+ .executeUpdate();
+ return rowsAffected;
+ }
+
+ public Contact getContact(Integer id)
+ {
+ return manager.find(Contact.class, id);
+ }
+
+ @Remove
+ public void remove()
+ {
+
+ }
+
+ private Customer createCustomer(int id)
+ {
+ System.out.println("CREATE CUSTOMER " + id);
+ try
+ {
+ Customer customer = new Customer();
+ customer.setId(id);
+ customer.setName((id % 2 == 0) ? "JBoss" : "Red Hat");
+ Set<Contact> contacts = new HashSet<Contact>();
+
+ Contact kabir = new Contact();
+ kabir.setId(1000 + id);
+ kabir.setCustomer(customer);
+ kabir.setName("Kabir");
+ kabir.setTlf("1111");
+ contacts.add(kabir);
+
+ Contact bill = new Contact();
+ bill.setId(2000 +id);
+ bill.setCustomer(customer);
+ bill.setName("Bill");
+ bill.setTlf("2222");
+ contacts.add(bill);
+
+ customer.setContacts(contacts);
+
+ manager.persist(customer);
+ return customer;
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ System.out.println("CREATE CUSTOMER " + id + " - END");
+ }
+ }
+
+}
Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java 2007-04-09 15:03:37 UTC (rev 62187)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java 2007-04-09 17:09:00 UTC (rev 62188)
@@ -43,7 +43,7 @@
Integer id;
String name;
- private Set<Contact> contacts;
+ private transient Set<Contact> contacts;
public Customer()
{
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java 2007-04-09 17:09:00 UTC (rev 62188)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.clusteredentity.unit;
+
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.clusteredentity.BulkOperationsTest;
+import org.jboss.ejb3.test.clusteredentity.Contact;
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * Sample client for the jboss container.
+ *
+ * @author Brian Stansberry
+ * @version $Id: EntityUnitTestCase.java 60697 2007-02-20 05:08:31Z bstansberry at jboss.com $
+ */
+public class BulkOperationsUnitTestCase
+extends JBossClusteredTestCase
+{
+ public BulkOperationsUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBulkOperations() throws Exception
+ {
+ System.out.println("*** testBulkOperations()");
+ String node0 = System.getProperty("jbosstest.cluster.node0");
+
+ Properties prop0 = new Properties();
+ prop0.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ prop0.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+ prop0.put("java.naming.provider.url", "jnp://" + node0 + ":1099");
+
+ System.out.println("===== Node0 properties: ");
+ System.out.println(prop0);
+
+ System.out.println("Lookup node 0");
+ InitialContext ctx0 = new InitialContext(prop0);
+
+ BulkOperationsTest tester = (BulkOperationsTest) ctx0.lookup("BulkOperationsTestBean/remote");
+
+ try
+ {
+ tester.createContacts();
+
+ List<Integer> rhContacts = tester.getContactsByCustomer("Red Hat");
+ assertNotNull("Red Hat contacts exist", rhContacts);
+ assertEquals("Created expected number of Red Hat contacts", 10, rhContacts.size());
+
+ assertEquals("Deleted all Red Hat contacts", 10, tester.deleteContacts());
+
+ List<Integer> jbContacts = tester.getContactsByCustomer("JBoss");
+ assertNotNull("JBoss contacts exist", jbContacts);
+ assertEquals("JBoss contacts remain", 10, jbContacts.size());
+
+ for (Integer id : rhContacts)
+ {
+ assertNull("Red Hat contact " + id + " cannot be retrieved",
+ tester.getContact(id));
+ }
+ rhContacts = tester.getContactsByCustomer("Red Hat");
+ if (rhContacts != null)
+ {
+ assertEquals("No Red Hat contacts remain", 0, rhContacts.size());
+ }
+
+ tester.updateContacts("Kabir", "Updated");
+ for (Integer id : jbContacts)
+ {
+ Contact contact = tester.getContact(id);
+ assertNotNull("JBoss contact " + id + " exists", contact);
+ String expected = ("Kabir".equals(contact.getName())) ? "Updated" : "2222";
+ assertEquals("JBoss contact " + id + " has correct TLF",
+ expected, contact.getTlf());
+ }
+
+ List<Integer> updated = tester.getContactsByTLF("Updated");
+ assertNotNull("Got updated contacts", updated);
+ assertEquals("Updated contacts", 5, updated.size());
+ }
+ finally
+ {
+ // cleanup the db so we can run this test multiple times w/o restarting the cluster
+ tester.remove();
+ }
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(BulkOperationsUnitTestCase.class, "clusteredentity-test.jar");
+ }
+}
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/OptimisticBulkOperationsUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/OptimisticBulkOperationsUnitTestCase.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/OptimisticBulkOperationsUnitTestCase.java 2007-04-09 17:09:00 UTC (rev 62188)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.clusteredentity.unit;
+
+import junit.framework.Test;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class OptimisticBulkOperationsUnitTestCase
+ extends BulkOperationsUnitTestCase
+{
+
+ /**
+ * @param name
+ */
+ public OptimisticBulkOperationsUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(OptimisticBulkOperationsUnitTestCase.class,
+ "optimistic-entity-cache-service.xml, clusteredentity-optimistic-test.jar");
+ }
+
+}
More information about the jboss-cvs-commits
mailing list