Issue 750 in google-guice: With guice-persist, it is not possible to provide a DataSource to providers.

26 views
Skip to first unread message

google...@googlecode.com

unread,
May 25, 2013, 11:19:41 AM5/25/13
to google-g...@googlegroups.com
Status: New
Owner: ----

New issue 750 by nigel.ma...@gmail.com: With guice-persist, it is not
possible to provide a DataSource to providers.
http://code.google.com/p/google-guice/issues/detail?id=750

JpaPersistService takes a parameter thus:
Properties persistenceProperties

However, this is used later to create an entity manager:
Persistence.createEntityManagerFactory(persistenceUnitName,
persistenceProperties);


The signature for that method is String, Map, NOT String, Properties.

If one is using Hibernate, you can pass the desired DataSource object in
using that Map with Environment.DATASOURCE storing the actual object.
Clearly you cannot do that if it's Properties (string->string map)

Changing this so that the persistenceProperties were a Map would solve this.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

google...@googlecode.com

unread,
Jul 23, 2013, 3:41:59 PM7/23/13
to google-g...@googlegroups.com

Comment #1 on issue 750 by nigel.ma...@gmail.com: With guice-persist, it is
not possible to provide a DataSource to providers.
http://code.google.com/p/google-guice/issues/detail?id=750

I.E: In JpaPersistService.java :


30a31
> import java.util.Map;
45c46
< private final Properties persistenceProperties;
---
> private final Map persistenceProperties;
49c50
< @Nullable @Jpa Properties persistenceProperties) {
---
> @Nullable @Jpa Map persistenceProperties) {

google...@googlecode.com

unread,
Dec 20, 2013, 9:19:38 AM12/20/13
to google-g...@googlegroups.com
Updates:
Labels: Component-Persist

Comment #2 on issue 750 by sberlin: With guice-persist, it is not possible
to provide a DataSource to providers.
http://code.google.com/p/google-guice/issues/detail?id=750

(No comment was entered for this change.)

google...@googlecode.com

unread,
Dec 20, 2013, 10:55:54 AM12/20/13
to google-g...@googlegroups.com

Comment #3 on issue 750 by nigel.ma...@gmail.com: With guice-persist, it is
not possible to provide a DataSource to providers.
http://code.google.com/p/google-guice/issues/detail?id=750

FWIW, this was my really simple patch to make this work, which means I can
do this:

javax.sql.DataSource ds;
// ...
Map p = new HashMap();
p.put( Environment.DATASOURCE, ds );
JpaPersistModule jpaPersistModule = new
JpaPersistModule("myapp-db").properties(p);

Should be broadly compatible, since Properties are also Maps.

---
From 0fac6920787289de42a2dea2f198e775447afbb9 Mon Sep 17 00:00:00 2001
From: Nigel Magnay <nigel....@gmail.com>
Date: Tue, 23 Jul 2013 20:48:53 +0100
Subject: [PATCH] Properties to be a map, so that objects can be used.

Signed-off-by: Nigel Magnay <nigel....@gmail.com>
---
.../src/com/google/inject/persist/jpa/JpaPersistModule.java | 11
++++++-----
.../src/com/google/inject/persist/jpa/JpaPersistService.java | 7 +++----
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git
a/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistModule.java
b/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistModule.java
index b318b27..9efbfed 100644
---
a/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistModule.java
+++
b/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistModule.java
@@ -35,6 +35,7 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;
+import java.util.Map;
import java.util.Properties;

import javax.persistence.EntityManager;
@@ -54,17 +55,17 @@ public final class JpaPersistModule extends
PersistModule {
this.jpaUnit = jpaUnit;
}

- private Properties properties;
+ private Map properties;
private MethodInterceptor transactionInterceptor;

@Override protected void configurePersistence() {
bindConstant().annotatedWith(Jpa.class).to(jpaUnit);

if (null != properties) {
-
bind(Properties.class).annotatedWith(Jpa.class).toInstance(properties);
+ bind(Map.class).annotatedWith(Jpa.class).toInstance(properties);
} else {
- bind(Properties.class).annotatedWith(Jpa.class)
- .toProvider(Providers.<Properties>of(null));
+ bind(Map.class).annotatedWith(Jpa.class)
+ .toProvider(Providers.<Map>of(null));
}

bind(JpaPersistService.class).in(Singleton.class);
@@ -94,7 +95,7 @@ public final class JpaPersistModule extends PersistModule
{
* @param properties A set of name value pairs that configure a JPA
persistence
* provider as per the specification.
*/
- public JpaPersistModule properties(Properties properties) {
+ public JpaPersistModule properties(Map properties) {
this.properties = properties;
return this;
}
diff --git
a/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistService.java
b/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistService.java
index b8fe35c..3bc5358 100644
---
a/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistService.java
+++
b/extensions/persist/src/com/google/inject/persist/jpa/JpaPersistService.java
@@ -28,8 +28,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import java.util.Properties;
-
+import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
@@ -42,11 +41,11 @@ class JpaPersistService implements
Provider<EntityManager>, UnitOfWork, PersistS
private final ThreadLocal<EntityManager> entityManager = new
ThreadLocal<EntityManager>();

private final String persistenceUnitName;
- private final Properties persistenceProperties;
+ private final Map persistenceProperties;

@Inject
public JpaPersistService(@Jpa String persistenceUnitName,
- @Nullable @Jpa Properties persistenceProperties) {
+ @Nullable @Jpa Map persistenceProperties) {
this.persistenceUnitName = persistenceUnitName;
this.persistenceProperties = persistenceProperties;
}
--
1.8.5.1

google...@googlecode.com

unread,
Mar 17, 2014, 9:19:04 AM3/17/14
to google-g...@googlegroups.com

Comment #4 on issue 750 by Sebastie...@gmail.com: With guice-persist, it is
not possible to provide a DataSource to providers.
http://code.google.com/p/google-guice/issues/detail?id=750

Patch provided is totally reasonable. There is no developer anymore on
Guice? Why I have to build my own version. Should this be already merged,
with a 3.0.1 build?
Reply all
Reply to author
Forward
0 new messages