diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbConfig.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbConfig.java new file mode 100644 index 00000000..350d5576 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbConfig.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +import javax.sql.DataSource; + +/** + * @author: aoshiguchen + * @date: 2022/11/3 + */ +public class CrispDbConfig { + /** + * 数据库名称 + */ + private String name; + /** + * 数据源提供者 + */ + private IDataSourceProvider dataSourceProvider; + /** + * 是否显示sql + */ + private Boolean showSql; + /** + * 是否开启调试模式 + */ + private Boolean debugMode; + + public CrispDbConfig(String name, IDataSourceProvider dataSourceProvider) { + this.name = name; + this.dataSourceProvider = dataSourceProvider; + this.showSql = Boolean.FALSE; + this.debugMode = Boolean.FALSE; + } + + public CrispDbConfig(String name, DataSource dataSource) { + this(name, new DefaultDataSourceProvider(dataSource)); + } + + public CrispDbConfig(IDataSourceProvider dataSourceProvider) { + this("unknown", dataSourceProvider); + } + + public CrispDbConfig(DataSource dataSource) { + this(new DefaultDataSourceProvider(dataSource)); + } +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbContext.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbContext.java new file mode 100644 index 00000000..21648b2e --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbContext.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +import java.sql.Connection; + +/** + * @author: aoshiguchen + * @date: 2022/11/3 + */ +public class CrispDbContext { + private final ThreadLocal connectionHolder = new ThreadLocal<>(); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbExecutor.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbExecutor.java new file mode 100644 index 00000000..984b13f9 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbExecutor.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +import javax.sql.DataSource; +import java.util.List; + +/** + * @author: aoshiguchen + * @date: 2022/11/3 + */ +class CrispDbExecutor implements CrispDbOperator { + /** + * 配置 + */ + private CrispDbConfig config; + /** + * 上下文 + */ + private CrispDbContext context; + + public CrispDbExecutor(CrispDbConfig config) { + this.config = config; + this.context = new CrispDbContext(); + } + + public CrispDbExecutor(IDataSourceProvider dataSourceProvider) { + this(new CrispDbConfig(dataSourceProvider)); + } + + public CrispDbExecutor(String name, IDataSourceProvider dataSourceProvider) { + this(new CrispDbConfig(name, dataSourceProvider)); + } + + public CrispDbExecutor(DataSource dataSource) { + this(new CrispDbConfig(dataSource)); + } + + public CrispDbExecutor(String name, DataSource dataSource) { + this(new CrispDbConfig(name, dataSource)); + } + + @Override + public List queryList(Class resultType, String sql, Object... params) { + return null; + } + + @Override + public T query(Class resultType, String sql, Object... params) { + return null; + } + + @Override + public CrispDbUpdateResult update(String sql, Object... params) { + return null; + } + + @Override + public CrispDbUpdateResult insert(String sql, Object... params) { + return null; + } + + @Override + public CrispDbUpdateResult delete(String sql, Object... params) { + return null; + } +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbKit.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbKit.java new file mode 100644 index 00000000..3a702ebb --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbKit.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +import fun.asgc.neutrino.core.util.LockUtil; + +import java.util.HashMap; +import java.util.Map; + +/** + * 清爽的数据库工具 + * @author: aoshiguchen + * @date: 2022/11/3 + */ +public class CrispDbKit { + /** + * 数据源缓存 + */ + private static Map crispDbConfigMap = new HashMap<>(); + /** + * 数据库操作实例 + */ + private static Map crispDbExecutorMap = new HashMap<>(); + /** + * 默认数据库的key + */ + private static final String DEFAULT_KEY = "default"; + + /** + * 设置默认数据库配置 + * @param config 数据库配置 + */ + public static void setConfig(CrispDbConfig config) { + setConfig(DEFAULT_KEY, config); + } + + /** + * 设置数据库配置 + * @param key 键 + * @param config 数据库配置 + */ + public static void setConfig(String key, CrispDbConfig config) { + crispDbConfigMap.put(key, config); + } + + /** + * 根据名称获取数据库配置 + * @param key 键 + * @return 数据库配置 + */ + private static CrispDbConfig getConfig(String key) { + return crispDbConfigMap.get(key); + } + + /** + * 获取默认数据库操作实例 + * @return + */ + private static CrispDbExecutor getDbExecutor() { + return getDbExecutor(DEFAULT_KEY); + } + + /** + * 获取数据库操作实例 + * @param key 键 + * @return 数据库操作实例 + */ + private static CrispDbExecutor getDbExecutor(String key) { + return LockUtil.doubleCheckProcessForNoException( + () -> !crispDbExecutorMap.containsKey(key), + key, + () -> { + CrispDbConfig config = getConfig(key); + if (null != config) { + crispDbExecutorMap.put(key, new CrispDbExecutor(config)); + } + }, + () -> crispDbExecutorMap.get(crispDbExecutorMap) + ); + } + + /** + * 切换数据源 + * @param name 数据源名称 + * @return 数据库操作实例 + */ + public static CrispDbExecutor use(String name) { + return getDbExecutor(name); + } +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbOperator.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbOperator.java new file mode 100644 index 00000000..651df9dd --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbOperator.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +import java.util.List; + +/** + * @author: aoshiguchen + * @date: 2022/11/3 + */ +public interface CrispDbOperator { + /** + * 查询数据列表 + * @param resultType 结果类型 + * @param sql sql + * @param params 参数列表 + * @return 查询结果列表 + * @param + */ + List queryList(Class resultType, String sql, Object... params); + + /** + * 查询单条记录 + * @param resultType 结果类型 + * @param sql sql + * @param params 参数列表 + * @return 查询结果 + * @param + */ + T query(Class resultType, String sql, Object... params); + + /** + * 更新 + * @param sql sql + * @param params 参数列表 + * @return 更新结果 + */ + CrispDbUpdateResult update(String sql, Object... params); + + /** + * 新增 + * @param sql sql + * @param params 参数列表 + * @return 新增结果 + */ + CrispDbUpdateResult insert(String sql, Object... params); + + /** + * 删除 + * @param sql sql + * @param params 参数列表 + * @return 删除结果 + */ + CrispDbUpdateResult delete(String sql, Object... params); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbUpdateResult.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbUpdateResult.java new file mode 100644 index 00000000..ea761a65 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/CrispDbUpdateResult.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +/** + * @author: aoshiguchen + * @date: 2022/11/3 + */ +public class CrispDbUpdateResult { + +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/DefaultDataSourceProvider.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/DefaultDataSourceProvider.java new file mode 100644 index 00000000..123c75d2 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/DefaultDataSourceProvider.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +import javax.sql.DataSource; + +/** + * @author: aoshiguchen + * @date: 2022/11/3 + */ +public class DefaultDataSourceProvider implements IDataSourceProvider { + /** + * 数据源 + */ + private DataSource dataSource; + + public DefaultDataSourceProvider(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public DataSource getDataSource() { + return dataSource; + } +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/IDataSourceProvider.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/IDataSourceProvider.java new file mode 100644 index 00000000..34cf6a3f --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/crisp/IDataSourceProvider.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.crisp; + +import javax.sql.DataSource; + +/** + * 数据源提供商 + * @author: aoshiguchen + * @date: 2022/11/3 + */ +public interface IDataSourceProvider { + /** + * 获取数据源 + * @return + */ + DataSource getDataSource(); +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMonthJob.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMonthJob.java index 0d440387..e06c2478 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMonthJob.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/job/FlowReportForMonthJob.java @@ -56,7 +56,7 @@ public class FlowReportForMonthJob implements IJobHandler { @Autowired private FlowReportDayMapper flowReportDayMapper; @Autowired - private FlowReportMonthMapper flowReportHourDOList; + private FlowReportMonthMapper flowReportMonthMapper; @Override public void execute(String param) throws Exception { @@ -96,7 +96,7 @@ public class FlowReportForMonthJob implements IJobHandler { } for (FlowReportMonthDO item : map.values()) { - flowReportHourDOList.add(item); + flowReportMonthMapper.add(item); } }