You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Lars-Fredrik Smedberg <it...@gmail.com> on 2015/05/07 13:26:05 UTC

Suspend ongoing tx (if any) in a portable way

Hi

What we need to do is to make sure that a specific code snippet not runs in
a JTA tx....

We want to do this in a portable way so what we do is the following (psuedo
code)

@Resource
TransactionSynchronizationRegistry tsr;

....

if (tsr.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) {
    ....run code as is...
}
else {
   ... run code by passing it through an EJB with
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) which in turn
runs the actual code
}

Is the above the simplest portable way of doing this in an JEE 6 container?

Any inputs would be great!

Regards
LF


-- 
Med vänlig hälsning / Best regards

Lars-Fredrik Smedberg

STATEMENT OF CONFIDENTIALITY:
The information contained in this electronic message and any
attachments to this message are intended for the exclusive use of the
address(es) and may contain confidential or privileged information. If
you are not the intended recipient, please notify Lars-Fredrik Smedberg
immediately at itsmeden@gmail.com, and destroy all copies of this
message and any attachments.

Re: Suspend ongoing tx (if any) in a portable way

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
@Romain

Seems like suspend/resume for the TransactionManager isnt available for all
app-servers (atleast not for the one we are still running some systems on
:)) so I guess I will stick to "wrapping" it in a NOT_SUPPORTED EJB call...

Thanks for the pointers...

Regards
LF

On Thu, May 7, 2015 at 3:38 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> that's a way but if you have the tx mgr you can also suspend the tx and
> resume it later
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com>
>
> 2015-05-07 15:24 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>
> > @Romain, thanks for the code pointer, just had a look at it...
> >
> > And about suspending an ongoing tx, is the way I did it (through the
> > NOT_SUPPORTED EJB) the preferred way?
> >
> > Regards
> > LF
> >
> > On Thu, May 7, 2015 at 2:51 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >
> > > Well javax.transaction.TransactionManager is portable, the jndi name is
> > not
> > > but should be easily configurable (or you can even try the 5-6 well
> known
> > > ones). You can check org.apache.openjpa.ee.AutomaticManagedRuntime for
> > this
> > > logic more or less
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > <http://rmannibucau.wordpress.com> | Github <
> > > https://github.com/rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > <http://www.tomitribe.com>
> > >
> > > 2015-05-07 14:46 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > >
> > > > @Romain
> > > >
> > > > I thought injecting the TransactionManager created non-portable code?
> > > >
> > > > Is there another way to actually suspend the ongoing transaction if
> > > > any....?
> > > >
> > > > Regards
> > > > LF
> > > >
> > > > On Thu, May 7, 2015 at 2:15 PM, Romain Manni-Bucau <
> > > rmannibucau@gmail.com>
> > > > wrote:
> > > >
> > > > > Injecting the tx manager looks reasonable but ends up to more or
> less
> > > the
> > > > > same yes.
> > > > >  Le 7 mai 2015 13:27, "Lars-Fredrik Smedberg" <it...@gmail.com>
> a
> > > > > écrit :
> > > > >
> > > > > > Hi
> > > > > >
> > > > > > What we need to do is to make sure that a specific code snippet
> not
> > > > runs
> > > > > in
> > > > > > a JTA tx....
> > > > > >
> > > > > > We want to do this in a portable way so what we do is the
> following
> > > > > (psuedo
> > > > > > code)
> > > > > >
> > > > > > @Resource
> > > > > > TransactionSynchronizationRegistry tsr;
> > > > > >
> > > > > > ....
> > > > > >
> > > > > > if (tsr.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) {
> > > > > >     ....run code as is...
> > > > > > }
> > > > > > else {
> > > > > >    ... run code by passing it through an EJB with
> > > > > > @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
> which
> > > in
> > > > > turn
> > > > > > runs the actual code
> > > > > > }
> > > > > >
> > > > > > Is the above the simplest portable way of doing this in an JEE 6
> > > > > container?
> > > > > >
> > > > > > Any inputs would be great!
> > > > > >
> > > > > > Regards
> > > > > > LF
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Med vänlig hälsning / Best regards
> > > > > >
> > > > > > Lars-Fredrik Smedberg
> > > > > >
> > > > > > STATEMENT OF CONFIDENTIALITY:
> > > > > > The information contained in this electronic message and any
> > > > > > attachments to this message are intended for the exclusive use of
> > the
> > > > > > address(es) and may contain confidential or privileged
> information.
> > > If
> > > > > > you are not the intended recipient, please notify Lars-Fredrik
> > > Smedberg
> > > > > > immediately at itsmeden@gmail.com, and destroy all copies of
> this
> > > > > > message and any attachments.
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Med vänlig hälsning / Best regards
> > > >
> > > > Lars-Fredrik Smedberg
> > > >
> > > > STATEMENT OF CONFIDENTIALITY:
> > > > The information contained in this electronic message and any
> > > > attachments to this message are intended for the exclusive use of the
> > > > address(es) and may contain confidential or privileged information.
> If
> > > > you are not the intended recipient, please notify Lars-Fredrik
> Smedberg
> > > > immediately at itsmeden@gmail.com, and destroy all copies of this
> > > > message and any attachments.
> > > >
> > >
> >
> >
> >
> > --
> > Med vänlig hälsning / Best regards
> >
> > Lars-Fredrik Smedberg
> >
> > STATEMENT OF CONFIDENTIALITY:
> > The information contained in this electronic message and any
> > attachments to this message are intended for the exclusive use of the
> > address(es) and may contain confidential or privileged information. If
> > you are not the intended recipient, please notify Lars-Fredrik Smedberg
> > immediately at itsmeden@gmail.com, and destroy all copies of this
> > message and any attachments.
> >
>



-- 
Med vänlig hälsning / Best regards

Lars-Fredrik Smedberg

STATEMENT OF CONFIDENTIALITY:
The information contained in this electronic message and any
attachments to this message are intended for the exclusive use of the
address(es) and may contain confidential or privileged information. If
you are not the intended recipient, please notify Lars-Fredrik Smedberg
immediately at itsmeden@gmail.com, and destroy all copies of this
message and any attachments.

Re: Suspend ongoing tx (if any) in a portable way

Posted by Romain Manni-Bucau <rm...@gmail.com>.
that's a way but if you have the tx mgr you can also suspend the tx and
resume it later


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-05-07 15:24 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:

> @Romain, thanks for the code pointer, just had a look at it...
>
> And about suspending an ongoing tx, is the way I did it (through the
> NOT_SUPPORTED EJB) the preferred way?
>
> Regards
> LF
>
> On Thu, May 7, 2015 at 2:51 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> > Well javax.transaction.TransactionManager is portable, the jndi name is
> not
> > but should be easily configurable (or you can even try the 5-6 well known
> > ones). You can check org.apache.openjpa.ee.AutomaticManagedRuntime for
> this
> > logic more or less
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <http://rmannibucau.wordpress.com> | Github <
> > https://github.com/rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com>
> >
> > 2015-05-07 14:46 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >
> > > @Romain
> > >
> > > I thought injecting the TransactionManager created non-portable code?
> > >
> > > Is there another way to actually suspend the ongoing transaction if
> > > any....?
> > >
> > > Regards
> > > LF
> > >
> > > On Thu, May 7, 2015 at 2:15 PM, Romain Manni-Bucau <
> > rmannibucau@gmail.com>
> > > wrote:
> > >
> > > > Injecting the tx manager looks reasonable but ends up to more or less
> > the
> > > > same yes.
> > > >  Le 7 mai 2015 13:27, "Lars-Fredrik Smedberg" <it...@gmail.com> a
> > > > écrit :
> > > >
> > > > > Hi
> > > > >
> > > > > What we need to do is to make sure that a specific code snippet not
> > > runs
> > > > in
> > > > > a JTA tx....
> > > > >
> > > > > We want to do this in a portable way so what we do is the following
> > > > (psuedo
> > > > > code)
> > > > >
> > > > > @Resource
> > > > > TransactionSynchronizationRegistry tsr;
> > > > >
> > > > > ....
> > > > >
> > > > > if (tsr.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) {
> > > > >     ....run code as is...
> > > > > }
> > > > > else {
> > > > >    ... run code by passing it through an EJB with
> > > > > @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) which
> > in
> > > > turn
> > > > > runs the actual code
> > > > > }
> > > > >
> > > > > Is the above the simplest portable way of doing this in an JEE 6
> > > > container?
> > > > >
> > > > > Any inputs would be great!
> > > > >
> > > > > Regards
> > > > > LF
> > > > >
> > > > >
> > > > > --
> > > > > Med vänlig hälsning / Best regards
> > > > >
> > > > > Lars-Fredrik Smedberg
> > > > >
> > > > > STATEMENT OF CONFIDENTIALITY:
> > > > > The information contained in this electronic message and any
> > > > > attachments to this message are intended for the exclusive use of
> the
> > > > > address(es) and may contain confidential or privileged information.
> > If
> > > > > you are not the intended recipient, please notify Lars-Fredrik
> > Smedberg
> > > > > immediately at itsmeden@gmail.com, and destroy all copies of this
> > > > > message and any attachments.
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Med vänlig hälsning / Best regards
> > >
> > > Lars-Fredrik Smedberg
> > >
> > > STATEMENT OF CONFIDENTIALITY:
> > > The information contained in this electronic message and any
> > > attachments to this message are intended for the exclusive use of the
> > > address(es) and may contain confidential or privileged information. If
> > > you are not the intended recipient, please notify Lars-Fredrik Smedberg
> > > immediately at itsmeden@gmail.com, and destroy all copies of this
> > > message and any attachments.
> > >
> >
>
>
>
> --
> Med vänlig hälsning / Best regards
>
> Lars-Fredrik Smedberg
>
> STATEMENT OF CONFIDENTIALITY:
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of the
> address(es) and may contain confidential or privileged information. If
> you are not the intended recipient, please notify Lars-Fredrik Smedberg
> immediately at itsmeden@gmail.com, and destroy all copies of this
> message and any attachments.
>

Re: Suspend ongoing tx (if any) in a portable way

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
@Romain, thanks for the code pointer, just had a look at it...

And about suspending an ongoing tx, is the way I did it (through the
NOT_SUPPORTED EJB) the preferred way?

Regards
LF

On Thu, May 7, 2015 at 2:51 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Well javax.transaction.TransactionManager is portable, the jndi name is not
> but should be easily configurable (or you can even try the 5-6 well known
> ones). You can check org.apache.openjpa.ee.AutomaticManagedRuntime for this
> logic more or less
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com>
>
> 2015-05-07 14:46 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>
> > @Romain
> >
> > I thought injecting the TransactionManager created non-portable code?
> >
> > Is there another way to actually suspend the ongoing transaction if
> > any....?
> >
> > Regards
> > LF
> >
> > On Thu, May 7, 2015 at 2:15 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >
> > > Injecting the tx manager looks reasonable but ends up to more or less
> the
> > > same yes.
> > >  Le 7 mai 2015 13:27, "Lars-Fredrik Smedberg" <it...@gmail.com> a
> > > écrit :
> > >
> > > > Hi
> > > >
> > > > What we need to do is to make sure that a specific code snippet not
> > runs
> > > in
> > > > a JTA tx....
> > > >
> > > > We want to do this in a portable way so what we do is the following
> > > (psuedo
> > > > code)
> > > >
> > > > @Resource
> > > > TransactionSynchronizationRegistry tsr;
> > > >
> > > > ....
> > > >
> > > > if (tsr.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) {
> > > >     ....run code as is...
> > > > }
> > > > else {
> > > >    ... run code by passing it through an EJB with
> > > > @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) which
> in
> > > turn
> > > > runs the actual code
> > > > }
> > > >
> > > > Is the above the simplest portable way of doing this in an JEE 6
> > > container?
> > > >
> > > > Any inputs would be great!
> > > >
> > > > Regards
> > > > LF
> > > >
> > > >
> > > > --
> > > > Med vänlig hälsning / Best regards
> > > >
> > > > Lars-Fredrik Smedberg
> > > >
> > > > STATEMENT OF CONFIDENTIALITY:
> > > > The information contained in this electronic message and any
> > > > attachments to this message are intended for the exclusive use of the
> > > > address(es) and may contain confidential or privileged information.
> If
> > > > you are not the intended recipient, please notify Lars-Fredrik
> Smedberg
> > > > immediately at itsmeden@gmail.com, and destroy all copies of this
> > > > message and any attachments.
> > > >
> > >
> >
> >
> >
> > --
> > Med vänlig hälsning / Best regards
> >
> > Lars-Fredrik Smedberg
> >
> > STATEMENT OF CONFIDENTIALITY:
> > The information contained in this electronic message and any
> > attachments to this message are intended for the exclusive use of the
> > address(es) and may contain confidential or privileged information. If
> > you are not the intended recipient, please notify Lars-Fredrik Smedberg
> > immediately at itsmeden@gmail.com, and destroy all copies of this
> > message and any attachments.
> >
>



-- 
Med vänlig hälsning / Best regards

Lars-Fredrik Smedberg

STATEMENT OF CONFIDENTIALITY:
The information contained in this electronic message and any
attachments to this message are intended for the exclusive use of the
address(es) and may contain confidential or privileged information. If
you are not the intended recipient, please notify Lars-Fredrik Smedberg
immediately at itsmeden@gmail.com, and destroy all copies of this
message and any attachments.

Re: Suspend ongoing tx (if any) in a portable way

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Well javax.transaction.TransactionManager is portable, the jndi name is not
but should be easily configurable (or you can even try the 5-6 well known
ones). You can check org.apache.openjpa.ee.AutomaticManagedRuntime for this
logic more or less


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-05-07 14:46 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:

> @Romain
>
> I thought injecting the TransactionManager created non-portable code?
>
> Is there another way to actually suspend the ongoing transaction if
> any....?
>
> Regards
> LF
>
> On Thu, May 7, 2015 at 2:15 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> > Injecting the tx manager looks reasonable but ends up to more or less the
> > same yes.
> >  Le 7 mai 2015 13:27, "Lars-Fredrik Smedberg" <it...@gmail.com> a
> > écrit :
> >
> > > Hi
> > >
> > > What we need to do is to make sure that a specific code snippet not
> runs
> > in
> > > a JTA tx....
> > >
> > > We want to do this in a portable way so what we do is the following
> > (psuedo
> > > code)
> > >
> > > @Resource
> > > TransactionSynchronizationRegistry tsr;
> > >
> > > ....
> > >
> > > if (tsr.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) {
> > >     ....run code as is...
> > > }
> > > else {
> > >    ... run code by passing it through an EJB with
> > > @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) which in
> > turn
> > > runs the actual code
> > > }
> > >
> > > Is the above the simplest portable way of doing this in an JEE 6
> > container?
> > >
> > > Any inputs would be great!
> > >
> > > Regards
> > > LF
> > >
> > >
> > > --
> > > Med vänlig hälsning / Best regards
> > >
> > > Lars-Fredrik Smedberg
> > >
> > > STATEMENT OF CONFIDENTIALITY:
> > > The information contained in this electronic message and any
> > > attachments to this message are intended for the exclusive use of the
> > > address(es) and may contain confidential or privileged information. If
> > > you are not the intended recipient, please notify Lars-Fredrik Smedberg
> > > immediately at itsmeden@gmail.com, and destroy all copies of this
> > > message and any attachments.
> > >
> >
>
>
>
> --
> Med vänlig hälsning / Best regards
>
> Lars-Fredrik Smedberg
>
> STATEMENT OF CONFIDENTIALITY:
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of the
> address(es) and may contain confidential or privileged information. If
> you are not the intended recipient, please notify Lars-Fredrik Smedberg
> immediately at itsmeden@gmail.com, and destroy all copies of this
> message and any attachments.
>

Re: Suspend ongoing tx (if any) in a portable way

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
@Romain

I thought injecting the TransactionManager created non-portable code?

Is there another way to actually suspend the ongoing transaction if any....?

Regards
LF

On Thu, May 7, 2015 at 2:15 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Injecting the tx manager looks reasonable but ends up to more or less the
> same yes.
>  Le 7 mai 2015 13:27, "Lars-Fredrik Smedberg" <it...@gmail.com> a
> écrit :
>
> > Hi
> >
> > What we need to do is to make sure that a specific code snippet not runs
> in
> > a JTA tx....
> >
> > We want to do this in a portable way so what we do is the following
> (psuedo
> > code)
> >
> > @Resource
> > TransactionSynchronizationRegistry tsr;
> >
> > ....
> >
> > if (tsr.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) {
> >     ....run code as is...
> > }
> > else {
> >    ... run code by passing it through an EJB with
> > @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) which in
> turn
> > runs the actual code
> > }
> >
> > Is the above the simplest portable way of doing this in an JEE 6
> container?
> >
> > Any inputs would be great!
> >
> > Regards
> > LF
> >
> >
> > --
> > Med vänlig hälsning / Best regards
> >
> > Lars-Fredrik Smedberg
> >
> > STATEMENT OF CONFIDENTIALITY:
> > The information contained in this electronic message and any
> > attachments to this message are intended for the exclusive use of the
> > address(es) and may contain confidential or privileged information. If
> > you are not the intended recipient, please notify Lars-Fredrik Smedberg
> > immediately at itsmeden@gmail.com, and destroy all copies of this
> > message and any attachments.
> >
>



-- 
Med vänlig hälsning / Best regards

Lars-Fredrik Smedberg

STATEMENT OF CONFIDENTIALITY:
The information contained in this electronic message and any
attachments to this message are intended for the exclusive use of the
address(es) and may contain confidential or privileged information. If
you are not the intended recipient, please notify Lars-Fredrik Smedberg
immediately at itsmeden@gmail.com, and destroy all copies of this
message and any attachments.

Re: Suspend ongoing tx (if any) in a portable way

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Injecting the tx manager looks reasonable but ends up to more or less the
same yes.
 Le 7 mai 2015 13:27, "Lars-Fredrik Smedberg" <it...@gmail.com> a écrit :

> Hi
>
> What we need to do is to make sure that a specific code snippet not runs in
> a JTA tx....
>
> We want to do this in a portable way so what we do is the following (psuedo
> code)
>
> @Resource
> TransactionSynchronizationRegistry tsr;
>
> ....
>
> if (tsr.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) {
>     ....run code as is...
> }
> else {
>    ... run code by passing it through an EJB with
> @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) which in turn
> runs the actual code
> }
>
> Is the above the simplest portable way of doing this in an JEE 6 container?
>
> Any inputs would be great!
>
> Regards
> LF
>
>
> --
> Med vänlig hälsning / Best regards
>
> Lars-Fredrik Smedberg
>
> STATEMENT OF CONFIDENTIALITY:
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of the
> address(es) and may contain confidential or privileged information. If
> you are not the intended recipient, please notify Lars-Fredrik Smedberg
> immediately at itsmeden@gmail.com, and destroy all copies of this
> message and any attachments.
>