Browse Source
Merge in DESIGN/design from ~DESTINY.LIN/design:mss/2.0 to mss/2.0 * commit 'aa68031e1686a0c7924f62b8164300b21c73f264': REPORT-114392 FR-FBP版本本地设计适配 修复数据连接与数据集问题mss/2.0
Destiny.Lin-林锦龙
4 months ago
2 changed files with 175 additions and 1 deletions
@ -0,0 +1,158 @@
|
||||
package com.fanruan.data; |
||||
|
||||
import com.fanruan.config.impl.data.ConnectionConfigProvider; |
||||
import com.fanruan.config.impl.data.ConnectionConfigWriter; |
||||
import com.fr.data.impl.Connection; |
||||
import com.fr.file.ConnectionConfig; |
||||
import com.fr.transaction.Configurations; |
||||
import com.fr.transaction.WorkerAdaptor; |
||||
import org.jetbrains.annotations.NotNull; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 对数据连接的配置封装,包装了事务 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/7/30 |
||||
*/ |
||||
public class ConnectionConfigWrapper implements ConnectionConfigProvider, ConnectionConfigWriter { |
||||
|
||||
private static final ConnectionConfigWrapper INSTANCE = new ConnectionConfigWrapper(); |
||||
|
||||
private ConnectionConfigWrapper() { |
||||
|
||||
} |
||||
|
||||
public static ConnectionConfigWrapper getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, Connection> getConnections() { |
||||
Map<String, Connection> connectionMap = new HashMap<>(ConnectionConfig.getInstance().getConnections()); |
||||
for (Map.Entry<String, Connection> entry : connectionMap.entrySet()) { |
||||
entry.getValue().setConnectionName(entry.getKey()); |
||||
} |
||||
return connectionMap; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, Connection> getConnectionsWithoutCheck() { |
||||
Map<String, Connection> connectionMap = new HashMap<>(ConnectionConfig.getInstance().getConnectionsWithoutCheck()); |
||||
for (Map.Entry<String, Connection> entry : connectionMap.entrySet()) { |
||||
entry.getValue().setConnectionName(entry.getKey()); |
||||
} |
||||
return connectionMap; |
||||
} |
||||
|
||||
@Override |
||||
public <T extends Connection> Map<String, T> getDesignateConnections(Class<T> clazz) { |
||||
Map<String, T> connectionMap = new HashMap<>(ConnectionConfig.getInstance().getDesignateConnections(clazz)); |
||||
for (Map.Entry<String, T> entry : connectionMap.entrySet()) { |
||||
entry.getValue().setConnectionName(entry.getKey()); |
||||
} |
||||
return connectionMap; |
||||
} |
||||
|
||||
@Override |
||||
public void addConnection(String connectionName, Connection connection) { |
||||
Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
ConnectionConfig.getInstance().addConnection(connectionName, connection); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public int getRemainingCon(int remove, int add) { |
||||
return ConnectionConfig.getInstance().getRemainingCon(remove, add); |
||||
} |
||||
|
||||
@Override |
||||
public void addConnectionWithoutCheck(String connectionName, Connection connection) { |
||||
Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
ConnectionConfig.getInstance().addConnectionWithoutCheck(connectionName, connection); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void removeConnection(String connectionName) { |
||||
Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
ConnectionConfig.getInstance().removeConnection(connectionName); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void renameConnection(String oldName, String newName) { |
||||
Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
ConnectionConfig.getInstance().renameConnection(oldName, newName); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public @Nullable Connection getConnection(@NotNull String connectionName) { |
||||
Connection connection = ConnectionConfig.getInstance().getConnection(connectionName); |
||||
if (connection != null) { |
||||
connection.setConnectionName(connectionName); |
||||
} |
||||
return connection; |
||||
} |
||||
|
||||
@Override |
||||
public @Nullable Connection getConnectionWithoutCheck(String connectionName) { |
||||
Connection connection = ConnectionConfig.getInstance().getConnectionWithoutCheck(connectionName); |
||||
if (connection != null) { |
||||
connection.setConnectionName(connectionName); |
||||
} |
||||
return connection; |
||||
} |
||||
|
||||
@Override |
||||
public void removeAllConnection() { |
||||
Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
ConnectionConfig.getInstance().removeAllConnection(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void updateConnection(String connName, Connection connection) { |
||||
Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
ConnectionConfig.getInstance().addConnection(connName, connection); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPutPermitted() { |
||||
return ConnectionConfig.getInstance().isPutPermitted(); |
||||
} |
||||
|
||||
@Override |
||||
public void safeRemoveAll() { |
||||
Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
ConnectionConfig.getInstance().safeRemoveAll(); |
||||
} |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue