[jboss-cvs] JBossAS SVN: r82795 - in projects/ejb3/trunk/docs/tutorial: cachedentity and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 13 05:03:57 EST 2009
Author: jaikiran
Date: 2009-01-13 05:03:57 -0500 (Tue, 13 Jan 2009)
New Revision: 82795
Added:
projects/ejb3/trunk/docs/tutorial/cachedentity/
projects/ejb3/trunk/docs/tutorial/cachedentity/META-INF/
projects/ejb3/trunk/docs/tutorial/cachedentity/META-INF/persistence.xml
projects/ejb3/trunk/docs/tutorial/cachedentity/build.xml
projects/ejb3/trunk/docs/tutorial/cachedentity/jndi.properties
projects/ejb3/trunk/docs/tutorial/cachedentity/log4j.xml
projects/ejb3/trunk/docs/tutorial/cachedentity/pom.xml
projects/ejb3/trunk/docs/tutorial/cachedentity/src/
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Contact.java
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Customer.java
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTest.java
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTestBean.java
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/client/
projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/client/CachedEntityRun.java
Log:
Working version of the CachedEntity tutorial for JBossAS-5.0 GA
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/META-INF/persistence.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/META-INF/persistence.xml (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/META-INF/persistence.xml 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+ version="1.0">
+ <persistence-unit name="tempdb">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.cache.use_second_level_cache" value="true"/>
+ <property name="hibernate.cache.use_query_cache" value="true"/>
+ <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"/>
+ <property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager"/>
+ <property name="hibernate.cache.region.jbc2.cfg.entity" value="mvcc-entity"/>
+ <property name="hibernate.cache.region.jbc2.cfg.query" value="local-query"/>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <property name="hibernate.show_sql" value="true"/>
+ </properties>
+
+ </persistence-unit>
+</persistence>
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/build.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/build.xml (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/build.xml 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,101 @@
+<?xml version="1.0"?>
+
+<!-- ======================================================================= -->
+<!-- JBoss build file -->
+<!-- ======================================================================= -->
+
+<project name="JBoss" default="ejbjar" basedir=".">
+
+ <property environment="env"/>
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="jboss.home" value="${env.JBOSS_HOME}"/>
+ <property name="jboss.server.config" value="all"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="build.artifact" value="jboss-ejb3-tutorial-cachedentity.jar"/>
+
+ <!-- Build classpath -->
+ <path id="classpath">
+ <!-- So that we can get jndi.properties for InitialContext -->
+ <pathelement location="${basedir}"/>
+ <!-- Only the jbossall-client.jar should ideally be sufficient -->
+ <fileset dir="${jboss.home}/client">
+ <include name="**/jbossall-client.jar"/>
+ </fileset>
+ <!-- Hibernate core classes -->
+ <fileset dir="${jboss.home}/common/lib">
+ <include name="hibernate-core.jar"/>
+ </fileset>
+ <fileset dir="${jboss.home}/server/${jboss.server.config}/lib">
+ <include name="**/*.jar"/>
+ </fileset>
+ <pathelement location="${build.classes.dir}"/>
+ </path>
+
+ <property name="build.classpath" refid="classpath"/>
+
+ <!-- =================================================================== -->
+ <!-- Prepares the build directory -->
+ <!-- =================================================================== -->
+ <target name="prepare">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.classes.dir}"/>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the source code -->
+ <!-- =================================================================== -->
+ <target name="compile" depends="prepare">
+ <javac srcdir="${src.dir}"
+ destdir="${build.classes.dir}"
+ debug="on"
+ deprecation="on"
+ optimize="off"
+ includes="**">
+ <classpath refid="classpath"/>
+ </javac>
+ </target>
+
+ <target name="ejbjar" depends="compile">
+ <jar jarfile="build/${build.artifact}">
+ <fileset dir="${build.classes.dir}">
+ <include name="**/*.class"/>
+ </fileset>
+ <fileset dir=".">
+ <include name="META-INF/*.*"/>
+ </fileset>
+
+ </jar>
+ <copy file="build/${build.artifact}" todir="${jboss.home}/server/${jboss.server.config}/deploy"/>
+ </target>
+
+ <target name="run" depends="ejbjar">
+ <java classname="org.jboss.tutorial.cachedentity.client.CachedEntityRun" fork="yes" dir=".">
+ <!-- node 1 -->
+ <arg value="localhost:1099"/>
+ <!--<arg value="192.168.1.1:1099"/>-->
+
+ <!-- node 2 -->
+ <arg value="localhost:1099"/>
+ <!--<arg value="192.168.1.2:1099"/>-->
+
+ <classpath refid="classpath"/>
+ </java>
+ </target>
+
+
+ <!-- =================================================================== -->
+ <!-- Cleans up generated stuff -->
+ <!-- =================================================================== -->
+ <target name="clean.db">
+ <delete dir="${jboss.home}/server/${jboss.server.config}/data/hypersonic"/>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build.dir}"/>
+ <delete file="${jboss.home}/server/${jboss.server.config}/deploy/${build.artifact}"/>
+ </target>
+
+
+</project>
+
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/build.xml
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/jndi.properties
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/jndi.properties (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/jndi.properties 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,4 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+java.naming.provider.url=localhost
+
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/jndi.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/log4j.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/log4j.xml (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/log4j.xml 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 32809 2005-06-24 04:49:29Z bill $ -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
+ <param name="Target" value="System.out"/>
+ <param name="Threshold" value="INFO"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Messagen -->
+ <!--
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+ -->
+ <param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L) -%m%n"/>
+ </layout>
+</appender>
+
+ <root>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/log4j.xml
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/pom.xml
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/pom.xml (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/pom.xml 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+
+
+
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-tutorial-common</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../common/</relativePath>
+ </parent>
+
+ <properties>
+ <ejb3.tutorial.client>org.jboss.tutorial.cachedentity.client.CachedEntityRun</ejb3.tutorial.client>
+ <!-- Pass the IP:port to the client -->
+ <jboss.ejb3.tutorial.client.args>localhost:1099 localhost:1099</jboss.ejb3.tutorial.client.args>
+ </properties>
+
+
+ <artifactId>jboss-ejb3-tutorial-cachedentity</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Caching of EJB3 Entities in JBoss</name>
+ <url>http://labs.jboss.com/jbossejb3/</url>
+ <description>
+ Tutorial showing caching of EJB3 entities in JBoss
+ </description>
+
+
+</project>
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/pom.xml
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Contact.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Contact.java (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Contact.java 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,97 @@
+/*
+ * 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.tutorial.cachedentity.bean;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.PostLoad;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+
+/**
+ *
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision$
+ */
+ at Entity
+ at Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)
+public class Contact implements Serializable
+{
+ Long id;
+ String name;
+ String tlf;
+ Customer customer;
+
+ public Contact()
+ {
+
+ }
+
+ @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long long1)
+ {
+ id = long1;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getTlf()
+ {
+ return tlf;
+ }
+
+ public void setTlf(String tlf)
+ {
+ this.tlf = tlf;
+ }
+
+ @ManyToOne
+ @JoinColumn(name="CUST_ID")
+ public Customer getCustomer()
+ {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer)
+ {
+ this.customer = customer;
+ }
+
+}
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Contact.java
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Customer.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Customer.java (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Customer.java 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,91 @@
+/*
+ * 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.tutorial.cachedentity.bean;
+
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.PostLoad;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+
+/**
+ * Company customer
+ *
+ * @author Emmanuel Bernard
+ * @author Kabir Khan
+ */
+ at Entity
+ at Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)
+public class Customer implements java.io.Serializable
+{
+ Long id;
+ String name;
+ private Set<Contact> contacts;
+
+ public Customer()
+ {
+ }
+
+ @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long long1)
+ {
+ id = long1;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String string)
+ {
+ name = string;
+ }
+
+ @Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)
+ @OneToMany(mappedBy="customer", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
+ public Set<Contact> getContacts()
+ {
+ return contacts;
+ }
+
+ public void setContacts(Set<Contact> contacts)
+ {
+ this.contacts = contacts;
+ }
+
+}
+
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/Customer.java
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTest.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTest.java (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTest.java 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,37 @@
+/*
+ * 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.tutorial.cachedentity.bean;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public interface EntityTest
+{
+ Customer createCustomer();
+
+ Customer findByCustomerId(Long id);
+
+
+}
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTest.java
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTestBean.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTestBean.java (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTestBean.java 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,86 @@
+/*
+ * 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.tutorial.cachedentity.bean;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+ at Stateless
+ at Remote(EntityTest.class)
+public class EntityTestBean implements EntityTest
+{
+ @PersistenceContext
+ private EntityManager manager;
+
+ /**
+ * Logger
+ */
+ private Logger logger = Logger.getLogger(EntityTestBean.class);
+
+ public Customer createCustomer()
+ {
+ Customer customer = new Customer();
+ customer.setName("JBoss");
+
+ Set<Contact> contacts = new HashSet<Contact>();
+ Contact kabir = new Contact();
+ kabir.setCustomer(customer);
+ kabir.setName("Kabir");
+ kabir.setTlf("1111");
+ contacts.add(kabir);
+
+ Contact bill = new Contact();
+ bill.setCustomer(customer);
+ bill.setName("Bill");
+ bill.setTlf("2222");
+ contacts.add(bill);
+
+ customer.setContacts(contacts);
+ manager.persist(customer);
+ logger.info("Created customer named " + customer.getName() + " with " + customer.getContacts().size() + " contacts");
+ return customer;
+ }
+
+ public Customer findByCustomerId(Long id)
+ {
+ logger.info("Find customer with id = " + id);
+ Customer customer = manager.find(Customer.class, id);
+ logger.info("Customer with id = " + id + " found");
+ return customer;
+ }
+
+
+
+}
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/bean/EntityTestBean.java
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/client/CachedEntityRun.java
===================================================================
--- projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/client/CachedEntityRun.java (rev 0)
+++ projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/client/CachedEntityRun.java 2009-01-13 10:03:57 UTC (rev 82795)
@@ -0,0 +1,86 @@
+/*
+ * 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.tutorial.cachedentity.client;
+
+import java.util.Properties;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.tutorial.cachedentity.bean.Contact;
+import org.jboss.tutorial.cachedentity.bean.Customer;
+import org.jboss.tutorial.cachedentity.bean.EntityTest;
+
+/**
+ *
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class CachedEntityRun
+{
+ public static void main(String[] args)throws NamingException
+ {
+ if (args.length != 2)
+ {
+ throw new RuntimeException("You need to pass in two parameters of the type ipaddress:port");
+ }
+
+ Properties prop1 = new Properties();
+ prop1.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ prop1.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+ prop1.put("java.naming.provider.url", "jnp://" + args[0]);
+
+ Properties prop2 = new Properties();
+ prop2.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ prop2.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+ prop2.put("java.naming.provider.url", "jnp://" + args[1]);
+
+ System.out.println("Saving customer to node1 = " + args[0]);
+ InitialContext ctx1 = new InitialContext(prop1);
+
+ EntityTest tester1 = (EntityTest)ctx1.lookup("EntityTestBean/remote");
+ Customer customer = tester1.createCustomer();
+ customer = tester1.findByCustomerId(customer.getId());
+
+ System.out.println("Looking for customer on node2 = " + args[1] + " (should be available in cache)");
+ InitialContext ctx2 = new InitialContext(prop2);
+
+ EntityTest tester2 = (EntityTest)ctx2.lookup("EntityTestBean/remote");
+
+ Set<Contact> contacts = customer.getContacts();
+
+ customer = tester2.findByCustomerId(customer.getId());
+ if (customer == null)
+ {
+ throw new RuntimeException("Customer was not found in node2 = " + args[1]);
+ }
+ System.out.println("Found customer on node2 (cache). Customer details follow:");
+ System.out.println("Customer: id=" + customer.getId() + "; name=" + customer.getName());
+
+ for (Contact contact : contacts)
+ {
+ System.out.println("\tContact: id=" + contact.getId() + "; name=" + contact.getName());
+ }
+
+ }
+}
Property changes on: projects/ejb3/trunk/docs/tutorial/cachedentity/src/org/jboss/tutorial/cachedentity/client/CachedEntityRun.java
___________________________________________________________________
Name: svn:executable
+ *
More information about the jboss-cvs-commits
mailing list