Author: rareddy
Date: 2009-07-27 17:20:17 -0400 (Mon, 27 Jul 2009)
New Revision: 1195
Modified:
trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ComponentType.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ConfigurationModelContainer.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicComponentType.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ConfigurationModelContainerImpl.java
trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
Log:
TEIID-742, TEIID-743
Modified: trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
===================================================================
--- trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-27
20:27:21 UTC (rev 1194)
+++ trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -387,7 +387,7 @@
InputStream in = null;
try{
in = dqpURL.openStream();
- Properties props = new Properties();
+ Properties props = new Properties(System.getProperties());
props.load(in);
String logMsg =
getResourceMessage("EmbeddedDriver.use_properties"); //$NON-NLS-1$
Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -777,7 +777,7 @@
}
/**
- * The speciality of nested properties is, in a given property file
+ * The specialty of nested properties is, in a given property file
* there can be values with pattern like "${...}"
* <code>
* key1=value1
@@ -785,24 +785,20 @@
* </code>
* where the value of the <code>key2</code> should resolve to
<code>value1/value2</code>
* also if the property in the pattern <code>${..}</code> is not found in
the loaded
- * properties, then it will look up for the property value in the
<code>System</code>
- * properties. Multiple nesting is OK, however recursive nested is not good, and
- * behaviour is undocumented in this case.
+ * properties, an exception is thrown. Multiple nesting is OK, however recursive
nested is not supported.
* @param original - Original properties to be resolved
* @return resolved properties object.
* @since 4.4
*/
public static Properties resolveNestedProperties(Properties original) {
- Properties modified = new Properties();
- for(Enumeration e = original.keys(); e.hasMoreElements();) {
+ for(Enumeration e = original.propertyNames(); e.hasMoreElements();) {
String key = (String)e.nextElement();
String value = original.getProperty(key);
// this will take care of the if there are any non-string properties,
// no nesting allowed on these.
if (value == null) {
- modified.put(key, original.get(key));
continue;
}
@@ -819,31 +815,17 @@
if (matched) {
String nestedkey = value.substring(start+2, end);
String nestedvalue = original.getProperty(nestedkey);
- if (nestedvalue == null) {
- nestedvalue = System.getProperty(nestedkey);
- }
// this will handle case where we did not resolve, mark it blank
if (nestedvalue == null) {
- value = null;
- break;
+ throw new
MetaMatrixRuntimeException(CorePlugin.Util.getString("PropertiesUtils.failed_to_resolve_property",
nestedkey)); //$NON-NLS-1$
}
value = value.substring(0,start)+nestedvalue+value.substring(end+1);
}
- else {
- break;
- }
}
- if (value != null) {
- // now add to the modified property list
- modified.setProperty(key, value);
- }
- else {
- // since we do not have this property, remove it..
- modified.remove(key);
- }
+ original.setProperty(key, value);
}
- return modified;
+ return original;
}
// ======================================================
@@ -879,7 +861,7 @@
boolean bPass = false;
- String sMatchFrag = "";
+ String sMatchFrag = ""; //$NON-NLS-1$
// List propNames = new ArrayList();
@@ -890,7 +872,7 @@
// which means anything passes.
pattern.trim();
if ( pattern.length() == 0 )
- pattern = "*";
+ pattern = "*"; //$NON-NLS-1$
int iFirstStar = pattern.indexOf( chStar );
int iLastStar = pattern.lastIndexOf( chStar );
Modified: trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties
===================================================================
--- trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties 2009-07-27
20:27:21 UTC (rev 1194)
+++ trunk/common-core/src/main/resources/com/metamatrix/core/i18n.properties 2009-07-27
21:20:17 UTC (rev 1195)
@@ -402,3 +402,4 @@
ERR.003.030.0181=Failed to connect to the Database at {0} check connection properties.
ExceptionHolder.converted_exception=Remote exception: {0} ... Original type hierarchy
{1}.
+PropertiesUtils.failed_to_resolve_property=failed to completely resolve the property
value for key {0}
\ No newline at end of file
Modified:
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
===================================================================
---
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -625,13 +625,12 @@
public void testNestedProperties() throws Exception {
System.setProperty("testdirectory",
"c:/metamatrix/testdirectory"); //$NON-NLS-1$ //$NON-NLS-2$
- Properties p = new Properties();
+ Properties p = new Properties(System.getProperties());
p.setProperty("key1", "value1"); //$NON-NLS-1$ //$NON-NLS-2$
p.setProperty("key2", "${key1}/value2"); //$NON-NLS-1$
//$NON-NLS-2$
p.put("key3", new Integer(-234)); //$NON-NLS-1$
p.setProperty("key4", "${key2}/value4"); //$NON-NLS-1$
//$NON-NLS-2$
p.setProperty("key5", "${testdirectory}/testdata");
//$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("key6", "${foo}"); //$NON-NLS-1$ //$NON-NLS-2$
p.setProperty("key7", "anotherdir/${testdirectory}/${key1}");
//$NON-NLS-1$ //$NON-NLS-2$
Properties m = PropertiesUtils.resolveNestedProperties(p);
@@ -639,8 +638,19 @@
assertEquals(new Integer(-234), m.get("key3")); //$NON-NLS-1$
assertEquals("value1/value2/value4", m.getProperty("key4"));
//$NON-NLS-1$ //$NON-NLS-2$
assertEquals("c:/metamatrix/testdirectory/testdata",
m.getProperty("key5")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals(null, m.getProperty("key6")); //$NON-NLS-1$
assertEquals("anotherdir/c:/metamatrix/testdirectory/value1",
m.getProperty("key7")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue(p == m); // no cloning.
+
+
+ p.setProperty("key6", "${foo}"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ try {
+ m = PropertiesUtils.resolveNestedProperties(p);
+ fail("must have failed to resovle as {foo} does not exist");
//$NON-NLS-1$
+ } catch(RuntimeException e) {
+ // pass
+ }
+
}
public void testOverrideProperties() {
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ComponentType.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ComponentType.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ComponentType.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -74,6 +74,8 @@
*/
Properties getDefaultPropertyValues();
+ Properties getDefaultPropertyValues(Properties props);
+
/**
* Returns the List <String> of properties that are defined as
* masked for this component type.
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ConfigurationModelContainer.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ConfigurationModelContainer.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/ConfigurationModelContainer.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -118,7 +118,9 @@
*/
Properties getDefaultPropertyValues(ComponentTypeID componentTypeID) ;
+ Properties getDefaultPropertyValues(Properties defaultProperties, ComponentTypeID
componentTypeID) ;
+
/**
* Return a collection of objects of type
<code>ResourceDescriptor</code>.
* These are all the hosts defined in this configuration.
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicComponentType.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicComponentType.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicComponentType.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -134,7 +134,12 @@
public Properties getDefaultPropertyValues() {
Properties result = new Properties();
-
+ result = getDefaultPropertyValues(result);
+ return result;
+
+ }
+
+ public Properties getDefaultPropertyValues(Properties props) {
Collection defns = getComponentTypeDefinitions();
for (Iterator it=defns.iterator(); it.hasNext();) {
@@ -145,18 +150,16 @@
if (value instanceof String) {
String v = (String) value;
if (v.trim().length() > 0) {
- result.put(ctd.getPropertyDefinition().getName(), v );
+ props.put(ctd.getPropertyDefinition().getName(), v );
}
} else {
- result.put(ctd.getPropertyDefinition().getName(), value.toString()
);
+ props.put(ctd.getPropertyDefinition().getName(), value.toString() );
}
}
}
-
- return result;
-
- }
+ return props;
+ }
/**
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ConfigurationModelContainerImpl.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ConfigurationModelContainerImpl.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/ConfigurationModelContainerImpl.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -302,8 +302,15 @@
public Properties getDefaultPropertyValues(ComponentTypeID componentTypeID) {
Properties result = new Properties();
+ result = getDefaultPropertyValues(result, componentTypeID);
+ return result;
+
+ }
+
+ public Properties getDefaultPropertyValues(Properties defaultProperties,
ComponentTypeID componentTypeID) {
+ Properties result = new Properties(defaultProperties);
- Collection defns = getAllComponentTypeDefinitions(componentTypeID);
+ Collection defns = getAllComponentTypeDefinitions(componentTypeID);
for (Iterator it=defns.iterator(); it.hasNext();) {
ComponentTypeDefn ctd = (ComponentTypeDefn) it.next();
@@ -321,10 +328,8 @@
}
}
}
-
- return result;
-
- }
+ return result;
+ }
Modified: trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java 2009-07-27
20:27:21 UTC (rev 1194)
+++ trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -140,7 +140,7 @@
setCommandPayload(context.commandPayload);
setVdbName(context.vdbName);
setVdbVersion(context.vdbVersion);
- setEnvironmentProperties(PropertiesUtils.clone(context.environmentProperties));
+ setEnvironmentProperties(context.environmentProperties);
setProcessDebug(context.processDebug);
setProcessorBatchSize(context.processorBatchSize);
setConnectorBatchSize(context.connectorBatchSize);
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorManager.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -338,7 +338,7 @@
connectorWorkerPool = WorkerPoolFactory.newWorkerPool(connectorName,
maxThreads);
// Create the Connector env
- Properties clonedProps = PropertiesUtils.resolveNestedProperties(props);
+ Properties clonedProps = new Properties(this.props);
ConnectorEnvironment connectorEnv = new ConnectorEnvironmentImpl(clonedProps, new
DefaultConnectorLogger(connectorID), env, connectorWorkerPool);
Modified:
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedConfigurationService.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -113,6 +113,7 @@
private ArrayList<VDBLifeCycleListener> vdbLifeCycleListeners = new
ArrayList<VDBLifeCycleListener>();
private ArrayList<ConnectorBindingLifeCycleListener>
connectorBindingLifeCycleListeners = new
ArrayList<ConnectorBindingLifeCycleListener>();
private UDFSource udfSource;
+ private Map<ConnectorBindingType, Properties>
defaultConnectorTypePropertiesCache = new HashMap<ConnectorBindingType,
Properties>();
private AbstractClassLoaderManager classLoaderManager = new
AbstractClassLoaderManager(Thread.currentThread().getContextClassLoader(), true, true) {
@@ -612,8 +613,23 @@
* @param binding
* @return properties for the connector binding given
*/
- public Properties getDefaultProperties(ConnectorBindingType type) {
- return
configurationModel.getDefaultPropertyValues((ComponentTypeID)type.getID());
+ public Properties getDefaultProperties(ConnectorBindingType type) {
+ if (type != null) {
+ Properties props = null;
+ synchronized (this.defaultConnectorTypePropertiesCache) {
+ props = this.defaultConnectorTypePropertiesCache.get(type);
+ if (props == null) {
+ props = new Properties(getUserPreferences());
+ props = configurationModel.getDefaultPropertyValues(props,
(ComponentTypeID)type.getID());
+ if (props.isEmpty()) {
+ props = type.getDefaultPropertyValues(props);
+ }
+ this.defaultConnectorTypePropertiesCache.put(type, props);
+ }
+ }
+ return props;
+ }
+ return new Properties(getUserPreferences());
}
/**
@@ -952,7 +968,7 @@
throws ApplicationInitializationException {
try {
- this.setUserPreferences(PropertiesUtils.clone(properties));
+ this.setUserPreferences(properties);
DQPEmbeddedPlugin.logInfo("EmbeddedConfigurationService.dqp_loading", new
Object[] {getProcessName()}); //$NON-NLS-1$
Modified:
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/runtime/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedDataService.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -48,6 +48,7 @@
import com.metamatrix.common.config.api.ComponentTypeID;
import com.metamatrix.common.config.api.ConnectorBinding;
import com.metamatrix.common.config.api.ConnectorBindingType;
+import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.common.util.crypto.CryptoException;
import com.metamatrix.common.util.crypto.CryptoUtil;
import com.metamatrix.common.vdb.api.VDBArchive;
@@ -499,10 +500,9 @@
Properties getDecryptedProperties(ConnectorBinding binding)
throws MetaMatrixComponentException{
+
+ Properties decryptedProperties = null;
- Properties bindingProperties = binding.getProperties();
- Properties decryptedProperties = new Properties();
-
// Get all the default properties for the connector type, so that
// if the connector binding does not have all the properties then these
// will take over, otherwise the connector binding ones overwrite
@@ -510,16 +510,9 @@
ConnectorBindingType type =
getConfigurationService().getConnectorType(id.getName());
// Index connector has no formal definition in the configuration file.
- if (type != null) {
- Properties props = getConfigurationService().getDefaultProperties(type);
- if (props == null || props.isEmpty()) {
- props = type.getDefaultPropertyValues();
- }
-
- if (props != null && !props.isEmpty()) {
- decryptedProperties.putAll(props);
- }
- }
+ decryptedProperties = new
Properties(getConfigurationService().getDefaultProperties(type));
+
+ Properties bindingProperties = binding.getProperties();
// now overlay the custom properties from the default properties.
decryptedProperties.putAll(bindingProperties);
@@ -536,7 +529,7 @@
}
}
}
- return decryptedProperties;
+ return PropertiesUtils.resolveNestedProperties(decryptedProperties);
}
/**
Modified:
trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
===================================================================
---
trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-07-27
20:27:21 UTC (rev 1194)
+++
trunk/runtime/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java 2009-07-27
21:20:17 UTC (rev 1195)
@@ -121,12 +121,12 @@
}
URL bootstrapURL = null;
- Properties props = info;
+ Properties props = new Properties(System.getProperties());
String processName = "embedded"; //$NON-NLS-1$
try {
bootstrapURL = URLHelper.buildURL(info.getProperty(DQPEmbeddedProperties.BOOTURL));
- props = PropertiesUtils.loadFromURL(bootstrapURL);
+ props.putAll(PropertiesUtils.loadFromURL(bootstrapURL));
props.putAll(info);
props = PropertiesUtils.resolveNestedProperties(props);