首页 文章 精选 留言 我的

精选列表

搜索[数据源],共7899篇文章
优秀的个人博客,低调大师

【重大更新】CloudCanal 社区版 1.0.2 正式发布,开放众多新数据源

CloudCanal是一款由ClouGence公司发行的集结构迁移、数据全量迁移/校验/订正、增量实时同步为一体的多源多端数据迁移同步平台。产品包含完整的产品化能力,助力企业打破数据孤岛、完成数据互融互通,从而更好的使用数据。 发版时间:2021年8月20日 版本号: 1.0.2 新特性 新增Oracle源端 新增PostgreSQL源端 新增Greenplum源端 新增PolarDbMySQL源端 新增Oracle目标端 新增PostgreSQL目标端 新增Greenplum目标端 新增Hive目标端 新增DRDS目标端 新增PolarDbMySQL目标端 新增AdbForMySQL目标端 新增校验任务结果查看 支持ClickHouse最新版本到22.1 ClickHouse 新增 ReplacingMergeTree 支持,并且默认选中该表引擎 BugFix&优化 修复timestamp on update current timestamp不同步问题 修复树状选择,筛选表,勾选掉一张表后又加载全部的问题 修复校验、订正任务重跑刷新的问题 修复源端阿里云 kafka 初始位点问题 修复Clickhouse对端同步无主键表问题 修复sidecar stdout打印过多日志问题 修复Kafka任务,获取分区NPE问题 修复因机器规格低导致的sidecar访问管控超时问题 修复机器timezone非东八区时的时区问题,现在CloudCanal时间值的写入和机器操作系统时区解耦 修复sidecar容器重启,sidecar进程没法正常重启的问题 优化写入对端 RocketMQ 性能 放开任务创建数量限制 关联资料 CloudCanal社区 CloudCanal Release信息汇总 CloudCanal安装使用文档(含下载地址) MySQL到ClickHouse实时同步-CloudCanal实战 构建基于kafka中转的混合云在线数据生态-cloudcanal实战 5分钟搞定 MySQL 到 ElasticSearch 迁移同步-CloudCanal实战

优秀的个人博客,低调大师

JFinal 表自动绑定插件实现,实现零配置,支持多数据源

以mysql数据库实现为例,其它的db也可基于这种方式自己实现 大概的思路是这样的,为了简少配置,所以不使用注解的方式 首先需要一个工具类来拿到所有的Model类大体的实现方式如下 package com.nmtx.utils; import java.io.File; import java.util.ArrayList; import java.util.List; import com.jfinal.kit.PathKit; import com.jfinal.kit.StrKit; public class ClassUtils { public static String classRootPath = null; public static List<Class<?>> scanPackage(String packageName) throws ClassNotFoundException { List<Class<?>> classList = new ArrayList<Class<?>>(); String path = getClassRootPath() + "/" + packageName.replace(".", "/"); List<String> fileNameList = getAllFileName(path); for (String fileName : fileNameList) { classList.add(Class.forName(fileName)); } return classList; } public static List<String> getAllFileName(String path) { List<String> fileNameList = new ArrayList<String>(); File rootFile = new File(path); if (rootFile.isFile()) { String fileName = rootFile.getPath().replace(PathKit.getRootClassPath(), "").replace(File.separator, ".") .replaceFirst(".", ""); String prefix = fileName.substring(fileName.lastIndexOf(".") + 1); if (prefix.equals("class")) { fileNameList.add(fileName.substring(0, fileName.lastIndexOf("."))); } } else { File[] files = rootFile.listFiles(); if (files != null) { for (File file : files) { fileNameList.addAll(getAllFileName(file.getPath())); } } } return fileNameList; } public static String getClassRootPath() { if (StrKit.isBlank(classRootPath)) classRootPath = PathKit.getRootClassPath(); return classRootPath; } public static void setClassRootPath(String classRootPath) { ClassUtils.classRootPath = classRootPath; } } 有了工具类,就去处理自动扫描插件,大概实现是这样的 package com.nmtx.plugins.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.jfinal.kit.StrKit; import com.jfinal.plugin.IPlugin; import com.jfinal.plugin.activerecord.ActiveRecordPlugin; import com.jfinal.plugin.activerecord.Model; import com.jfinal.plugin.c3p0.C3p0Plugin; import com.nmtx.plugins.db.impl.TableToModelByUnderline; import com.nmtx.utils.ClassUtils; public class AutoTabelPlugin implements IPlugin { private String db; private ActiveRecordPlugin arp; private String pacekageName; private String idKey; private ITableToModelFormat tableToModelFormate; private C3p0Plugin c3p0Plugin; public AutoTabelPlugin(C3p0Plugin erpC3p0, ActiveRecordPlugin arp, String db, String packageName, String idKey, ITableToModelFormat tableToModelFormate) { this.db = db; this.arp = arp; this.idKey = idKey; this.tableToModelFormate = tableToModelFormate; this.c3p0Plugin = erpC3p0; } public AutoTabelPlugin(C3p0Plugin erpC3p0, ActiveRecordPlugin arp, String db, String packageName, String idKey) { this.db = db; this.arp = arp; this.idKey = idKey; this.pacekageName = packageName; this.tableToModelFormate = new TableToModelByUnderline(); this.c3p0Plugin = erpC3p0; } @SuppressWarnings({ "unchecked" }) public List<Class<? extends Model<?>>> getModelClass() throws ClassNotFoundException { List<Class<?>> classes = ClassUtils.scanPackage(pacekageName); List<Class<? extends Model<?>>> modelClasses = new ArrayList<Class<? extends Model<?>>>(); for (Class<?> classer : classes) { modelClasses.add((Class<? extends Model<?>>) classer); } return modelClasses; } public boolean start() { try { HashMap<String, String> tableMap = getTableMap(); List<Class<? extends Model<?>>> modelClasses = getModelClass(); for (Class<? extends Model<?>> modelClass : modelClasses) { String tableName = tableMap.get(modelClass.getSimpleName()); if (tableName != null) { if (StrKit.notBlank(idKey)) { arp.addMapping(tableName, idKey, modelClass); } else { arp.addMapping(tableName, modelClass); } } } } catch (ClassNotFoundException e) { throw new RuntimeException("auto table mappming is exception" + e); } return true; } /** * 获取Model和表名的映射 * * @return */ private HashMap<String, String> getTableMap() { HashMap<String, String> map = new HashMap<String, String>(); Connection connection = null; PreparedStatement preStatement = null; ResultSet resultSet = null; try { c3p0Plugin.start(); connection = c3p0Plugin.getDataSource().getConnection(); preStatement = connection.prepareStatement( "select table_name as tableName from information_schema.tables where table_schema='" + db + "' and table_type='base table'"); resultSet = preStatement.executeQuery(); while (resultSet.next()) { String tableName = resultSet.getString(1); map.put(tableToModelFormate.getTableByModel(tableName), tableName); } } catch (Exception e) { closeConnection(connection, preStatement, resultSet); throw new RuntimeException("auto table mappming is exception" + e); } finally { closeConnection(connection, preStatement, resultSet); } return map; } private void closeConnection(Connection connection, PreparedStatement preStatement, ResultSet resultSet) { try { if (resultSet != null) { resultSet.close(); } if (preStatement != null) { preStatement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException("auto close db connection is exception" + e); } } public boolean stop() { return true; } } 因为java里的属性一般都是驼峰规则,代码看起来舒服一点,这里以数据库中以大写字母为例,表名为T_USER,对应Model名为User实现如下 接口定义 package com.nmtx.plugins.db; public interface ITableToModelFormat { public String generateTableNameToModelName(String tableName); } 实现如下 package com.nmtx.plugins.db.impl; import com.nmtx.plugins.db.ITableToModelFormat; public class TableToModelByUnderline implements ITableToModelFormat{ public String generateTableNameToModelName(String tableName) { StringBuilder modelName = new StringBuilder(); tableName = tableName.substring(2).toLowerCase(); String tableNames[] = tableName.split("_"); for(String tableNameTemp:tableNames){ modelName.append(fisrtStringToUpper(tableNameTemp)); } return modelName.toString(); } private String fisrtStringToUpper(String string){ return string.replaceFirst(string.substring(0, 1),string.substring(0, 1).toUpperCase()); } } 如果不同的格式可以实现不同的方法,根据自己的需求,这样就完成了自动扫描插件,使用起来也方便如下 C3p0Plugin spuC3p0= new C3p0Plugin(getProperty("jdbc.mysql.url"), getProperty("jdbc.mysql.username").trim(), getProperty("jdbc.mysql.password").trim(), getProperty("jdbc.mysql.driverClass")); spuC3p0.setMaxPoolSize(Integer.parseInt(getProperty("jdbc.mysql.maxPool"))); spuC3p0.setMinPoolSize(Integer.parseInt(getProperty("jdbc.mysql.minPool"))); spuC3p0.setInitialPoolSize(Integer.parseInt(getProperty("jdbc.mysql.initialPoolSize"))); ActiveRecordPlugin spuArp = new ActiveRecordPlugin(DbConfigName.SPU, spuC3p0); AutoTabelPlugin spuAutoTabelPlugin = new AutoTabelPlugin(spuC3p0, spuArp, getProperty("jdbc.mysql.spu.db"), "com.nmtx.manager.model", "ID"); me.add(spuAutoTabelPlugin); me.add(spuArp); 如果有多个就可以配置多个插件,而无需在管映射了,新增Model直接新增即可,不要再管映射

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册