Author: ieb
Date: Thu Nov 20 16:59:17 2008
New Revision: 719436

URL: http://svn.apache.org/viewvc?rev=719436&view=rev
Log:
Added Guice module for JPA Sample.

Added:
    
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/EclipseEntityManagerProvider.java
   (with props)
    
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/JPASocialModule.java
   (with props)
    
incubator/shindig/trunk/java/samples/src/main/resources/socialjpa.properties   
(with props)
    
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/JPASocialModuleTest.java
   (with props)
Modified:
    incubator/shindig/trunk/java/samples/pom.xml
    
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/Bootstrap.java

Modified: incubator/shindig/trunk/java/samples/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/pom.xml?rev=719436&r1=719435&r2=719436&view=diff
==============================================================================
--- incubator/shindig/trunk/java/samples/pom.xml (original)
+++ incubator/shindig/trunk/java/samples/pom.xml Thu Nov 20 16:59:17 2008
@@ -48,6 +48,12 @@
   <build>
     <resources>
       <resource>
+        <directory>${basedir}/src/main/resources</directory>
+        <includes>
+          <include>**/*</include>
+        </includes>
+      </resource>
+      <resource>
         <targetPath>META-INF</targetPath>
         <directory>${basedir}/../../</directory>
         <includes>

Modified: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/Bootstrap.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/Bootstrap.java?rev=719436&r1=719435&r2=719436&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/Bootstrap.java
 (original)
+++ 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/Bootstrap.java
 Thu Nov 20 16:59:17 2008
@@ -38,14 +38,14 @@
 import org.eclipse.persistence.config.PersistenceUnitProperties;
 import org.eclipse.persistence.config.TargetServer;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
 import javax.persistence.spi.PersistenceUnitTransactionType;
 
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * 
  */

Added: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/EclipseEntityManagerProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/EclipseEntityManagerProvider.java?rev=719436&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/EclipseEntityManagerProvider.java
 (added)
+++ 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/EclipseEntityManagerProvider.java
 Thu Nov 20 16:59:17 2008
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.opensocial.jpa.eclipselink;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.name.Named;
+
+import javax.persistence.EntityManager;
+
+/**
+ * Creates an Eclipse Entity Manager.
+ */
+public class EclipseEntityManagerProvider implements Provider<EntityManager> {
+
+  private Bootstrap bootstrap;
+  private String unitName;
+
+  /**
+   * 
+   */
+  @Inject
+  public EclipseEntityManagerProvider(Bootstrap bootstrap,
+      @Named("jpa.socialapi.unitname") String unitName) {
+    this.unitName = unitName;
+    this.bootstrap = bootstrap;
+  }
+
+  /**
+   * [EMAIL PROTECTED]
+   * 
+   * @see com.google.inject.Provider#get()
+   */
+  public EntityManager get() {
+    return bootstrap.getEntityManager(unitName);
+  }
+
+}

Propchange: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/EclipseEntityManagerProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/EclipseEntityManagerProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Added: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/JPASocialModule.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/JPASocialModule.java?rev=719436&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/JPASocialModule.java
 (added)
+++ 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/JPASocialModule.java
 Thu Nov 20 16:59:17 2008
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.opensocial.jpa.spi;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.CreationException;
+import com.google.inject.Scopes;
+import com.google.inject.name.Names;
+import com.google.inject.spi.Message;
+
+import org.apache.shindig.common.util.ResourceLoader;
+import org.apache.shindig.social.opensocial.jpa.PersonDb;
+import 
org.apache.shindig.social.opensocial.jpa.eclipselink.EclipseEntityManagerProvider;
+import org.apache.shindig.social.opensocial.spi.ActivityService;
+import org.apache.shindig.social.opensocial.spi.AppDataService;
+import org.apache.shindig.social.opensocial.spi.PersonService;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Properties;
+
+import javax.persistence.EntityManager;
+
+/**
+ * 
+ */
+public class JPASocialModule extends AbstractModule {
+
+  private final static String DEFAULT_PROPERTIES = "socialjpa.properties";
+  private Properties properties;
+
+  /**
+   * 
+   */
+  public JPASocialModule() {
+    InputStream is = null;
+    try {
+      is = 
this.getClass().getClassLoader().getResourceAsStream(DEFAULT_PROPERTIES);
+      if (is == null) {
+        System.err.println("Cant loacate properties");
+        throw new IOException("Failed to open " + DEFAULT_PROPERTIES);
+      }
+      properties = new Properties();
+      properties.load(is);
+    } catch (IOException e) {
+      throw new CreationException(Arrays.asList(new Message(
+          "Unable to load properties: " + DEFAULT_PROPERTIES)));
+    } finally {
+      try {
+        if (is != null) {
+          is.close();
+        }
+      } catch (IOException e) {
+        // dont care about this.
+      }
+    }
+  }
+
+  /**
+   * [EMAIL PROTECTED]
+   * 
+   * @see com.google.inject.AbstractModule#configure()
+   */
+  @Override
+  protected void configure() {
+    Names.bindProperties(this.binder(), properties);
+    bind(EntityManager.class).toProvider(EclipseEntityManagerProvider.class)
+        .in(Scopes.SINGLETON);
+    bind(ActivityService.class).to(ActivityServiceDb.class)
+        .in(Scopes.SINGLETON);
+    bind(PersonService.class).to(PersonServiceDb.class).in(Scopes.SINGLETON);
+    bind(AppDataService.class).to(AppDataServiceDb.class).in(Scopes.SINGLETON);
+  }
+}

Propchange: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/JPASocialModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/JPASocialModule.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Added: 
incubator/shindig/trunk/java/samples/src/main/resources/socialjpa.properties
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/src/main/resources/socialjpa.properties?rev=719436&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/samples/src/main/resources/socialjpa.properties 
(added)
+++ 
incubator/shindig/trunk/java/samples/src/main/resources/socialjpa.properties 
Thu Nov 20 16:59:17 2008
@@ -0,0 +1,7 @@
+db.driver=org.apache.derby.jdbc.EmbeddedDriver
+db.url=jdbc:derby:target/testdb;create=true
+db.user=sa
+db.password= 
+db.write.min=1
+db.read.min=1
+jpa.socialapi.unitname=default

Propchange: 
incubator/shindig/trunk/java/samples/src/main/resources/socialjpa.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/JPASocialModuleTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/JPASocialModuleTest.java?rev=719436&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/JPASocialModuleTest.java
 (added)
+++ 
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/JPASocialModuleTest.java
 Thu Nov 20 16:59:17 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.opensocial.jpa.test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+import org.apache.shindig.social.opensocial.jpa.spi.JPASocialModule;
+import org.apache.shindig.social.opensocial.spi.ActivityService;
+import org.apache.shindig.social.opensocial.spi.AppDataService;
+import org.apache.shindig.social.opensocial.spi.PersonService;
+
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class JPASocialModuleTest {
+
+  @Test
+  public void bootstrap() {
+    Injector injector = Guice.createInjector(new JPASocialModule());
+    @SuppressWarnings("unused")
+    PersonService personService = injector.getInstance(PersonService.class);
+    @SuppressWarnings("unused")
+    ActivityService activityService = injector
+        .getInstance(ActivityService.class);
+    @SuppressWarnings("unused")
+    AppDataService appDataService = injector.getInstance(AppDataService.class);
+  }
+
+}

Propchange: 
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/JPASocialModuleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/JPASocialModuleTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id


Reply via email to