Browse Source
* commit '8a069f4f6873df7b6393e47fb386700de1afb8f7': REPORT-126235 放开插件的classFinder REPORT-114392 FR-FBP版本本地设计适配 修复数据连接与数据集问题fbp-1.0
superman
4 months ago
3 changed files with 181 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