Comment #3 on issue 750 by [email protected]: 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 <[email protected]>
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 <[email protected]>
---
.../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

--
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

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to