@ -4,7 +4,6 @@ import com.fanruan.config.impl.data.ConnectionConfigProviderFactory;
import com.fr.config.remote.RemoteConfigEvent ;
import com.fr.data.driver.DriverClassNotFoundException ;
import com.fr.data.impl.Connection ;
import com.fr.data.impl.ConnectionBean ;
import com.fr.data.impl.JDBCDatabaseConnection ;
import com.fr.data.impl.JNDIDatabaseConnection ;
import com.fr.data.metric.utils.DatabaseConnectionMetricHandler ;
@ -31,6 +30,8 @@ import com.fr.stable.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter ;
import com.fr.workspace.WorkContext ;
import com.fr.workspace.server.database.DataBaseTypeOperator ;
import com.fr.workspace.server.entity.connection.BatchConnectionModifyBean ;
import com.fr.workspace.server.entity.connection.ConnectionBean ;
import com.fr.workspace.server.repository.connection.ConnectionRepository ;
import org.jetbrains.annotations.NotNull ;
@ -217,19 +218,25 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
Arrays . stream ( res ) . map ( n - > ( NameObject ) n ) . forEach ( no - > updatedMap . put ( no . getName ( ) , ( Connection ) no . getObject ( ) ) ) ;
List < String > removedConnNames = new ArrayList < > ( ) ;
List < ConnectionBean > addedOrUpdated Connections = new ArrayList < > ( ) ;
List < ConnectionBean > addConnections = new ArrayList < > ( ) ;
List < ConnectionBean > updateConnection = new ArrayList < > ( ) ;
MapCompareUtils . contrastMapEntries ( populatedConnectionsSnapshot , updatedMap , ( entryEventKind , s , connection ) - > {
switch ( entryEventKind ) {
case REMOVED :
removedConnNames . add ( s ) ;
break ;
case ADDED :
addConnections . add ( new ConnectionBean ( connection , s ) ) ;
if ( connection instanceof JDBCDatabaseConnection ) {
DatabaseConnectionMetricHandler . handleSaveConnection ( ( JDBCDatabaseConnection ) connection , null ) ;
}
break ;
case UPDATED :
addedOrUpdatedConnections . add ( new ConnectionBean ( s , StringUtils . EMPTY , connection ) ) ;
updateConnection . add ( new ConnectionBean ( connection , s ) ) ;
if ( connection instanceof JDBCDatabaseConnection ) {
DatabaseConnectionMetricHandler . handleSaveConnection ( ( JDBCDatabaseConnection ) connection , null ) ;
}
break ;
default :
break ;
}
@ -261,9 +268,12 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
}
} ) ;
this . validateDatabaseType ( addedOrUpdatedConnections ) ;
this . validateConnections ( addedOrUpdatedConnections ) ;
this . alterConnections ( removedConnNames , addedOrUpdatedConnections ) ;
List < ConnectionBean > validateBeans = new ArrayList < > ( ) ;
validateBeans . addAll ( addConnections ) ;
validateBeans . addAll ( updateConnection ) ;
this . validateDatabaseType ( validateBeans ) ;
this . validateConnections ( validateBeans ) ;
this . alterConnections ( new BatchConnectionModifyBean ( addConnections , removedConnNames , updateConnection ) ) ;
}
/ * *
@ -326,15 +336,10 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
}
private void alterConnections ( List < String > removedConnNames , List < ConnectionBean > addedOrUpdatedConnections ) {
private void alterConnections ( BatchConnectionModifyBean bean ) {
try {
/// 数据连接要改为单个修改的形式(考虑配合newUI)
ConnectionRepository . getInstance ( ) . add ( new com . fr . workspace . server . entity . connection . ConnectionBean ( addedOrUpdatedConnections . get ( 0 ) . getConnection ( ) , "FRDemo" ) ) ;
//WorkContext.getCurrent().get(ConnectionOperator.class, exceptionInfo -> saveByOldWay(removedConnNames, addedOrUpdatedConnections))
// .saveConnection(removedConnNames, addedOrUpdatedConnections);
ConnectionRepository . getInstance ( ) . save ( bean ) ;
// hades:远程环境时,由于时直接RPC调用远程修改,因此设计器本地配置需要失效
if ( ! WorkContext . getCurrent ( ) . isLocal ( ) ) {
EventDispatcher . fire ( RemoteConfigEvent . EDIT , "ConnectionConfig" ) ;