geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From viol...@apache.org
Subject svn commit: r1058512 - in /geronimo/samples/trunk/samples/osgi/showmethemoney: ./ showmethemoney-ds/ showmethemoney-ds/src/ showmethemoney-ds/src/main/ showmethemoney-ds/src/main/resources/ showmethemoney-ds/src/main/resources/OSGI-INF/ showmethemoney-...
Date Thu, 13 Jan 2011 11:16:15 GMT
Author: violalu
Date: Thu Jan 13 11:16:15 2011
New Revision: 1058512

URL: http://svn.apache.org/viewvc?rev=1058512&view=rev
Log:
GERONIMO-5715
Add datasource as osgi service.

Added:
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/pom.xml
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/OSGI-INF/
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/OSGI-INF/blueprint/
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/util/
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/util/ServiceUtil.java
    geronimo/samples/trunk/samples/osgi/showmethemoney/sql/
    geronimo/samples/trunk/samples/osgi/showmethemoney/sql/MoneyDB.sql
Modified:
    geronimo/samples/trunk/samples/osgi/showmethemoney/pom.xml
    geronimo/samples/trunk/samples/osgi/showmethemoney/readme.txt
    geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/ShowMoneyServlet.java

Modified: geronimo/samples/trunk/samples/osgi/showmethemoney/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/osgi/showmethemoney/pom.xml?rev=1058512&r1=1058511&r2=1058512&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/osgi/showmethemoney/pom.xml (original)
+++ geronimo/samples/trunk/samples/osgi/showmethemoney/pom.xml Thu Jan 13 11:16:15 2011
@@ -16,9 +16,7 @@
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <artifactId>osgi</artifactId>
@@ -39,5 +37,6 @@
     <module>showmethemoney-api</module>
     <module>showmethemoney-server</module>
     <module>showmethemoney-web</module>
+    <module>showmethemoney-ds</module>
   </modules>
 </project>
\ No newline at end of file

Modified: geronimo/samples/trunk/samples/osgi/showmethemoney/readme.txt
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/osgi/showmethemoney/readme.txt?rev=1058512&r1=1058511&r2=1058512&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/osgi/showmethemoney/readme.txt (original)
+++ geronimo/samples/trunk/samples/osgi/showmethemoney/readme.txt Thu Jan 13 11:16:15 2011
@@ -24,12 +24,15 @@ INSTALL
 
 1. Start Server, go to Geronimo directory, execute these commands from a command prompt:
         cd %Geronimo_HOME%/bin 
-	    geronimo.bat run
+        geronimo.bat run
  2. Install Bundles. Press "enter", you can go into karaf command mode       
         geronimo>install file:/D:/samplesTrunk/samples/osgi/showmethemoney/showmethemoney-api/target/showmethemoney-api-3.0-SNAPSHOT.jar
         geronimo>install file:/D:/samplesTrunk/samples/osgi/showmethemoney/showmethemoney-server/target/showmethemoney-server-3.0-SNAPSHOT.jar
-        
- 3. Deploy web app using deployer tool.
+         geronimo>install file:/D:/samplesTrunk/samples/osgi/showmethemoney/showmethemoney-ds/target/showmethemoney-ds-3.0-SNAPSHOT.jar
+  
+ 3. Run sql under sql/moneydb.sql  against derby database moneydb
+         
+ 4. Deploy web app using deployer tool.
        cd %Geronimo_Home%/bin
        deploy.[bat|sh] deploy D:/samplesTrunk/samples/osgi/showmethemoney/showmethemoney-web/showmethemoney-web-3.0-SNAPSHOT.war
   Access http://[IP_Address]:8080/showmoney/

Added: geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/pom.xml?rev=1058512&view=auto
==============================================================================
--- geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/pom.xml (added)
+++ geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/pom.xml Thu Jan 13
11:16:15 2011
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>showmethemoney</artifactId>
+    <groupId>org.apache.geronimo.samples.osgi.showmethemoney</groupId>
+    <version>3.0-SNAPSHOT</version>
+  </parent>  
+  
+  <artifactId>showmethemoney-ds</artifactId>
+  <packaging>bundle</packaging>
+ 
+  <name>Geronimo Samples :: OSGI Sample :: showmethemoney-ds</name>
+  <description>Show Me The Money Derby DataSource</description>
+  
+  <dependencies>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+        </dependency>
+        <!--<dependency>
+            <groupId>org.apache.aries.transaction</groupId>
+            <artifactId>org.apache.aries.transaction.blueprint</artifactId>
+            <version>${ariesTransactionVersion}</version>
+        </dependency>-->
+        <dependency>
+            <groupId>org.apache.geronimo.components</groupId>
+            <artifactId>geronimo-transaction</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Version>${pom.version}</Bundle-Version>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1058512&view=auto
==============================================================================
--- geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml
(added)
+++ geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-ds/src/main/resources/OSGI-INF/blueprint/blueprint.xml
Thu Jan 13 11:16:15 2011
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                default-activation="eager">
+  
+    <bean id="derbyXADataSource" class="org.apache.derby.jdbc.EmbeddedXADataSource">
+        <property name="databaseName" value="moneydb"/>
+        <!-- This creates the database on the fly. -->
+       <property name="createDatabase" value="create" />
+    </bean>
+  
+    <service id="MoneyDataSource" ref="derbyXADataSource" interface="javax.sql.XADataSource">
+        <service-properties>
+            <entry key="osgi.jndi.service.name" value="jdbc/MoneyDataSource"/>
+        </service-properties>
+    </service>
+
+  
+    <bean id="derbyDataSource" class="org.apache.derby.jdbc.EmbeddedDataSource">
+        <property name="databaseName" value="moneydb"/>
+        <!-- This creates the database on the fly. -->
+       <property name="createDatabase" value="create" />
+    </bean>
+  
+    <service id="NoTxMoneyDataSource" ref="derbyDataSource" interface="javax.sql.DataSource">
+        <service-properties>
+            <entry key="osgi.jndi.service.name" value="jdbc/NoTxMoneyDataSource"/>
+        </service-properties>
+    </service>
+  
+</blueprint>

Modified: geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/ShowMoneyServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/ShowMoneyServlet.java?rev=1058512&r1=1058511&r2=1058512&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/ShowMoneyServlet.java
(original)
+++ geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/ShowMoneyServlet.java
Thu Jan 13 11:16:15 2011
@@ -20,6 +20,11 @@ import java.io.PrintWriter;
 import java.io.IOException;
 import javax.servlet.ServletException;
 import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -35,8 +40,11 @@ import javax.naming.NameClassPair;
 import javax.naming.NamingException;
 import javax.naming.NamingEnumeration;
 import javax.naming.Binding;
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
 
 import org.apache.geronimo.samples.osgi.showmethemoney.api.ShowMoneyService;
+import org.apache.geronimo.samples.osgi.showmethemoney.web.util.ServiceUtil;
 
 /**
  * Show me the money!
@@ -47,6 +55,10 @@ public class ShowMoneyServlet extends Ht
     @Resource
     private BundleContext bundleContext;
     
+    private DataSource dataSource= null;
+    
+    Connection conn = null;
+    PreparedStatement stmt = null;
        
     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
@@ -64,10 +76,36 @@ public class ShowMoneyServlet extends Ht
            Context ctx2 = (Context) ctx.lookup("osgi:service");
            ShowMoneyService sm = (ShowMoneyService)ctx2.lookup("org.apache.geronimo.samples.osgi.showmethemoney.api.ShowMoneyService");
            pw.println(sm.showmoney()); 
+           
+           dataSource = (DataSource)ServiceUtil.getOSGIService(DataSource.class.getName(),"(osgi.jndi.service.name=jdbc/NoTxMoneyDataSource)");
+           
+           try {
+conn = dataSource.getConnection();
+//conn.setAutoCommit(false);
+stmt = conn.prepareStatement("select * from customer");
+ResultSet rs = stmt.executeQuery();
+
+while (rs.next()){
+	pw.println(rs.getString("name"));
+} 
+
+} catch (SQLException e) {
+// TODO Auto-generated catch block
+ pw.println(e.toString());
+}
+           
        } catch (NamingException e){
            pw.println(e.toString());
-       }   
-     
+       }  
+       finally {  
+          try {
+        stmt.close();
+conn.close();
+} catch (SQLException e) {
+// TODO Auto-generated catch block
+e.printStackTrace();
+}
+}
     }
 
     @Override

Added: geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/util/ServiceUtil.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/util/ServiceUtil.java?rev=1058512&view=auto
==============================================================================
--- geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/util/ServiceUtil.java
(added)
+++ geronimo/samples/trunk/samples/osgi/showmethemoney/showmethemoney-web/src/main/java/org/apache/geronimo/samples/osgi/showmethemoney/web/util/ServiceUtil.java
Thu Jan 13 11:16:15 2011
@@ -0,0 +1,66 @@
+/**
+ *  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.geronimo.samples.osgi.showmethemoney.web.util;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * ServiceUtil provides servlet specific client side
+ * utility functions.
+ */
+public class ServiceUtil {
+private static final String OSGI_SERVICE_PREFIX = "osgi:service/";
+
+    
+/**
+     * Lookup and return an osgi service
+     * 
+     * @return Object
+     * @exception javax.io.IOException
+     *                If an exception occurs during the service
+     *                lookup
+     * 
+     */
+    public static final Object getOSGIService(String serviceName) {
+        
+        return getOSGIService(serviceName, null);
+    }
+
+    /**
+     * Lookup and return an osgi service
+     * 
+     * @return Object
+     * 
+     */
+    public static final Object getOSGIService(String serviceName, String filter) {
+        
+        String name = OSGI_SERVICE_PREFIX + serviceName;
+        if (filter != null) {
+            name = name + "/" + filter;
+        }
+
+        try {
+            InitialContext ic = new InitialContext();
+            return ic.lookup(name);
+        } catch (NamingException e) {
+            
+            e.printStackTrace();
+            return null;
+        }
+    }
+}
\ No newline at end of file

Added: geronimo/samples/trunk/samples/osgi/showmethemoney/sql/MoneyDB.sql
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/osgi/showmethemoney/sql/MoneyDB.sql?rev=1058512&view=auto
==============================================================================
--- geronimo/samples/trunk/samples/osgi/showmethemoney/sql/MoneyDB.sql (added)
+++ geronimo/samples/trunk/samples/osgi/showmethemoney/sql/MoneyDB.sql Thu Jan 13 11:16:15
2011
@@ -0,0 +1,18 @@
+--  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.
+CREATE TABLE Customer(	customerId VARCHAR(255) PRIMARY KEY,name VARCHAR(255));
+
+
+INSERT INTO Customer(customerId, name) VALUES('12345','John Doe');



Mime
View raw message