|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.fr.design.data.datapane.connect; |
|
|
|
|
|
|
|
|
|
import com.fr.data.core.db.JDBCSecurityChecker; |
|
|
|
|
import com.fr.data.impl.Connection; |
|
|
|
|
import com.fr.data.impl.JDBCDatabaseConnection; |
|
|
|
|
import com.fr.data.impl.JNDIDatabaseConnection; |
|
|
|
@ -22,6 +23,7 @@ import com.fr.stable.StringUtils;
|
|
|
|
|
import com.fr.stable.core.PropertyChangeAdapter; |
|
|
|
|
|
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.HashMap; |
|
|
|
@ -157,24 +159,49 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
|
|
|
|
|
/** |
|
|
|
|
* Update. |
|
|
|
|
*/ |
|
|
|
|
public void update(ConnectionConfig connectionConfig) { |
|
|
|
|
public void update(ConnectionConfig connectionConfig) throws Exception { |
|
|
|
|
// Nameable[]居然不能强转成NameObject[],一定要这么写...
|
|
|
|
|
Nameable[] res = this.update(); |
|
|
|
|
Map<String, Connection> updatedMap = new LinkedHashMap<>(); |
|
|
|
|
Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject())); |
|
|
|
|
|
|
|
|
|
List<String> removedConnNames = new ArrayList<>(); |
|
|
|
|
Map<String, Connection> addedOrUpdatedConnections = new LinkedHashMap<>(); |
|
|
|
|
MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { |
|
|
|
|
switch (entryEventKind) { |
|
|
|
|
case REMOVED: |
|
|
|
|
connectionConfig.removeConnection(s); |
|
|
|
|
removedConnNames.add(s); |
|
|
|
|
break; |
|
|
|
|
case ADDED: |
|
|
|
|
case UPDATED: |
|
|
|
|
connectionConfig.addConnection(s, connection); |
|
|
|
|
addedOrUpdatedConnections.put(s, connection); |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.checkSecurity(addedOrUpdatedConnections); |
|
|
|
|
alterConnections(removedConnNames, addedOrUpdatedConnections); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void alterConnections(List<String> removedConnNames, Map<String, Connection> addedOrUpdatedConnections) { |
|
|
|
|
removedConnNames.forEach(n -> ConnectionConfig.getInstance().removeConnection(n)); |
|
|
|
|
addedOrUpdatedConnections.forEach((name, conn) -> ConnectionConfig.getInstance().addConnection(name, conn)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkSecurity(Map<String, Connection> addedOrUpdatedConnections) throws Exception { |
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, Connection> entry : addedOrUpdatedConnections.entrySet()) { |
|
|
|
|
Connection connection = entry.getValue(); |
|
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
|
try { |
|
|
|
|
JDBCSecurityChecker.checkURL(((JDBCDatabaseConnection) connection).getURL()); |
|
|
|
|
JDBCSecurityChecker.checkValidationQuery(((JDBCDatabaseConnection) connection).getDbcpAttr().getValidationQuery()); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", entry.getKey()) + ", " + e.getMessage(), e.getCause()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|