mirror of https://github.com/apache/openjpa.git
OPENJPA-380
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@578260 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
91917c406c
commit
89b030c3d1
|
@ -611,6 +611,14 @@ public interface OpenJPAConfiguration
|
||||||
* @since 0.3.0
|
* @since 0.3.0
|
||||||
*/
|
*/
|
||||||
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.
|
||||||
|
|
|
@ -834,6 +834,10 @@ public class OpenJPAConfigurationImpl
|
||||||
metaRepository = newMetaDataRepositoryInstance();
|
metaRepository = newMetaDataRepositoryInstance();
|
||||||
return metaRepository;
|
return metaRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean metaDataRepositoryAvailable(){
|
||||||
|
return metaRepository != null;
|
||||||
|
}
|
||||||
|
|
||||||
public MetaDataRepository newMetaDataRepositoryInstance() {
|
public MetaDataRepository newMetaDataRepositoryInstance() {
|
||||||
return (MetaDataRepository) metaRepositoryPlugin.instantiate(
|
return (MetaDataRepository) metaRepositoryPlugin.instantiate(
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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)"/>
|
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>
|
||||||
|
|
Loading…
Reference in New Issue