Works like a charm, even with pretty old Progress jdbc driver! Thanks a lot 
Romain.

Cheers,
Dmitry

-----Original Message-----
From: Romain Manni-Bucau [mailto:rmannibu...@gmail.com] 
Sent: Thursday, September 27, 2018 10:03 PM
To: users@tomee.apache.org
Subject: Re: Apache Ignite initialization before EntityManagerFactory

Well, long story short you can create any instance from your app classloader 
and make it a resource using resources.xml.

The datasources follow that rule and just need some tricks in some cases:

1. If you want it to be jta managed then you need to use the jta wrapper (see 
https://rmannibucau.wordpress.com/2014/04/11/openejbtomee-custom-datasource-jta-integration/
)
2. To ensure it works with jpa, add type=DataSource as for any default 
datasource - even using class-name.

Le jeu. 27 sept. 2018 23:43, Shultz, Dmitry <dmitry_shu...@kaltire.com> a écrit 
:

> I figured it out when found this:
> https://rmannibucau.wordpress.com/2013/11/05/openejbtomee-resources-ho
> w-does-it-work/
> and this
> http://svn.apache.org/repos/asf/tomee/tomee/trunk/container/openejb-co
> re/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
>
> Everything seems to be working now.
> However, I noticed the resource factory method is called twice (7.0.4) 
> not sure how bad it is.
>
>
> Cheers,
> Dmitry
>
> -----Original Message-----
> From: Shultz, Dmitry
> Sent: Thursday, September 27, 2018 1:28 PM
> To: users@tomee.apache.org
> Subject: RE: Apache Ignite initialization before EntityManagerFactory
>
> Thanks Romain.
>
> Ignite is using static variables internally to track it's cache 
> instances, so EntityManagerFactory and Ignite must be initiated by the 
> same classloader, not sure if it will create problem with custom 
> resource for Ignite, I will try to play with it and lazy persistence unit 
> later.
>
> For now I would like to figure out how to instantiate the DataSource 
> properly using class-name/factory-name approach (I'm going to need 
> this for another use case as well).
>
> I can see the
> https://github.com/apache/tomee/blob/master/container/openejb-core/src
> /test/java/org/apache/openejb/config/typed/util/ServerContextTest.java
> is using DataSourceBuilder and ServerContext to create the DataSource 
> resource. Is there anything like that can be used from my custom 
> factory method?
>
> Cheers,
> Dmitry
>
> -----Original Message-----
> From: Romain Manni-Bucau [mailto:rmannibu...@gmail.com]
> Sent: Thursday, September 27, 2018 12:28 PM
> To: users@tomee.apache.org
> Subject: Re: Apache Ignite initialization before EntityManagerFactory
>
> This works, you can also create an ignite resource just to create 
> ignite instance.
>
> That said, did you try to make your persistence unit lazy? Can make it 
> working and let you start ignite from your app.
>
> Le jeu. 27 sept. 2018 21:01, Shultz, Dmitry 
> <dmitry_shu...@kaltire.com> a écrit :
>
> > Figured out some way to make sure Ignite is initialized before 
> > EntityManagerFactory, not sure if it's the right way though. Please 
> > let me know if I'm doing something conceptually wrong here.
> >
> > I'm trying to use the  class-name and factory-name (as described here:
> > http://tomee.apache.org/application-resources.html) to make sure the 
> > DataSource is initialized after Ignite.start() is called. The 
> > sequence problem seems to be resolved, but I'm not sure how to 
> > properly manually instantiate the JTA managed datasource.
> >
> > Here is my resources.xml:
> >
> > <resources>
> >
> >     <Resource id="myDS" type="javax.sql.DataSource"
> > class-name="com.bla.bla.DataSourceFactory" factory-name="create">
> >         JdbcDriver   = org.postgresql.Driver
> >         JdbcUrl      = jdbc:postgresql://localhost:5432/mydb
> >         UserName     = user
> >         Password     = test
> >         maxActive = 10
> >         maxIdle = 10
> >         TestOnBorrow = true
> >         TestWhileIdle = true
> >         TestOnReturn = true
> >         ValidationQuery = SELECT 1
> >         JtaManaged=true
> >     </Resource>
> > </resources>
> >
> >
> > Here is my factory method (ofcom.bla.bla.DataSourceFactory):
> >
> > public Object create() {
> >
> >         initIgnite();
> >
> >         BasicManagedDataSource resource = new 
> > BasicManagedDataSource("myDB");
> >         resource.setJdbcDriver("org.postgresql.Driver");
> >         resource.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb");
> >         resource.setUserName("user");
> >         resource.setPassword("test");
> >         resource.setTestOnBorrow(true);
> >         resource.setTestWhileIdle(true);
> >         resource.setTestOnReturn(true);
> >         resource.setValidationQuery("SELECT 1");
> >
> >         return resource;
> >     }
> >
> > BasicManagedDataSource doesn't have the setJtaManaged(), so it's 
> > probably not a good choice... Also, and I'm seeing this in the log:
> >
> > 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> > org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> > property 'JdbcDriver' for resource 'my-app/myDS'
> > 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> > org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> > property 'JdbcUrl' for resource 'my-app / myDS '
> > 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> > org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> > property 'UserName' for resource 'my-app / myDS '
> > 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> > org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> > property 'Password' for resource 'my-app / myDS '
> > ...
> >
> >
> > From: Shultz, Dmitry
> > Sent: Thursday, September 27, 2018 10:03 AM
> > To: users@tomee.apache.org
> > Subject: Apache Ignite initialization before EntityManagerFactory
> >
> > Hi All,
> >
> > I'm trying to use Apache Ignite as a L2 cache in my app.
> >
> > Both JPA/Hibernate and Ignite are configured to work together, but 
> > I'm not sure how to make the Ignite to started before JPA/Hibernate 
> > is
> initialized.
> > Right now the war deployment fails when deployer is trying to create 
> > EntityManagerFactory and can't find the specified (in 
> > persistence.xml) Ignite instance. Do I have to deploy another app 
> > (with Ignite.start() in
> > it) before the 'main' app or there is some other way to do it?
> >
> > Cheers,
> > Dmitry
> >
> >
>

Reply via email to