From: Vance K. <va...@us...> - 2006-03-20 08:51:48
|
User: vancek Date: 06/03/20 00:51:46 Added: andromda-ejb3/src/site/xdoc howto17.xml Log: initial revision Revision Changes Path 1.1 cartridges/andromda-ejb3/src/site/xdoc/howto17.xml Index: howto17.xml =================================================================== <?xml version="1.0" encoding="iso-8859-1"?> <document> <properties> <author email="va...@us...">Vance Karimi</author> <title>AndroMDA - EJB3 - HowTo Caching and Clustering</title> </properties> <body> <section name="Caching and Clustering"> <p> This howto will guide you to use the EJB3 cartridge caching and clustering facilities, based on the JBoss distributed/clustered caching environment. </p> <p> <i> JBoss Cache supports a high performance, in-memory, transactional, and replicated cache for the cluster. </i> </p> <p> JBoss Cache has 2 types of caching </p> <p> <ul> <li> <b>Entity Cache</b> - caching database objects like entity POJOs and query results. <ul> <li>POJOs are cached in-memory.</li> <li>Reduces round trips to the database server.</li> <li> Access by one node in the cluster makes the POJO available to all nodes via the distributed entity cache. </li> </ul> </li> <li> <b>State Cache</b> - stores application state information. <ul> <li>HTTP session state can be cached and accessed across all nodes.</li> <li>Caching includes stateful session beans.</li> <li>Can cache <i>transient</i> properties across nodes</li> </ul> </li> </ul> </p> <p> The following example was taken from the manageable entities howto with the caching options enabled. The manageable components are not relevent here and will not be discussed. </p> <p> <img src="images/org/andromda/test/17/a/uml.gif"/> </p> <p> <ul> <li class="gen">Auto-generated source that does not need manual editing</li> <li class="impl">Auto-generated source that should be edited manually</li> <li class="changed">File that is affected by the modifications applied in this section</li> </ul> </p> <p> <ul> <li class="gen"><a class="changed" href="src/org/andromda/test/howto17/a/CarEmbeddable.java.txt"><code>CarEmbeddable.java</code></a></li> <li class="impl"><a href="src/org/andromda/test/howto17/a/Car.java.txt"><code>Car.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/CarType.java.txt"><code>CarType.java</code></a></li> <li class="gen"><a class="changed" href="src/org/andromda/test/howto17/a/PersonEmbeddable.java.txt"><code>PersonEmbeddable.java</code></a></li> <li class="impl"><a href="src/org/andromda/test/howto17/a/Person.java.txt"><code>Person.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/ServiceLocator.java.txt"><code>ServiceLocator.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/RentalServiceBean.java.txt"><code>RentalServiceBean.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/RentalServiceRemote.java.txt"><code>RentalServiceRemote.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/RentalServiceDelegate.java.txt"><code>RentalServiceDelegate.java</code></a></li> <li class="impl"><a href="src/org/andromda/test/howto17/a/RentalServiceBeanImpl.java.txt"><code>RentalServiceBeanImpl.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/RentalServiceException.java.txt"><code>RentalServiceException.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/RentalException.java.txt"><code>RentalException.java</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/ejb-jar.xml.txt"><code>ejb-jar.xml</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/jboss.xml.txt"><code>jboss.xml</code></a></li> <li class="gen"><a href="src/org/andromda/test/howto17/a/persistence.xml.txt"><code>persistence.xml</code></a></li> <li class="gen"><a class="changed" href="src/org/andromda/test/howto17/a/ejb3-entity-cache-service.xml.txt"><code>ejb3-entity-cache-service.xml</code></a></li> </ul> </p> <a name="Cache_Config"/> <subsection name="Cache Configuration"> <p> The cartridge allows you to configure a few caching properties through namespace properties in the andromda.xml descriptor. As a minimum, make sure the <code>hibernateCacheProvider</code> and <code>hibernateTreecacheMbeanObject</code> properties are defined to use inbuilt JBoss Cache with JBoss. <source language="xml"><![CDATA[ <namespace name="ejb3"> <properties> ... <property name="hibernateCacheProvider">org.jboss.ejb3.entity.TreeCacheProviderHook</property> <property name="hibernateTreecacheMbeanObject">jboss.cache:service=EJB3EntityTreeCache</property> <!-- uncomment to enable default entity cache settings <property name="hibernateEntityCache">TRANSACTIONAL</property> --> <!-- uncomment to enable default association caching configuration <property name="hibernateAssociationCache">TRANSACTIONAL</property> --> ... </properties> </namespace> ]]></source> The <code>hibernateEntityCache</code> and <code>hibernateAssociationCache</code> properties define the default cache settings if you choose to enable entity and association caching. </p> <p> Your <code>persistence.xml</code> descriptor will look like: <source language="xml"><![CDATA[ <?xml version="1.0" encoding="UTF-8"?> <!-- Attention: Generated code! Do not modify by hand! Generated by: persistence.xml.vsl in andromda-ejb3-cartridge. --> <persistence> <persistence-unit name="howtomodel2"> <jta-data-source>java:/jdbc/howtomodel2</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/> <property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook"/> <property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache"/> </properties> </persistence-unit> </persistence> ]]></source> </p> </subsection> <a name="Entity_Cache"/> <subsection name="Entity Cache"> <p> In situations where data, persisted by entity beans are rarely changed, you can employ the entity cache option to avoid unnecessary round-trips to the database. </p> <p> To enable entity caching, you enable the <code>hibernateEnableCache</code> ejb3 namespace property in your andromda.xml like so: <source language="xml"><![CDATA[ <namespace name="ejb3"> <properties> ... <property name="hibernateEnableCache">true</property> <property name="useDefaultCacheRegion">false</property> ... </properties> </namespace> ]]></source> </p> <p> The <code>useDefaultCacheRegion</code> property allows you to specify whether you want all entities use the default cache region specified in <code>ejb3-entity-cache-service.xml</code>. By default, this is set to <code>false</code>. If you set to <code>true</code>, the user specified cache regions for entities will not be defined. </p> <p> If you enable the default entity cache strategy in your andromda.xml descriptor, by enabling <code>hibernateEntityCache</code>, then the cache strategy for all entities will be assigned using its specified value. To override this default value, you can model the <code>@andromda.persistence.entity.cache</code> tagged value on individual entities. </p> <p> Once you have enabled entity caching, you will notice the <code>@org.hibernate.annotations.Cache</code> annotation at the class level in all entity mapped superclasses. </p> <p> The corresponding entity cache region is defined in the <code>ejb3-entity-cache-service.xml</code> configuration service file for the <code>Car</code> and <code>Person</code> entities: <source language="xml"><![CDATA[ .... <!-- The Car entity cache --> <region name="/org/andromda/howto2/rental/Car"> <attribute name="maxNodes">10000</attribute> <attribute name="timeToLiveSeconds">5000</attribute> </region> <!-- The Person entity cache --> <region name="/org/andromda/howto2/rental/Person"> <attribute name="maxNodes">10000</attribute> <attribute name="timeToLiveSeconds">5000</attribute> </region> .... ]]></source> </p> <p> You must deploy the <code>ejb3-entity-cache-service.xml</code> to your JBoss deploy folder as you do with your ear package bundle. Remember, if you have other cached enabled applications, you must merge the changes to the <code>ejb3-entity-cache-service.xml</code> manually, otherwise you will override previous configurations. </p> </subsection> <a name="Association_Cache"/> <subsection name="Association Cache"> <p> To enable entity association relationship caching, you enable the <code>hibernateEnableAssociationsCache</code> ejb3 namespace property in your andromda.xml like so: <source language="xml"><![CDATA[ <namespace name="ejb3"> <properties> ... <property name="hibernateEnableCache">true</property> <property name="hibernateEnableAssociationsCache">true</property> ... </properties> </namespace> ]]></source> You must have <code>hibernateEnableCache</code> enabled. </p> <p> If you enable the default association cache strategy in your andromda.xml descriptor, by enabling <code>hibernateAssociationCache</code>, then the cache strategy for all collection associationas will be assigned using its specified value. To override this default value, you can model the <code>@andromda.persistence.association.cache</code> tagged value on individual target association ends. </p> <p> Once you have enabled entity association caching, you will notice the <code>@org.hibernate.annotations.Cache</code> annotation on One-To-Many and Many-To-Many relationships. </p> </subsection> <a name="Query_Cache"/> <subsection name="Query Cache"> <p> To enable entity query caching, you enable the <code>hibernateUseQueryCache</code> ejb3 namespace property in your andromda.xml like so: <source language="xml"><![CDATA[ <namespace name="ejb3"> <properties> ... <property name="hibernateEnableCache">true</property> <property name="hibernateUseQueryCache">true</property> <property name="useDefaultCacheRegion">false</property> ... </properties> </namespace> ]]></source> You must have <code>hibernateEnableCache</code> enabled. You then need to enable caching for each finder method using the <code>@andromda.ejb.query.useCache</code> tagged value. </p> <p> The <code>useDefaultCacheRegion</code> property allows you to specify whether you want all queries to use the default cache region specified in <code>ejb3-entity-cache-service.xml</code>. By default, this is set to <code>false</code>. If you set to <code>true</code>, the user specified cache regions will not be defined and the hint on queries to set the cache region will not be assigned. </p> <p> The cartridge will look for at least one query which is marked for caching. If it finds one such query, the <code>persistence.xml</code> descriptor will include the <code>hibernate.cache.use_query_cache</code> like so: <source language="xml"><![CDATA[ <?xml version="1.0" encoding="UTF-8"?> <!-- Attention: Generated code! Do not modify by hand! Generated by: persistence.xml.vsl in andromda-ejb3-cartridge. --> <persistence> <persistence-unit name="howtomodel2"> <jta-data-source>java:/jdbc/howtomodel2</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/> <property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook"/> <property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache"/> <property name="hibernate.cache.use_query_cache">true</property> </properties> </persistence-unit> ]]></source> </p> <p> In the above example, the <code>Car</code> entity has the <code>findByType</code> finder marked as cacheable. When generating the Car mapped superclass <code>findByType</code> finder method, the cartridge will set the <code>org.hibernate.cacheRegion</code> hint automatically like so: <source><![CDATA[ public static java.util.List<Car> findByType(javax.persistence.EntityManager em, org.andromda.howto2.rental.CarType type) { javax.persistence.Query query = em.createQuery("FROM Car AS car WHERE car.type = :type"); query.setParameter("type", type.name()); query.setHint("org.hibernate.cacheRegion", "/org/andromda/howto2/rental/Car_findByType"); return query.getResultList(); } ]]></source> </p> <p> The corresponding cache region is defined in the <code>ejb3-entity-cache-service.xml</code> configuration service file: <source language="xml"><![CDATA[ .... <!-- The Car findByType query cache --> <region name="/org/andromda/howto2/rental/Car_findByType"> <attribute name="maxNodes">1000</attribute> <attribute name="timeToLiveSeconds">5000</attribute> </region> .... ]]></source> </p> <p> You must deploy the <code>ejb3-entity-cache-service.xml</code> to your JBoss deploy folder as you do with your ear package bundle. Remember, if you have other cached enabled applications, you must merge the changes to the <code>ejb3-entity-cache-service.xml</code> manually, otherwise you will override previous configurations. </p> </subsection> <a name="Clustering"/> <subsection name="Clustering Session Beans"> <p> Enabling session bean clustering is achieved by setting the <code>enableClustering</code> ejb3 namespace property to true. <source language="xml"><![CDATA[ <namespace name="ejb3"> <properties> ... property name="enableClustering">true</property> ... </properties> </namespace> ]]></source> This will automatically add the <code>@org.jboss.annotation.ejb.Clustered</code> JBoss annotation to all session beans which will enable load-balancing and failover of all requests. The default load balance policy <code>org.jboss.ha.framework.interfaces.RandomRobin</code> is used. </p> <p> There is nothing more you need to do for stateless session beans. For stateful session beans, you must make sure that the JBoss Cache session state replication service is deployed. Simply make sure that <code>ejb3-clustered-sfsbcache-service.xml</code> exists in your JBoss deploy directory. </p> </subsection> <a name="Further_Reading"/> <subsection name="Further Reading"> <p> Visit the following links to find out more information </p> <p> <ul> <li>http://clusterstore.demo.jboss.com/</li> <li>http://docs.jboss.org/ejb3/app-server/tutorial/clusteredentity/clusteredentity.html</li> </ul> </p> </subsection> </section> </body> </document> |
From: Vance K. <va...@us...> - 2006-04-17 02:06:25
|
User: vancek Date: 06/04/16 19:06:24 Modified: andromda-ejb3/src/site/xdoc howto17.xml Log: added navigation to webservice howto Revision Changes Path 1.2 +5 -0 cartridges/andromda-ejb3/src/site/xdoc/howto17.xml Index: howto17.xml =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/site/xdoc/howto17.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- howto17.xml 20 Mar 2006 08:51:46 -0000 1.1 +++ howto17.xml 17 Apr 2006 02:06:24 -0000 1.2 @@ -339,5 +339,10 @@ </p> </subsection> </section> + <section name="Next"> + <p> + To expose service operations and session beans as webservices click <a href="howto18.html">here</a>. + </p> + </section> </body> </document> |