[jbosstools-commits] JBoss Tools SVN: r22838 - in trunk/hibernatetools/plugins: org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Jun 16 14:27:24 EDT 2010


Author: vyemialyanchyk
Date: 2010-06-16 14:27:24 -0400 (Wed, 16 Jun 2010)
New Revision: 22838

Modified:
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationJavaClasspathTab.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
Log:
https://jira.jboss.org/browse/JBIDE-6103 - fix -> refactoring: get rid of rejectRefreshProfile, use DriverManager to get correct driver properties instead of ConnectionProfile

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java	2010-06-16 14:43:09 UTC (rev 22837)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java	2010-06-16 18:27:24 UTC (rev 22838)
@@ -42,6 +42,7 @@
 import org.dom4j.io.DOMWriter;
 import org.eclipse.datatools.connectivity.IConnectionProfile;
 import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.datatools.connectivity.drivers.DriverInstance;
 import org.eclipse.osgi.util.NLS;
 import org.hibernate.HibernateException;
 import org.hibernate.MappingException;
@@ -64,13 +65,11 @@
 
 	private ConsoleConfigurationPreferences prefs;
 	private Map<String, FakeDelegatingDriver> fakeDrivers;
-	private boolean rejectProfileRefresh;
 
 	public ConfigurationFactory(ConsoleConfigurationPreferences prefs,
-			Map<String, FakeDelegatingDriver> fakeDrivers, boolean rejectProfileRefresh) {
+			Map<String, FakeDelegatingDriver> fakeDrivers) {
 		this.prefs = prefs;
 		this.fakeDrivers = fakeDrivers;
-		this.rejectProfileRefresh = rejectProfileRefresh;
 	}
 
 	public ConsoleConfigurationPreferences getPreferences() {
@@ -375,36 +374,31 @@
 		IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(
 				connectionProfile);
 		if (profile != null) {
-			if (!rejectProfileRefresh) {
-				ConnectionProfileUtil.refreshProfile(profile);
-			}
-			//
+			DriverInstance driverInstance = 
+				ConnectionProfileUtil.getDriverDefinition(prefs.getConnectionProfileName());
+			final Properties cpProperties = profile.getProperties(profile.getProviderId());
 			final Properties invokeProperties = localCfg.getProperties();
 			// set this property to null!
 			invokeProperties.remove(Environment.DATASOURCE);
 			localCfg.setProperties(invokeProperties);
-			Properties cpProperties = profile.getProperties(profile.getProviderId());
 			// seems we should not setup dialect here
 			// String dialect =
 			// "org.hibernate.dialect.HSQLDialect";//cpProperties.getProperty("org.eclipse.datatools.connectivity.db.driverClass");
 			// invoke.setProperty(Environment.DIALECT, dialect);
-			String driver = cpProperties
-					.getProperty("org.eclipse.datatools.connectivity.db.driverClass"); //$NON-NLS-1$
-			localCfg.setProperty(Environment.DRIVER, driver);
+			String driverClass = driverInstance.getProperty("org.eclipse.datatools.connectivity.db.driverClass"); //$NON-NLS-1$
+			localCfg.setProperty(Environment.DRIVER, driverClass);
 			// TODO:
 			@SuppressWarnings("unused")
-			String driverJarPath = cpProperties.getProperty("jarList"); //$NON-NLS-1$
+			String driverJarPath = driverInstance.getJarList();
 			String url = cpProperties.getProperty("org.eclipse.datatools.connectivity.db.URL"); //$NON-NLS-1$
 			// url += "/";// +
 			// cpProperties.getProperty("org.eclipse.datatools.connectivity.db.databaseName");
 			localCfg.setProperty(Environment.URL, url);
-			String user = cpProperties
-					.getProperty("org.eclipse.datatools.connectivity.db.username"); //$NON-NLS-1$
+			String user = cpProperties.getProperty("org.eclipse.datatools.connectivity.db.username"); //$NON-NLS-1$
 			if (null != user && user.length() > 0) {
 				localCfg.setProperty(Environment.USER, user);
 			}
-			String pass = cpProperties
-					.getProperty("org.eclipse.datatools.connectivity.db.password"); //$NON-NLS-1$
+			String pass = cpProperties.getProperty("org.eclipse.datatools.connectivity.db.password"); //$NON-NLS-1$
 			if (null != pass && pass.length() > 0) {
 				localCfg.setProperty(Environment.PASS, pass);
 			}
@@ -454,4 +448,5 @@
 			}
 		}
 	}
+
 }

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java	2010-06-16 14:43:09 UTC (rev 22837)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java	2010-06-16 18:27:24 UTC (rev 22838)
@@ -21,17 +21,47 @@
  */
 package org.hibernate.console;
 
+import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
 import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.datatools.connectivity.drivers.DriverInstance;
 
+/**
+ * @author Vitali Yemialyanchyk
+ */
 public class ConnectionProfileUtil {
-	
-	public static void refreshProfile(IConnectionProfile profile) {
-		// refresh profile (refresh jpa connection):
-		// get fresh information about current db structure and update error markers  
-		if (profile.getConnectionState() == IConnectionProfile.CONNECTED_STATE){
-			profile.disconnect(null);
+
+	public static String getDriverDefinitionId(IConnectionProfile profile) {
+		if (profile == null) {
+			return null;
 		}
-		profile.connect(null);
+		return profile.getBaseProperties().getProperty(
+				ConnectionProfileConstants.PROP_DRIVER_DEFINITION_ID);
 	}
-	
+
+	public static DriverInstance getDriverDefinition(String connectionProfile) {
+		if (connectionProfile == null) {
+			return null;
+		}
+		IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(
+				connectionProfile);
+		if (profile == null) {
+			return null;
+		}
+		String driverID = getDriverDefinitionId(profile);
+		return org.eclipse.datatools.connectivity.drivers.DriverManager.getInstance()
+				.getDriverInstanceByID(driverID);
+	}
+
+	/*
+	 * try get a path to the sql driver jar file from DTP connection profile
+	 */
+	public static String getConnectionProfileDriverURL(String connectionProfile) {
+		DriverInstance di = getDriverDefinition(connectionProfile);
+		if (di == null) {
+			return null;
+		}
+		return di.getJarList();
+	}
+
 }

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java	2010-06-16 14:43:09 UTC (rev 22837)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java	2010-06-16 18:27:24 UTC (rev 22838)
@@ -35,10 +35,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 
-import org.eclipse.datatools.connectivity.IConnectionProfile;
-import org.eclipse.datatools.connectivity.ProfileManager;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.cfg.Configuration;
@@ -60,9 +57,6 @@
 	/* TODO: move this out to the actual users of the configuraiton/sf ? */
 	private Configuration configuration;
 	private SessionFactory sessionFactory;
-	
-	// internal flag to prohibit long time profile refresh
-	private boolean rejectProfileRefresh = false;
 
 	/** Unique name for this configuration */
 	public String getName() {
@@ -125,57 +119,51 @@
 	}
 
 	/*
-	 * try get a path to the sql driver jar file from DTP connection profile
-	 */
-	protected String getConnectionProfileDriverURL() {
-		String connectionProfile = prefs.getConnectionProfileName();
-		if (connectionProfile == null) {
-			return null;
-		}
-		IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(connectionProfile);
-		if (profile == null) {
-			return null;
-		}
-		if (!rejectProfileRefresh) {
-			ConnectionProfileUtil.refreshProfile(profile);
-		}
-		//
-		Properties cpProperties = profile.getProperties(profile.getProviderId());
-		String driverJarPath = cpProperties.getProperty("jarList"); //$NON-NLS-1$
-		return driverJarPath;
-	}
-
-	/*
 	 * get custom classpath URLs 
 	 */
 	protected URL[] getCustomClassPathURLs() {
 		URL[] customClassPathURLsTmp = prefs.getCustomClassPathURLS();
 		URL[] customClassPathURLs = null;
-		String driverURL = getConnectionProfileDriverURL();
-		URL url = null;
+		String driverURL = ConnectionProfileUtil.getConnectionProfileDriverURL(prefs.getConnectionProfileName());
+		URL[] urls = null;
 		if (driverURL != null) {
-			try {
-				url = new URL("file:/" + driverURL); //$NON-NLS-1$
-			} catch (MalformedURLException e) {
-				// just ignore
+			String[] driverURLParts = driverURL.split(";"); //$NON-NLS-1$
+			urls = new URL[driverURLParts.length];
+			for (int i = 0; i < driverURLParts.length; i++) {
+				try {
+					urls[i] = new URL("file:/" + driverURLParts[i].trim()); //$NON-NLS-1$
+				} catch (MalformedURLException e) {
+					urls[i] = null; 
+				}
 			}
 		}
 		// should DTP connection profile driver jar file be inserted
-		boolean insertFlag = ( url != null );
-		if (insertFlag) {
-			for (int i = 0; i < customClassPathURLsTmp.length; i++) {
-				if (url.equals(customClassPathURLsTmp[i])) {
-					insertFlag = false;
-					break;
+		int insertItems = ( urls != null ) ? urls.length : 0;
+		if (insertItems > 0) {
+			insertItems = 0;
+			for (int i = 0; i < urls.length; i++) {
+				if (urls[i] == null) {
+					continue;
 				}
+				int j = 0;
+				for (; j < customClassPathURLsTmp.length; j++) {
+					if (customClassPathURLsTmp[j].equals(urls[i])) {
+						break;
+					}
+				}
+				if (j == customClassPathURLsTmp.length) {
+					urls[insertItems++] = urls[i];
+				}
 			}
 		}
-		if (insertFlag) {
-			customClassPathURLs = new URL[customClassPathURLsTmp.length + 1];
+		if (insertItems > 0) {
+			customClassPathURLs = new URL[customClassPathURLsTmp.length + insertItems];
 	        System.arraycopy(customClassPathURLsTmp, 0, 
 	        		customClassPathURLs, 0, customClassPathURLsTmp.length);
 	        // insert DTP connection profile driver jar file URL after the default classpath entries
-			customClassPathURLs[customClassPathURLsTmp.length] = url;
+			for (int i = 0; i < insertItems; i++) {
+				customClassPathURLs[customClassPathURLsTmp.length + i] = urls[i];
+			}
 		} else {
 			customClassPathURLs = customClassPathURLsTmp;
 		}
@@ -227,7 +215,7 @@
 		executionContext = new DefaultExecutionContext(getName(), classLoader);
 		Configuration result = (Configuration)execute(new Command() {
 			public Object execute() {
-				ConfigurationFactory csf = new ConfigurationFactory(prefs, fakeDrivers, rejectProfileRefresh);
+				ConfigurationFactory csf = new ConfigurationFactory(prefs, fakeDrivers);
 				return csf.createConfiguration(cfg, includeMappings);
 			}
 		});
@@ -235,7 +223,6 @@
 	}
 
 	protected ClassLoader getParentClassLoader() {
-		//Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
 		ClassLoader cl = Thread.currentThread().getContextClassLoader();
 		//ClassLoader cl = ConsoleConfiguration.class.getClassLoader();
 		return cl;
@@ -410,13 +397,4 @@
 			}
 		});
 	}
-
-	public boolean isRejectProfileRefresh() {
-		return rejectProfileRefresh;
-	}
-
-	public void setRejectProfileRefresh(boolean rejectProfileRefresh) {
-		this.rejectProfileRefresh = rejectProfileRefresh;
-	}
-
 }
\ No newline at end of file

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationJavaClasspathTab.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationJavaClasspathTab.java	2010-06-16 14:43:09 UTC (rev 22837)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationJavaClasspathTab.java	2010-06-16 18:27:24 UTC (rev 22838)
@@ -63,9 +63,6 @@
 		if (resUserClasses && resExistArchive) {
 			try {
 				ConsoleConfiguration ccTest = new ConsoleConfiguration(new EclipseLaunchConsoleConfigurationPreferences(launchConfig));
-				// should not try to connect to db - refresh profile try to create db connection
-				// so just reject this
-				ccTest.setRejectProfileRefresh(true);
 				ccTest.buildWith(null, false);
 			} catch (Exception ex) {
 				resUserClasses = false;



More information about the jbosstools-commits mailing list