From ddba469848b10e203e995646ea6a62c74c3b68d6 Mon Sep 17 00:00:00 2001 From: blafond Date: Mon, 28 Aug 2017 15:24:53 -0500 Subject: [PATCH] TEIIDDES-3099 * Fixed issue with resource adapter property defs being correctly loaded --- .../client/admin/ConnectionManager.java | 10 ++- .../client/admin/v8/AdminConstants.java | 2 + .../client/admin/v8/ResourceAdapterCache.java | 84 +++++++++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/ConnectionManager.java b/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/ConnectionManager.java index 23da0c9dc8..e495250fbb 100644 --- a/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/ConnectionManager.java +++ b/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/ConnectionManager.java @@ -204,9 +204,11 @@ public Collection getTranslators() { } public Collection getTemplatePropertyDefns(String templateName) throws Exception { - Collection result = new ArrayList(); - result.addAll(this.translatorCache.getTemplatePropertyDefns(templateName)); - result.addAll(dataSourceCache.getTemplatePropertyDefns(templateName)); - return result; + + if( this.resourceAdapterCache.isResourceAdapter(templateName) ) { + return this.resourceAdapterCache.getTemplatePropertyDefns(templateName); + } + + return this.dataSourceCache.getTemplatePropertyDefns(templateName); } } diff --git a/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/AdminConstants.java b/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/AdminConstants.java index 9e9133ad35..78f5f6ff55 100644 --- a/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/AdminConstants.java +++ b/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/AdminConstants.java @@ -31,6 +31,8 @@ public interface AdminConstants { String ADD = "add"; //$NON-NLS-1$ String CONFIG_PROPERTIES = "config-properties"; //$NON-NLS-1$ String CONNECTION_DEFINITIONS = "connection-definitions"; //$NON-NLS-1$ + String READ_RAR_DESCRIPTION = "read-rar-description"; //$NON-NLS-1$ + String RAR_NAME = "rar-name"; //$NON-NLS-1$ String READ_RESOURCE_DESCRIPTION = "read-resource-description"; //$NON-NLS-1$ String ANY = "any"; //$NON-NLS-1$ String MODULE = "module"; //$NON-NLS-1$ diff --git a/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/ResourceAdapterCache.java b/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/ResourceAdapterCache.java index cf61ad4a05..91224f2233 100644 --- a/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/ResourceAdapterCache.java +++ b/plugins/teiid/org.teiid.runtime.client/src/org/teiid/runtime/client/admin/v8/ResourceAdapterCache.java @@ -23,8 +23,10 @@ import org.teiid.adminapi.AdminException; import org.teiid.adminapi.AdminProcessingException; import org.teiid.adminapi.PropertyDefinition; +import org.teiid.adminapi.impl.PropertyDefinitionMetadata; import org.teiid.designer.runtime.spi.ITeiidDataSource; import org.teiid.designer.runtime.spi.ITeiidServer; +import org.teiid.designer.runtime.spi.TeiidPropertyDefinition; import org.teiid.runtime.client.Messages; import org.teiid.runtime.client.TeiidRuntimePlugin; import org.teiid.runtime.client.admin.TeiidDataSource; @@ -43,6 +45,8 @@ public class ResourceAdapterCache implements AdminConstants { private Set deployedResourceAdaptorNames; + private HashMap> resoureAdapterTempPropDefs; + public ResourceAdapterCache(AdminConnectionManager adminConnectionManager, ITeiidServer teiidServer) { super(); this.manager = adminConnectionManager; @@ -381,4 +385,84 @@ private void activateConnectionFactory(String rarName) throws AdminException { this.manager.cliCall(ACTIVATE, new String[] { SUBSYSTEM, RESOURCE_ADAPTERS, RESOURCE_ADAPTER, rarName }, null, new ResultCallback()); } + + public Collection getTemplatePropertyDefinitions(String templateName) throws AdminException { + if( resoureAdapterTempPropDefs == null ) { + this.resoureAdapterTempPropDefs = new HashMap>(); + } + + Collection props = this.resoureAdapterTempPropDefs.get(templateName); + + if( props == null ) { + props = loadTemplatePropertyDefinition(templateName); + this.resoureAdapterTempPropDefs.put(templateName, props); + } + + return props; + } + + public boolean isResourceAdapter(String name) { + return resourceAdapterIDs.contains(name); + } + + private Collection loadTemplatePropertyDefinition(String templateName) throws AdminException { + if( resoureAdapterTempPropDefs == null ) { + this.resoureAdapterTempPropDefs = new HashMap>(); + } + + Collection props = new ArrayList(); + + BuildPropertyDefinitions builder = new BuildPropertyDefinitions(); + + // get resource adapter node properties + manager.cliCall(READ_RAR_DESCRIPTION, new String[] {SUBSYSTEM, TEIID}, new String[] {RAR_NAME, templateName}, builder); + + // get resource adapter properties + manager.cliCall(READ_RESOURCE_DESCRIPTION, new String[] { + SUBSYSTEM, RESOURCE_ADAPTERS, + RESOURCE_ADAPTER, templateName, + CONNECTION_DEFINITIONS, ANY}, null, builder); + + + // add driver specific properties + PropertyDefinitionMetadata cp = new PropertyDefinitionMetadata(); + cp.setName(CONNECTION_PROPERTIES); + cp.setDisplayName("Additional Driver Properties"); + cp.setDescription("The connection-properties element allows you to pass in arbitrary connection properties to the Driver.connect(url, props) method. Supply comma separated name-value pairs"); //$NON-NLS-1$ + cp.setRequired(false); + cp.setAdvanced(true); + props = builder.getPropertyDefinitions(); + props.add(cp); + + return props; + } + + @SuppressWarnings("unchecked") + public Collection getTemplatePropertyDefns(String templateName) throws Exception { + + Collection propDefs = getTemplatePropertyDefinitions(templateName); + + Collection teiidPropDefns = new ArrayList(); + + for (PropertyDefinition propDefn : propDefs) { + TeiidPropertyDefinition teiidPropertyDefn = new TeiidPropertyDefinition(); + + teiidPropertyDefn.setName(propDefn.getName()); + teiidPropertyDefn.setDisplayName(propDefn.getDisplayName()); + teiidPropertyDefn.setDescription(propDefn.getDescription()); + teiidPropertyDefn.setPropertyTypeClassName(propDefn.getPropertyTypeClassName()); + teiidPropertyDefn.setDefaultValue(propDefn.getDefaultValue()); + teiidPropertyDefn.setAllowedValues(propDefn.getAllowedValues()); + teiidPropertyDefn.setModifiable(propDefn.isModifiable()); + teiidPropertyDefn.setConstrainedToAllowedValues(propDefn.isConstrainedToAllowedValues()); + teiidPropertyDefn.setAdvanced(propDefn.isAdvanced()); + teiidPropertyDefn.setRequired(propDefn.isRequired()); + teiidPropertyDefn.setMasked(propDefn.isMasked()); + + teiidPropDefns.add(teiidPropertyDefn); + } + + return teiidPropDefns; + } + }