Modeshapes multiples upload, sequencers and transactions
dcdh1983 Apr 27, 2014 7:02 PMHello,
I've got a question about sequencers and EJB transactions when uploading mutliples images files into ModeShape.
I've got a first EJB called by my view. This EJB is responsible to call other EJBs and one of them is in charge of uploading image files to ModeShape. This EJB is called EJB Repository for this explaination.It is a @Stateless EJB and it have a Repository injected object and it uses the JcrTools to upload file easily into ModeShape. The EJB Repository is called as many time as I have a file to upload.
I use an image sequencer to retrieve image file metadata.
My image sequencer is defined as this:
<sequencers>
<sequencer name="image-sequencer" classname="image" module="org.modeshape.sequencer.image" path-expression="/fichiers(//*.(png|jpg|gif)[*])/jcr:content[@jcr:data] => /metadata/$1"/>
</sequencers>
I should obtain these results after uploading two images files:
File | image metadata from sequencer | |
---|---|---|
Node path | /fichiers/one.jpg | /metadata/one |
Node path | /fichiers/two.jpg | /metadata/two |
For your information, fichiers and metadata nodes are not presents each time the test is run. I manually delete them, then they are dynamically created by each test. My exemple is simpler. I could create these nodes and it will work. But in my real application I may have more than one node level to dynamically create.
First case : Require Transaction on the EJB Repository
The transaction defined by default on the EJB Repository is Required.
I obtain these results:
File | image metadata from sequencer | |
---|---|---|
Node path | /fichiers/one.jpg | /metadata/one |
Node path | /fichiers[2]/two.jpg | /metadata/two |
It is ok for the metadata part but it fails in file paths nodes. Files one.jpg and two.jpg are not presents on the same parent node. We've got a sibling.
Second case : Transaction set to Support on the EJB Repository
In this case the transaction of the EJB Repository is bound to the parent EJB. The transaction is the same each time the EJB Repository is called for uploading an image file.
I obtain these results:
File | image metadata from sequencer | |
---|---|---|
Node path | /fichiers/one.jpg | /metadata/one |
Node path | /fichiers/two.jpg | /metadata[2]/two |
The result is the opposite compared with the first case. We've got a sibling on the metadata parent nodes paths.
My point of view.
Here is an explaination. Takes it with caution, I may have wrong.
In the first case a new transaction is created each time the EJB Repository is called. Each transaction can't know what the other is or has doing. So the second call to the EJB Repository will not find the node previously created by the first transaction. The second call will create a new "fichiers" node resulting to a sibling node.
I think it is the same for the second case. Each sequencer has his own transaction and can't know if common parent node was created by a previous running transaction.
Are these explanations corrects ? Is there a workaround to avoid sibling nodes for common dynamic created path ?
I think that this problem could be linked with this thread: https://community.jboss.org/thread/233260
Thanks by advance.
Regards,
Damien
My environnement:
- ModeShape 4.0 Alpha 2
- Wildfly 8.0.0