2025-04-07 16:44:25 +08:00
|
|
|
|
using Apache.IoTDB.DataStructure;
|
|
|
|
|
|
using Apache.IoTDB;
|
|
|
|
|
|
using JiShe.CollectBus.IoTDBProvider.Interface;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.IoTDBProvider.Provider
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 表模型Session连接池
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class TableSessionPoolAdapter : IIoTDBSessionPool
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly TableSessionPool _sessionPool;
|
|
|
|
|
|
private readonly IoTDBOptions _options;
|
|
|
|
|
|
|
|
|
|
|
|
public TableSessionPoolAdapter(IoTDBOptions options)
|
|
|
|
|
|
{
|
|
|
|
|
|
_options = options;
|
|
|
|
|
|
_sessionPool = new TableSessionPool.Builder()
|
|
|
|
|
|
.SetNodeUrls(options.ClusterList)
|
|
|
|
|
|
.SetUsername(options.UserName)
|
|
|
|
|
|
.SetPassword(options.Password)
|
|
|
|
|
|
.SetFetchSize(options.FetchSize)
|
|
|
|
|
|
.SetPoolSize(options.PoolSize)
|
|
|
|
|
|
.SetDatabase(options.DataBaseName)
|
|
|
|
|
|
.Build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 打开连接池
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task OpenAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
await _sessionPool.Open(false);
|
|
|
|
|
|
if (_options.OpenDebugMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
_sessionPool.OpenDebugMode(builder => builder.AddConsole());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量插入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tablet"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<int> InsertAsync(Tablet tablet)
|
|
|
|
|
|
{
|
2025-04-11 14:50:46 +08:00
|
|
|
|
var result = await _sessionPool.InsertAsync(tablet);
|
|
|
|
|
|
if (result != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception($"{nameof(TableSessionPoolAdapter)} ");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
2025-04-07 16:44:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sql"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<SessionDataSet> ExecuteQueryStatementAsync(string sql)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await _sessionPool.ExecuteQueryStatementAsync(sql);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
_sessionPool?.Close().ConfigureAwait(false).GetAwaiter().GetResult();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|