|
|
|
@ -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; |
|
|
|
@ -20,10 +21,9 @@ import com.fr.stable.ArrayUtils;
|
|
|
|
|
import com.fr.stable.Nameable; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.core.PropertyChangeAdapter; |
|
|
|
|
import com.fr.transaction.Configurations; |
|
|
|
|
import com.fr.transaction.WorkerFacade; |
|
|
|
|
|
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.HashMap; |
|
|
|
@ -159,7 +159,7 @@ 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<>(); |
|
|
|
@ -180,14 +180,28 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 之前丢有可能是因为没有放事务里吧
|
|
|
|
|
Configurations.modify(new WorkerFacade(ConnectionConfig.class) { |
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
removedConnNames.forEach(n -> ConnectionConfig.getInstance().removeConnection(n)); |
|
|
|
|
addedOrUpdatedConnections.forEach((name, conn) -> ConnectionConfig.getInstance().addConnection(name, conn)); |
|
|
|
|
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 |
|
|
|
|