cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/3] cayenne git commit: CAY-2423
Date Wed, 11 Apr 2018 11:45:39 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 6bdef0c5b -> 9dce81b8b


CAY-2423

Added checks for configuration in connection to database: additional validation for username
and password; checks for possibility connect to database; added possibility to add empty name
and password; save configuration with adapter set as "Automatic".


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/123c2fbe
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/123c2fbe
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/123c2fbe

Branch: refs/heads/master
Commit: 123c2fbeba451ea1fdd1d0ed88282e3eac9e38be
Parents: 67aad8a
Author: kkomyak <const1993@gmail.com>
Authored: Wed Apr 4 12:06:12 2018 +0300
Committer: kkomyak <const1993@gmail.com>
Committed: Mon Apr 9 11:47:24 2018 +0300

----------------------------------------------------------------------
 .../modeler/action/GetDbConnectionAction.java   | 17 +++++----
 .../modeler/dialog/db/DataSourceWizard.java     |  2 +
 .../cayenne/modeler/pref/DBConnectionInfo.java  | 39 ++++++++++++--------
 3 files changed, 35 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/123c2fbe/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GetDbConnectionAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GetDbConnectionAction.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GetDbConnectionAction.java
index 17433b0..8328861 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GetDbConnectionAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/GetDbConnectionAction.java
@@ -42,7 +42,7 @@ public class GetDbConnectionAction extends DBWizardAction<DbActionOptionsDialog>
     private static final String ACTION_NAME = "Configure Connection";
     private static final String ICON_NAME = "icon-dbi-config.png";
 
-    public GetDbConnectionAction(Application application) {
+    public GetDbConnectionAction(final Application application) {
         super(ACTION_NAME, application);
     }
 
@@ -51,22 +51,25 @@ public class GetDbConnectionAction extends DBWizardAction<DbActionOptionsDialog>
     }
 
     @Override
-    protected DbActionOptionsDialog createDialog(Collection<String> catalogs, Collection<String>
schemas,
-                                                 String currentCatalog, String currentSchema,
int command) {
+    protected DbActionOptionsDialog createDialog(final Collection<String> catalogs,
final Collection<String> schemas,
+                                                 final String currentCatalog, final String
currentSchema, final int command) {
         // NOOP
         return null;
     }
 
     @Override
-    public void performAction(ActionEvent e) {
+    public void performAction(final ActionEvent e) {
         final DataSourceWizard connectWizard = dataSourceWizardDialog(DIALOG_TITLE);
-        if(connectWizard == null) {
+        if (connectWizard == null) {
             return;
         }
 
-        DataMapDefaults dataMapDefaults = getProjectController().
+        final DataMapDefaults dataMapDefaults = getProjectController().
                 getDataMapPreferences(getProjectController().getCurrentDataMap());
-        dataMapDefaults.getCurrentPreference().put(DB_ADAPTER_PROPERTY, connectWizard.getConnectionInfo().getDbAdapter());
+
+        if (connectWizard.getConnectionInfo().getDbAdapter() != null) {
+            dataMapDefaults.getCurrentPreference().put(DB_ADAPTER_PROPERTY, connectWizard.getConnectionInfo().getDbAdapter());
+        }
         dataMapDefaults.getCurrentPreference().put(URL_PROPERTY, connectWizard.getConnectionInfo().getUrl());
         dataMapDefaults.getCurrentPreference().put(USER_NAME_PROPERTY, connectWizard.getConnectionInfo().getUserName());
         dataMapDefaults.getCurrentPreference().put(PASSWORD_PROPERTY, connectWizard.getConnectionInfo().getPassword());

http://git-wip-us.apache.org/repos/asf/cayenne/blob/123c2fbe/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
index 0ecb849..6294041 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
@@ -214,6 +214,8 @@ public class DataSourceWizard extends CayenneController {
 			this.dataSource = info.makeDataSource(classLoader);
 			try (Connection connection = dataSource.getConnection()) {
 			} catch (SQLException ignore) {
+				reportError("Connection Error", ignore);
+				return;
 			}
 		} catch (Throwable th) {
 			reportError("Connection Error", th);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/123c2fbe/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
index 28ccc97..4295254 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
@@ -36,8 +36,11 @@ import org.apache.cayenne.modeler.ClassLoadingService;
 import org.apache.cayenne.pref.CayennePreference;
 import org.apache.cayenne.util.Util;
 
+import static org.apache.commons.lang3.StringUtils.isBlank;
+
 public class DBConnectionInfo extends CayennePreference {
 
+	private static final String EMPTY_STRING = "";
 	public static final String DB_ADAPTER_PROPERTY = "dbAdapter";
 	public static final String JDBC_DRIVER_PROPERTY = "jdbcDriver";
 	public static final String PASSWORD_PROPERTY = "password";
@@ -62,7 +65,7 @@ public class DBConnectionInfo extends CayennePreference {
 		setCurrentPreference(dbConnectionInfoPreferences);
 	};
 
-	public DBConnectionInfo(String nameNode, boolean initFromPreferences) {
+	public DBConnectionInfo(final String nameNode, final boolean initFromPreferences) {
 		this();
 		setNodeName(nameNode);
 		if (initFromPreferences) {
@@ -79,7 +82,7 @@ public class DBConnectionInfo extends CayennePreference {
 	}
 
 	@Override
-	public void setObject(CayennePreference object) {
+	public void setObject(final CayennePreference object) {
 		if (object instanceof DBConnectionInfo) {
 			setUrl(((DBConnectionInfo) object).getUrl());
 			setUserName(((DBConnectionInfo) object).getUserName());
@@ -125,7 +128,7 @@ public class DBConnectionInfo extends CayennePreference {
 		return nodeName;
 	}
 
-	public void setNodeName(String nodeName) {
+	public void setNodeName(final String nodeName) {
 		this.nodeName = nodeName;
 	}
 
@@ -133,7 +136,7 @@ public class DBConnectionInfo extends CayennePreference {
 		return dbAdapter;
 	}
 
-	public void setDbAdapter(String dbAdapter) {
+	public void setDbAdapter(final String dbAdapter) {
 		this.dbAdapter = dbAdapter;
 	}
 
@@ -141,15 +144,15 @@ public class DBConnectionInfo extends CayennePreference {
 		return jdbcDriver;
 	}
 
-	public void setJdbcDriver(String jdbcDriver) {
+	public void setJdbcDriver(final String jdbcDriver) {
 		this.jdbcDriver = jdbcDriver;
 	}
 
 	public String getPassword() {
-		return password;
+		return password == null ? EMPTY_STRING : password;
 	}
 
-	public void setPassword(String password) {
+	public void setPassword(final String password) {
 		this.password = password;
 	}
 
@@ -157,15 +160,15 @@ public class DBConnectionInfo extends CayennePreference {
 		return url;
 	}
 
-	public void setUrl(String url) {
+	public void setUrl(final String url) {
 		this.url = url;
 	}
 
 	public String getUserName() {
-		return userName;
+		return userName == null ? EMPTY_STRING : userName;
 	}
 
-	public void setUserName(String userName) {
+	public void setUserName(final String userName) {
 		this.userName = userName;
 	}
 
@@ -173,14 +176,14 @@ public class DBConnectionInfo extends CayennePreference {
 		return dbConnectionInfoPreferences;
 	}
 
-	public void setDbConnectionInfoPreferences(Preferences dbConnectionInfoPreferences) {
+	public void setDbConnectionInfoPreferences(final Preferences dbConnectionInfoPreferences)
{
 		this.dbConnectionInfoPreferences = dbConnectionInfoPreferences;
 	}
 
 	/**
 	 * Creates a DbAdapter based on configured values.
 	 */
-	public DbAdapter makeAdapter(ClassLoadingService classLoader) throws Exception {
+	public DbAdapter makeAdapter(final ClassLoadingService classLoader) throws Exception {
 		String adapterClassName = getDbAdapter();
 		Application appInstance = Application.getInstance();
 
@@ -203,7 +206,7 @@ public class DBConnectionInfo extends CayennePreference {
 	 * Returned DataSource is not pooling its connections. It can be wrapped in
 	 * PoolManager if pooling is needed.
 	 */
-	public DataSource makeDataSource(ClassLoadingService classLoader) throws SQLException {
+	public DataSource makeDataSource(final ClassLoadingService classLoader) throws SQLException
{
 
 		// validate...
 		if (getJdbcDriver() == null) {
@@ -214,6 +217,10 @@ public class DBConnectionInfo extends CayennePreference {
 			throw new SQLException("No DB URL set.");
 		}
 
+		if (!isBlank(getPassword()) && isBlank(getUserName())) {
+			throw new SQLException("No username when password is set.");
+		}
+
 		// load driver...
 		Driver driver;
 
@@ -230,7 +237,7 @@ public class DBConnectionInfo extends CayennePreference {
 	/**
 	 * Updates another DBConnectionInfo with this object's values.
 	 */
-	public boolean copyTo(DBConnectionInfo dataSourceInfo) {
+	public boolean copyTo(final DBConnectionInfo dataSourceInfo) {
 		boolean updated = false;
 
 		if (!Util.nullSafeEquals(dataSourceInfo.getUrl(), getUrl())) {
@@ -269,7 +276,7 @@ public class DBConnectionInfo extends CayennePreference {
 	 * an adapter update here. </i>
 	 * </p>
 	 */
-	public boolean copyTo(DataSourceInfo dataSourceInfo) {
+	public boolean copyTo(final DataSourceInfo dataSourceInfo) {
 		boolean updated = false;
 
 		if (!Util.nullSafeEquals(dataSourceInfo.getDataSourceUrl(), getUrl())) {
@@ -295,7 +302,7 @@ public class DBConnectionInfo extends CayennePreference {
 		return updated;
 	}
 
-	public boolean copyFrom(DataSourceInfo dataSourceInfo) {
+	public boolean copyFrom(final DataSourceInfo dataSourceInfo) {
 		boolean updated = false;
 
 		if (!Util.nullSafeEquals(dataSourceInfo.getDataSourceUrl(), getUrl())) {


Mime
View raw message