You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/04/17 09:05:23 UTC
svn commit: r1326953 - in /openejb/trunk/openejb/container/openejb-core/src:
main/java/org/apache/openejb/assembler/classic/
main/java/org/apache/openejb/resource/jdbc/
main/resources/META-INF/org.apache.openejb.embedded/
main/resources/META-INF/org.ap...
Author: rmannibucau
Date: Tue Apr 17 07:05:22 2012
New Revision: 1326953
URL: http://svn.apache.org/viewvc?rev=1326953&view=rev
Log:
OPENEJB-1274 JMX database pools
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/JMXBasicDataSource.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/JMXDataSourceTest.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicDataSource.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java
openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Tue Apr 17 07:05:22 2012
@@ -1492,6 +1492,7 @@ public class Assembler extends Assembler
public void createResource(ResourceInfo serviceInfo) throws OpenEJBException {
ObjectRecipe serviceRecipe = createRecipe(serviceInfo);
serviceRecipe.setProperty("transactionManager", transactionManager);
+ serviceRecipe.setProperty("ServiceId", serviceInfo.id);
serviceRecipe.setProperty("properties", new UnsetPropertiesRecipe());
replaceResourceAdapterProperty(serviceRecipe);
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicDataSource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicDataSource.java?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicDataSource.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicDataSource.java Tue Apr 17 07:05:22 2012
@@ -41,6 +41,19 @@ public class BasicDataSource extends org
* not ciphered. The {@link PlainTextPasswordCipher} can also be used.
*/
private String passwordCipher = null;
+ private JMXBasicDataSource jmxDs = null;
+
+ public BasicDataSource(final String name) {
+ registerAsMbean(name);
+ }
+
+ private void registerAsMbean(final String name) {
+ try {
+ jmxDs = new JMXBasicDataSource(name, this);
+ } catch (Exception ignored) {
+ // probably osgi where dynamic mbean is not supported
+ }
+ }
/**
* Returns the password codec class name to use to retrieve plain text
@@ -210,12 +223,24 @@ public class BasicDataSource extends org
final ReentrantLock l = lock;
l.lock();
try {
+ try {
+ unregisterMBean();
+ } catch (Exception ignored) {
+ // no-op
+ }
+
super.close();
} finally {
l.unlock();
}
}
+ private void unregisterMBean() {
+ if (jmxDs != null) {
+ jmxDs.unregister();
+ }
+ }
+
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
final ReentrantLock l = lock;
l.lock();
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java Tue Apr 17 07:05:22 2012
@@ -16,15 +16,14 @@
*/
package org.apache.openejb.resource.jdbc;
-import org.apache.openejb.loader.SystemInstance;
-
-import javax.sql.DataSource;
import java.io.File;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
+import javax.sql.DataSource;
+import org.apache.openejb.loader.SystemInstance;
@SuppressWarnings({"UnusedDeclaration"})
public class BasicManagedDataSource extends org.apache.commons.dbcp.managed.BasicManagedDataSource {
@@ -41,6 +40,19 @@ public class BasicManagedDataSource exte
* not ciphered. The {@link PlainTextPasswordCipher} can also be used.
*/
private String passwordCipher = null;
+ private JMXBasicDataSource jmxDs = null;
+
+ public BasicManagedDataSource(final String name) {
+ registerAsMbean(name);
+ }
+
+ private void registerAsMbean(final String name) {
+ try {
+ jmxDs = new JMXBasicDataSource(name, this);
+ } catch (Exception ignored) {
+ // probably osgi where dynamic mbean is not supported
+ }
+ }
/**
* Returns the password codec class name to use to retrieve plain text
@@ -214,12 +226,24 @@ public class BasicManagedDataSource exte
final ReentrantLock l = lock;
l.lock();
try {
+ try {
+ unregisterMBean();
+ } catch (Exception ignored) {
+ // no-op
+ }
+
super.close();
} finally {
l.unlock();
}
}
+ private void unregisterMBean() {
+ if (jmxDs != null) {
+ jmxDs.unregister();
+ }
+ }
+
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
final ReentrantLock l = lock;
l.lock();
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java Tue Apr 17 07:05:22 2012
@@ -42,7 +42,7 @@ import java.util.Properties;
*/
public class DataSourceFactory {
- public static DataSource create(final boolean managed, final Class impl, final String definition) throws IllegalAccessException, InstantiationException, IOException {
+ public static DataSource create(final String name, final boolean managed, final Class impl, final String definition) throws IllegalAccessException, InstantiationException, IOException {
final org.apache.commons.dbcp.BasicDataSource ds;
@@ -57,12 +57,12 @@ public class DataSourceFactory {
DataSource dataSource = (DataSource) recipe.create();
if (managed) {
- ds = new DbcpManagedDataSource(dataSource);
+ ds = new DbcpManagedDataSource(name, dataSource);
} else {
- ds = new DbcpDataSource(dataSource);
+ ds = new DbcpDataSource(name, dataSource);
}
} else {
- ds = (org.apache.commons.dbcp.BasicDataSource) create(managed);
+ ds = (org.apache.commons.dbcp.BasicDataSource) create(name, managed);
}
// force the driver class to be set
@@ -81,17 +81,17 @@ public class DataSourceFactory {
properties.remove("LoginTimeout");
}
- public static DataSource create(boolean managed) {
+ public static DataSource create(String name, boolean managed) {
org.apache.commons.dbcp.BasicDataSource ds;
if (managed) {
XAResourceWrapper xaResourceWrapper = SystemInstance.get().getComponent(XAResourceWrapper.class);
if (xaResourceWrapper != null) {
- ds = new ManagedDataSourceWithRecovery(xaResourceWrapper);
+ ds = new ManagedDataSourceWithRecovery(name, xaResourceWrapper);
} else {
- ds = new BasicManagedDataSource();
+ ds = new BasicManagedDataSource(name);
}
} else {
- ds = new BasicDataSource();
+ ds = new BasicDataSource(name);
}
return ds;
}
@@ -108,7 +108,8 @@ public class DataSourceFactory {
private final DataSource dataSource;
- public DbcpDataSource(DataSource dataSource) {
+ public DbcpDataSource(final String name, final DataSource dataSource) {
+ super(name);
this.dataSource = dataSource;
}
@@ -138,7 +139,8 @@ public class DataSourceFactory {
private final DataSource dataSource;
- public DbcpManagedDataSource(DataSource dataSource) {
+ public DbcpManagedDataSource(final String name, final DataSource dataSource) {
+ super(name);
this.dataSource = dataSource;
}
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/JMXBasicDataSource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/JMXBasicDataSource.java?rev=1326953&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/JMXBasicDataSource.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/JMXBasicDataSource.java Tue Apr 17 07:05:22 2012
@@ -0,0 +1,184 @@
+package org.apache.openejb.resource.jdbc;
+
+import javax.management.Description;
+import javax.management.MBeanServer;
+import javax.management.ManagedAttribute;
+import javax.management.ObjectName;
+import org.apache.openejb.monitoring.DynamicMBeanWrapper;
+import org.apache.openejb.monitoring.LocalMBeanServer;
+import org.apache.openejb.monitoring.ObjectNameBuilder;
+
+// @MBean: don't put it since it is not a pojo
+@Description("describe a datasource pool")
+public class JMXBasicDataSource {
+ private transient final org.apache.commons.dbcp.BasicDataSource ds;
+
+ private transient ObjectName objectName;
+
+ public JMXBasicDataSource(final String name, final org.apache.commons.dbcp.BasicDataSource ds) {
+ this.ds = ds;
+
+ final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
+ jmxName.set("ObjectType", "datasources");
+ jmxName.set("DataSource", name);
+ objectName = jmxName.build();
+
+ final MBeanServer server = LocalMBeanServer.get();
+ if (server.isRegistered(objectName)) {
+ jmxName.set("DataSource", name + "(" + System.identityHashCode(this) + ")");
+ objectName = jmxName.build();
+ }
+ try {
+ server.registerMBean(new DynamicMBeanWrapper(this), objectName);
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO
+ }
+ }
+
+ public void unregister() {
+ try {
+ LocalMBeanServer.get().unregisterMBean(objectName);
+ } catch (Exception e) {
+ // ignored
+ }
+ }
+
+ @ManagedAttribute
+ @Description("The class loader instance to use to load the JDBC driver.")
+ public String getDriverClassName() {
+ return ds.getDriverClassName();
+ }
+
+ @ManagedAttribute
+ @Description("The connection URL to be passed to our JDBC driver to establish a connection.")
+ public String getUrl() {
+ return ds.getUrl();
+ }
+
+ @ManagedAttribute
+ @Description("The SQL query that will be used to validate connections from this pool before returning them to the caller.")
+ public String getValidationQuery() {
+ return ds.getValidationQuery();
+ }
+
+ @ManagedAttribute
+ @Description("The connection username to be passed to our JDBC driver to establish a connection.")
+ public String getUsername() {
+ return ds.getUsername();
+ }
+
+ @ManagedAttribute
+ @Description("Timeout in seconds before connection validation queries fail.")
+ public int getValidationQueryTimeout() {
+ return ds.getValidationQueryTimeout();
+ }
+
+ @ManagedAttribute
+ @Description("The initial number of connections that are created when the pool is started.")
+ public int getInitialSize() {
+ return ds.getInitialSize();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of active connections that can be allocated from this pool at the same time,"
+ + " or negative for no limit.")
+ public int getMaxActive() {
+ return ds.getMaxActive();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of connections that can remain idle in the pool, without extra ones being"
+ + "destroyed, or negative for no limit.")
+ public int getMaxIdle() {
+ return ds.getMaxIdle();
+ }
+
+ @ManagedAttribute
+ @Description("The minimum number of active connections that can remain idle in the pool, without extra ones"
+ + " being created when the evictor runs, or 0 to create none.")
+ public int getMinIdle() {
+ return ds.getMinIdle();
+ }
+
+ @ManagedAttribute
+ @Description("The minimum number of active connections that can remain idle in the pool, without extra ones"
+ + " being created when the evictor runs, or 0 to create none.")
+ public int getNumTestsPerEvictionRun() {
+ return ds.getNumTestsPerEvictionRun();
+ }
+
+ @ManagedAttribute
+ @Description("The minimum amount of time an object may sit idle in the pool before it is eligible for eviction"
+ + " by the idle object evictor (if any).")
+ public long getMinEvictableIdleTimeMillis() {
+ return ds.getMinEvictableIdleTimeMillis();
+ }
+
+ @ManagedAttribute
+ @Description("The number of milliseconds to sleep between runs of the idle object evictor thread.")
+ public long getTimeBetweenEvictionRunsMillis() {
+ return ds.getTimeBetweenEvictionRunsMillis();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of open statements that can be allocated from the statement pool at the same time,"
+ + " or non-positive for no limit.")
+ public int getMaxOpenPreparedStatements() {
+ return ds.getMaxOpenPreparedStatements();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of milliseconds that the pool will wait (when there are no available connections) "
+ + "for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.")
+ public long getMaxWait() {
+ return ds.getMaxWait();
+ }
+
+ @ManagedAttribute
+ @Description("The default auto-commit state of connections created by this pool.")
+ public boolean getDefaultAutoCommit() {
+ return ds.getDefaultAutoCommit();
+ }
+
+ @ManagedAttribute
+ @Description("Prepared statement pooling for this pool.")
+ public boolean getPoolPreparedStatements() {
+ return ds.isPoolPreparedStatements();
+ }
+
+ @ManagedAttribute
+ @Description("The indication of whether objects will be validated before being borrowed from the pool.")
+ public boolean getTestOnBorrow() {
+ return ds.getTestOnBorrow();
+ }
+
+ @ManagedAttribute
+ @Description("The indication of whether objects will be validated before being returned to the pool.")
+ public boolean getTestOnReturn() {
+ return ds.getTestOnReturn();
+ }
+
+ @ManagedAttribute
+ @Description("The indication of whether objects will be validated by the idle object evictor (if any).")
+ public boolean getTestWhileIdle() {
+ return ds.getTestWhileIdle();
+ }
+
+ @ManagedAttribute
+ @Description("The default \"catalog\" of connections created by this pool.")
+ public String getDefaultCatalog() {
+ return ds.getDefaultCatalog();
+ }
+
+ @ManagedAttribute
+ @Description("The default read-only state of connections created by this pool.")
+ public boolean getDefaultReadOnly() {
+ return ds.getDefaultReadOnly();
+ }
+
+ @ManagedAttribute
+ @Description("The default TransactionIsolation state of connections created by this pool.")
+ public int getDefaultTransactionIsolation() {
+ return ds.getDefaultTransactionIsolation();
+ }
+}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java Tue Apr 17 07:05:22 2012
@@ -33,7 +33,8 @@ public class ManagedDataSourceWithRecove
private TransactionManager suppliedTransactionManager;
private final XAResourceWrapper xaResourceWrapper;
- public ManagedDataSourceWithRecovery(XAResourceWrapper xaResourceWrapper) {
+ public ManagedDataSourceWithRecovery(final String name, final XAResourceWrapper xaResourceWrapper) {
+ super(name);
this.xaResourceWrapper = xaResourceWrapper;
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml Tue Apr 17 07:05:22 2012
@@ -522,8 +522,9 @@
service="Resource"
types="javax.sql.DataSource, DataSource"
factory-name="create"
- constructor="JtaManaged, JdbcDriver, Definition"
+ constructor="ServiceId, JtaManaged, JdbcDriver, Definition"
class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
+ ServiceId
Definition
@@ -720,8 +721,9 @@
service="Resource"
types="javax.sql.DataSource, DataSource"
factory-name="create"
- constructor="JtaManaged, JdbcDriver, Definition"
+ constructor="ServiceId, JtaManaged, JdbcDriver, Definition"
class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
+ ServiceId
Definition
Modified: openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml Tue Apr 17 07:05:22 2012
@@ -553,8 +553,9 @@
service="Resource"
types="javax.sql.DataSource, DataSource"
factory-name="create"
- constructor="JtaManaged, JdbcDriver, Definition"
+ constructor="ServiceId, JtaManaged, JdbcDriver, Definition"
class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
+ ServiceId
Definition
@@ -754,8 +755,9 @@
service="Resource"
types="javax.sql.DataSource, DataSource"
factory-name="create"
- constructor="JtaManaged, JdbcDriver, Definition"
+ constructor="ServiceId, JtaManaged, JdbcDriver, Definition"
class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
+ ServiceId
Definition
Added: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/JMXDataSourceTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/JMXDataSourceTest.java?rev=1326953&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/JMXDataSourceTest.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/JMXDataSourceTest.java Tue Apr 17 07:05:22 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.apache.openejb.config;
+
+import java.lang.management.ManagementFactory;
+import java.util.Properties;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Configuration;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertTrue;
+
+@RunWith(ApplicationComposer.class)
+public class JMXDataSourceTest {
+ @Test
+ public void checkDsIsRegistered() throws MalformedObjectNameException {
+ final ObjectName on = new ObjectName("openejb.management:ObjectType=datasources,DataSource=JMXDataSourceTest");
+ assertTrue(ManagementFactory.getPlatformMBeanServer().isRegistered(on));
+ }
+
+ @Configuration
+ public Properties config() {
+ final Properties p = new Properties();
+ p.put("JMXDataSourceTest", "new://Resource?type=DataSource");
+ p.put("JMXDataSourceTest.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("JMXDataSourceTest.JdbcUrl", "jdbc:hsqldb:mem:bval");
+ return p;
+ }
+
+ @Module
+ public Persistence persistence() {
+ final PersistenceUnit unit = new PersistenceUnit("JMXDataSourceTest-unit");
+ unit.addClass(EntityToValidate.class);
+ unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+ unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
+ unit.setExcludeUnlistedClasses(true);
+
+ final Persistence persistence = new Persistence(unit);
+ persistence.setVersion("2.0");
+ return persistence;
+ }
+
+ @Entity
+ public static class EntityToValidate {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long i) {
+ id = i;
+ }
+ }
+}
Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java Tue Apr 17 07:05:22 2012
@@ -273,7 +273,7 @@ public class JpaTest extends TestCase {
}
private DataSource createJtaDataSource(TransactionManager transactionManager) throws Exception {
- BasicManagedDataSource ds = new BasicManagedDataSource();
+ BasicManagedDataSource ds = new BasicManagedDataSource(getClass().getName() + "createJtaDs");
ds.setTransactionManager(transactionManager);
ds.setDriverClassName("org.hsqldb.jdbcDriver");
ds.setUrl("jdbc:hsqldb:mem:JpaTest");
@@ -286,7 +286,7 @@ public class JpaTest extends TestCase {
}
private DataSource createNonJtaDataSource() throws Exception {
- BasicDataSource ds = new BasicDataSource();
+ BasicDataSource ds = new BasicDataSource(getClass().getName() + "createNonJtaDs");
ds.setDriverClassName("org.hsqldb.jdbcDriver");
ds.setUrl("jdbc:hsqldb:mem:JpaTest");
ds.setUsername("sa");
Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java?rev=1326953&r1=1326952&r2=1326953&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java Tue Apr 17 07:05:22 2012
@@ -254,7 +254,7 @@ public class UnenhancedTest extends Test
}
private DataSource createJtaDataSource(TransactionManager transactionManager) throws Exception {
- BasicManagedDataSource ds = new BasicManagedDataSource();
+ BasicManagedDataSource ds = new BasicManagedDataSource(getClass().getName() + ".createJtaDs");
ds.setTransactionManager(transactionManager);
ds.setDriverClassName("org.hsqldb.jdbcDriver");
ds.setUrl("jdbc:hsqldb:mem:JpaTest");
@@ -267,7 +267,7 @@ public class UnenhancedTest extends Test
}
private DataSource createNonJtaDataSource() throws Exception {
- BasicDataSource ds = new BasicDataSource();
+ BasicDataSource ds = new BasicDataSource(getClass().getName() + ".createNonJtaDs");
ds.setDriverClassName("org.hsqldb.jdbcDriver");
ds.setUrl("jdbc:hsqldb:mem:JpaTest");
ds.setUsername("sa");