Destiny.Lin
5 months ago
8 changed files with 138 additions and 62 deletions
@ -0,0 +1,67 @@ |
|||||||
|
package com.fr.design.data.datapane.connect; |
||||||
|
|
||||||
|
import com.fr.data.driver.DriverClassNotFoundException; |
||||||
|
import com.fr.data.impl.Connection; |
||||||
|
import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean; |
||||||
|
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.workspace.server.repository.connection.BaseConnectionSource; |
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
/** |
||||||
|
* 本地Connection资源操作 |
||||||
|
* |
||||||
|
* @author Destiny.Lin |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2024/5/29 |
||||||
|
*/ |
||||||
|
public class LocalConnectionSource extends BaseConnectionSource { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void add(ConnectionInfoBean bean) throws Exception { |
||||||
|
Connection connection = ConnectionProcessorFactory.createConnection(bean); |
||||||
|
validate(bean.getConnectionName(), connection); |
||||||
|
ConnectionProcessorFactory.addConnection(bean); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void delete(ConnectionInfoBean bean) throws Exception { |
||||||
|
ConnectionProcessorFactory.deleteConnection(bean.getConnectionName()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void update(ConnectionInfoBean bean) throws Exception { |
||||||
|
Connection connection = ConnectionProcessorFactory.createConnection(bean); |
||||||
|
validate(bean.getConnectionName(), connection); |
||||||
|
ConnectionProcessorFactory.updateConnection(bean.getConnectionName(), bean); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean lock(String str) { |
||||||
|
// 本地默认锁定成功,让其执行后续动作
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean unlock(String str) { |
||||||
|
// 本地默认解锁成功
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isLock(String str) { |
||||||
|
// 本地默认未锁定
|
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
private void validate(String name, Connection connection) throws SQLException { |
||||||
|
try { |
||||||
|
connection.validateSettings(); |
||||||
|
} catch (DriverClassNotFoundException e) { |
||||||
|
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||||
|
} catch (Exception e) { |
||||||
|
throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", name) + ", " + e.getMessage(), e.getCause()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue