OPENJPA-849: Load supported properties from resource.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@735760 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-01-19 17:47:19 +00:00
parent 8c50f73fe4
commit cdc015fae8
3 changed files with 90 additions and 2 deletions

View File

@ -0,0 +1,44 @@
/*
* 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.conf;
import java.util.Set;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
/**
* Test supported configuration properties for EntityManagerFactory,
* EntityManager and Query.
*
* @author Pinaki Poddar
*
*/
public class TestConfigurationProperties
extends SingleEMFTestCase {
public void setUp() throws Exception {
super.setUp();
assertNotNull(emf);
}
public void testEMFSupportedProperties() {
Set<String> p = emf.getSupportedProperties();
assertTrue(p.contains("javax.persistence.jdbc.driver"));
}
}

View File

@ -18,11 +18,13 @@
*/
package org.apache.openjpa.persistence;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -69,6 +71,7 @@ public class EntityManagerFactoryImpl
private transient Constructor<FetchPlan> _plan = null;
private transient StoreCache _cache = null;
private transient QueryResultCache _queryCache = null;
private Set<String> _supportedPropertyKeys;
/**
* Default constructor provided for auto-instantiation.
@ -348,7 +351,22 @@ public class EntityManagerFactoryImpl
}
public Set<String> getSupportedProperties() {
throw new UnsupportedOperationException(
"JPA 2.0 - Method not yet implemented");
if (_supportedPropertyKeys != null)
return _supportedPropertyKeys;
_supportedPropertyKeys = new HashSet<String>();
try {
InputStream rsrc = this.getClass()
.getResourceAsStream("supported_emf.properties");
if (rsrc == null)
return _supportedPropertyKeys;
Properties p = new Properties();
p.load(rsrc);
for (Object key : p.keySet()) {
_supportedPropertyKeys.add(key.toString());
}
} catch (Exception ex) {
}
return _supportedPropertyKeys;
}
}

View File

@ -0,0 +1,26 @@
# 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.
# ------------------------------------------------------------------------------
# Enumerates property keys supported by OpenJPA EntityManagerFactory.
#
# This enumeration includes both JPA Specification defined properties and
# OpenJPA-specific extension properties.
#
# Document the properties as values. Runtime, however, only reads the keys.
#-------------------------------------------------------------------------------
javax.persistence.jdbc.driver: Fully-qualified class name of JDBC Driver.