You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2010/01/19 17:26:21 UTC

svn commit: r900834 - in /servicemix/smx4/specs/trunk: ./ java-persistence-api-2.0/ java-persistence-api-2.0/src/ java-persistence-api-2.0/src/main/ java-persistence-api-2.0/src/main/java/ java-persistence-api-2.0/src/main/java/javax/ java-persistence-...

Author: jbonofre
Date: Tue Jan 19 16:26:20 2010
New Revision: 900834

URL: http://svn.apache.org/viewvc?rev=900834&view=rev
Log:
[SMX4-450] Create specs bundle for JPA 2.0.

Added:
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/pom.xml   (with props)
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/persistence/
    servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/persistence/Persistence.java   (with props)
Modified:
    servicemix/smx4/specs/trunk/pom.xml

Added: servicemix/smx4/specs/trunk/java-persistence-api-2.0/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/java-persistence-api-2.0/pom.xml?rev=900834&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/java-persistence-api-2.0/pom.xml (added)
+++ servicemix/smx4/specs/trunk/java-persistence-api-2.0/pom.xml Tue Jan 19 16:26:20 2010
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+
+    <!--
+
+        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.
+    -->
+    
+    <modelVersion>4.0.0</modelVersion>
+    
+    <parent>
+        <groupId>org.apache.servicemix.specs</groupId>
+        <artifactId>specs</artifactId>
+        <version>1.5-SNAPSHOT</version>
+    </parent>
+    
+    <groupId>org.apache.servicemix.specs</groupId>
+    <artifactId>org.apache.servicemix.specs.java-persistence-api-2.0</artifactId>
+    <packaging>bundle</packaging>
+    <version>1.5-SNAPSHOT</version>
+    <name>Apache ServiceMix Specs :: JAVA PERSISTENCE API 2.0</name>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.specs</groupId>
+            <artifactId>org.apache.servicemix.specs.locator</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jpa_2.0_spec</artifactId>
+            <version>1.0</version>
+        </dependency>
+    </dependencies>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>javax.persistence*;version=2.0;-split-package:=merge-first</Export-Package>
+                        <Import-Package>*</Import-Package>
+                        <Private-Package>org.apache.servicemix.specs.locator;-split-package:=merge-first</Private-Package>
+                        <Bundle-Activator>org.apache.servicemix.specs.locator.Activator</Bundle-Activator>
+                        <Implementation-Title>Apache ServiceMix</Implementation-Title>
+                        <Implementation-Version>${project.version}</Implementation-Version>
+                    </instructions>
+                    <unpackBundle>true</unpackBundle>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <artifactSet>
+                                <includes>
+                                    <include>org.apache.geronimo.specs:geronimo-jpa_3.0_spec</include>
+                                    <include>org.apache.servicemix.specs:org.apache.servicemix.specs.locator</include>
+                                    <include>${project.groupId}:${project.artifactId}</include>
+                                </includes>
+                            </artifactSet>
+                            <filters>
+                                <filter>
+                                    <artifact>org.apache.geronimo.specs:geronimo-jpa_3.0_spec</artifact>
+                                    <excludes>
+                                        <exclude>javax/**</exclude>
+                                    </excludes>
+                                </filter>
+                                <filter>
+                                    <artifact>org.apache.servicemix.specs:org.apache.servicemix.specs.locator</artifact>
+                                    <excludes>
+                                        <exclude>org/**</exclude>
+                                    </excludes>
+                                </filter>
+                            </filters>
+                            <createSourcesJar>${createSourceJar}</createSourcesJar>
+                            <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
+                            <createDependencyReducedPom>true</createDependencyReducedPom>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <profiles>
+        <profile>
+            <id>deploy</id>
+            <properties>
+                <createSourcesJar>true</createSourcesJar>
+            </properties>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-source-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-sources</id>
+                                <phase>process-classes</phase>
+                                <goals>
+                                    <goal>jar</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-dependency-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>unpack-sources</id>
+                                <phase>generate-sources</phase>
+                                <goals>
+                                    <goal>unpack</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>org.apache.servicemix.specs</groupId>
+                                            <artifactId>org.apache.servicemix.specs.locator</artifactId>
+                                            <classifier>sources</classifier>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${project.build.directory}/sources</outputDirectory>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-javadoc-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>package</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>jar</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                        <configuration>
+                            <minmemory>128m</minmemory>
+                            <maxmemory>512m</maxmemory>
+                            <sourcepath>${project.build.directory}/sources</sourcepath>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>
\ No newline at end of file

Propchange: servicemix/smx4/specs/trunk/java-persistence-api-2.0/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/persistence/Persistence.java?rev=900834&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/persistence/Persistence.java (added)
+++ servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/persistence/Persistence.java Tue Jan 19 16:26:20 2010
@@ -0,0 +1,160 @@
+/*
+ * 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.
+ */
+
+//
+// This source code implements specifications defined by the Java
+// Community Process. In order to remain compliant with the specification
+// DO NOT add / change / or delete method signatures!
+//
+package javax.persistence;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.spi.PersistenceProvider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+/**
+ * Bootstrap class that is used to obtain {@link javax.persistence.EntityManagerFactory}
+ * references.
+ */
+public class Persistence {
+    
+    protected static final Set<PersistenceProvider> providers = new HashSet<PersistenceProvider>();
+    // Changed to the hard coded PERSISTENCE_PROVIDER value to pass signature tests.
+    // public static final java.lang.String PERSISTENCE_PROVIDER = PersistenceProvider.class.getName();
+    public static final java.lang.String PERSISTENCE_PROVIDER = "javax.persistence.spi.PersistenceProvider";
+    static final String PERSISTENCE_PROVIDER_PROPERTY = "javax.persistence.provider";
+    static final String PERSISTENCE_PROVIDER_SERVICE = "META-INF/services/"
+        + PersistenceProvider.class.getName();
+    
+    /**
+     * Create and return an EntityManagerFactory for the named persistence unit.
+     * 
+     * @param persistenceUnitName The name of the persistence unit
+     * @return The factory that creates EntityManagers configured according to the specified persistence unit
+     */
+    public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName) {
+        return createEntityManagerFactory(persistenceUnitName, Collections.EMPTY_MAP);
+    }
+    
+    public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
+        
+        if (properties == null) {
+            properties = Collections.EMPTY_MAP;
+        }
+        
+        // start by loading a provider explicitly specified in properties. The spec
+        // doesn't seem to forbid providers that are not deployed as a service
+        Object providerName = properties.get(PERSISTENCE_PROVIDER_PROPERTY);
+        if (providerName instanceof String) {
+            EntityManagerFactory factory = createFactory(providerName.toString(), persistenceUnitName, properties);
+            if (factory != null) {
+                return factory;
+            }
+        }
+        
+        // If we are deployed into an OSGi environment, leverage it
+        Class providerClass = org.apache.servicemix.specs.locator.OsgiLocator.locate("javax.persistence.spi.PersistenceProvider");
+        if (providerClass != null) {
+            try {
+                PersistenceProvider provider = (PersistenceProvider) providerClass.newInstance();
+                return provider.createEntityManagerFactory(persistenceUnitName, properties);
+            }
+            catch (Exception e) {
+                throw new PersistenceException("Provider error. Provider: " + providerName, e);
+            }
+        }
+        
+        // load correctly deployed providers
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        try {
+            Enumeration<URL> providers = loader.getResources(PERSISTENCE_PROVIDER_SERVICE);
+            while (providers.hasMoreElements()) {
+                
+                String name = getProviderName(providers.nextElement());
+                
+                if (name != null) {
+                    
+                    EntityManagerFactory factory = createFactory(name, persistenceUnitName, properties);
+                    
+                    if (factory != null) {
+                        return factory;
+                    }
+                }
+            }
+        }
+        catch (IOException e) {
+            // spec doesn't mention any exceptions thrown by this method
+        }
+        
+        return null;
+    }
+    
+    static String getProviderName(URL url) throws IOException {
+        
+        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
+        
+        String providerName;
+        
+        try {
+            providerName = in.readLine();
+        }
+        finally {
+            in.close();
+        }
+        
+        if (providerName != null) {
+            providerName = providerName.trim();
+        }
+        
+        return providerName;
+    }
+    
+    static EntityManagerFactory createFactory(String providerName, String persistenceUnitName, Map properties) throws PersistenceException {
+        
+        Class providerClass;
+        try {
+            providerClass = Class.forName(providerName, true, Thread.currentThread().getContextClassLoader());
+        }
+        catch (Exception e) {
+            throw new PersistenceException("Invalid or inaccessible provider class: " + providerName, e);
+        }
+        
+        try {
+            PersistenceProvider provider = (PersistenceProvider) providerClass.newInstance();
+            return provider.createEntityManagerFactory(persistenceUnitName, properties);
+        }
+        catch (Exception e) {
+            throw new PersistenceException("Provider error. Provider: " + providerName, e);
+        }
+        
+    }
+
+}

Propchange: servicemix/smx4/specs/trunk/java-persistence-api-2.0/src/main/java/javax/persistence/Persistence.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: servicemix/smx4/specs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/pom.xml?rev=900834&r1=900833&r2=900834&view=diff
==============================================================================
--- servicemix/smx4/specs/trunk/pom.xml (original)
+++ servicemix/smx4/specs/trunk/pom.xml Tue Jan 19 16:26:20 2010
@@ -53,6 +53,7 @@
         <module>javamail-api-1.4</module>
         <module>activation-api-1.1</module>
         <module>java-persistence-api-1.1.1</module>
+        <module>java-persistence-api-2.0</module>
     </modules>
 
     <scm>