cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r398240 - in /incubator/cayenne/trunk/cayenne-jpa/src: main/java/org/apache/cayenne/jpa/bridge/ main/java/org/apache/cayenne/jpa/cspi/ main/java/org/apache/cayenne/jpa/spi/ test/java/org/apache/cayenne/jpa/bridge/ test/java/org/apache/cayen...
Date Sat, 29 Apr 2006 21:38:54 GMT
Author: aadamchik
Date: Sat Apr 29 14:38:52 2006
New Revision: 398240

URL: http://svn.apache.org/viewcvs?rev=398240&view=rev
Log:
finished Cayenne stack loader. 
(Cayenne JPA provider no longer cares about cayenne.xml  and uses persistence.xml instead)
DataMap converter and class enhancer are still not finished

Added:
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java
      - copied, changed from r398226, incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/CayenneQueryHints.java
    incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/QueryHintsTest.java
      - copied, changed from r398226, incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/CayenneQueryHintsTest.java
    incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactoryTest.java
Removed:
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/CayenneQueryHints.java
    incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/CayenneQueryHintsTest.java
Modified:
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaIndirectQuery.java
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactory.java
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JndiJpaDataSourceFactory.java
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceProvider.java
    incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceUnitInfo.java
    incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
    incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
Sat Apr 29 14:38:52 2006
@@ -212,6 +212,7 @@
         JpaEntityVisitor() {
             addChildVisitor(JpaAttribute.class, new JpaAttributeVisitor());
             addChildVisitor(JpaTable.class, new JpaTableVisitor());
+            addChildVisitor(JpaNamedQuery.class, new JpaNamedQueryVisitor());
         }
 
         @Override
@@ -233,7 +234,7 @@
             JpaNamedQuery jpaQuery = (JpaNamedQuery) path.getObject();
             JpaIndirectQuery cayenneQuery;
 
-            JpaQueryHint hint = jpaQuery.getHint(CayenneQueryHints.QUERY_TYPE_HINT);
+            JpaQueryHint hint = jpaQuery.getHint(QueryHints.QUERY_TYPE_HINT);
             if (hint != null && !Util.isEmptyString(hint.getValue())) {
                 try {
                     Class cayenneQueryClass = Class.forName(hint.getValue(), true, Thread
@@ -265,7 +266,19 @@
 
             cayenneQuery.setName(jpaQuery.getName());
             cayenneQuery.setJpaQuery(jpaQuery);
-            ((DataMap) targetPath.firstInstanceOf(DataMap.class)).addQuery(cayenneQuery);
+
+            DataMap parentMap = (DataMap) targetPath.firstInstanceOf(DataMap.class);
+
+            ObjEntity parentEntity = (ObjEntity) targetPath
+                    .firstInstanceOf(ObjEntity.class);
+            if (parentEntity != null) {
+                cayenneQuery.setParentEntity(parentEntity);
+            }
+            else {
+                cayenneQuery.setParentMap(parentMap);
+            }
+
+            parentMap.addQuery(cayenneQuery);
 
             return cayenneQuery;
         }

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaIndirectQuery.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaIndirectQuery.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaIndirectQuery.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaIndirectQuery.java
Sat Apr 29 14:38:52 2006
@@ -16,6 +16,8 @@
 package org.apache.cayenne.jpa.bridge;
 
 import org.apache.cayenne.jpa.map.JpaNamedQuery;
+import org.objectstyle.cayenne.map.DataMap;
+import org.objectstyle.cayenne.map.ObjEntity;
 import org.objectstyle.cayenne.query.IndirectQuery;
 
 /**
@@ -26,6 +28,8 @@
 public abstract class JpaIndirectQuery extends IndirectQuery {
 
     protected JpaNamedQuery jpaQuery;
+    protected DataMap parentMap;
+    protected ObjEntity parentEntity;
 
     public JpaNamedQuery getJpaQuery() {
         return jpaQuery;
@@ -33,5 +37,21 @@
 
     public void setJpaQuery(JpaNamedQuery query) {
         this.jpaQuery = query;
+    }
+
+    public ObjEntity getParentEntity() {
+        return parentEntity;
+    }
+
+    public void setParentEntity(ObjEntity parentEntity) {
+        this.parentEntity = parentEntity;
+    }
+
+    public DataMap getParentMap() {
+        return parentMap;
+    }
+
+    public void setParentMap(DataMap parentMap) {
+        this.parentMap = parentMap;
     }
 }

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/JpaSQLTemplate.java
Sat Apr 29 14:38:52 2006
@@ -15,8 +15,10 @@
  */
 package org.apache.cayenne.jpa.bridge;
 
+import org.objectstyle.cayenne.CayenneRuntimeException;
 import org.objectstyle.cayenne.map.EntityResolver;
 import org.objectstyle.cayenne.query.Query;
+import org.objectstyle.cayenne.query.SQLTemplate;
 
 /**
  * An indirect query that resolves to Cayenne SQLTemplate using information from JPA query
@@ -26,9 +28,24 @@
  */
 public class JpaSQLTemplate extends JpaIndirectQuery {
 
+    /**
+     * Creates a SQLTemplate using query hints.
+     */
     @Override
     protected Query createReplacementQuery(EntityResolver resolver) {
-        throw new UnsupportedOperationException("TODO");
-    }
+        SQLTemplate query = new SQLTemplate();
+        query.setDefaultTemplate(jpaQuery.getQuery());
+
+        if (parentEntity != null) {
+            query.setRoot(parentEntity);
+        }
+        else if (parentMap != null) {
+            query.setRoot(parentMap);
+        }
+        else {
+            throw new CayenneRuntimeException("Unknown query root. Name: " + getName());
+        }
 
+        return query;
+    }
 }

Copied: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java
(from r398226, incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/CayenneQueryHints.java)
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java?p2=incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java&p1=incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/CayenneQueryHints.java&r1=398226&r2=398240&rev=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/CayenneQueryHints.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/QueryHints.java
Sat Apr 29 14:38:52 2006
@@ -16,7 +16,7 @@
 package org.apache.cayenne.jpa.bridge;
 
 
-public interface CayenneQueryHints {
+public interface QueryHints {
 
     public static final String QUERY_TYPE_HINT = "cayenne.query.type";
 

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactory.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactory.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactory.java
Sat Apr 29 14:38:52 2006
@@ -15,30 +15,58 @@
  */
 package org.apache.cayenne.jpa.cspi;
 
+import java.sql.SQLException;
+import java.util.Properties;
+
 import javax.persistence.spi.PersistenceUnitInfo;
 import javax.sql.DataSource;
 
+import org.apache.cayenne.jpa.JpaProviderException;
+import org.apache.cayenne.jpa.spi.JndiJpaDataSourceFactory;
 import org.apache.cayenne.jpa.spi.JpaDataSourceFactory;
-import org.objectstyle.cayenne.access.DataDomain;
-import org.objectstyle.cayenne.access.DataNode;
-import org.objectstyle.cayenne.conf.Configuration;
+import org.objectstyle.cayenne.access.ConnectionLogger;
+import org.objectstyle.cayenne.access.QueryLogger;
+import org.objectstyle.cayenne.conf.ConnectionProperties;
+import org.objectstyle.cayenne.conn.PoolManager;
+import org.objectstyle.cayenne.util.Util;
 
 /**
- * A {@link JpaDataSourceFactory} that returns a DataSource from the existing in Cayenne
- * stack, matching JPA descriptor names against Cayenne names. It is assumed that there
- * Configuration singleton is set. The name of the DataDomain is assumed to be equal to
- * peristence unit name and the name of the DataSource - DataNode name.
+ * A {@link JpaDataSourceFactory} that attempts to create a DataSource based on Cayenne
+ * provider-specific properties. If such properties are not present, a DataSource is
+ * obtained via JNDI.
+ * <p>
+ * Properties are specified in the correspondign section of the <em>persistence.xml</em>
+ * file. All property names related to a given named DataSource must be prefixed with
+ * <em>"CayenneDataSource.[datasource name]."</em>. The following properties
are
+ * supported:
+ * </p>
+ * <ul>
+ * <li>CayenneDataSource.[datasource name].jdbc.driver - (required) JDBC driver class</li>
+ * <li>CayenneDataSource.[datasource name].jdbc.url - (required) Database URL</li>
+ * <li>CayenneDataSource.[datasource name].jdbc.username - Database login id</li>
+ * <li>CayenneDataSource.[datasource name].jdbc.password - Database password</li>
+ * <li>CayenneDataSource.[datasource name].jdbc.minConnections - (optional) Minimal
pool
+ * size</li>
+ * <li>CayenneDataSource.[datasource name].jdbc.maxConnections - (optional) Maximum
pool
+ * size</li>
+ * </ul>
+ * <p>
+ * Another optional property is
+ * <em>CayenneDataSource.[datasource name].cayenne.adapter</em>. It is not strictly
+ * related to the DataSource configuration, but Cayenne provider will use to configure the
+ * same {@link org.objectstyle.cayenne.access.DataNode} that will use the DataSource. If
+ * not set, an AutoAdapter is used.
  * 
  * @author Andrus Adamchik
  */
-public class CjpaDataSourceFactory implements JpaDataSourceFactory {
+public class CjpaDataSourceFactory extends JndiJpaDataSourceFactory {
 
-    public DataSource getJtaDataSource(String name, PersistenceUnitInfo info) {
-        return getDataSource(name, info);
-    }
+    public static final String DATA_SOURCE_PREFIX = "CayenneDataSource.";
+    public static final String MIN_CONNECTIONS_SUFFIX = "minConnections";
+    public static final String MAX_CONNECTIONS_SUFFIX = "maxConnections";
 
-    public DataSource getNonJtaDataSource(String name, PersistenceUnitInfo info) {
-        return getDataSource(name, info);
+    static String getPropertyName(String dataSourceName, String suffix) {
+        return DATA_SOURCE_PREFIX + dataSourceName + "." + suffix;
     }
 
     protected DataSource getDataSource(String name, PersistenceUnitInfo info) {
@@ -46,19 +74,79 @@
             return null;
         }
 
-        Configuration config = Configuration.getSharedConfiguration();
-        DataDomain domain = config.getDomain(info.getPersistenceUnitName());
+        DataSource ds = getCayenneDataSource(name, info.getProperties());
+        return ds != null ? ds : super.getDataSource(name, info);
+    }
+
+    protected DataSource getCayenneDataSource(String name, Properties properties) {
 
-        // try default domain
-        if (domain == null) {
-            domain = config.getDomain();
+        String driverName = properties.getProperty(getDriverKey(name));
+        if (Util.isEmptyString(driverName)) {
+            return null;
         }
 
-        if (domain == null) {
+        String url = properties.getProperty(getUrlKey(name));
+        if (Util.isEmptyString(url)) {
             return null;
         }
 
-        DataNode node = domain.getNode(name);
-        return node != null ? node.getDataSource() : null;
+        int minConnection;
+        try {
+            minConnection = Integer.parseInt(properties
+                    .getProperty(getMinConnectionsKey(name)));
+        }
+        catch (Exception e) {
+            minConnection = 1;
+        }
+
+        int maxConnection;
+        try {
+            maxConnection = Integer.parseInt(properties
+                    .getProperty(getMaxConnectionsKey(name)));
+        }
+        catch (Exception e) {
+            maxConnection = 1;
+        }
+
+        // this code follows Cayenne DriverDataSourceFactory logic...
+        try {
+            return new PoolManager(
+                    driverName,
+                    url,
+                    minConnection,
+                    maxConnection,
+                    properties.getProperty(getUserKey(name)),
+                    properties.getProperty(getPasswordKey(name)),
+                    new ConnectionLogger());
+        }
+        catch (SQLException e) {
+            QueryLogger.logConnectFailure(e);
+            throw new JpaProviderException("Error creating connection pool", e);
+        }
+    }
+
+    protected String getDriverKey(String dataSourceName) {
+        return getPropertyName(dataSourceName, ConnectionProperties.DRIVER_KEY);
+    }
+
+    protected String getUrlKey(String dataSourceName) {
+        return getPropertyName(dataSourceName, ConnectionProperties.URL_KEY);
     }
+
+    protected String getUserKey(String dataSourceName) {
+        return getPropertyName(dataSourceName, ConnectionProperties.USER_NAME_KEY);
+    }
+
+    protected String getPasswordKey(String dataSourceName) {
+        return getPropertyName(dataSourceName, ConnectionProperties.PASSWORD_KEY);
+    }
+
+    protected String getMinConnectionsKey(String dataSourceName) {
+        return getPropertyName(dataSourceName, MIN_CONNECTIONS_SUFFIX);
+    }
+
+    protected String getMaxConnectionsKey(String dataSourceName) {
+        return getPropertyName(dataSourceName, MAX_CONNECTIONS_SUFFIX);
+    }
+
 }

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
Sat Apr 29 14:38:52 2006
@@ -16,21 +16,32 @@
 package org.apache.cayenne.jpa.cspi;
 
 import java.io.InputStream;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
 
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.spi.PersistenceUnitInfo;
 import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
 
 import org.apache.cayenne.jpa.bridge.DataMapConverter;
 import org.apache.cayenne.jpa.conf.EntityMapLoader;
+import org.apache.cayenne.jpa.conf.JpaLoaderContext;
 import org.apache.cayenne.jpa.map.JpaEntityMap;
 import org.apache.cayenne.jpa.spi.JpaPersistenceProvider;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.objectstyle.cayenne.access.DataDomain;
+import org.objectstyle.cayenne.access.DataNode;
 import org.objectstyle.cayenne.conf.Configuration;
+import org.objectstyle.cayenne.conf.ConnectionProperties;
+import org.objectstyle.cayenne.dba.AutoAdapter;
+import org.objectstyle.cayenne.dba.DbAdapter;
 import org.objectstyle.cayenne.map.DataMap;
 import org.objectstyle.cayenne.util.ResourceLocator;
+import org.objectstyle.cayenne.util.Util;
+import org.objectstyle.cayenne.validation.SimpleValidationFailure;
 import org.objectstyle.cayenne.validation.ValidationResult;
 
 /**
@@ -74,8 +85,8 @@
     }
 
     /**
-     * Registers Cayenne-specific ClassTransformers with PersistenceUnitInfo and returns
-     * {@link CjpaEntityManagerFactory}.
+     * Maps PersistenceUnitInfo to Cayenne DataDomain and returns a
+     * {@link CjpaEntityManagerFactory} which is a DataDomain wrapper.
      */
     @Override
     public EntityManagerFactory createContainerManagerFactory(PersistenceUnitInfo info) {
@@ -92,7 +103,24 @@
             DataMapConverter converter = new DataMapConverter(loader.getContext());
             DataMap cayenneMap = converter.toDataMap(name, jpaMap);
 
-            domain.addMap(cayenneMap);
+            DataSource dataSource = info.getTransactionType() == PersistenceUnitTransactionType.JTA
+                    ? info.getJtaDataSource()
+                    : info.getNonJtaDataSource();
+
+            DbAdapter adapter = createCustomAdapter(loader.getContext(), info);
+
+            DataNode node = new DataNode(name);
+
+            if (adapter == null) {
+                adapter = new AutoAdapter(new NodeDataSource(node));
+            }
+
+            node.setAdapter(adapter);
+
+            node.setDataSource(dataSource);
+            node.addDataMap(cayenneMap);
+
+            domain.addNode(node);
 
             // report conflicts...
             ValidationResult conflicts = loader.getContext().getConflicts();
@@ -106,8 +134,72 @@
         return new CjpaEntityManagerFactory(domain, info);
     }
 
+    protected DbAdapter createCustomAdapter(
+            JpaLoaderContext context,
+            PersistenceUnitInfo info) {
+
+        String adapterKey = CjpaDataSourceFactory.getPropertyName(info
+                .getPersistenceUnitName(), ConnectionProperties.ADAPTER_KEY);
+        String adapterClass = info.getProperties().getProperty(adapterKey);
+
+        if (Util.isEmptyString(adapterClass)) {
+            return null;
+        }
+
+        try {
+            Class dbAdapterClass = Class.forName(adapterClass, true, info
+                    .getClassLoader());
+            return (DbAdapter) dbAdapterClass.newInstance();
+        }
+        catch (Exception e) {
+            context.recordConflict(new SimpleValidationFailure(
+                    info,
+                    "Failed to load adapter '"
+                            + adapterClass
+                            + "', message: "
+                            + e.getLocalizedMessage()));
+            return null;
+        }
+    }
+
     public Configuration getConfiguration() {
         return configuration;
+    }
+
+    // TODO: andrus, 4/29/2006 - this is copied from non-public conf.NodeDataSource. In
+    // Cayenne > 1.2 make it public.
+    class NodeDataSource implements DataSource {
+
+        DataNode node;
+
+        NodeDataSource(DataNode node) {
+            this.node = node;
+        }
+
+        public Connection getConnection() throws SQLException {
+            return node.getDataSource().getConnection();
+        }
+
+        public Connection getConnection(String username, String password)
+                throws SQLException {
+            return node.getDataSource().getConnection(username, password);
+        }
+
+        public PrintWriter getLogWriter() throws SQLException {
+            return node.getDataSource().getLogWriter();
+        }
+
+        public void setLogWriter(PrintWriter out) throws SQLException {
+            node.getDataSource().setLogWriter(out);
+        }
+
+        public void setLoginTimeout(int seconds) throws SQLException {
+            node.getDataSource().setLoginTimeout(seconds);
+        }
+
+        public int getLoginTimeout() throws SQLException {
+            return node.getDataSource().getLoginTimeout();
+        }
     }
 
     class LazyConfiguration extends Configuration {

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JndiJpaDataSourceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JndiJpaDataSourceFactory.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JndiJpaDataSourceFactory.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JndiJpaDataSourceFactory.java
Sat Apr 29 14:38:52 2006
@@ -20,7 +20,6 @@
 import javax.persistence.spi.PersistenceUnitInfo;
 import javax.sql.DataSource;
 
-
 /**
  * A JNDI-based implementation of the JPADataSourceFactory.
  * 
@@ -29,14 +28,14 @@
 public class JndiJpaDataSourceFactory implements JpaDataSourceFactory {
 
     public DataSource getJtaDataSource(String name, PersistenceUnitInfo info) {
-        return getDataSource(name);
+        return getDataSource(name, info);
     }
 
     public DataSource getNonJtaDataSource(String name, PersistenceUnitInfo info) {
-        return getDataSource(name);
+        return getDataSource(name, info);
     }
 
-    protected DataSource getDataSource(String name) {
+    protected DataSource getDataSource(String name, PersistenceUnitInfo info) {
         if (name == null) {
             return null;
         }

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceProvider.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceProvider.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceProvider.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceProvider.java
Sat Apr 29 14:38:52 2006
@@ -40,7 +40,7 @@
     public static final String NON_JTA_DATA_SOURCE_PROPERTY = "javax.persistence.nonJtaDataSource
";
 
     // provider-specific properties
-    public static final String DATA_SOURCE_FACTORY_PROPERTY = "org.objectstyle.cayenne.jpa.jpaDataSourceFactory";
+    public static final String DATA_SOURCE_FACTORY_PROPERTY = "org.apache.cayenne.jpa.jpaDataSourceFactory";
 
     protected PersistenceUnitLoader unitLoader;
     protected Properties defaultProperties;
@@ -83,6 +83,15 @@
         if (map != null) {
             ui.addProperties(map);
         }
+        
+        // set default properties if they are not set explicitly
+        Properties properties = ui.getProperties();
+        for(Map.Entry property : defaultProperties.entrySet()) {
+            if(!properties.containsKey(property.getKey())) {
+                properties.put(property.getKey(), property.getValue());
+            }
+        }
+        
 
         // check if we are allowed to handle this unit (JPA Spec, 7.2)
         String provider = ui.getPersistenceProviderClassName();

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceUnitInfo.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceUnitInfo.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceUnitInfo.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/spi/JpaPersistenceUnitInfo.java
Sat Apr 29 14:38:52 2006
@@ -28,6 +28,8 @@
 import javax.persistence.spi.PersistenceUnitTransactionType;
 import javax.sql.DataSource;
 
+import org.apache.cayenne.jpa.JpaProviderException;
+
 /**
  * A java bean that provides access to persistent unit properties per
  * <code>javax.persistence.spi.PersistenceUnitInfo</code> interface.
@@ -39,8 +41,6 @@
     // spec defaults
     static final PersistenceUnitTransactionType DEFAULT_TRANSACTION_TYPE = PersistenceUnitTransactionType.JTA;
 
-    protected JpaPersistenceProvider provider;
-
     protected String persistenceUnitName;
     protected List<String> mappingFileNames;
     protected List<URL> jarFileUrls;
@@ -55,11 +55,6 @@
     protected ClassLoader classLoader;
 
     public JpaPersistenceUnitInfo() {
-        this(null);
-    }
-
-    public JpaPersistenceUnitInfo(JpaPersistenceProvider provider) {
-        this.provider = provider;
 
         this.mappingFileNames = new ArrayList<String>(2);
         this.jarFileUrls = new ArrayList<URL>(2);
@@ -85,14 +80,18 @@
     }
 
     String getProperty(String key) {
-        String property = properties.getProperty(key);
-        return property != null || provider == null ? property : provider
-                .getDefaultProperty(key);
+        return properties.getProperty(key);
     }
 
     JpaDataSourceFactory getJpaDataSourceFactory() {
         String factory = getProperty(JpaPersistenceProvider.DATA_SOURCE_FACTORY_PROPERTY);
 
+        if (factory == null) {
+            throw new JpaProviderException("No value for '"
+                    + JpaPersistenceProvider.DATA_SOURCE_FACTORY_PROPERTY
+                    + "' property - can't build DataSource factory.");
+        }
+
         try {
             return (JpaDataSourceFactory) Class.forName(
                     factory,
@@ -100,7 +99,7 @@
                     Thread.currentThread().getContextClassLoader()).newInstance();
         }
         catch (Throwable th) {
-            throw new RuntimeException("Error instantiating a JPADataSourceFactory: "
+            throw new JpaProviderException("Error instantiating a JPADataSourceFactory: "
                     + factory, th);
         }
     }

Modified: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
Sat Apr 29 14:38:52 2006
@@ -38,7 +38,7 @@
         assertEntity1(entityIt.next());
         assertEntity2(entityIt.next());
 
-        assertEquals(2, dataMap.getQueries().size());
+        assertEquals(4, dataMap.getQueries().size());
     }
 
     protected void assertEntity1(ObjEntity entity1) {

Copied: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/QueryHintsTest.java
(from r398226, incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/CayenneQueryHintsTest.java)
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/QueryHintsTest.java?p2=incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/QueryHintsTest.java&p1=incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/CayenneQueryHintsTest.java&r1=398226&r2=398240&rev=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/CayenneQueryHintsTest.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/QueryHintsTest.java
Sat Apr 29 14:38:52 2006
@@ -17,13 +17,13 @@
 
 import junit.framework.TestCase;
 
-public class CayenneQueryHintsTest extends TestCase {
+public class QueryHintsTest extends TestCase {
 
     public void testQueryTypes() throws Exception {
         assertEquals(JpaProcedureQuery.class, Class
-                .forName(CayenneQueryHints.PROCEDURE_QUERY));
-        assertEquals(JpaSelectQuery.class, Class.forName(CayenneQueryHints.SELECT_QUERY));
+                .forName(QueryHints.PROCEDURE_QUERY));
+        assertEquals(JpaSelectQuery.class, Class.forName(QueryHints.SELECT_QUERY));
         assertEquals(JpaSQLTemplate.class, Class
-                .forName(CayenneQueryHints.SQL_TEMPLATE_QUERY));
+                .forName(QueryHints.SQL_TEMPLATE_QUERY));
     }
 }

Added: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactoryTest.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactoryTest.java?rev=398240&view=auto
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactoryTest.java
(added)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/cspi/CjpaDataSourceFactoryTest.java
Sat Apr 29 14:38:52 2006
@@ -0,0 +1,26 @@
+/*
+ *  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.
+ */
+package org.apache.cayenne.jpa.cspi;
+
+import junit.framework.TestCase;
+
+public class CjpaDataSourceFactoryTest extends TestCase {
+
+    public void testGetDriverKey() {
+        CjpaDataSourceFactory factory = new CjpaDataSourceFactory();
+        assertEquals("CayenneDataSource.xyz.jdbc.driver", factory.getDriverKey("xyz"));
+    }
+}

Modified: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java?rev=398240&r1=398239&r2=398240&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java
Sat Apr 29 14:38:52 2006
@@ -39,10 +39,10 @@
 @Entity
 @Table(name = "mock_persistent_1", catalog = "catalog1", schema = "schema1")
 @NamedQueries( {
-        @NamedQuery(name = "query1", query = "select x", hints = {
+        @NamedQuery(name = "entityQuery1", query = "select x", hints = {
                 @QueryHint(name = "hint1", value = "value1"),
                 @QueryHint(name = "hint2", value = "value2")
-        }), @NamedQuery(name = "query2", query = "select y")
+        }), @NamedQuery(name = "entityQuery2", query = "select y")
 })
 @IdClass(ObjectId.class)
 public class MockCayenneEntity1 extends CayenneDataObject {



Mime
View raw message