[jboss-cvs] JBossAS SVN: r104102 - in projects/jpa/trunk/impl/src: test/java/org/jboss/jpa/impl/test/deployment and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 20 16:09:03 EDT 2010
Author: smarlow at redhat.com
Date: 2010-04-20 16:09:01 -0400 (Tue, 20 Apr 2010)
New Revision: 104102
Modified:
projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java
projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java
Log:
JBJPA-27 support for detecting version from persistence.xml files and passing it to the JPA 2 provider
Modified: projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java
===================================================================
--- projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java 2010-04-20 19:56:22 UTC (rev 104101)
+++ projects/jpa/trunk/impl/src/main/java/org/jboss/jpa/impl/deployment/PersistenceUnitInfoImpl.java 2010-04-20 20:09:01 UTC (rev 104102)
@@ -40,6 +40,7 @@
import org.hibernate.ejb.HibernatePersistence;
import org.jboss.logging.Logger;
+import org.jboss.metadata.jpa.spec.PersistenceMetaData;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
import org.jboss.metadata.jpa.spec.TransactionType;
@@ -77,7 +78,7 @@
/**
* Note that the jarFiles in metaData are ignore and should be
* specified in the jarFiles argument.
- *
+ *
* @param metaData the persistence unit meta data
* @param props properties for the persistence provider
* @param classLoader the class loader used for entity class loading
@@ -88,6 +89,24 @@
*/
public PersistenceUnitInfoImpl(PersistenceUnitMetaData metaData, Properties props, ClassLoader classLoader, URL persistenceUnitRootUrl, List<URL> jarFiles, Context ctx) throws NamingException
{
+ this(null, metaData, props, classLoader, persistenceUnitRootUrl, jarFiles, ctx);
+ }
+
+ /**
+ * Note that the jarFiles in metaData are ignore and should be
+ * specified in the jarFiles argument.
+ *
+ * @param persistenceMetaData the persistence meta data
+ * @param metaData the persistence unit meta data
+ * @param props properties for the persistence provider
+ * @param classLoader the class loader used for entity class loading
+ * @param persistenceUnitRootUrl a jar or JarInputStream where the entities are packaged
+ * @param jarFiles a list of URLs pointing to jar or JarInputStreams where entities are packaged
+ * @param ctx naming context for looking up data sources
+ * @throws NamingException when a data source can't be located
+ */
+ public PersistenceUnitInfoImpl(PersistenceMetaData persistenceMetaData, PersistenceUnitMetaData metaData, Properties props, ClassLoader classLoader, URL persistenceUnitRootUrl, List<URL> jarFiles, Context ctx) throws NamingException
+ {
log.debug("Using class loader " + classLoader);
this.setClassLoader(classLoader);
@@ -102,8 +121,8 @@
PersistenceUnitTransactionType transactionType = getJPATransactionType(metaData);
this.setTransactionType(transactionType);
this.setValidationMode( convertToValidationMode( metaData.getValidationMode() ) );
- //FIXME set appropriate version when accessible from metadata
- this.setPersistenceXMLSchemaVersion( null);
+ // default to a JPA 1.0 persistence.xml (version must be specified for JPA 2.0 or greater)
+ this.setPersistenceXMLSchemaVersion( persistenceMetaData == null ? "1.0" : persistenceMetaData.getVersion());
this.setSharedCacheMode(getSharedCacheMode(metaData.getSharedCacheMode()));
if (metaData.getProvider() != null) this.setPersistenceProviderClassName(metaData.getProvider());
/*
Modified: projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java
===================================================================
--- projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java 2010-04-20 19:56:22 UTC (rev 104101)
+++ projects/jpa/trunk/impl/src/test/java/org/jboss/jpa/impl/test/deployment/PersistenceUnitInfoImplTestCase.java 2010-04-20 20:09:01 UTC (rev 104102)
@@ -22,7 +22,7 @@
package org.jboss.jpa.impl.test.deployment;
import static junit.framework.Assert.assertNull;
-
+import static junit.framework.Assert.assertSame;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -33,6 +33,7 @@
import org.jboss.jpa.impl.deployment.PersistenceUnitInfoImpl;
import org.jboss.jpa.impl.test.common.BrainlessContext;
+import org.jboss.metadata.jpa.spec.PersistenceMetaData;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
import org.jboss.metadata.jpa.spec.ValidationMode;
import org.junit.Test;
@@ -94,4 +95,27 @@
PersistenceUnitInfoImpl puii = new PersistenceUnitInfoImpl(metaData, props, classLoader, persistenceUnitRootUrl, jarFiles, ctx);
assertNull(puii.getValidationMode());
}
+
+ @Test
+ public void testSchemaVersion() throws Exception
+ {
+ PersistenceUnitMetaData metaData = new PersistenceUnitMetaData();
+ metaData.setJtaDataSource("dummy-datasource");
+ metaData.setName("dummy-name");
+ PersistenceMetaData persistenceMetaData = new PersistenceMetaData();
+ persistenceMetaData.setVersion("2.0");
+ Properties props = new Properties();
+ ClassLoader classLoader = null;
+ URL persistenceUnitRootUrl = null;
+ List<URL> jarFiles = new ArrayList<URL>();
+ Context ctx = new BrainlessContext() {
+ @Override
+ public Object lookup(String name) throws NamingException
+ {
+ return null;
+ }
+ };
+ PersistenceUnitInfoImpl puii = new PersistenceUnitInfoImpl(persistenceMetaData, metaData, props, classLoader, persistenceUnitRootUrl, jarFiles, ctx);
+ assertSame("2.0",puii.getPersistenceXMLSchemaVersion());
+ }
}
More information about the jboss-cvs-commits
mailing list