Author: massi Date: Wed Jul 2 16:02:10 2014 New Revision: 1607406 URL: http://svn.apache.org/r1607406 Log: Fixed SYNCOPE-523
Added: syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/DriverLoader.java Modified: syncope/trunk/installer/pom.xml syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/PersistenceValidator.java syncope/trunk/installer/src/main/resources/izpack/install.xml Modified: syncope/trunk/installer/pom.xml URL: http://svn.apache.org/viewvc/syncope/trunk/installer/pom.xml?rev=1607406&r1=1607405&r2=1607406&view=diff ============================================================================== --- syncope/trunk/installer/pom.xml (original) +++ syncope/trunk/installer/pom.xml Wed Jul 2 16:02:10 2014 @@ -69,17 +69,6 @@ under the License. <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> - - <dependency> - <groupId>org.postgresql</groupId> - <artifactId>postgresql</artifactId> - <version>9.3-1101-jdbc41</version> - </dependency> - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>5.1.31</version> - </dependency> <dependency> <groupId>commons-codec</groupId> Added: syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/DriverLoader.java URL: http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/DriverLoader.java?rev=1607406&view=auto ============================================================================== --- syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/DriverLoader.java (added) +++ syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/DriverLoader.java Wed Jul 2 16:02:10 2014 @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.installer.utilities; + +import java.net.MalformedURLException; +import org.apache.syncope.installer.enums.DBs; + +import java.net.URL; +import java.net.URLClassLoader; +import java.sql.Driver; + +public class DriverLoader extends URLClassLoader { + + private final static String POSTGRES_JAR = "http://jdbc.postgresql.org/download/postgresql-9.3-1101.jdbc41.jar"; + + private final static String MYSQL_JAR + = "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar"; + + private static final String POSTGRES_CLASS_DRIVER = "org.postgresql.Driver"; + + private static final String MYSQL_CLASS_DRIVER = "com.mysql.jdbc.Driver"; + + private DriverLoader(final URL[] urls) { + super(urls); + addURL(urls[0]); + } + + private static DriverLoader driverLoader; + + public static Driver load(final DBs selectedDB) { + Driver driver = null; + switch (selectedDB) { + case POSTGRES: + driver = downloadDriver(POSTGRES_JAR, POSTGRES_CLASS_DRIVER); + break; + case MYSQL: + driver = downloadDriver(MYSQL_JAR, MYSQL_CLASS_DRIVER); + break; + case SQLSERVER: + break; + case ORACLE: + break; + default: + break; + } + return driver; + } + + private static Driver downloadDriver(final String driverUrl, final String driverClassName) { + Driver driver = null; + try { + final URL[] url = {new URL(driverUrl)}; + driverLoader = new DriverLoader(url); + driver = (Driver) driverLoader.loadClass(driverClassName).newInstance(); + } catch (ClassNotFoundException e) { + } catch (InstantiationException ex) { + } catch (IllegalAccessException ex) { + } catch (MalformedURLException ex) { + } + + return driver; + } +} Modified: syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/PersistenceValidator.java URL: http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/PersistenceValidator.java?rev=1607406&r1=1607405&r2=1607406&view=diff ============================================================================== --- syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/PersistenceValidator.java (original) +++ syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/PersistenceValidator.java Wed Jul 2 16:02:10 2014 @@ -19,16 +19,14 @@ package org.apache.syncope.installer.validators; import com.izforge.izpack.api.data.InstallData; -import java.sql.DriverManager; +import java.sql.Driver; import java.sql.SQLException; +import java.util.Properties; import org.apache.syncope.installer.enums.DBs; +import org.apache.syncope.installer.utilities.DriverLoader; public class PersistenceValidator extends AbstractValidator { - private static final String POSTGRES_CLASS_DRIVER = "org.postgresql.Driver"; - - private static final String MYSQL_CLASS_DRIVER = "com.mysql.jdbc.Driver"; - private String persistenceUrl; private String persistenceDbuser; @@ -70,9 +68,9 @@ public class PersistenceValidator extend switch (selectedDB) { case POSTGRES: - return checkConnection(POSTGRES_CLASS_DRIVER); + return checkConnection(selectedDB); case MYSQL: - return checkConnection(MYSQL_CLASS_DRIVER); + return checkConnection(selectedDB); case SQLSERVER: warning = new StringBuilder("Remember to check your SqlServer db connection"); return Status.WARNING; @@ -85,17 +83,18 @@ public class PersistenceValidator extend } } - private Status checkConnection(final String driverClass) { + private Status checkConnection(final DBs selectedDb) { + try { - Class.forName(driverClass); - DriverManager.getConnection(persistenceUrl, persistenceDbuser, persistenceDbPassword); + final Driver driver = DriverLoader.load(selectedDb); + final Properties props = new Properties(); + props.put("user", persistenceDbuser); + props.put("password", persistenceDbPassword); + driver.connect(persistenceUrl, props); return Status.OK; } catch (SQLException ex) { error = new StringBuilder("Db connection error: please check your insert data"); return Status.ERROR; - } catch (ClassNotFoundException ex) { - error = new StringBuilder("General error please contact Apache Syncope developers!"); - return Status.ERROR; } } Modified: syncope/trunk/installer/src/main/resources/izpack/install.xml URL: http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/resources/izpack/install.xml?rev=1607406&r1=1607405&r2=1607406&view=diff ============================================================================== --- syncope/trunk/installer/src/main/resources/izpack/install.xml (original) +++ syncope/trunk/installer/src/main/resources/izpack/install.xml Wed Jul 2 16:02:10 2014 @@ -133,8 +133,6 @@ under the License. </resources> <jar src="../syncope-installer-1.2.0-SNAPSHOT.jar" stage="install"/> - <jar src="lib/postgresql-9.3-1101-jdbc41.jar"/> - <jar src="lib/mysql-connector-java-5.1.31.jar"/> <jar src="lib/commons-logging-1.1.3.jar"/> <jar src="lib/commons-codec-1.9.jar"/> <jar src="lib/commons-io-2.4.jar"/>