OPENJPA-380

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@578260 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2007-09-21 20:38:31 +00:00
parent 91917c406c
commit 89b030c3d1
5 changed files with 63 additions and 3 deletions

View File

@ -612,6 +612,14 @@ public interface OpenJPAConfiguration
*/ */
public MetaDataRepository getMetaDataRepositoryInstance(); 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. * Create a new empty metadata repository of the configured type.
*/ */

View File

@ -835,6 +835,10 @@ public class OpenJPAConfigurationImpl
return metaRepository; return metaRepository;
} }
public boolean metaDataRepositoryAvailable(){
return metaRepository != null;
}
public MetaDataRepository newMetaDataRepositoryInstance() { public MetaDataRepository newMetaDataRepositoryInstance() {
return (MetaDataRepository) metaRepositoryPlugin.instantiate( return (MetaDataRepository) metaRepositoryPlugin.instantiate(
MetaDataRepository.class, this); MetaDataRepository.class, this);

View File

@ -389,9 +389,11 @@ public abstract class AbstractBrokerFactory
broker.close(); broker.close();
} }
// remove metadata repository from listener list if(_conf.metaDataRepositoryAvailable()) {
PCRegistry.removeRegisterClassListener // remove metadata repository from listener list
(_conf.getMetaDataRepositoryInstance()); PCRegistry.removeRegisterClassListener
(_conf.getMetaDataRepositoryInstance());
}
_conf.close(); _conf.close();
_closed = true; _closed = true;

View File

@ -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();
}
}

View File

@ -54,4 +54,13 @@
value="buildSchema(ForeignKeys=true)"/> value="buildSchema(ForeignKeys=true)"/>
</properties> </properties>
</persistence-unit> </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> </persistence>