Skip to content

Commit

Permalink
TEIIDDES-1526 NPE In JdbcManagerImpl Starting With Clean Workspace An…
Browse files Browse the repository at this point in the history
…d Running JDBC Importer

Problem was the profile listener was being notified at the time the JDBC sources were being requested. Because the
profile listener called "reload" the JDBC manager was shutdown and restarted during the request for sources. Changed
so that start and shutdown are only called one time and reload just refreshes the sources and drivers.
  • Loading branch information
elvisisking committed Nov 1, 2012
1 parent 425a816 commit 05e750b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ JdbcRelationalPlugin.modelContainerName = JDBC Model Container
#=================================================================================================================================
# JdbcRelationalUtil

JdbcRelationalUtil.jdbcManagerName = Default JDBC Manager
RelationalModelProcessorImpl.Skipping_{0}_with_no_name=Skipping {0} with no name
RelationalModelProcessorImpl.DefaultNameForProcParamWithNoName=ParamWithNoName{0}
RelationalModelProcessorImpl.NoDatatypeManager=No type mapping object found; no datatypes will be assigned to imported Columns and Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.jdbc.JdbcException;
import org.teiid.designer.jdbc.JdbcManager;
import org.teiid.designer.jdbc.JdbcManagerImpl;
import org.teiid.designer.jdbc.JdbcPlugin;
import org.teiid.designer.jdbc.JdbcSource;
import org.teiid.designer.jdbc.relational.ModelerJdbcRelationalConstants;
Expand All @@ -32,8 +33,6 @@ public class JdbcRelationalUtil implements ModelerJdbcRelationalConstants {

private static final String I18N_PREFIX = I18nUtil.getPropertyPrefix(JdbcRelationalUtil.class);

private static final String JDBC_MANAGER_NAME = getString("jdbcManagerName"); //$NON-NLS-1$

private static final String ESCAPE_CHARACTER = "\""; //$NON-NLS-1$

private static JdbcManager mgr;
Expand Down Expand Up @@ -63,13 +62,11 @@ public static String escapeDatabaseObjectName( String name ) {
}

/**
* @return the JDBC manager (never <code>null</code>)
* @since 4.0
*/
public static JdbcManager getJdbcManager() {
if (JdbcRelationalUtil.mgr == null) {
JdbcRelationalUtil.mgr = JdbcPlugin.createJdbcManager(JDBC_MANAGER_NAME);
}
return JdbcRelationalUtil.mgr;
return JdbcPlugin.getJdbcManager();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static JdbcManager get() {
private ProfileManager profileManager;
private DriverManager driverManager;
private boolean sourcesUpdated;
private boolean driversUpdated;
private ProfileListener profileListener;

/**
Expand Down Expand Up @@ -267,20 +268,19 @@ public JdbcFactory getFactory() {
*/
@Override
public List getJdbcDrivers() {
if (drivers == null) {
if (this.driversUpdated) {
synchronized (driversLock) {
if (drivers == null) {
final JdbcFactoryImpl factory = new JdbcFactoryImpl();
drivers = factory.createJdbcDriverContainer();
final DriverInstance[] tempDrivers = driverManager.getDriverInstancesByCategory("org.eclipse.datatools.connectivity.db.category"); //$NON-NLS-1$
for (final DriverInstance driverInstance : tempDrivers) {
final JdbcDriver driver = factory.createJdbcDriver();
driver.setName(driverInstance.getName());
driver.setPreferredDriverClassName(driverInstance.getNamedPropertyByID("org.eclipse.datatools.connectivity.db.driverClass")); //$NON-NLS-1$
driver.setUrlSyntax(driverInstance.getNamedPropertyByID("org.eclipse.datatools.connectivity.db.URL")); //$NON-NLS-1$
driver.setJdbcDriverContainer(drivers);
drivers.getJdbcDrivers().add(driver);
}
this.driversUpdated = false;
final JdbcFactoryImpl factory = new JdbcFactoryImpl();
drivers = factory.createJdbcDriverContainer();
final DriverInstance[] tempDrivers = driverManager.getDriverInstancesByCategory("org.eclipse.datatools.connectivity.db.category"); //$NON-NLS-1$
for (final DriverInstance driverInstance : tempDrivers) {
final JdbcDriver driver = factory.createJdbcDriver();
driver.setName(driverInstance.getName());
driver.setPreferredDriverClassName(driverInstance.getNamedPropertyByID("org.eclipse.datatools.connectivity.db.driverClass")); //$NON-NLS-1$
driver.setUrlSyntax(driverInstance.getNamedPropertyByID("org.eclipse.datatools.connectivity.db.URL")); //$NON-NLS-1$
driver.setJdbcDriverContainer(drivers);
drivers.getJdbcDrivers().add(driver);
}
}
}
Expand Down Expand Up @@ -310,20 +310,27 @@ public JdbcSource getJdbcSource( final IConnectionProfile profile ) {
*/
@Override
public List getJdbcSources() {
if (sources == null || sourcesUpdated) {
if (this.sourcesUpdated) {
synchronized (sourcesLock) {
if (sources == null) {
final JdbcFactoryImpl factory = new JdbcFactoryImpl();
sources = factory.createJdbcSourceContainer();
final IConnectionProfile[] tempProfiles = profileManager.getProfilesByCategory("org.eclipse.datatools.connectivity.db.category"); //$NON-NLS-1$
for (final IConnectionProfile profile : tempProfiles) {
final JdbcSource source = getJdbcSource(profile);
source.setJdbcSourceContainer(sources);
sources.getJdbcSources().add(source);
}
this.sourcesUpdated = false;
final JdbcFactoryImpl factory = new JdbcFactoryImpl();
sources = factory.createJdbcSourceContainer();

final IConnectionProfile[] tempProfiles = profileManager.getProfilesByCategory("org.eclipse.datatools.connectivity.db.category"); //$NON-NLS-1$

// first time this is called the profile listener is notified and reload is called
if (this.sourcesUpdated) {
return getJdbcSources();
}

for (final IConnectionProfile profile : tempProfiles) {
final JdbcSource source = getJdbcSource(profile);
source.setJdbcSourceContainer(sources);
sources.getJdbcSources().add(source);
}
}
}

return sources.getJdbcSources();
}

Expand Down Expand Up @@ -593,8 +600,8 @@ public IStatus isValid( final JdbcSource jdbcSource ) {
*/
@Override
public void reload( final IProgressMonitor monitor ) {
shutdown();
start();
this.sourcesUpdated = true;
this.driversUpdated = true;
}

/* (non-Javadoc)
Expand Down Expand Up @@ -678,6 +685,8 @@ public void start() {
profileListener = new ProfileListener();
profileManager.addProfileListener(profileListener);
driverManager = DriverManager.getInstance();
this.sourcesUpdated = true;
this.driversUpdated = true;
}

protected void setProfileManager(ProfileManager profManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,23 @@ public String getString( final String key,
};

static JdbcPlugin INSTANCE = null;
private static JdbcManagerImpl jdbcMgr;

public static boolean DEBUG = false;

/**
* Starts the manager for the {@link JdbcDriver} instances by loading the instances from the supplied model. This method is safe
* to call more than once; the method returns whether the manager was actually started.
*
* @param jdbcModelUri the full path to the model file containing the {@link JdbcDriver} instances.
* @return true if the manager was started, or false if the manager was already started
* @throws JdbcException if there is an error loading the manager
* @see #getJdbcDriverManager()
* @return the JDBC manager (never <code>null</code>)
*/
public static JdbcManager createJdbcManager( final String name ) {
final JdbcManagerImpl mgr = new JdbcManagerImpl(name);
mgr.start();
return mgr;
public static JdbcManager getJdbcManager() {
if (JdbcPlugin.jdbcMgr == null) {
JdbcPlugin.jdbcMgr = new JdbcManagerImpl(Util.getString("jdbcManagerName")); //$NON-NLS-1$
JdbcPlugin.jdbcMgr.start();
}

return JdbcPlugin.jdbcMgr;
}

/**
Expand Down Expand Up @@ -248,4 +249,23 @@ public void start( final BundleContext context ) throws Exception {
((PluginUtilImpl)Util).initializePlatformLogger(this); // This must be called to initialize the platform logger!
}

/**
* {@inheritDoc}
*
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
JdbcManager mgr = JdbcManagerImpl.get();

if ((mgr != null) && (mgr instanceof JdbcManagerImpl)) {
((JdbcManagerImpl)mgr).shutdown();
}

if (JdbcPlugin.jdbcMgr != null) {
JdbcPlugin.jdbcMgr.shutdown();
}

super.stop(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ JdbcSource_driver_category = JDBC Driver Info
# %%% END OF OVERRIDDEN EMF GENERATED PROPERTIES %%%
# ====================================================================

jdbcManagerName = Default JDBC Manager

JdbcManagerImpl.Unable_to_create_class_loader_for_the_driver=Unable to create class loader for the driver {0}
JdbcManagerImpl.The_name_is_empty=The name is empty
JdbcManagerImpl.The_name_must_begin_with_a_letter_or_digit=The name must begin with a letter or digit
Expand Down

0 comments on commit 05e750b

Please sign in to comment.