|
|
@ -3,12 +3,11 @@ package com.fr.design.data.datapane.connect; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigWriterFactory; |
|
|
|
import com.fanruan.config.impl.data.ConnectionConfigWriterFactory; |
|
|
|
import com.fr.config.remote.RemoteConfigEvent; |
|
|
|
import com.fr.config.remote.RemoteConfigEvent; |
|
|
|
import com.fr.data.driver.DriverClassNotFoundException; |
|
|
|
|
|
|
|
import com.fr.data.impl.Connection; |
|
|
|
import com.fr.data.impl.Connection; |
|
|
|
import com.fr.data.impl.JDBCDatabaseConnection; |
|
|
|
import com.fr.data.impl.JDBCDatabaseConnection; |
|
|
|
import com.fr.data.impl.JNDIDatabaseConnection; |
|
|
|
import com.fr.data.impl.JNDIDatabaseConnection; |
|
|
|
import com.fr.data.metric.utils.DatabaseConnectionMetricHandler; |
|
|
|
import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean; |
|
|
|
import com.fr.data.operator.DataOperator; |
|
|
|
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory; |
|
|
|
import com.fr.design.ExtraDesignClassManager; |
|
|
|
import com.fr.design.ExtraDesignClassManager; |
|
|
|
import com.fr.design.data.MapCompareUtils; |
|
|
|
import com.fr.design.data.MapCompareUtils; |
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
@ -219,28 +218,26 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject())); |
|
|
|
Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject())); |
|
|
|
|
|
|
|
|
|
|
|
List<String> removedConnNames = new ArrayList<>(); |
|
|
|
List<String> removedConnNames = new ArrayList<>(); |
|
|
|
List<ConnectionBean> addConnections = new ArrayList<>(); |
|
|
|
List<ConnectionInfoBean> addConnections = new ArrayList<>(); |
|
|
|
List<ConnectionBean> updateConnection = new ArrayList<>(); |
|
|
|
List<ConnectionInfoBean> updateConnection = new ArrayList<>(); |
|
|
|
MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { |
|
|
|
MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { |
|
|
|
|
|
|
|
try { |
|
|
|
switch (entryEventKind) { |
|
|
|
switch (entryEventKind) { |
|
|
|
case REMOVED: |
|
|
|
case REMOVED: |
|
|
|
removedConnNames.add(s); |
|
|
|
removedConnNames.add(s); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ADDED: |
|
|
|
case ADDED: |
|
|
|
addConnections.add(new ConnectionBean(connection, s)); |
|
|
|
addConnections.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); |
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
|
|
|
|
DatabaseConnectionMetricHandler.handleSaveConnection((JDBCDatabaseConnection) connection, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case UPDATED: |
|
|
|
case UPDATED: |
|
|
|
updateConnection.add(new ConnectionBean(connection, s)); |
|
|
|
updateConnection.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); |
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
|
|
|
|
DatabaseConnectionMetricHandler.handleSaveConnection((JDBCDatabaseConnection) connection, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
}, new MapCompareUtils.UpdateRule<String, Connection>() { |
|
|
|
}, new MapCompareUtils.UpdateRule<String, Connection>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean needUpdate(Connection origin, Connection connection) { |
|
|
|
public boolean needUpdate(Connection origin, Connection connection) { |
|
|
@ -269,23 +266,22 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
List<ConnectionBean> validateBeans = new ArrayList<>(); |
|
|
|
List<ConnectionInfoBean> validateBeans = new ArrayList<>(); |
|
|
|
validateBeans.addAll(addConnections); |
|
|
|
validateBeans.addAll(addConnections); |
|
|
|
validateBeans.addAll(updateConnection); |
|
|
|
validateBeans.addAll(updateConnection); |
|
|
|
this.validateDatabaseType(validateBeans); |
|
|
|
this.validateDatabaseType(validateBeans); |
|
|
|
this.validateConnections(validateBeans); |
|
|
|
this.alterConnections(addConnections, removedConnNames, updateConnection); |
|
|
|
this.alterConnections(new BatchConnectionModifyBean(addConnections, removedConnNames, updateConnection)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 校验是否支持所有新增和修改数据连接的数据库类型 |
|
|
|
* 校验是否支持所有新增和修改数据连接的数据库类型 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void validateDatabaseType(@NotNull List<ConnectionBean> addedOrUpdatedConnections) { |
|
|
|
public void validateDatabaseType(@NotNull List<ConnectionInfoBean> addedOrUpdatedConnections) throws Exception { |
|
|
|
Set<String> notSupportedConnections = new HashSet<>(); |
|
|
|
Set<String> notSupportedConnections = new HashSet<>(); |
|
|
|
if (!addedOrUpdatedConnections.isEmpty()) { |
|
|
|
if (!addedOrUpdatedConnections.isEmpty()) { |
|
|
|
for (ConnectionBean bean : addedOrUpdatedConnections) { |
|
|
|
for (ConnectionInfoBean bean : addedOrUpdatedConnections) { |
|
|
|
Connection connection = bean.getConnection(); |
|
|
|
Connection connection = ConnectionProcessorFactory.createConnection(bean); |
|
|
|
// 仅校验jdbc连接,其他插件数据连接不进行校验
|
|
|
|
// 仅校验jdbc连接,其他插件数据连接不进行校验;
|
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
DBTypes dataBaseTypePoint = DataBaseTypePointManager.getInstance().getDataBaseTypePoint(connection.getDriver(), connection.feature()); |
|
|
|
DBTypes dataBaseTypePoint = DataBaseTypePointManager.getInstance().getDataBaseTypePoint(connection.getDriver(), connection.feature()); |
|
|
|
if (connectionIsNotSupported(connection, dataBaseTypePoint)) { |
|
|
|
if (connectionIsNotSupported(connection, dataBaseTypePoint)) { |
|
|
@ -322,25 +318,18 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validateConnections(List<ConnectionBean> addedOrUpdatedConnections) throws Exception { |
|
|
|
private void alterConnections(List<ConnectionInfoBean> addConnections, List<String> removedConnNames, List<ConnectionInfoBean> updateConnection) { |
|
|
|
|
|
|
|
|
|
|
|
for (ConnectionBean connectionBean : addedOrUpdatedConnections) { |
|
|
|
|
|
|
|
Connection connection = connectionBean.getConnection(); |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ConnectionRepository.getInstance().validSettings(new com.fr.workspace.server.entity.connection.ConnectionBean(connection)); |
|
|
|
for (ConnectionInfoBean bean : addConnections) { |
|
|
|
} catch (DriverClassNotFoundException e) { |
|
|
|
ConnectionRepository.getInstance().add(bean); |
|
|
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", connectionBean.getName()) + ", " + e.getMessage(), e.getCause()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (ConnectionInfoBean bean : updateConnection) { |
|
|
|
|
|
|
|
ConnectionRepository.getInstance().update(bean); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (String name : removedConnNames) { |
|
|
|
|
|
|
|
ConnectionRepository.getInstance().delete(new ConnectionInfoBean(name)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void alterConnections(BatchConnectionModifyBean bean) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
ConnectionRepository.getInstance().save(bean); |
|
|
|
|
|
|
|
// hades:远程环境时,由于时直接RPC调用远程修改,因此设计器本地配置需要失效
|
|
|
|
// hades:远程环境时,由于时直接RPC调用远程修改,因此设计器本地配置需要失效
|
|
|
|
if (!WorkContext.getCurrent().isLocal()) { |
|
|
|
if (!WorkContext.getCurrent().isLocal()) { |
|
|
|
EventDispatcher.fire(RemoteConfigEvent.EDIT, "ConnectionConfig"); |
|
|
|
EventDispatcher.fire(RemoteConfigEvent.EDIT, "ConnectionConfig"); |
|
|
|