mirror of https://github.com/apache/openjpa.git
OPENJPA-380
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@578271 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f42bfb718e
commit
62e56cd910
|
@ -611,6 +611,14 @@ public interface OpenJPAConfiguration
|
|||
* @since 0.3.0
|
||||
*/
|
||||
public MetaDataRepository getMetaDataRepositoryInstance();
|
||||
|
||||
/**
|
||||
* Returns true if a metaDataRepository has been created for this
|
||||
* configuration.
|
||||
*
|
||||
* @since 1.1.0 1.0.1
|
||||
*/
|
||||
public boolean metaDataRepositoryAvailable();
|
||||
|
||||
/**
|
||||
* Create a new empty metadata repository of the configured type.
|
||||
|
|
|
@ -852,6 +852,10 @@ public class OpenJPAConfigurationImpl
|
|||
metaRepository = newMetaDataRepositoryInstance();
|
||||
return metaRepository;
|
||||
}
|
||||
|
||||
public boolean metaDataRepositoryAvailable(){
|
||||
return metaRepository != null;
|
||||
}
|
||||
|
||||
public MetaDataRepository newMetaDataRepositoryInstance() {
|
||||
return (MetaDataRepository) metaRepositoryPlugin.instantiate(
|
||||
|
|
|
@ -388,9 +388,11 @@ public abstract class AbstractBrokerFactory
|
|||
broker.close();
|
||||
}
|
||||
|
||||
// remove metadata repository from listener list
|
||||
PCRegistry.removeRegisterClassListener
|
||||
(_conf.getMetaDataRepositoryInstance());
|
||||
if(_conf.metaDataRepositoryAvailable()) {
|
||||
// remove metadata repository from listener list
|
||||
PCRegistry.removeRegisterClassListener
|
||||
(_conf.getMetaDataRepositoryInstance());
|
||||
}
|
||||
|
||||
_conf.close();
|
||||
_closed = true;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.openjpa.persistence.simple;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestEntityManagerFactory extends TestCase {
|
||||
|
||||
/*
|
||||
* This test uses a mis-configured persistence unit to verify that we will
|
||||
* not connect to the database when an unused emf is closed.
|
||||
*/
|
||||
public void testCloseUnusedEMF() {
|
||||
EntityManagerFactory emf =
|
||||
Persistence.createEntityManagerFactory("invalid");
|
||||
emf.close();
|
||||
}
|
||||
}
|
|
@ -54,4 +54,13 @@
|
|||
value="buildSchema(ForeignKeys=true)"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="invalid">
|
||||
<properties>
|
||||
<property name="openjpa.ConnectionDriverName"
|
||||
value="org.apache.commons.dbcp.BasicDataSource" />
|
||||
<property name="openjpa.ConnectionProperties"
|
||||
value="DriverClassName=not.a.real.Driver,Url=jdbc:notreal://"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
|
|
Loading…
Reference in New Issue