You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2014/04/16 16:50:57 UTC

svn commit: r1587932 - in /tomee/tomee/trunk/examples: ./ datasource-versioning/ datasource-versioning/src/ datasource-versioning/src/test/ datasource-versioning/src/test/java/ datasource-versioning/src/test/java/org/ datasource-versioning/src/test/jav...

Author: andygumbrecht
Date: Wed Apr 16 14:50:57 2014
New Revision: 1587932

URL: http://svn.apache.org/r1587932
Log:
Add datasource-versioning example

Added:
    tomee/tomee/trunk/examples/datasource-versioning/   (with props)
    tomee/tomee/trunk/examples/datasource-versioning/pom.xml
    tomee/tomee/trunk/examples/datasource-versioning/src/
    tomee/tomee/trunk/examples/datasource-versioning/src/test/
    tomee/tomee/trunk/examples/datasource-versioning/src/test/java/
    tomee/tomee/trunk/examples/datasource-versioning/src/test/java/org/
    tomee/tomee/trunk/examples/datasource-versioning/src/test/java/org/superbiz/
    tomee/tomee/trunk/examples/datasource-versioning/src/test/java/org/superbiz/AlternateDriverJarTest.java
    tomee/tomee/trunk/examples/datasource-versioning/src/test/resources/
    tomee/tomee/trunk/examples/datasource-versioning/src/test/resources/META-INF/
    tomee/tomee/trunk/examples/datasource-versioning/src/test/resources/META-INF/beans.xml
Modified:
    tomee/tomee/trunk/examples/pom.xml
    tomee/tomee/trunk/examples/realm-in-tomee/   (props changed)

Propchange: tomee/tomee/trunk/examples/datasource-versioning/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Apr 16 14:50:57 2014
@@ -0,0 +1,4 @@
+*.iml
+.idea
+target
+*.log

Added: tomee/tomee/trunk/examples/datasource-versioning/pom.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/datasource-versioning/pom.xml?rev=1587932&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/datasource-versioning/pom.xml (added)
+++ tomee/tomee/trunk/examples/datasource-versioning/pom.xml Wed Apr 16 14:50:57 2014
@@ -0,0 +1,128 @@
+<?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 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>
+  <groupId>org.superbiz</groupId>
+  <artifactId>datasource-versioning</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1.0-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: Datasource Versioning</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <openejb.version>4.6.1-SNAPSHOT</openejb.version>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.1</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>2.8</version>
+        <executions>
+          <execution>
+            <id>AlternateDriverJarTest</id>
+            <phase>process-test-resources</phase>
+            <goals>
+              <goal>copy</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.derby</groupId>
+                  <artifactId>derby</artifactId>
+                  <version>10.10.1.1</version>
+                  <type>jar</type>
+                  <overWrite>false</overWrite>
+                  <outputDirectory>${project.build.directory}/drivers</outputDirectory>
+                  <destFileName>derby-10.10.1.1.jar</destFileName>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.apache.derby</groupId>
+                  <artifactId>derby</artifactId>
+                  <version>10.9.1.0</version>
+                  <type>jar</type>
+                  <overWrite>false</overWrite>
+                  <outputDirectory>${project.build.directory}/drivers</outputDirectory>
+                  <destFileName>derby-10.9.1.0.jar</destFileName>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-5</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+    <!--
+    The <scope>test</scope> guarantees that non of your runtime
+    code is dependent on any OpenEJB classes.
+    -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>4.6.1-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+</project>

Added: tomee/tomee/trunk/examples/datasource-versioning/src/test/java/org/superbiz/AlternateDriverJarTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/datasource-versioning/src/test/java/org/superbiz/AlternateDriverJarTest.java?rev=1587932&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/datasource-versioning/src/test/java/org/superbiz/AlternateDriverJarTest.java (added)
+++ tomee/tomee/trunk/examples/datasource-versioning/src/test/java/org/superbiz/AlternateDriverJarTest.java Wed Apr 16 14:50:57 2014
@@ -0,0 +1,130 @@
+/*
+ * 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.superbiz;
+
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Configuration;
+import org.apache.openejb.testing.Module;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.LocalBean;
+import javax.ejb.Singleton;
+import javax.sql.DataSource;
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.util.Properties;
+
+@RunWith(ApplicationComposer.class)
+public class AlternateDriverJarTest {
+
+    private static final String USER = "SA";
+    private static final String PASSWORD = "";
+
+    @Configuration
+    public Properties config() {
+
+        final File drivers = new File(new File("target"), "drivers").getAbsoluteFile();
+
+        final Properties p = new Properties();
+        p.put("openejb.jdbc.datasource-creator", "dbcp-alternative");
+
+        File file = new File(drivers, "derby-10.10.1.1.jar");
+        Assert.assertTrue("Failed to find: " + file, file.exists());
+
+        p.put("JdbcOne", "new://Resource?type=DataSource&classpath="
+                + file.getAbsolutePath().replace("\\", "/"));
+        p.put("JdbcOne.JdbcDriver", "org.apache.derby.jdbc.EmbeddedDriver");
+        p.put("JdbcOne.JdbcUrl", "jdbc:derby:memory:JdbcOne;create=true");
+        p.put("JdbcOne.UserName", USER);
+        p.put("JdbcOne.Password", PASSWORD);
+        p.put("JdbcOne.JtaManaged", "false");
+
+        file = new File(drivers, "derby-10.9.1.0.jar");
+        Assert.assertTrue("Failed to find: " + file, file.exists());
+
+        p.put("JdbcTwo", "new://Resource?type=DataSource&classpath="
+                + file.getAbsolutePath().replace("\\", "/"));
+        p.put("JdbcTwo.JdbcDriver", "org.apache.derby.jdbc.EmbeddedDriver");
+        p.put("JdbcTwo.JdbcUrl", "jdbc:derby:memory:JdbcTwo;create=true");
+        p.put("JdbcTwo.UserName", USER);
+        p.put("JdbcTwo.Password", PASSWORD);
+        p.put("JdbcTwo.JtaManaged", "false");
+        return p;
+    }
+
+    @Module
+    public EjbJar app() throws Exception {
+        return new EjbJar()
+                .enterpriseBean(new SingletonBean(JdbcOne.class).localBean())
+                .enterpriseBean(new SingletonBean(JdbcTwo.class).localBean());
+    }
+
+    @EJB
+    private JdbcOne one;
+
+    @EJB
+    private JdbcTwo two;
+
+    @Test
+    public void testBoth() throws Exception {
+
+        final String oneDriverVersion = one.getDriverVersion();
+        System.out.println("oneDriverVersion = " + oneDriverVersion);
+        Assert.assertEquals("Should be using 10.10.1.1 - (1458268)", "10.10.1.1 - (1458268)", oneDriverVersion);
+
+        final String twoDriverVersion = two.getDriverVersion();
+        System.out.println("twoDriverVersion = " + twoDriverVersion);
+        Assert.assertEquals("Should be using 10.9.1.0 - (1344872)", "10.9.1.0 - (1344872)", twoDriverVersion);
+    }
+
+    @LocalBean
+    @Singleton
+    public static class JdbcOne {
+
+        @Resource(name = "JdbcOne")
+        private DataSource ds;
+
+        public String getDriverVersion() throws Exception {
+
+            final Connection con = ds.getConnection();
+            final DatabaseMetaData md = con.getMetaData();
+            return md.getDriverVersion();
+        }
+    }
+
+    @LocalBean
+    @Singleton
+    public static class JdbcTwo {
+
+        @Resource(name = "JdbcTwo")
+        private DataSource ds;
+
+        public String getDriverVersion() throws Exception {
+
+            final Connection con = ds.getConnection();
+            final DatabaseMetaData md = con.getMetaData();
+            return md.getDriverVersion();
+        }
+    }
+}

Added: tomee/tomee/trunk/examples/datasource-versioning/src/test/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/datasource-versioning/src/test/resources/META-INF/beans.xml?rev=1587932&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/datasource-versioning/src/test/resources/META-INF/beans.xml (added)
+++ tomee/tomee/trunk/examples/datasource-versioning/src/test/resources/META-INF/beans.xml Wed Apr 16 14:50:57 2014
@@ -0,0 +1 @@
+<beans/>

Modified: tomee/tomee/trunk/examples/pom.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/pom.xml?rev=1587932&r1=1587931&r2=1587932&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/pom.xml (original)
+++ tomee/tomee/trunk/examples/pom.xml Wed Apr 16 14:50:57 2014
@@ -57,6 +57,7 @@
     <module>custom-injection</module>
     <module>datasource-ciphered-password</module>
     <module>datasource-definition</module>
+    <module>datasource-versioning</module>
     <module>decorators</module>
     <module>deltaspike-configproperty</module>
     <module>deltaspike-exception-handling</module>

Propchange: tomee/tomee/trunk/examples/realm-in-tomee/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Apr 16 14:50:57 2014
@@ -1,2 +1,3 @@
 target
 *.iml
+.idea