Hi,

I've updated my code at
http://wiki.apache.org/myfaces/Extensions/CDI/DevDoc/Drafts/Transactional
It is not really tested and lacks some fallback-scenarios (i.e. null-handling, 
etc.), but it is a starting point to inject scoped EntityManagers for every 
CDI-scope.

Regards,
Arne

--

Arne Limburg - Enterprise Developer
OpenKnowledge GmbH, Oldenburg
Bismarckstraße 13, 26122 Oldenburg
Mobil: +49 (0) 151 - 108 22 942
Tel: +49 (0) 441 - 4082-0
Fax: +49 (0) 441 - 4082-111
arne.limb...@openknowledge.de
http://www.openknowledge.de

Registergericht: Amtsgericht Oldenburg, HRB 4670
Geschäftsführer: Lars Röwekamp, Jens Schumann

Von: Gerhard Petracek [mailto:gerhard.petra...@gmail.com]
Gesendet: Montag, 15. Februar 2010 13:44
An: MyFaces Development
Betreff: Re: [Ext-CDI] @Transactional

hi arne,

thx for providing the source code.
i'll have a look at it after the jsfdays.

one of the goals is to provide an alternative conversation scope for cdi which 
allows to use the conversation concepts provided by orchestra.
so we have to ensure that it works with every custom cdi scope.
(cdi conversations would be the default scope)

regards,
gerhard

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

2010/2/15 Arne Limburg 
<arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>>
Hi,

I've prototyped some code that injects conversation-scoped EntityManagers 
reading the unitName from the qualifier annotation and added @Transactional 
support for this EntityManagers. This code needs some thinking though, e.g. how 
to handle the default-case (no unitName specified)...

If you want to take a look at it, I have created a Wiki page and added my code 
as attachment:
http://wiki.apache.org/myfaces/Extensions/CDI/DevDoc/Drafts/Transactional

This code could be a starting point to implement Orchestra-like conversations 
(starting with CDI-Conversations)...

Regards,
Arne

--

Arne Limburg - Enterprise Developer
OpenKnowledge GmbH, Oldenburg
Bismarckstraße 13, 26122 Oldenburg
Mobil: +49 (0) 151 - 108 22 942
Tel: +49 (0) 441 - 4082-0
Fax: +49 (0) 441 - 4082-111
arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>
http://www.openknowledge.de

Registergericht: Amtsgericht Oldenburg, HRB 4670
Geschäftsführer: Lars Röwekamp, Jens Schumann

-----Ursprüngliche Nachricht-----
Von: Mark Struberg [mailto:strub...@yahoo.de<mailto:strub...@yahoo.de>]
Gesendet: Samstag, 13. Februar 2010 20:27
An: MyFaces Development
Betreff: AW: [Ext-CDI] @Transactional

> I am afraid supporting multiple persistence-units in that
> scenario is very difficult...

Nope, it's really easy. I simply use Qualifiers to distinguish between them.

@Qualifier
public @instance Core {}

@Qualifier
public @instance Other {}

----
@RequestScoped
public class EMProducer {
private @PersistenceContext(unitName="core") EntityManager emCore;
private @PersistenceContext(unitName="other") EntityManager emOther;


public @Produces @Core EntityManager getCoreEM() {return emCore;}
public @Produces @Other EntityManager getOtherEM() {return emOther;}


Injection happens with

private @Inject @Core EntityManager


Got the idea?

LieGrue,
strub

--- Arne Limburg 
<arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>> schrieb 
am Sa, 13.2.2010:

> Von: Arne Limburg 
> <arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>>
> Betreff: AW: [Ext-CDI] @Transactional
> An: "MyFaces Development" 
> <dev@myfaces.apache.org<mailto:dev@myfaces.apache.org>>
> Datum: Samstag, 13. Februar 2010, 20:06
> Hi Mark,
>
> thank you for your feedback. I was aware of the requirement
> of CDI-containers to inject JavaEE resources in a
> JavaEE-environment, but Gerhard and I are thinking about a
> generic non-JavaEE-solution for EntityManager-injection. And
> at least weld does no injection of JavaEE-resources in this
> case. How does OpenWebBeans?
> I am afraid supporting multiple persistence-units in that
> scenario is very difficult...
>
> Nonetheless it would be nice to see your
> multiple-database-handling TransactionInterceptor in CODI.
>
> Regards,
> Arne
>
> --
>
> Arne Limburg - Enterprise Developer
> OpenKnowledge GmbH, Oldenburg
> Bismarckstraße 13, 26122 Oldenburg
> Mobil: +49 (0) 151 - 108 22 942
> Tel: +49 (0) 441 - 4082-0
> Fax: +49 (0) 441 - 4082-111
> arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>
> http://www.openknowledge.de

>
> Registergericht: Amtsgericht Oldenburg, HRB 4670
> Geschäftsführer: Lars Röwekamp, Jens Schumann
>
> -----Ursprüngliche Nachricht-----
> Von: Mark Struberg [mailto:strub...@yahoo.de<mailto:strub...@yahoo.de>]
>
> Gesendet: Samstag, 13. Februar 2010 15:39
> An: MyFaces Development
> Betreff: AW: [Ext-CDI] @Transactional
>
> Hi!
>
> The JSR-299 spec defines that we have to support injection
> of EE-Resources.
>
> This was more explicit in the old version of the spec, but
> unless the wording got shortened, I still think injection of
> @PersistenceUnit and @PersistenceContext must be supported
> by any JSR-299 container (at least in an EE environment).
>
> For OpenWebBeans, you can simply use our
> openwebbeans-resource plugin. Please note that this is
> necessary because OWB is modular, and openwebbeans-impl (the
> core) will have no EE dependencies at all (not even JSF,
> JPA, etc!) This will get picked up automatically if it is
> available in the classpath, e.g. you can simply define the
> following maven dependency:
>
>         <dependency>
>
> <groupId>org.apache.openwebbeans</groupId>
>
> <artifactId>openwebbeans-resource</artifactId>
>
> <version>${owb.version}</version>
>         </dependency>
>
> OWB supports 2 different scenarios. If you are not running
> in a JTA aware container like e.g. OpenEJB, you will
> automatically use a simple resource version of an SPI
> implementation which uses
> Persistence#createEntityManagerFactory(unitName) for
> injecting (Thus getting an extended EM). If you use e.g.
> OpenEJB, we are able to get the injectable resources
> directly from there (thus getting a transactional EM).
>
> Once this is available, you can simply create a producer
> method for the EntityManager:
> https://svn.apache.org/repos/asf/openwebbeans/trunk/samples/reservation/src/main/java/org/apache/webbeans/reservation/util/EntityManagerUtil.java

>
> There is also an example on how to implement a
> TransactionalInterceptor:
> https://svn.apache.org/repos/asf/openwebbeans/trunk/samples/reservation/src/main/java/org/apache/webbeans/reservation/intercept/TransactionalInterceptor.java

>
> In my company, I already implemented a
> TransactionalInteceptor which is capable of handling
> multiple databases at a time and also correctly handles
> nested transactions. I hope to migrate this over to CODI in
> the near future.
>
>
> LieGrue,
> strub
>
>
> --- Arne Limburg 
> <arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>>
> schrieb am Sa, 13.2.2010:
>
> > Von: Arne Limburg 
> > <arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>>
> > Betreff: AW: [Ext-CDI] @Transactional
> > An: "'MyFaces Development'" 
> > <dev@myfaces.apache.org<mailto:dev@myfaces.apache.org>>
> > Datum: Samstag, 13. Februar 2010, 14:42
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Hi Gerhard,
> >
> >
> >
> > OK, I got what you did,
> > basically I did the same. You are right,
> > that was pretty straight-forward, but I had to
> hard-code
> > the persistence-unit
> > name.
> >
> >
> >
> > I have two ideas to inject the
> > persistence-unit name into the
> > producer-method for the EntityManager:
> >
> >
> >
> > First idea: A
> > @PersistenceUnitName qualifier-annotation to
> > inject the name into the producer-method. Client code
> would
> > have somethink like
> >
> > public class Configuration
> > {
> >
> >
> >
> >   @Produces
> > @PersistenceUnitName
> >
> >   String
> > getPersistenceUnitName() {
> >
> > ...
> >
> > Not really nice, but the
> > simplest solution to generify it.
> >
> >
> >
> > Second idea:
> >
> > The @PersistenceContext
> > qualifier has a @Nonbind attribute
> > persistenceUnitName which we can extract in the
> producer
> > method. But then we
> > get in scoping issues. Especially when having
> multiple
> > persistence-units within
> > one deployment. The second problem is: How can the
> > @Transactional annotation
> > know the persistence-unit-name.
> >
> >
> >
> > Any other ideas?
> >
> >
> >
> > Regards,
> >
> > Arne
> >
> >
> >
> > --
> >
> >
> >
> > Arne Limburg - Enterprise
> > Developer
> >
> > OpenKnowledge GmbH,
> > Oldenburg
> >
> > Bismarckstraße 13, 26122
> > Oldenburg
> >
> > Mobil: +49 (0) 151 - 108 22
> > 942
> >
> > Tel: +49 (0) 441 -
> > 4082-0
> >
> > Fax: +49 (0) 441 -
> > 4082-111
> >
> > arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>
> >
> >
> > http://www.openknowledge.de

> >
> >
> >
> >
> > Registergericht: Amtsgericht
> > Oldenburg, HRB 4670
> >
> > Geschäftsführer: Lars
> > Röwekamp, Jens Schumann
> >
> >
> >
> >
> >
> > Von: Gerhard Petracek
> > [mailto:gerhard.petra...@gmail.com<mailto:gerhard.petra...@gmail.com>]
>
> >
> > Gesendet: Samstag, 13. Februar 2010 14:32
> >
> > An: MyFaces Development
> >
> > Betreff: Re: [Ext-CDI] @Transactional
> >
> >
> >
> >
> >
> > hi arne,
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > i used the EntityManager to get
> > an EntityTransaction.
> >
> >
> >
> >
> >
> > you have to use cdi to create and
> > inject it.
> >
> >
> >
> >
> >
> > (i used some producer methods.)
> >
> >
> >
> >
> >
> > i created @PersistenceUnit which
> > is a cdi qualifier and
> >
> >
> >
> >
> >
> > @Transactional which is a cdi
> > interceptor binding.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > basically it works and it isn't
> > hard to use.
> >
> >
> >
> >
> >
> > however, we have to think about an
> > approach to provide as
> > much as possible in a generic way.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > regards,
> >
> >
> >
> >
> >
> > gerhard
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > http://www.irian.at

> >
> >
> >
> > Your JSF powerhouse -
> >
> > JSF Consulting, Development and
> >
> > Courses in English and German
> >
> >
> >
> > Professional Support for Apache MyFaces
> >
> >
> >
> >
> >
> >
> >
> > 2010/2/13 Arne Limburg 
> > <arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>>
> >
> >
> >
> >
> >
> >
> > Hi
> > Gerhard,
> >
> >
> >
> > Did
> > you mean "i used
> > UserTransaction"? If not, how do you receive your
> > EntityTransaction?
> >
> >
> >
> > I am
> > working on a solution to
> > get request-scoped EntityManagers injected within a
> > servlet-container that does
> > not even support the web-profile (which are the
> current
> > jetty and the current
> > tomcat). I am not able to get an EntityManager
> injected via
> > @PersistenceContext
> > in that environment. So it would be nice if there were
> some
> > CDI-Extension to
> > achieve this. The implementation would be pretty
> > straight-forward except the
> > configuration of the persistence-unit name and the
> handling
> > of different
> > persistence-units within one CDI-deployment
> > unit.
> >
> >
> >
> > Using
> > JTA-Transactions vs.
> > resource-local EntityTransactions is another issue
> > here.
> >
> >
> >
> >
> >
> > Regards,
> >
> > Arne
> >
> >
> >
> > --
> >
> >
> >
> > Arne
> > Limburg - Enterprise
> > Developer
> >
> > OpenKnowledge GmbH,
> > Oldenburg
> >
> > Bismarckstraße
> > 13, 26122 Oldenburg
> >
> > Mobil: +49 (0) 151
> > - 108 22 942
> >
> > Tel: +49 (0) 441 -
> > 4082-0
> >
> > Fax: +49 (0) 441 -
> > 4082-111
> >
> > arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>
> >
> >
> > http://www.openknowledge.de
> >
> >
> >
> > Registergericht:
> > Amtsgericht Oldenburg,
> > HRB 4670
> >
> > Geschäftsführer:
> > Lars Röwekamp, Jens
> > Schumann
> >
> >
> >
> >
> >
> >
> >
> > Von: Gerhard
> > Petracek 
> > [mailto:gerhard.petra...@gmail.com<mailto:gerhard.petra...@gmail.com>]
> >
> >
> > Gesendet: Freitag, 12. Februar 2010 19:59
> >
> > An: MyFaces Development
> >
> > Betreff: Re: [Ext-CDI] @Transactional
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > hi
> > arne,
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > yes
> > - i used EntityTransaction in the prototype and it
> works
> > pretty well in a
> > servlet container (that was the base idea).
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > regards,
> >
> >
> >
> >
> >
> > gerhard
> >
> >
> >
> > http://www.irian.at

> >
> >
> >
> > Your JSF powerhouse -
> >
> > JSF Consulting, Development and
> >
> > Courses in English and German
> >
> >
> >
> > Professional Support for Apache MyFaces
> >
> >
> >
> > 2010/2/12
> > Arne Limburg 
> > <arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>>
> >
> >
> >
> >
> >
> >
> > Hi
> > folks,
> >
> >
> >
> > I saw the discussion of adding an
> > @Transactional-Annotation to your
> > CDI extensions. I think Gerhard wrote it. I wonder if
> it
> > deals with JTA
> > transactions (which indeed would be pretty
> > straight-forward) or with
> > EntityTransactions of an resource-local EntityManager.
> I am
> > working on the
> > latter one and just would want to know if someone else
> is
> > working on such
> > stuff. I think it would be great, when we could
> archive
> > injection of
> > resource-local EntityManagers with transaction-support
> to
> > deploy it on a tomcat
> > or jetty. What do you think?
> >
> >
> >
> > Regards,
> >
> > Arne
> >
> >
> >
> > --
> >
> >
> >
> > Arne Limburg - Enterprise
> > Developer
> >
> > OpenKnowledge GmbH, Oldenburg
> >
> > Bismarckstraße
> > 13, 26122 Oldenburg
> >
> > Mobil:
> > +49 (0) 151 - 108 22 942
> >
> > Tel:
> > +49 (0) 441 - 4082-0
> >
> > Fax:
> > +49 (0) 441 - 4082-111
> >
> > arne.limb...@openknowledge.de<mailto:arne.limb...@openknowledge.de>
> >
> >
> > http://www.openknowledge.de

> >
> >
> >
> >
> > Registergericht:
> > Amtsgericht Oldenburg, HRB 4670
> >
> > Geschäftsführer:
> > Lars Röwekamp, Jens Schumann
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Sie sind Spam leid? Yahoo! Mail verfügt über einen
> herausragenden Schutz gegen Massenmails.
> http://mail.yahoo.com
>

__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen 
Massenmails.
http://mail.yahoo.com

Reply via email to