Syncronizing across two cmp entity bean methods for each ins
joe543 Jan 5, 2002 9:39 AMHi,
I'm using Tomcat3.2.3+Jboss2.4.1 on SuSE Linux 7.2 against PostgreSQL 7.
I have bought and downloaded the base docs from the flashline site but have not found the answer I'm looking for i.e. How do I test for locking on an entity bean instance?
I have a situation where I want client access to a db row(CMP entity bean) to be synchronized.
There are two methods on the entity bean - a read(actually a custom finder) and a write(which just updates a counter) which I would like to be executed from a session facade together/atomically. It doesn't neccessarily have to be from a session facade but that's what I'm currently using. There is only a single record in the db for proof of concept purposes.
I was hoping that the locking-policy: QueuedPessimisticEJBLock as defined in standardjboss.xml would do the trick. Maybe it is working but I'm not 100% sure about what to look for. Can I assume that it makes no sense for the stateless session bean instance to be isolated? Does locking occur on the entity instance for each method call or does it occur across method calls (on the entity bean instance as a whole). What is the default behaviour provide for? Essentially, the question is how can I synchronized across a custom finder and a write method on the entity instance if I'm calling those methods from a stateless session bean?
To simulate the load I'm using ApacheJMeter. Of course synchronizing the clients' access from within the servlet works but due to obvious reasons I'd like to avoid that scenario!
Some relevent files:
My jboss.xml file:
<?xml version="1.0" encoding="Cp1252"?>
false
<container-configurations />
<resource-managers />
<enterprise-beans>
<ejb-name>TestSessionBean</ejb-name>
<jndi-name>test/TestSession</jndi-name>
<configuration-name>Standard Stateless SessionBean</configuration-name>
<ejb-name>TestBean</ejb-name>
<jndi-name>test/Test</jndi-name>
<configuration-name>Standard CMP EntityBean</configuration-name>
</enterprise-beans>
My ejb-jar.xml file:
<ejb-jar>
<display-name>Testing</display-name>
<enterprise-beans>
This is a Test
<ejb-name>TestBean</ejb-name>
test.servlets.interfaces.TestHome
test.servlets.interfaces.Test
<ejb-class>test.servlets.bean.TestBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
False
<cmp-field><field-name>id</field-name></cmp-field>
<cmp-field><field-name>imageURI</field-name></cmp-field>
<cmp-field><field-name>destinationURI</field-name></cmp-field>
<cmp-field><field-name>impressionCounter</field-name></cmp-field>
<cmp-field><field-name>accountNumber</field-name></cmp-field>
<primkey-field>id</primkey-field>
findLeastHit
impressioncounter >= 0
Models a test session facade
<ejb-name>TestSessionBean</ejb-name>
test.servlets.interfaces.TestSessionHome
test.servlets.interfaces.TestSession
<ejb-class>test.servlets.bean.TestSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/Test</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
test.servlets.interfaces.TestHome
test.servlets.interfaces.Test
<ejb-link>TestBean</ejb-link>
</ejb-ref>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<ejb-name>TestBean</ejb-name>
<method-name>*</method-name>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
And lastly, jaws.xml:
<enterprise-beans>
<ejb-name>TestBean</ejb-name>
<table-name>testbean</table-name>
<create-table>true</create-table>
findLeastHit
where impressioncounter >= 0
<remove-table>true</remove-table>
</enterprise-beans>
<!--java:/PostgresDS-->
java:/DefaultDS
<!-- <type-mapping>PostgreSQL</type-mapping>
<type-mappings>
<type-mapping>
PostgreSQL
<java-type>java.lang.Long</java-type>
<jdbc-type>BIGINT</jdbc-type>
<sql-type>BIGINT</sql-type>
<java-type>java.util.Date</java-type>
<jdbc-type>DATE</jdbc-type>
<sql-type>DATE</sql-type>
<java-type>java.lang.Float</java-type>
<jdbc-type>FLOAT</jdbc-type>
<sql-type>FLOAT</sql-type>
<java-type>java.sql.TimeStamp</java-type>
<jdbc-type>TIMESTAMP</jdbc-type>
<sql-type>TIMESTAMP</sql-type>
<java-type>java.lang.Object</java-type>
<jdbc-type>BLOB</jdbc-type>
<sql-type>BLOB</sql-type>
<java-type>java.lang.Integer</java-type>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<java-type>java.lang.Character</java-type>
<jdbc-type>CHAR</jdbc-type>
<sql-type>CHAR</sql-type>
<java-type>java.lang.Byte</java-type>
<jdbc-type>TINYINT</jdbc-type>
<sql-type>TINYINT</sql-type>
<java-type>java.lang.String</java-type>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(256)</sql-type>
<java-type>java.lang.Integer</java-type>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<java-type>java.lang.Double</java-type>
<jdbc-type>DOUBLE</jdbc-type>
<sql-type>DOUBLE</sql-type>
</type-mapping>
</type-mappings>-->
Any help or advice is much appreciated.
Joe