From bda2015398ba033ef966ad69bb6b5c8c7d3979af Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Wed, 15 Nov 2006 00:30:24 +0000 Subject: [PATCH] added openjpa.Id property, and put logic in PersistenceUnitInfoImpl to set the openjpa.Id property to the persistence unit name if no openjpa.Id property is discovered. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@475084 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/conf/OpenJPAConfiguration.java | 18 ++++++++++++++++++ .../openjpa/conf/OpenJPAConfigurationImpl.java | 12 ++++++++++++ .../apache/openjpa/conf/localizer.properties | 9 +++++++++ .../persistence/PersistenceUnitInfoImpl.java | 5 ++++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java index 4091775be..0fb90878f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java @@ -1383,4 +1383,22 @@ public interface OpenJPAConfiguration * configuration. */ public StoreFacadeTypeRegistry getStoreFacadeTypeRegistry(); + + /** + * An environment-specific identifier for this configuration. This + * might correspond to a JPA persistence-unit name, or to some other + * more-unique value available in the current environment. + * + * @since 0.9.7 + */ + public String getId(); + + /** + * An environment-specific identifier for this configuration. This + * might correspond to a JPA persistence-unit name, or to some other + * more-unique value available in the current environment. + * + * @since 0.9.7 + */ + public void setId(String id); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java index bac75e56f..287d7f514 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java @@ -127,6 +127,7 @@ public class OpenJPAConfigurationImpl public ObjectValue orphanedKeyPlugin; public ObjectValue compatibilityPlugin; public QueryCompilationCacheValue queryCompilationCachePlugin; + public StringValue id; // custom values public BrokerFactoryValue brokerFactoryPlugin; @@ -465,6 +466,8 @@ public class OpenJPAConfigurationImpl queryCompilationCachePlugin.setInstantiatingGetter( "getQueryCompilationCacheInstance"); addValue(queryCompilationCachePlugin); + + addString("Id"); // initialize supported options that some runtimes may not support supportedOptions.add(OPTION_NONTRANS_READ); @@ -1404,6 +1407,15 @@ public class OpenJPAConfigurationImpl public StoreFacadeTypeRegistry getStoreFacadeTypeRegistry() { return _storeFacadeRegistry; } + + public String getId() { + return id.get(); + } + + public void setId(String id) { + assertNotReadOnly(); + this.id.set(id); + } public void instantiateAll() { super.instantiateAll(); diff --git a/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties b/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties index ebfdc8ad9..db83d1e90 100644 --- a/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties +++ b/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties @@ -557,6 +557,15 @@ QueryCompilationCache-displayorder: 50 QueryCompilationCache-expert: true QueryCompilationCache-interface: java.util.Map +Id-name: Configuration ID +Id-desc: An environment-specific identifier for this configuration. This \ + might correspond to a JPA persistence-unit name, or to some other \ + more-unique value available in the current environment. +Id-type: General +Id-cat: Persistence +Id-displayorder: 50 +Id-expert: true + no-named-cf: use a DataSource bound to JNDI diff-specs: Attempt to configure for multiple specifications. Was configured \ for "{0}". Attempt to now configure for "{1}". This attempt will be \ diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java index 3439642b6..901eb01e8 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java @@ -357,6 +357,9 @@ public class PersistenceUnitInfoImpl map.remove(PersistenceProviderImpl.CLASS_TRANSFORMER_OPTIONS); } + if (!map.containsKey("openjpa.Id")) + map.put("openjpa.Id", info.getPersistenceUnitName()); + Properties metaFactoryProps = new Properties(); if (info.getManagedClassNames() != null && !info.getManagedClassNames().isEmpty()) { @@ -416,7 +419,7 @@ public class PersistenceUnitInfoImpl } map.put("openjpa.MetaDataFactory", factory); } - + // always record provider name for product derivations to access if (info.getPersistenceProviderClassName() != null) map.put(KEY_PROVIDER, info.getPersistenceProviderClassName());