Discussion:
JpaPersistModule, Hibernate and URL Variables
Evan Ruff
2018-02-14 10:38:16 UTC
Permalink
Hey guys,

I've got what I think is a pretty straightforward task but I'm having a
little issue figuring out where to attach in my code.

I've got an embedded H2 database being used in an installed application to
manage state of some objects. I'm using Hibernate as my JPA implementation
and everything is working great. The one issue I have is that the path of
the database file is set in my URL as:

jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

which changes depending on how the application is executed. I'd like to
have the database file be written in a location set by an environment
variable, so that I'd have:

jdbc:h2:file:*$APP_DB_PATH*
/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

I've tried several different forms and it doesn't seem to be taking.

Has anyone encountered this and could give me a pointer on how to implement?

Thanks!

E
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/ed5b261c-62de-41b1-872f-7585ca134d0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-02-14 15:43:45 UTC
Permalink
When are you passing this string?
Is it part of you Giuce Module??

Could you read the environment variable before creating the string and
than manually create the URL string?
Post by Evan Ruff
Hey guys,
I've got what I think is a pretty straightforward task but I'm having
a little issue figuring out where to attach in my code.
I've got an embedded H2 database being used in an installed
application to manage state of some objects. I'm using Hibernate as my
JPA implementation and everything is working great. The one issue I
jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is executed. I'd like
to have the database file be written in a location set by
jdbc:h2:file:*$APP_DB_PATH*/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem to be taking.
Has anyone encountered this and could give me a pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/ed5b261c-62de-41b1-872f-7585ca134d0f%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/ed5b261c-62de-41b1-872f-7585ca134d0f%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/ef884498-fa77-e37d-ca1b-2bc0bd6b5e81%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Sondre Bjornebekk
2018-02-14 15:58:11 UTC
Permalink
If you always want to use h2, you could just simply build the string using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--?

If you wanted to inject different JPA providers, you could certainly use
Guice for that (since you posted here) - I have a HibernateSessionFactory
that provides a session per request like this:

@Provides
@RequestScoped
private Session provideSession() {



And then for my jUnit tests I have:

@Provides
@Singleton
private Session provideSession() {


in a

public class TestGuiceModule extends AbstractModule


Would that fit your use case?

Cheers,

-S-
Post by Evan Ruff
Hey guys,
I've got what I think is a pretty straightforward task but I'm having a
little issue figuring out where to attach in my code.
I've got an embedded H2 database being used in an installed application to
manage state of some objects. I'm using Hibernate as my JPA implementation
and everything is working great. The one issue I have is that the path of
jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is executed. I'd like to
have the database file be written in a location set by an environment
jdbc:h2:file:*$APP_DB_PATH*
/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem to be taking.
Has anyone encountered this and could give me a pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/6e5d4d2f-5f5c-430b-93ef-aca089efb688%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Evan Ruff
2018-02-14 20:06:34 UTC
Permalink
Hey guys,

So I'm actually just letting Guice Persist pull it straight out of
META-INF/persistence.xml file.

I'm wondering where I can either change the URL or set it explicitly, while
still using Guice Persist.

thanks!

E

On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre Bjornebekk
Post by Sondre Bjornebekk
If you always want to use h2, you could just simply build the string using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--?
If you wanted to inject different JPA providers, you could certainly use
Guice for that (since you posted here) - I have a HibernateSessionFactory
@Provides
@RequestScoped
private Session provideSession() {
@Provides
@Singleton
private Session provideSession() {
in a
public class TestGuiceModule extends AbstractModule
Would that fit your use case?
Cheers,
-S-
Post by Evan Ruff
Hey guys,
I've got what I think is a pretty straightforward task but I'm having a
little issue figuring out where to attach in my code.
I've got an embedded H2 database being used in an installed application
to manage state of some objects. I'm using Hibernate as my JPA
implementation and everything is working great. The one issue I have is
jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is executed. I'd like to
have the database file be written in a location set by an environment
jdbc:h2:file:*$APP_DB_PATH*
/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem to be taking.
Has anyone encountered this and could give me a pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/5c35a644-645a-4419-85c3-9a3a159fc87d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-02-14 23:13:37 UTC
Permalink
Maybe you can make your path relative to the user directory as described here:
http://www.h2database.com/html/faq.html#database_files
Post by Evan Ruff
Hey guys,
So I'm actually just letting Guice Persist pull it straight out of
META-INF/persistence.xml file.
I'm wondering where I can either change the URL or set it explicitly, while
still using Guice Persist.
thanks!
E
On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre Bjornebekk
Post by Sondre Bjornebekk
If you always want to use h2, you could just simply build the string
using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--?
Post by Sondre Bjornebekk
If you wanted to inject different JPA providers, you could certainly
use
Post by Sondre Bjornebekk
Guice for that (since you posted here) - I have a
HibernateSessionFactory
Post by Sondre Bjornebekk
@Provides
@RequestScoped
private Session provideSession() {
@Provides
@Singleton
private Session provideSession() {
in a
public class TestGuiceModule extends AbstractModule
Would that fit your use case?
Cheers,
-S-
Post by Evan Ruff
Hey guys,
I've got what I think is a pretty straightforward task but I'm
having a
Post by Sondre Bjornebekk
Post by Evan Ruff
little issue figuring out where to attach in my code.
I've got an embedded H2 database being used in an installed
application
Post by Sondre Bjornebekk
Post by Evan Ruff
to manage state of some objects. I'm using Hibernate as my JPA
implementation and everything is working great. The one issue I have
is
jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
Post by Sondre Bjornebekk
Post by Evan Ruff
which changes depending on how the application is executed. I'd like
to
Post by Sondre Bjornebekk
Post by Evan Ruff
have the database file be written in a location set by an
environment
Post by Sondre Bjornebekk
Post by Evan Ruff
jdbc:h2:file:*$APP_DB_PATH*
/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem to be taking.
Has anyone encountered this and could give me a pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/5c35a644-645a-4419-85c3-9a3a159fc87d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CC173E92-331F-4CC5-BD39-2F2430BFFF38%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Evan Ruff
2018-02-15 11:05:26 UTC
Permalink
I'd really like to be able to define the location of the DB, as multiple
services will be accessing it.

I'm okay with moving away from the persistence.xml file and rolling the
configuration in code, but I'm not sure where to do that while still using
JpaPersistModule. Has anyone tried a declarative approach? Any examples
anywhere?

E
Post by Stephan Classen
http://www.h2database.com/html/faq.html#database_files
Post by Evan Ruff
Hey guys,
So I'm actually just letting Guice Persist pull it straight out of
META-INF/persistence.xml file.
I'm wondering where I can either change the URL or set it explicitly,
while still using Guice Persist.
thanks!
E
On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre Bjornebekk
Post by Sondre Bjornebekk
If you always want to use h2, you could just simply build the string using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--
?
If you wanted to inject different JPA providers, you could certainly use
Guice for that (since you posted here) - I have a HibernateSessionFactory
@Provides
@RequestScoped
private Session provideSession() {
@Provides
@Singleton
private Session provideSession() {
in a
public class TestGuiceModule extends AbstractModule
Would that fit your use case?
Cheers,
-S-
Post by Evan Ruff
Hey guys,
I've got what I think is a pretty straightforward task but I'm having a
little issue figuring out where to attach in my code.
I've got an embedded H2 database being used in an installed application
to manage state of some objects. I'm using Hibernate as my JPA
implementation and everything is working great. The one issue I have is
jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is executed. I'd like to
have the database file be written in a location set by an environment
jdbc:h2:file:*$APP_DB_PATH*
/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem to be taking.
Has anyone encountered this and could give me a pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-02-15 11:47:27 UTC
Permalink
Only way you can try to achieve this is the methode:
JpaPersistModule.setProperties()
The properties passed in will be used to create the entity manager
factory (see JpaPersistService.start())

Maybe you can overwrite the URL in the properties you pass.
Post by Evan Ruff
I'd really like to be able to define the location of the DB, as
multiple services will be accessing it.
I'm okay with moving away from the persistence.xml file and rolling
the configuration in code, but I'm not sure where to do that while
still using JpaPersistModule. Has anyone tried a declarative approach?
Any examples anywhere?
E
http://www.h2database.com/html/faq.html#database_files
<http://www.h2database.com/html/faq.html#database_files>
Am 14. Februar 2018 21:06:34 MEZ schrieb Evan Ruff
Hey guys,
So I'm actually just letting Guice Persist pull it straight
out of META-INF/persistence.xml file.
I'm wondering where I can either change the URL or set it
explicitly, while still using Guice Persist.
thanks!
E
On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre
If you always want to use h2, you could just simply build
the string using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--
<https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv-->?
If you wanted to inject different JPA providers, you could
certainly use Guice for that (since you posted here) - I
have a HibernateSessionFactory that provides a session per
@Provides @RequestScoped private SessionprovideSession() {
@Provides @Singleton private SessionprovideSession() {
in a
public class TestGuiceModuleextends AbstractModule
Would that fit your use case?
Cheers,
-S-
On Wednesday, February 14, 2018 at 10:38:16 AM UTC, Evan
Hey guys,
I've got what I think is a pretty straightforward task
but I'm having a little issue figuring out where to
attach in my code.
I've got an embedded H2 database being used in an
installed application to manage state of some objects.
I'm using Hibernate as my JPA implementation and
everything is working great. The one issue I have is
jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is
executed. I'd like to have the database file be
written in a location set by an environment variable,
jdbc:h2:file:*$APP_DB_PATH*/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem
to be taking.
Has anyone encountered this and could give me a
pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/32d4dd9d-c41e-1ca1-9333-635c5ab5916f%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Evan Ruff
2018-02-15 13:46:48 UTC
Permalink
scl,

Thanks for the tip, this works as expected. JpaPersistModule is final
(ARGH) but I created a static utility class with an install method that
handles it. I build the database connection string using the env props and
then I'm able to set it using the JpaPersistModule.properties( <?,?> prop )
method. Set a map of strings in there, and it appears that it will use
those values to overwrite what comes out of the META-INF/persistence.xml
file.

Best of both worlds!

Thanks!

E
Post by Stephan Classen
JpaPersistModule.setProperties()
The properties passed in will be used to create the entity manager factory
(see JpaPersistService.start())
Maybe you can overwrite the URL in the properties you pass.
I'd really like to be able to define the location of the DB, as multiple
services will be accessing it.
I'm okay with moving away from the persistence.xml file and rolling the
configuration in code, but I'm not sure where to do that while still using
JpaPersistModule. Has anyone tried a declarative approach? Any examples
anywhere?
E
Post by Stephan Classen
http://www.h2database.com/html/faq.html#database_files
Post by Evan Ruff
Hey guys,
So I'm actually just letting Guice Persist pull it straight out of
META-INF/persistence.xml file.
I'm wondering where I can either change the URL or set it explicitly,
while still using Guice Persist.
thanks!
E
On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre Bjornebekk
Post by Sondre Bjornebekk
If you always want to use h2, you could just simply build the string using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--
?
If you wanted to inject different JPA providers, you could certainly
use Guice for that (since you posted here) - I have a
@***@RequestScopedprivate Session provideSession() {
@***@Singletonprivate Session provideSession() {
in a
public class TestGuiceModule extends AbstractModule
Would that fit your use case?
Cheers,
-S-
Post by Evan Ruff
Hey guys,
I've got what I think is a pretty straightforward task but I'm having
a little issue figuring out where to attach in my code.
I've got an embedded H2 database being used in an installed
application to manage state of some objects. I'm using Hibernate as my JPA
implementation and everything is working great. The one issue I have is
jdbc:h2:file:./data/
application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is executed. I'd like
to have the database file be written in a location set by an environment
jdbc:h2:file:*$APP_DB_PATH*
/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem to be taking.
Has anyone encountered this and could give me a pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/9089d9ce-3580-4a5b-97c6-e757484b2413%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-02-15 13:50:46 UTC
Permalink
Can't you simply do the following??

public class MyModule extends ServletModule {
  protected void configureServlets() {
    install(new JpaPersistModule("myJpaUnit").setProperties(myProperties));
  }
}
Post by Evan Ruff
scl,
Thanks for the tip, this works as expected. JpaPersistModule is final
(ARGH) but I created a static utility class with an install method
that handles it. I build the database connection string using the env
props and then I'm able to set it using the
JpaPersistModule.properties( <?,?> prop ) method. Set a map of strings
in there, and it appears that it will use those values to overwrite
what comes out of the META-INF/persistence.xml file.
Best of both worlds!
Thanks!
E
JpaPersistModule.setProperties()
The properties passed in will be used to create the entity manager
factory (see JpaPersistService.start())
Maybe you can overwrite the URL in the properties you pass.
Post by Evan Ruff
I'd really like to be able to define the location of the DB, as
multiple services will be accessing it.
I'm okay with moving away from the persistence.xml file and
rolling the configuration in code, but I'm not sure where to do
that while still using JpaPersistModule. Has anyone tried a
declarative approach? Any examples anywhere?
E
Maybe you can make your path relative to the user directory
http://www.h2database.com/html/faq.html#database_files
<http://www.h2database.com/html/faq.html#database_files>
Am 14. Februar 2018 21:06:34 MEZ schrieb Evan Ruff
Hey guys,
So I'm actually just letting Guice Persist pull it
straight out of META-INF/persistence.xml file.
I'm wondering where I can either change the URL or set it
explicitly, while still using Guice Persist.
thanks!
E
On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5,
If you always want to use h2, you could just simply
build the string using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--
<https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv-->?
If you wanted to inject different JPA providers, you
could certainly use Guice for that (since you posted
here) - I have a HibernateSessionFactory that
@Provides @RequestScoped private SessionprovideSession() {
@Provides @Singleton private SessionprovideSession() {
in a
public class TestGuiceModuleextends AbstractModule
Would that fit your use case?
Cheers,
-S-
On Wednesday, February 14, 2018 at 10:38:16 AM UTC,
Hey guys,
I've got what I think is a pretty straightforward
task but I'm having a little issue figuring out
where to attach in my code.
I've got an embedded H2 database being used in an
installed application to manage state of some
objects. I'm using Hibernate as my JPA
implementation and everything is working great.
The one issue I have is that the path of the
jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is
executed. I'd like to have the database file be
written in a location set by an environment
jdbc:h2:file:*$APP_DB_PATH*/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't
seem to be taking.
Has anyone encountered this and could give me a
pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the
Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it,
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice
<https://groups.google.com/group/google-guice>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/9089d9ce-3580-4a5b-97c6-e757484b2413%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/9089d9ce-3580-4a5b-97c6-e757484b2413%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/eba0600b-503b-0b30-43ad-dcec3c99b82a%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Evan Ruff
2018-02-15 14:05:23 UTC
Permalink
I mean, sure you could, but I don't like to put the business login in my
Bootstrap too much. It just felt cleaner the way I did it. I have defaults,
logging, failover, warnings etc if the environment isn't setup quite the
way I think it should be.
Post by Stephan Classen
Can't you simply do the following??
public class MyModule extends ServletModule {
protected void configureServlets() {
install(new JpaPersistModule("myJpaUnit").setProperties(myProperties));
}
}
scl,
Thanks for the tip, this works as expected. JpaPersistModule is final
(ARGH) but I created a static utility class with an install method that
handles it. I build the database connection string using the env props and
then I'm able to set it using the JpaPersistModule.properties( <?,?> prop )
method. Set a map of strings in there, and it appears that it will use
those values to overwrite what comes out of the META-INF/persistence.xml
file.
Best of both worlds!
Thanks!
E
Post by Stephan Classen
JpaPersistModule.setProperties()
The properties passed in will be used to create the entity manager
factory (see JpaPersistService.start())
Maybe you can overwrite the URL in the properties you pass.
I'd really like to be able to define the location of the DB, as multiple
services will be accessing it.
I'm okay with moving away from the persistence.xml file and rolling the
configuration in code, but I'm not sure where to do that while still using
JpaPersistModule. Has anyone tried a declarative approach? Any examples
anywhere?
E
Post by Stephan Classen
http://www.h2database.com/html/faq.html#database_files
Post by Evan Ruff
Hey guys,
So I'm actually just letting Guice Persist pull it straight out of
META-INF/persistence.xml file.
I'm wondering where I can either change the URL or set it explicitly,
while still using Guice Persist.
thanks!
E
On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre Bjornebekk
Post by Sondre Bjornebekk
If you always want to use h2, you could just simply build the string using
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--
?
If you wanted to inject different JPA providers, you could certainly
use Guice for that (since you posted here) - I have a
@***@RequestScopedprivate Session provideSession() {
@***@Singletonprivate Session provideSession() {
in a
public class TestGuiceModule extends AbstractModule
Would that fit your use case?
Cheers,
-S-
Post by Evan Ruff
Hey guys,
I've got what I think is a pretty straightforward task but I'm having
a little issue figuring out where to attach in my code.
I've got an embedded H2 database being used in an installed
application to manage state of some objects. I'm using Hibernate as my JPA
implementation and everything is working great. The one issue I have is
jdbc:h2:file:./data/
application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
which changes depending on how the application is executed. I'd like
to have the database file be written in a location set by an environment
jdbc:h2:file:*$APP_DB_PATH*
/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
I've tried several different forms and it doesn't seem to be taking.
Has anyone encountered this and could give me a pointer on how to implement?
Thanks!
E
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/9089d9ce-3580-4a5b-97c6-e757484b2413%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/9089d9ce-3580-4a5b-97c6-e757484b2413%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/cad39edf-8bf9-4ac9-9130-3e355a68cbd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...