Skip to content

Commit

Permalink
TEIIDDES-1518: Fix class not found for teiid drivers
Browse files Browse the repository at this point in the history
* Since no other plugin depends on the teiid8 plugin, the
  connectivity plugin cannot load the teiid drivers when
  initing a jdbc connection.

* Use the default server to obtain the teiid driver as this can
  cross the extension point and provide the driver from the
  execution admin implementation.

* Need to provide modeler core with the default teiid server
  rather than just the version in order for the connectivity
  plugin to obtain the default server.
  • Loading branch information
Paul Richardson committed Dec 7, 2012
1 parent fb82889 commit f019288
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.103.0,4.0.0)",
org.eclipse.datatools.connectivity.sqm.server.ui;bundle-version="[1.1.100,2.0.0)",
org.teiid.datatools.connectivity.model;bundle-version="[8.0.0,9.0.0)",
org.eclipse.equinox.security;bundle-version="1.1.100",
org.teiid.designer.spi;bundle-version="8.0.0"
org.teiid.designer.spi;bundle-version="8.0.0",
org.teiid.designer.core;bundle-version="8.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.eclipse.datatools.modelbase.dbdefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCConnectionProfileConstants;
import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants;
import org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.runtime.spi.ITeiidServer;

/**
* @since 8.0
Expand Down Expand Up @@ -73,17 +75,15 @@ protected Object createConnection( ClassLoader cl ) throws Throwable {
}
}

Driver jdbcDriver = null;
try {
jdbcDriver = (Driver)cl.loadClass(driverClass).newInstance();
}
catch (Exception ex) {}
ITeiidServer defaultServer = ModelerCore.getDefaultServer();

Driver jdbcDriver = defaultServer.getTeiidDriver(driverClass);

if (jdbcDriver == null) {
jdbcDriver = (Driver)this.getClass().getClassLoader().loadClass(driverClass).newInstance();
if (jdbcDriver != null) {
return jdbcDriver.connect(connectURL, connectionProps);
}

return jdbcDriver.connect(connectURL, connectionProps); // return super.createConnection(cl);
throw new Exception("Cannot find Teiid Driver"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.teiid.designer.core.workspace.ModelWorkspaceManagerSaveParticipant;
import org.teiid.designer.query.IQueryService;
import org.teiid.designer.runtime.registry.TeiidRuntimeRegistry;
import org.teiid.designer.runtime.spi.ITeiidServer;
import org.teiid.designer.runtime.spi.ITeiidServerVersionListener;
import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion;
Expand Down Expand Up @@ -341,7 +342,7 @@ public static enum RegistryOption {
// rules.
private static boolean IGNORE_VALIDATION_PREFERNCES_ON_BUILD = false;

private static ITeiidServerVersion teiidServerVersion = null;
private static ITeiidServer defaultTeiidServer = null;

private static Set<ITeiidServerVersionListener> teiidServerVersionListeners;

Expand Down Expand Up @@ -2074,18 +2075,27 @@ public static interface ILicense {
String PRODUCER_NAME = getProducerName();
String VERSION = getVersion();
}

/**
* Get the targeted teiid server
*
* @return teiid server
*/
public static ITeiidServer getDefaultServer() {
return defaultTeiidServer;
}

/**
* Get the targeted teiid server version
*
* @return teiid server version
*/
public static ITeiidServerVersion getTeiidServerVersion() {
if (teiidServerVersion == null) {
if (defaultTeiidServer == null) {
return TeiidServerVersion.DEFAULT_TEIID_8_SERVER;
}

return teiidServerVersion;
return defaultTeiidServer.getServerVersion();
}

/**
Expand Down Expand Up @@ -2117,23 +2127,23 @@ public static void removeTeiidServerVersionListener(ITeiidServerVersionListener
/**
* Set the version of the targeted teiid server
*
* @param serverVersion
* @param defaultServer
*/
public static void setTeiidServerVersion(ITeiidServerVersion serverVersion) {
teiidServerVersion = serverVersion;
public static void setDefaultServer(ITeiidServer defaultServer) {
defaultTeiidServer = defaultServer;

if (teiidServerVersionListeners == null)
return;

for (ITeiidServerVersionListener listener : teiidServerVersionListeners) {
listener.versionChanged(serverVersion);
listener.versionChanged(defaultServer.getServerVersion());
}
}

/**
* Get the teiid data type manager service for the
* targeted teiid server. The targeted teiid server
* can be changed using {@link #setTeiidServerVersion(ITeiidServerVersion)}
* can be changed using {@link #setDefaultServer(ITeiidServerVersion)}
*
* @return
*/
Expand All @@ -2148,7 +2158,7 @@ public static IDataTypeManagerService getTeiidDataTypeManagerService() {
/**
* Get the teiid query service for the
* targeted teiid server. The targeted teiid server
* can be changed using {@link #setTeiidServerVersion(ITeiidServerVersion)}
* can be changed using {@link #setDefaultServer(ITeiidServerVersion)}
*
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

import static org.teiid.designer.runtime.DqpPlugin.PLUGIN_ID;
import static org.teiid.designer.runtime.DqpPlugin.Util;
import java.sql.Driver;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.WeakHashMap;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -114,8 +113,6 @@ private static boolean equivalent( Object thisObj,
// ===========================================================================================================================
// Constructors
// ===========================================================================================================================

private static Map<String, TeiidServer> servers = new WeakHashMap();

/**
* Constructs on new <code>Server</code>.
Expand Down Expand Up @@ -610,6 +607,12 @@ public String getAdminDriverPath() throws Exception {
return admin.getAdminDriverPath();
}

@Override
public Driver getTeiidDriver(String driverClass) throws Exception {
connect();
return admin.getTeiidDriver(driverClass);
}

@Override
public void update(ITeiidServer otherServer) {
CoreArgCheck.isNotNull(otherServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ public void setDefaultServer( ITeiidServer teiidServer ) {
ITeiidServer oldDefaultServer = this.defaultServer;
this.defaultServer = teiidServer;

ModelerCore.setTeiidServerVersion(defaultServer.getServerVersion());
ModelerCore.setDefaultServer(defaultServer);

if (notify) {
notifyListeners(ExecutionConfigurationEvent.createSetDefaultServerEvent(oldDefaultServer, this.defaultServer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.teiid.designer.runtime.spi;

import java.sql.Driver;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -212,4 +213,15 @@ ITeiidDataSource getOrCreateDataSource(String displayName,
* @throws Exception
*/
String getAdminDriverPath() throws Exception;

/**
* Get the teiid server driver for the given class
*
* @param driverClass
*
* @return instance of {@link Driver}
*
* @throws Exception
*/
Driver getTeiidDriver(String driverClass) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -63,6 +64,9 @@ public class ExecutionAdmin implements IExecutionAdmin {

private static String PLUGIN_ID = "org.teiid.8-2"; //$NON-NLS-1$

/**
* Test VDB model
*/
public static final String TEST_VDB = "<vdb name=\"ping\" version=\"1\">" + //$NON-NLS-1$
"<model visible=\"true\" name=\"Foo\" type=\"PHYSICAL\" path=\"/dummy/Foo\">" + //$NON-NLS-1$
"<source name=\"s\" translator-name=\"loopback\"/>" + //$NON-NLS-1$
Expand Down Expand Up @@ -194,9 +198,7 @@ public void deployVdb( IFile vdbFile ) throws Exception {
this.eventManager.notifyListeners(ExecutionConfigurationEvent.createDeployVDBEvent(vdb.getName()));
}

/**
* Closes the admin and re-sets the cached items from the server
*/
@Override
public void disconnect() {
//
this.admin.close();
Expand Down Expand Up @@ -708,6 +710,16 @@ public String getAdminDriverPath() {
return Admin.class.getProtectionDomain().getCodeSource().getLocation().getFile();
}

@Override
public Driver getTeiidDriver(String driverClass) throws Exception {
Class<?> klazz = getClass().getClassLoader().loadClass(driverClass);
Object driver = klazz.newInstance();
if (driver instanceof Driver)
return (Driver) driver;

throw new Exception(NLS.bind(Messages.cannotLoadDriverClass, driverClass));
}

/**
* Executes VDB refresh when a VDB is loading - as a background job.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class Messages extends NLS {
public static String connectorDetailedName;

public static String failedToGetDriverMappings;
public static String cannotLoadDriverClass;

static {
NLS.initializeMessages("org.teiid8.runtime.messages", Messages.class); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ invalidNullPropertyValue = The property "{0}" must have a value.
missingPropertyDefinition = No property definition found for property "{0}"
unknownPropertyType = Property "{0}" has an unknown type of "{1}"
connectorDetailedName = {0} : {1}
failedToGetDriverMappings = Failed to get installed driver mappings for request driver "{0}".
failedToGetDriverMappings = Failed to get installed driver mappings for request driver "{0}".

cannotLoadDriverClass = Server cannot load the driver class "{0}"

0 comments on commit f019288

Please sign in to comment.