Skip to content

Commit

Permalink
Merge pull request #325 from mdrillin/TEIIDDES-2114
Browse files Browse the repository at this point in the history
improves teiid connection importer support for resource adapters
  • Loading branch information
blafond committed Apr 15, 2014
2 parents 593f138 + af05b10 commit fcd3769
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dataSourcePropertiesPanel_invalidPropertyMsg=One or more property has an invalid
dataSourcePropertiesPanel_validPropertyTooltip=The value for {0}
dataSourcePropertiesPanel_invalidPropertyTooltip=Enter a valid value for {0}
dataSourcePropertiesPanelOk=Data Source Properties OK
dataSourcePropertiesPanel_requiredLabel=* - required property
dataSourcePropertiesPanel_requiredLabel=* - denotes required property

dataSourcePanel_newButtonText=New...
dataSourcePanel_deleteButtonText=Delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public String getDataSourceDriverName() {
if(isCreateNew) {
return this.driversPanel.getSelectedDriverName();
}
return this.dataSourceManager.getDataSourceDriver(this.editDSName);
return this.dataSourceManager.getDataSourceDriver(this.editDSName,null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.teiid.core.designer.util.CoreStringUtil;
import org.teiid.designer.runtime.spi.ITeiidDataSource;
import org.teiid.designer.runtime.spi.TeiidPropertyDefinition;
import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;
import org.teiid.designer.teiidimporter.ui.Messages;
Expand Down Expand Up @@ -223,7 +230,7 @@ public void run( IProgressMonitor monitor ) throws InvocationTargetException {
public List<PropertyItem> getDataSourcePropertyItems(String dsName) {

// Get the driver template properties
String driverName = getDataSourceDriver(dsName);
String driverName = getDataSourceDriver(dsName, null);
List<PropertyItem> propertyItems = getDriverPropertyItems(driverName);

if(!propertyItems.isEmpty()) {
Expand Down Expand Up @@ -337,33 +344,128 @@ public List<PropertyItem> getDriverPropertyItems(String driverName) {
return propertyItemList;
}

/**
* Create a map of class-name to the associated DataSource template name. This
* matches the className of the datasource to the 'managedconnectionfactory-class' name from the template.
* @param teiidDataSources the collection of Teiid DataSources
* @return Map of RA class-name to DS template name
*/
public Map<String,String> getClassNameDriverNameMap(Collection<ITeiidDataSource> teiidDataSources) {
Map<String,String> raClassToDriverNameMap = new HashMap<String,String>();

// Get all distinct class-names from dataSources
Set<String> dsClassNames = new HashSet<String>();
for(ITeiidDataSource ds : teiidDataSources) {
String dsClass = ds.getPropertyValue("class-name"); //$NON-NLS-1$
if(!CoreStringUtil.isEmpty(dsClass)) {
dsClassNames.add(dsClass);
}
}

// Get all available templates from the server
Set<String> availableTemplateNames;
try {
availableTemplateNames = teiidImportServer.getDataSourceTemplateNames();
} catch (Exception ex) {
availableTemplateNames = Collections.EMPTY_SET;
UTIL.log(ex);
}

for(String className : dsClassNames) {
// Loop through all available templates. break if matching template is found
for(String templateName : availableTemplateNames) {
Collection<TeiidPropertyDefinition> propDefns;
try {
// Get the driver template properties
propDefns = teiidImportServer.getTemplatePropertyDefns(templateName);
// Get default value for managedconnectionfactory-class
String mcfDefault = getManagedConnectionFactoryClassDefault(propDefns);
if(className.equals(mcfDefault)) {
raClassToDriverNameMap.put(className, templateName);
break;
}
} catch (Exception ex) {
UTIL.log(ex);
}
}
}

return raClassToDriverNameMap;
}

/**
* Get the Driver name for the supplied DataSource name - from the TeiidServer
* @param dsName the data source name
* @param raClassNameDriverNameMap optionally supplied mapping of className to TemplateName
* @return the dataSource driver name
*/
public String getDataSourceDriver(String dsName) {
public String getDataSourceDriver(String dsName, Map<String,String> raClassNameDriverNameMap) {
String driverName = null;
ITeiidServerVersion teiidVersion = null;
Properties props = new Properties();
try {
props = teiidImportServer.getDataSourceProperties(dsName);
teiidVersion = teiidImportServer.getTeiidServerVersion();
} catch (Exception ex) {
UTIL.log(ex);
return null;
}
driverName = props.getProperty(DRIVER_KEY);
// If driver-name not found, look for class name and match up the .rar

// If driver-name not found - 1) use map (if supplied) to get the driverName or 2) attempt to match server template
if(CoreStringUtil.isEmpty(driverName)) {
String className = props.getProperty(CLASSNAME_KEY);
if(!CoreStringUtil.isEmpty(className)) {
driverName = TranslatorHelper.getDriverNameForClass(className, teiidVersion);

if(raClassNameDriverNameMap!=null) {
driverName = raClassNameDriverNameMap.get(className);
} else {
String dsTemplateName = findDSTemplateWithMatchingClass(className);
if(!CoreStringUtil.isEmpty(dsTemplateName)) {
driverName = dsTemplateName;
}
}
}
return driverName;
}

/**
* Iterates through all of the available dataSource templates to find template with 'managedconnectionfactory-class' that
* matches the supplied className. If no match is found, null is returned.
* @param className the dataSource class name
* @return the templateName with 'managedconnectionfactory-class' that matches className, null if not found.
*/
private String findDSTemplateWithMatchingClass(String className) {
if(CoreStringUtil.isEmpty(className)) return null;

String dsTemplateName = null;

// Get all available templates from the server
Set<String> availableTemplateNames;
try {
availableTemplateNames = teiidImportServer.getDataSourceTemplateNames();
} catch (Exception ex) {
availableTemplateNames = Collections.EMPTY_SET;
UTIL.log(ex);
}

// Loop through all available templates. break if matching template is found
for(String templateName : availableTemplateNames) {
Collection<TeiidPropertyDefinition> propDefns;
try {
// Get the driver template properties
propDefns = teiidImportServer.getTemplatePropertyDefns(templateName);
// Get default value for managedconnectionfactory-class
String mcfDefault = getManagedConnectionFactoryClassDefault(propDefns);
if(className.equals(mcfDefault)) {
dsTemplateName = templateName;
break;
}
} catch (Exception ex) {
UTIL.log(ex);
}
}

return dsTemplateName;
}

/**
* Determine if this is a 'rar' type driver that is deployed with Teiid
* @param driverName the name of the driver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ErrorDialog;
Expand Down Expand Up @@ -465,6 +466,10 @@ private void refreshDataSourceList( ) {
dataSources = new ArrayList<ITeiidDataSource>();
UTIL.log(ex);
}

// get className - driverMap for RA sources
Map<String,String> classNameDriverNameMap = dataSourceManager.getClassNameDriverNameMap(dataSources);

for(ITeiidDataSource dataSource: dataSources) {
DataSourceItem dsObj = new DataSourceItem();
// ------------------------
Expand All @@ -483,7 +488,7 @@ private void refreshDataSourceList( ) {
}

// Driver name
String dsDriver = dataSourceManager.getDataSourceDriver(name);
String dsDriver = dataSourceManager.getDataSourceDriver(name, classNameDriverNameMap);
dsObj.setDriver(dsDriver);
// ------------------------
// Add PropertyItem to List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISharedImages;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.core.designer.util.CoreStringUtil;
Expand Down Expand Up @@ -66,6 +68,7 @@ public final class DataSourcePropertiesPanel extends Composite implements UiCons

private List<DataSourcePropertiesPanelListener> listeners = new ArrayList<DataSourcePropertiesPanelListener>();
private Button resetButton;
private Text propDescriptionText;

/**
* DataSourcePropertiesPanel constructor
Expand Down Expand Up @@ -137,6 +140,15 @@ private void createTablePanel(Composite parent, boolean isReadOnly) {
Label reqdLabel = new Label(panel,SWT.NONE);
reqdLabel.setText(Messages.dataSourcePropertiesPanel_requiredLabel);

// Create Property description label below table
propDescriptionText = new Text(panel, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL);
propDescriptionText.setBackground(parent.getBackground());
propDescriptionText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
GridData descriptionLabelGridData = new GridData(GridData.FILL_HORIZONTAL);
descriptionLabelGridData.horizontalIndent = 20;
descriptionLabelGridData.heightHint = (2 * propDescriptionText.getLineHeight());
propDescriptionText.setLayoutData(descriptionLabelGridData);

ColumnViewerToolTipSupport.enableFor(this.propertiesViewer);
this.propertiesViewer.setContentProvider(new IStructuredContentProvider() {
/**
Expand Down Expand Up @@ -496,8 +508,10 @@ private PropertyItem getSelectedProperty() {
* Handler for selection changed events
*/
void handlePropertySelected( SelectionChangedEvent event ) {
if(isReadOnly) return;
IStructuredSelection selection = (IStructuredSelection)event.getSelection();
setPropertyDescriptionText(selection);

if(isReadOnly) return;

if (selection.isEmpty()) {
if (this.resetButton.isEnabled()) {
Expand All @@ -511,7 +525,20 @@ void handlePropertySelected( SelectionChangedEvent event ) {
}
}
}


/*
* Sets the property description text below the table
* @selection the selection
*/
private void setPropertyDescriptionText(IStructuredSelection selection) {
if(selection==null || selection.isEmpty()) {
this.propDescriptionText.setText(""); //$NON-NLS-1$
} else {
PropertyItem prop = (PropertyItem)selection.getFirstElement();
this.propDescriptionText.setText(prop.getDescription());
}
}

/*
* Handler for ResetAction
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Properties;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.core.designer.util.CoreStringUtil;
import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;
import org.teiid.designer.teiidimporter.ui.UiConstants;
import org.teiid.designer.ui.common.UiConstants.ConnectionProfileIds;
Expand Down Expand Up @@ -45,13 +44,13 @@ public class TranslatorHelper implements UiConstants {
public static final String TEIID_SALESORCE_DRIVER_DISPLAYNAME = "Salesforce"; //$NON-NLS-1$
public static final String TEIID_WEBSERVICE_DRIVER_DISPLAYNAME = "WebService"; //$NON-NLS-1$

public static final String TEIID_FILE_CLASS = "org.teiid.resource.adapter.file.FileManagedConnectionFactory"; //$NON-NLS-1$
public static final String TEIID_GOOGLE_CLASS = "org.teiid.resource.adapter.google.SpreadsheetManagedConnectionFactory"; //$NON-NLS-1$
public static final String TEIID_INFINISPAN_CLASS = "org.teiid.resource.adapter.infinispan.InfinispanManagedConnectionFactory"; //$NON-NLS-1$
public static final String TEIID_LDAP_CLASS = "org.teiid.resource.adapter.ldap.LDAPManagedConnectionFactory"; //$NON-NLS-1$
public static final String TEIID_SALESORCE_CLASS = "org.teiid.resource.adapter.salesforce.SalesForceManagedConnectionFactory"; //$NON-NLS-1$
public static final String TEIID_WEBSERVICE_CLASS = "org.teiid.resource.adapter.ws.WSManagedConnectionFactory"; //$NON-NLS-1$
public static final String TEIID_MONGODB_CLASS = "org.teiid.resource.adapter.mongodb.MongoDBManagedConnectionFactory"; //$NON-NLS-1$
// public static final String TEIID_FILE_CLASS = "org.teiid.resource.adapter.file.FileManagedConnectionFactory"; //$NON-NLS-1$
// public static final String TEIID_INFINISPAN_CLASS = "org.teiid.resource.adapter.infinispan.InfinispanManagedConnectionFactory"; //$NON-NLS-1$
// public static final String TEIID_LDAP_CLASS = "org.teiid.resource.adapter.ldap.LDAPManagedConnectionFactory"; //$NON-NLS-1$
// public static final String TEIID_SALESORCE_CLASS = "org.teiid.resource.adapter.salesforce.SalesForceManagedConnectionFactory"; //$NON-NLS-1$
// public static final String TEIID_WEBSERVICE_CLASS = "org.teiid.resource.adapter.ws.WSManagedConnectionFactory"; //$NON-NLS-1$
// public static final String TEIID_MONGODB_CLASS = "org.teiid.resource.adapter.mongodb.MongoDBManagedConnectionFactory"; //$NON-NLS-1$

public static final String ACCESS = "access"; //$NON-NLS-1$
public static final String DB2 = "db2"; //$NON-NLS-1$
Expand Down Expand Up @@ -218,52 +217,6 @@ public static String getTranslator(String driverName, Collection<String> transla
return JDBC_ANSI;
}

/**
* Get the Driver Name for the supplied class and server version
* @param driverClassName the driver class name
* @param teiidVersion the teiid version
* @return the driver name
*/
public static String getDriverNameForClass(String driverClassName, ITeiidServerVersion teiidVersion) {
String driverName = null;
if(!CoreStringUtil.isEmpty(driverClassName)) {
// Teiid 8.3 and below
if(!isTeiid84OrHigher(teiidVersion)) {
if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_FILE_CLASS)) {
driverName = TranslatorHelper.TEIID_FILE_DRIVER;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_GOOGLE_CLASS)) {
driverName = TranslatorHelper.TEIID_GOOGLE_DRIVER;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_INFINISPAN_CLASS)) {
driverName = TranslatorHelper.TEIID_INFINISPAN_DRIVER;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_LDAP_CLASS)) {
driverName = TranslatorHelper.TEIID_LDAP_DRIVER;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_SALESORCE_CLASS)) {
driverName = TranslatorHelper.TEIID_SALESORCE_DRIVER;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_WEBSERVICE_CLASS)) {
driverName = TranslatorHelper.TEIID_WEBSERVICE_DRIVER;
}
// Teiid 8.4 and higher
} else {
if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_FILE_CLASS)) {
driverName = TranslatorHelper.TEIID_FILE_DRIVER_84UP;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_GOOGLE_CLASS)) {
driverName = TranslatorHelper.TEIID_GOOGLE_DRIVER_84UP;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_INFINISPAN_CLASS)) {
driverName = TranslatorHelper.TEIID_INFINISPAN_DRIVER_84UP;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_LDAP_CLASS)) {
driverName = TranslatorHelper.TEIID_LDAP_DRIVER_84UP;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_SALESORCE_CLASS)) {
driverName = TranslatorHelper.TEIID_SALESORCE_DRIVER_84UP;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_WEBSERVICE_CLASS)) {
driverName = TranslatorHelper.TEIID_WEBSERVICE_DRIVER_84UP;
} else if(driverClassName.equalsIgnoreCase(TranslatorHelper.TEIID_MONGODB_CLASS)) {
driverName = TranslatorHelper.TEIID_MONGODB_DRIVER_84UP;
}
}
}
return driverName;
}

/**
* Test whether the version is 8.4 or higher. (.rar deployments were changed in 8.4)
* We assume false, and may not be able to determine - if wildcards are used.
Expand Down

0 comments on commit fcd3769

Please sign in to comment.