geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject svn commit: r376831 - in /geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence: EntityNotFoundException.java NoResultException.java NonUniqueResultException.java Persistence.java
Date Fri, 10 Feb 2006 20:25:41 GMT
Author: jlaskowski
Date: Fri Feb 10 12:25:38 2006
New Revision: 376831

URL: http://svn.apache.org/viewcvs?rev=376831&view=rev
Log:
Fix for #OpenEJB-109: Create javax.persistence classes, interfaces, enums and annotations
by Andrus Adamchik

Added:
    geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/EntityNotFoundException.java
  (with props)
    geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NoResultException.java
  (with props)
    geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NonUniqueResultException.java
  (with props)
    geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
  (with props)

Added: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/EntityNotFoundException.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/EntityNotFoundException.java?rev=376831&view=auto
==============================================================================
--- geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/EntityNotFoundException.java
(added)
+++ geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/EntityNotFoundException.java
Fri Feb 10 12:25:38 2006
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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;
+
+
+public class EntityNotFoundException extends RuntimeException {
+
+    public EntityNotFoundException() {
+        super();
+    }
+
+    public EntityNotFoundException(String message) {
+        super(message);
+    }
+
+    public EntityNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public EntityNotFoundException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/EntityNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NoResultException.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NoResultException.java?rev=376831&view=auto
==============================================================================
--- geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NoResultException.java
(added)
+++ geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NoResultException.java
Fri Feb 10 12:25:38 2006
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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;
+
+
+public class NoResultException extends RuntimeException {
+
+    public NoResultException() {
+        super();
+    }
+
+    public NoResultException(String message) {
+        super(message);
+    }
+
+    public NoResultException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoResultException(Throwable cause) {
+        super(cause);
+    }
+
+}

Propchange: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NoResultException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NonUniqueResultException.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NonUniqueResultException.java?rev=376831&view=auto
==============================================================================
--- geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NonUniqueResultException.java
(added)
+++ geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NonUniqueResultException.java
Fri Feb 10 12:25:38 2006
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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;
+
+
+public class NonUniqueResultException extends RuntimeException {
+
+    public NonUniqueResultException() {
+        super();
+    }
+
+    public NonUniqueResultException(String message) {
+        super(message);
+    }
+
+    public NonUniqueResultException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NonUniqueResultException(Throwable cause) {
+        super(cause);
+    }
+
+}

Propchange: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/NonUniqueResultException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java?rev=376831&view=auto
==============================================================================
--- geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
(added)
+++ geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
Fri Feb 10 12:25:38 2006
@@ -0,0 +1,157 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.Map;
+
+import javax.persistence.spi.PersistenceProvider;
+
+/**
+ * Bootstrap class that is used to obtain {@link javax.persistence.EntityManagerFactory}
+ * references.
+ */
+public class Persistence {
+
+    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);
+    }
+
+    /**
+     * Create and return an EntityManagerFactory for the named persistence unit using the
+     * given properties.
+     * 
+     * @param persistenceUnitName The name of the persistence unit
+     * @param props Additional properties to use when creating the factory. The values of
+     *            these properties override any values that may have been configured
+     *            elsewhere.
+     * @return The factory that creates EntityManagers configured according to the
+     *         specified persistence unit.
+     */
+    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;
+            }
+        }
+
+        // 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) {
+
+        try {
+            Class providerClass = Class.forName(providerName, true, Thread
+                    .currentThread()
+                    .getContextClassLoader());
+            PersistenceProvider provider = (PersistenceProvider) providerClass
+                    .newInstance();
+            return provider.createEntityManagerFactory(persistenceUnitName, properties);
+        }
+        catch (Exception e) {
+            return null;
+        }
+    }
+}

Propchange: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message