1 Star 0 Fork 729

linhaisongtao / anyline

forked from AnyLine / anyline 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

招募开发合伙伴,个人或组织皆可
这里有【400+】数据库,总有一个是你熟悉的

详细说明请参考:
http://doc.anyline.org/
开发测试来环境请使用【8.7.1-SNAPSHOT】版本 语法测试请参考【各数据库模拟环境】
发版务必到【中央库】找一个正式版本,不要把SNAPSHOT版本发到生产环境
关于多数据源,请先阅读
【三种方式注册数据源】 【三种方式切换数据源】 【多数据源事务控制】
低代码平台、数据中台等场景需要生成SQL/操作元数据参考
【JDBCAdapter】 【SQL及日志】 【service.metadata】 【SQL.metadata】

快速开始请参考示例源码(各种各样最简单的hello world):
https://gitee.com/anyline/anyline-simple

一个字都不想看,就想直接启动项目的下载这个源码:
https://gitee.com/anyline/anyline-simple-clear

有问题请不要自行百度,因为百度收录的内容有可能过期或版本不一致, 有问题请联系

                
   QQ群(86020680)           或                  微信群

简介

AnyLine的核心是一个基于spring生态的D-ORM(动态对象关系影射), 其重点是:

  • 以最简单、快速方式操作 数据库结果集
  • 兼容各种数据库,统一生成或执行DML/DDL,读写表结构、索引等元数据
  • 一切基于动态、基于运行时(包括数据源、数据结构等)

常用于动态结构场景的底层支持,作为SQL解析引擎或适配器出现, 如:数据中台、可视化、低代码、SAAS、自定义表单、异构数据库迁移同步、 物联网车联网数据处理、 数据清洗、运行时自定义报表/查询条件/数据结构、 爬虫数据解析等。 参考【适用场景
实际开发过程中主要用来:

  • 运行时动态注册切换数据源
  • 生成动态SQL(重点是复杂的动态查询条件)
  • 查询、操作元数据(如表结构、索引等)
  • 屏蔽不同数据库的语法差异(主要是DDL差异)

已经有ORM了 为什么还要有AnyLine, 与ORM有什么区别

  • 面向场景不同
    anyline主要面向动态场景,就是运行时随时可变的场景。
    如我们常用的动态数据源,不是在部署时可以固定在配置文件中,
    而是可能在不确定的时间,由不确定的用户提供的不确定数据源。
  • 针对产品不同
    anyline一般不会直接用来开发一个面向终端用户的产品(如ERP、CRM等),
    而是要开发一个中间产品(如低代码平台),让用户通过中间产品来生成一个最终产品。
    再比如用anyline开发一个自定义查询分析工具,让用户通过这个工具根据业务需求生成动态报表。
  • 操作对象不同
    anyline主要操作元数据,因为在项目开发之初,可能就没有一个如ERP/CRM之类的明确的产品,
    当然也就没有订单、客户之类的具体对象及属性,所以也没什么具体数据可操作。
  • 面向用户(开发设计人员)不同
    ORM的用户基本上看看文档复制个模板就可以开工了, 而anyline用户因为其面对的产品的特点也决定了这部分用户不可能以一个固定的思维去完成自己的产品,
    这也直接导致了anyline经常会没有一个工具或方法能满足用户突然而来的灵感与思路。 那就只能随用户灵感而动。也正是用户源源不断的灵感聚沙了现在的anyline。
    所以anyline的用户大部分也是其作者。
  • 所以对用户(开发设计人员)要求不同
    一个ORM用户用了许多年的连接池,他可以只知道配置哪几个默认参数,也能正常开展工作。
    但anyline的用户不行,他要求这个团队中至少有一个人要明白其所以然。这就说来话长了,有兴趣进群慢慢说吧。

实际操作中与ORM最明显的区别是

  • 摒弃了各种繁琐呆板的实体类以及相关的配置文件
    让数据库操作更简单,不要一动就是一整套的service/dao/mapping/VOPODTO有用没用的各种O,生成个简单的SQL也各种判断遍历。
  • 强强化了结果集的对象概念
    面向对象的对象不是只有get/set/注解这么弱
    需要把数据及对数据的操作封装在一起,作为一个相互依存的整体,并实现高度的抽象
    要关注元数据,不要关注姓名、年龄等具体属性
    强化针对结果集的数据二次处理能力
    如结果集的聚合、过滤、行列转换、格式化及各种数学计算尽量作到一键...一键...
    而不要像ORM提供的entity, map, list除了提供个get/set/foreach,稍微有点用的又要麻烦程序员各种判断各种遍历
    参考【疑问与优劣对比

与如何实现

数据操作的两个阶段,1.针对数据库中数据 2.针对数据库查询的结果集(内存中的数据)

  • 提供一个通用的AnylineService实现对数据库的一切操作
  • 提供一对DataSet/DataRow实现对内存数据的一切数学计算
    DataSet/DataRow不是对List/Map的简单封装 他将是提高我们开发速度的重要工具,各种想到想不到的数学计算,只要不是与业务相关的都应该能实现

AnyLine解决或提供了什么

动态、运行时

即运行时才能最终确定 动态的数据源、数据结构、展现形式
如我们需要开发一个数据中台或者一个数据清洗插件,编码阶段我们还不知道数据来源、什么类型的数据库甚至不是数据库、会有什么数据结构对应什么样的实体类,
如果需要前端展示的话,更不会知道不同的终端需要什么各种五花八门的数据组合
那只能定义一个高度抽象的实体了,想来想去也只有Collection可以胜任了。

简单快速的操作数据库

最常见的操作:根据条件分页查询一个表的几列
这一动就要倾巢出动一整套的service/dao/vo dto 各种O/mapper,生成个查询条件各种封装、为了拼接个SQL又是各种if else forearch
如果查询条件是由前端的最终用户动态提供的,那Java里if完了还不算完,xml中if也少不了
一旦分了页,又要搞出另一套数据结构,另一组接口,另一组参数(当然这种拙劣的设计只是极个别,不能代表ORM)

简单快速的操作结果集

数据库负责的是存储,其结构肯定是与业务需要不一样的。所以结果集需要处理。当我们需要用Map处理数据或数学计算时,
如最常见的数据格式化、筛选、分组、平均值、合计、方差等聚合计算
再如空值的处理包括, "", null, "null","\n","\r","\t"," "全角、半角等各种乱七八糟的情况
这时就会发现Map太抽象了,除了get/set/forearch好像也没别的可施展了。
要处理的细节太多了,if都不够用了。

动态数据源

再比如多数据源的情况下,要切换个数据源又是IOC又是AOP一堆设计模式全出场。经常是在方法配置个拦截器。
在同一个方法里还能切换个数据源了?
数据中台里有可能有几百几千个数据源,还得配上几千个方法?
数据源是用户动态提交的呢怎么拦截呢?
这不是DB Util的本职工作么,还要借助其他?
哪个项目少了AOP依赖还切换不了数据源了?

重复工作

如果只是写个helloworld,以上都不是问题,没什么解决不了的。但实际工作中是需要考虑工作量和开发速度的。
比如一个订单可能有几十上百列的数据,每个分析师需要根据不同的列查询。有那么几十列上同时需要<>=!=IN FIND_IN_SET多种查询方式算正常吧
不能让开发人员挨个写一遍吧,写一遍是没问题,但修改起来可就不是一遍两遍的事了
所以需要提供一个字典让用户自己去配置,低代码开发平台、自定义报表、动态查询条件应该经常有这个需求。
当用户提交上来一个列名、一个运算算、一组值,怎么执行SQL呢,不能在代码中各种判断吧,如果=怎么合成SQL,如果IN怎么合成SQL

多方言

DML方面hibernate还可以处理,DDL呢?国产库呢?

当然这种问题很难有定论,只能在实际应用过程中根据情况取舍。
可以参考【适用场景】和【实战对比】中的示例
造型之前,当然要搞明白优势劣势,参考【优势劣势

误解

当然我们并不是要抛弃Entity或ORM,相反的 AnyLine源码中也使用了多达几十个Entity
在一些 可预知的 固定的 场景下,Entity的优势还是不可替代的
程序员应该有分辨场景的能力
AnyLine希望程序员手中多一个数据库操作的利器,而不是被各种模式各种hello world限制

如何使用

数据操作不要再从生成xml/dao/service以及各种配置各种O开始
默认的service已经提供了大部分的数据库操作功能。
操作过程大致如下:

DataSet set = service.querys("HR_USER(ID, NM)", 
    condition(true, "anyline根据约定自动生成的=, in, like等查询条件"));  

这里的查询条件不再需要各种配置, 各种if else foreach标签
Anyline会自动生成, 生成规则可以【参考】这里的【约定规则】
分页也不需要另外的插件,更不需要繁琐的计算和配置,指定true或false即可

如何集成

只需要一个依赖、一个注解即可实现与springboot, netty等框架项目完美整合,参考【入门系列】 大概的方式就是在需要操作数据库的地方注入AnylineService 接下来service就可以完成大部分的数据库操作了。常用示例可以参考【示例代码

兼容

如果实现放不下那些已存在的各种XOOO
DataSet与Entity之间可以相互转换
或者这样:

EntitySet<User> = service.querys(User.class, 
    condition(true, "anyline根据约定自动生成的查询条件")); 
//true:表示需要分页
//为什么不用返回的是一个EntitySet而不是List?
//因为分页情况下, EntitySet中包含了分页数据, 而List不行。
//无论是否分页都返回相同的数据结构,而不需要根据是否分页实现两个接口返回不同的数据结构



//也可以这样(如果真要这样就不要用anyline了, 还是用MyBatis, Hibernate之类吧)
public class UserService extends AnylinseService<User> 
userService.querys(condition(true, "anyline根据约定自动生成的查询条件")); 

适用场景

  • 低代码后台
    主要用来处理动态属性、动态数据源、运行时自定义查询条件、元数据管理等。
    比较容易落地的几个场景如财务、库存等ERP模块用户经常需要输出不同格式的报表,根据不同维度查询统计数据
    前端可以用百度amis前端低代码框架,后端由anyline解析SQL及查询条件,管理元数据。
    【示例】

  • 数据中台
    动态处理各种异构数据源、强大的结果集批量处理能力,不再需要对呆板的实体类各种遍历各种转换。

  • 通常需要在运行时频繁的注册、切换、注销数据源
    【示例】

  • 可视化数据源
    主要用来处理动态属性,以及适配前端的多维度多结构的数据转换
    【参考】

  • 物联网车联网数据处理
    如车载终端、交通信号灯、数字化工厂传感器、环境检测设备数据等
    这种场景通常会涉及到时序数据库
    时序库虽然快,但是结构简单,数据需要经过各种组合后给业务系统
    时序库通常需要在运行时操作大量的DDL
    【示例】

  • 数据清洗、数据批量处理
    各种结构的数据、更多的是不符合标准甚至是错误的结构
    这种场景下需要一个灵活的数据结构来统一处理各种结构的数据
    再想像一下临时有几个数据需要处理一下(如补齐或替换几个字符)
    这个时候先去创建个Entity, XML, Service, Dao吗
    【示例】

  • 报表输出,特别是用户自定义报表
    类似于可视化环境, 样式相对简单一点,但精度要求极高,需要控制到像素、字体等
    如检验检测报告、资质证书等,当然这需要配合 anyline-office
    【office示例】

  • 工作流(运行时自定义表单/查询条件/数据结构)
    各个阶段都要自定义,比低代码要求更高的是:操作用户不懂编程 【示例】

  • 网络爬虫数据解析
    不固定的结构、html解析(当然不是用正则或dom那太费脑子了)
    【参考】

  • 异构数据库迁移同步
    动态的数据结构可以灵活的适配多种不同的表, 需不需要反复的get/set
    兼容多种数据库的DDL也可以方便的在不同类型的数据库中执行
    【核心代码示例(Mysql到Apache Ignite)】
    【基础应用项目】 【完整应用代替datax】

  • 还有一种很实现的场景是 许多项目到了交付的那一天 实体也没有设计完成
    别说设计了,需求都有可能还没结束就催交付了, Entity哪里找
    【示例】

关于数据库的适配 【更多查看】

【示例源码】

MySQLMySQL PostgreSQLPostgreSQL Oracle 11GOracle SQL ServerSQL Server MariaDBMariaDB IBM DB2 clickhouseclickhouse sqlitesqlite 达梦达梦 tdenginetdengine derbyderby H2H2 hsqldbhsqldb 人大金仓人大金仓 OpenGaussOpenGauss Neo4jNeo4j 瀚高瀚高 HiveApache Hive 南大通用南大通用 cassandracassandra oceanbaseoceanbase 神舟通用神舟通用 polardbpolardb questdbquestdb timescaletimescale 海量数据Vastbase(海量数据) 恒生电子LightDB(恒生电子) 万里数据库greatdb(万里数据库) 云和恩墨mogdb(云和恩墨) 中兴GoldenDBGoldenDB(中兴) GaiaDB-XGaiaDB-X(百度云) TiDBTiDB AntDBAntDB(亚信) cituscitus TDSQLTDSQL(TBase)(腾讯云) 磐维数据库磐维数据库(中国移动) 中国联通cudbCUDB(中国联通) 沐融信息科技MuDB(沐融) 北京酷克数据HashData(酷克) 热璞HotDB(热璞) 优炫UXDB(优炫) 星环KunDB(星环) StarDBStarDB(京东) YiDBYiDB(天翼数智) UbiSQLUbiSQL(平安科技) 华胜信泰xigemaDB(华胜信泰) 星瑞格SinoDB(星瑞格) CockroachDBCockroachDB InfluxDBInfluxDB InformixInformix MongoDBMongoDB MogoDBMogoDB RethinkDBRethinkDB SAP HANASAP HANA voltdbvoltdb voltdbApache Ignite voltdbApache Doris

没有示例的看这个目录下有没有 【anyline-data-jdbc-dialect】还没有的请联系群管理员

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2015 anyline_core Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

基于spring生态的D-ORM,兼容各种小众国产数据库。运行时动态注册切换数据源,生成DDL/DML。读写元数据。常用于动态场景的底层支持,如:数据中台、可视化、低代码后台、工作流、自定义表单、异构数据库迁移同步、物联网车联网数据处理、数据清洗、运行时自定义报表/查询条件/数据结构、爬虫数据解析等,只需要一个注解即可与spring完美整合。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/linhaisongtao/anyline.git
git@gitee.com:linhaisongtao/anyline.git
linhaisongtao
anyline
anyline
master

搜索帮助