MongoDB
parent
c28ce8fa92
commit
5febc67e89
|
@ -17,6 +17,11 @@
|
|||
<version>4.4.0</version> <!-- 使用最新版本 -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.8.0</version> <!-- 请根据实际情况使用最新版本 -->
|
||||
</dependency>
|
||||
|
||||
<!-- Elasticsearch Low Level REST Client -->
|
||||
<dependency>
|
||||
|
|
|
@ -4,7 +4,6 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fasterxml.jackson.databind.ser.std.StringSerializer;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
@ -39,6 +38,8 @@ import net.srt.vo.DataDatabaseVO;
|
|||
import net.srt.vo.SchemaTableDataVo;
|
||||
import net.srt.vo.SqlGenerationVo;
|
||||
import net.srt.vo.TableVo;
|
||||
import org.apache.commons.net.ftp.FTP;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
|
@ -53,6 +54,9 @@ import srt.cloud.framework.dbswitch.core.model.TableDescription;
|
|||
import srt.cloud.framework.dbswitch.core.service.IMetaDataByJdbcService;
|
||||
import srt.cloud.framework.dbswitch.core.service.impl.MetaDataByJdbcServiceImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
@ -147,7 +151,7 @@ public class DataDatabaseServiceImpl extends BaseServiceImpl<DataDatabaseDao, Da
|
|||
ProductTypeEnum productTypeEnum = ProductTypeEnum.getByIndex(vo.getDatabaseType());
|
||||
|
||||
IMetaDataByJdbcService metaDataService = new MetaDataByJdbcServiceImpl(productTypeEnum);
|
||||
if (StringUtil.isBlank(vo.getJdbcUrl())) {
|
||||
if (StringUtil.isNotBlank(vo.getJdbcUrl())) {
|
||||
if(productTypeEnum.getUrl()!=null){
|
||||
vo.setJdbcUrl(productTypeEnum.getUrl()
|
||||
.replace("{host}", vo.getDatabaseIp())
|
||||
|
@ -155,7 +159,7 @@ public class DataDatabaseServiceImpl extends BaseServiceImpl<DataDatabaseDao, Da
|
|||
.replace("{database}", vo.getDatabaseName()));
|
||||
}
|
||||
}
|
||||
if (vo.getIsJdbc()== IsJdbc.NO.getValue()){
|
||||
if (vo.getIsJdbc().equals(IsJdbc.YES.getValue())){
|
||||
metaDataService.testQuerySQL(
|
||||
vo.getJdbcUrl(),
|
||||
vo.getUserName(),
|
||||
|
@ -181,6 +185,7 @@ public class DataDatabaseServiceImpl extends BaseServiceImpl<DataDatabaseDao, Da
|
|||
} catch (Exception e) {
|
||||
// 捕获连接异常
|
||||
System.err.println("redis异常" + e.getMessage());
|
||||
throw new ServerException("连接失败");
|
||||
} finally {
|
||||
// 关闭连接
|
||||
jedis.close();
|
||||
|
@ -208,6 +213,7 @@ public class DataDatabaseServiceImpl extends BaseServiceImpl<DataDatabaseDao, Da
|
|||
System.out.println("消息发送成功");
|
||||
} catch (Exception e) {
|
||||
System.err.println("连接失败: " + e.getMessage());
|
||||
throw new ServerException("连接失败");
|
||||
} finally {
|
||||
// 关闭生产者
|
||||
if (producer != null) {
|
||||
|
@ -230,8 +236,46 @@ public class DataDatabaseServiceImpl extends BaseServiceImpl<DataDatabaseDao, Da
|
|||
System.out.println("连接数据库成功");
|
||||
} catch (Exception e) {
|
||||
System.err.println("连接MongoDB报错: " + e.getMessage());
|
||||
throw new ServerException("连接失败");
|
||||
}
|
||||
}
|
||||
//
|
||||
if(vo.getDatabaseType().equals(Judgment.FTP.getIndex())){
|
||||
// String server = "ftp.example.com";
|
||||
String user = vo.getUserName();
|
||||
String password = vo.getPassword();
|
||||
|
||||
FTPClient ftpClient = new FTPClient();
|
||||
|
||||
try {
|
||||
// 连接到 FTP 服务器
|
||||
ftpClient.connect(vo.getDatabaseIp(),Integer.valueOf(vo.getDatabasePort()));
|
||||
ftpClient.login(user, password);
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
|
||||
// 打印服务器返回的欢迎信息
|
||||
System.out.println("Connected to " + vo.getDatabaseIp() + ".");
|
||||
System.out.println(ftpClient.getReplyString());
|
||||
|
||||
// 设置文件传输类型为二进制
|
||||
ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
|
||||
|
||||
// 上传文件
|
||||
uploadFile(ftpClient, vo.getDatabaseIp(), "D:/desktop/ftp.txt");
|
||||
|
||||
// 下载文件
|
||||
// downloadFile(ftpClient, "C:/Users/栗永斌/Desktop/新建 文本文档.txt", "C:/Users/栗永斌/Desktop/新建 文本文档.txt");
|
||||
|
||||
// 登出并断开连接
|
||||
ftpClient.logout();
|
||||
ftpClient.disconnect();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -241,6 +285,39 @@ public class DataDatabaseServiceImpl extends BaseServiceImpl<DataDatabaseDao, Da
|
|||
}
|
||||
}
|
||||
|
||||
private static void uploadFile(FTPClient ftpClient, String localFilePath, String remoteFilePath) throws IOException {
|
||||
FileInputStream inputStream = new FileInputStream(new File(remoteFilePath));
|
||||
|
||||
try {
|
||||
// 上传文件
|
||||
boolean uploaded = ftpClient.storeFile(localFilePath, inputStream);
|
||||
|
||||
if (uploaded) {
|
||||
System.out.println("File uploaded successfully.");
|
||||
} else {
|
||||
System.out.println("Failed to upload file.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
// private static void downloadFile(FTPClient ftpClient, String remoteFilePath, String localFilePath) throws IOException {
|
||||
// FileOutputStream outputStream = new FileOutputStream(new File(localFilePath));
|
||||
//
|
||||
// // 下载文件
|
||||
// boolean downloaded = ftpClient.retrieveFile(remoteFilePath, outputStream);
|
||||
// outputStream.close();
|
||||
//
|
||||
// if (downloaded) {
|
||||
// System.out.println("File downloaded successfully.");
|
||||
// } else {
|
||||
// System.out.println("Failed to download file.");
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<TableVo> getTablesById(Long id) {
|
||||
DataDatabaseEntity dataDatabaseEntity = baseMapper.selectById(id);
|
||||
|
|
|
@ -104,8 +104,9 @@ public enum ProductTypeEnum {
|
|||
REDIS(17, "com.mysql.jdbc.Driver","/* ping */ SELECT 1", ""),
|
||||
KAFKA(18, "com.mysql.jdbc.Driver","/* ping */ SELECT 1", ""),
|
||||
ES(19, "com.mysql.jdbc.Driver","/* ping */ SELECT 1", ""),
|
||||
FTP(20, "com.mysql.jdbc.Driver","/* ping */ SELECT 1", ""),
|
||||
MONGODB(21, "com.mysql.jdbc.Driver","/* ping */ SELECT 1", ""),
|
||||
FTP(20, "com.mysql.jdbc.Driver","/* ping */ SELECT 1", "ftp://example.com"),
|
||||
MONGODB(21, "com.mysql.jdbc.Driver","/* ping */ SELECT 1", "mongodb://{username}:{password}@{host}:{port}/{database}"),
|
||||
|
||||
;
|
||||
|
||||
private Integer index;
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue