1 Star 0 Fork 725

ruanyh / anyline

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

8.3.8之前提交历史记录查看https://github.com/anylineorg/anyline-history.git

快速开始请参考示例代码:
https://gitee.com/anyline/anyline-simple

AnyLine的核心是一个基于spring-jdbc生态的快捷数据库操作工具
摒弃了各种繁琐呆板的Service/Dao/Entity/*O/Mapper 没有mybatis 没有各种配置 各种O
以最简单+快速的方式操作数据库,并针对结果集附加了数据的二次处理功能

适用场景

适合于抽象设计阶段(实体概念还不明确或者设计不限于某个特别的实体)
常用于需要动态结构的场景
特别适合于需要大量复杂动态的查询,以及查询的结果集需要经过深度处理的场景
如:可视化数据源、低代码后台、物联网数据处理、数据清洗、报表输出、运行时自定义表单/查询条件/数据结构等

不适用场景

对已经非常明确的实体执行增删改查操作
不要跨过设计人员直接拿给业务开发人员用

如何使用

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

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

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

返回的DataSet上附加了常用的数据二次处理功能如:排序、维度转换、截取、去重、方差、偏差、交集合集差集、分组、
行列转换、类SQL过滤筛选(like,eq,in,less,between...)、JSON、XML格式转换等

如何集成

只需要一个依赖、一个注解即可实现与springboot,netty等框架项目完美整合
直接看代码【anyline-simple-hello】
生产环境可以参考这几个pom
【anyboot-start】 没有web环境,如定时任务,爬虫等
【anyboot-start-mvc】 基于spring-mvc
【anyboot-start-mvc-mysql】 基于spring-mvc MySQL数据库
【anyboot-start-mvc-jsp-mysql】 基于spring-mvc MySQL数据库 支持JSP
以下可以略过

根据数据库类型添加依赖,如

<dependency>
    <groupId>org.anyline</groupId>
    <artifactId>anyline-jdbc-mysql(oracle|clickhouse...)</artifactId>
    <version>8.5.3-20220630</version>
</dependency>

在需要操作数据库的地方注入AnylineService

@Qualifier("anyline.service")
protected AnylineService service;

接下来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根据约定自动生成的查询条件")); 

实战对比

在理想的HelloWord环境下,任何方式都可以快速实现目标,更能体现优劣的是复杂多变的实战环境。

 首先要承认银弹是没有的,所以先说 劣势

  • 在增、删、改、查4个过程中,增的环境劣势比较明显
  • 操作查询结果时,不能像Entity一样有IDE的提示和自动补齐,减少了IDE的协助确实让许多人寸步难行,
    大部分人也是在这里被劝退的。
  • 在插入数据时,不能像像Entity一样:userService.save(user),而是需要指定表名:service.save(HR_USER, row);

  以上问题如果平衡的

  • AnyLine返回的结果集与Entity之间随时可以相互转换,也可以在查询时直接返回Entity

 有思想的程序员会想为何要造个轮子 可靠吗,所以再说 疑问

  • AnylineLine并非新造了一个轮子,只是简单的把业务参数传给了底层的spring-jdbc
    接下来的操作(如事务控制、连接池等)完全交给了spring-jdbc(没有能力作好的事我们不作)

  • 如果非要说是一个新轮子,那只能说原来的轮子太难用,太消耗程序员体力了。
    正事还没开始就先生成一堆的mapper,OOO,各种铺垫
    铺垫完了要操作数据实现业务了,依然啰嗦,各种 劳力 不劳心 的遍历及加减乘除

 所以重点说 优势

  1. 关于查询条件

    这是开发人员最繁重的体力劳动之一
    接收参数、验证、格式化、层层封装传递到mapper.xml,再各种判断、遍历就为生成一条SQL
    下面的这些标签许多人可能感觉习以为常了

 <if test="code != null and code != '' ">
    AND CODE = #{code}
 </if>

 <if test="name != null and name != '' ">
  AND NAME like concat('%',#{name},'%')
</if>

<if test="types != null and types.size > 0 ">
    AND TYPE IN
    <foreach collection="types" item="type" open="(" close=")" separator=",">
        #{type}
    </foreach>
</if>
但这并不正常,这期间还有什么是必须程序员参的,程序员不参与就自动不了,就约定不了的吗?
  
换一种方式处理:  
不要mapper.xml了,也更不要定位SQL的ID的
    
直接在java中这样处理,其他的交给工具        
condition("CODE:code","NAME:name%", "TYPE:[type]")   

    这应该不需要注释了,更多的约定可以参考这里的【约定规则】

  2. 结果集的二次操作

    这是开发人员最繁重的劳动之二
    从数据库中查询出数据后,根据业务需求还需要对结果集作各种操作,最简单的如加减乘除、交集差集、筛选过滤等
    这些常见的操作DataSet中都已经提供默认实现了,如ngl表达式、聚合函数、类SQL筛选过滤、维度转换等。

 3. 关于动态数据结构

    这里要说的数据结构也就是数据库查询后返回的结果集,常用的数据结构有两种
    1).DataRow类似于一个Map
    2).DataSet是DataRow的集合,并内含了分页信息

    以下场景中将逐步体现出相对于List,Entity的优势
    1). 最常见的如更新或查询部分列
        DataRow row = service.query("HR_USER(ID,CODE)")
        service.update(row,"CODE")

    2).可视化数据源、报表输出、数据清洗
        这些场景下都需要的数据结构都是灵活多变的
        经常是针对不同的业务从多个表中合成不同的结构集
        甚至是运行时根据用户输入动态结合的结构集
        输出结果集后又需要大量的对比及聚合操作
        这种情况下显示不可能为每个结果集生成一个对应Entity,只能是动态的Map结构
        在对结构集的二次操作上,DataRow/DataSet可以在抽象设计阶段就完成,而Entity却很难                           

    3).低代码后台、元数据管理
        作为一个低代码的后台,首先需要具体灵活可定制的表结构(通常会是一个半静半动的结构)
        我们将不再操作具体的业务对象与属性。对大部分业务的操作都只能通过抽象的元数据进行。
        举例来说一个简单的求和过程,原来在对静态结构时常用的的遍历、Lamda、反射都难堪重任了。
        我们能接收到的信息通常是这样的:类型(学生)、属性(年龄)、条件(年级=1)、聚合公式(平均值)
        Anyline的实现过程类似这样
        DataSet set = service.querys(学生,年级=1);
        int 平均年龄 = set.agg(平均值,年龄);

    4).运行时自定义表单、查询条件
        许多情况下我们的基础版本产品,很难满足用户100%的需求,
        而这些新需求又大部分是一些简单的表单、查询条件
        如果是让程序员去开发一个表单,添加几个查询条件,那确实很简单
        但用户不是程序员,我们也不可能为每个用户提供全面全天候的技术支持
        考虑到成本与用户体验的问题通常会给用户提供一个自定义表单与查询条件的功能
        自定义并不难,难的是对自定义表单的存储、查询、关联,以及对自定义查询条件的支持
        与上一条说的元数据管理一样,我们在代码实现环节还是不知道会有什么对象什么属性
        当然也更不会有对应的service, dao, mapper, VO/DTO/BO/DO/PO/POJO
        Anyline的动态查询类似这样实现
        service.query(类型(属性集合),condition().add('对比方式','属性','值');

    5).物联网环境(特别是像Cassandra、ClickHouse等列式数据库 InfluxDB、TimescaleDB等时序数据库)
        与低代码平台类似都需要一种动态的结构,并且为了数据读取的高效,数据在水平方向上变的更分散。
        这与最终用户需要显示的格式完全不一样,直接通过数据库查询出来的原始数据通常是类似这样

时间戳 KEY VALUE
1657330073131 LAT 39.917055
1657330073131 LNG 116.392191
1657330073132 LAT 39.917055
1657330073132 LNG 116.392191
1657330073133 LAT 39.917055
1657330073134 LNG 116.392191

         而最终展示的界面可能是这样:

时间戳 LNG LAT
1657330073131 116.392191 39.917055
1657330073131 116.392191 39.917055
日期(向下合并) 时间点1(向右合并) 时间点2(向右合并) 时间点...N
LNG LAT LNG LAT LNG LAT
01-01 116.392191 39.917055 116.392191 39.917055 116.392191 39.917055
01-02 116.392191 39.917055 116.392191 39.917055 116.392191 39.917055

        当然实战中会比这更复杂,历经实战的程序员一定体验过什么是千变万化、什么是刁钻苛刻
        数据库中将不再有一一对应的hello表格,java中也没有对应的Entity
        可以想像的出来基于一个静态结构或者原始的Map,List结构需要程序员负责多少体力
        要在这个基础上实现让用户自定义报表,那可能比把用户培养成一个程序员还要困难

        而一个有思想的程序员应该会把以上问题抽象成简单的行列转换的问题
        并在项目之前甚至没有项目的时候就已经解决之。
        各种维度的转换可以参考DataSet.pivot()的几个重载 或示例代码 anyline-simple-result

                                   

    6).关于分页查询的数据存储结构

         通过默认的方式查询
  • 如果没有分页 可以通过DataSet结构接收数据
  • 如果有分页了 可以通过DataSet结构接收数据
  • 不同的是分页后DataSet.PageNavi中会嵌入详细的分页信息
         通过User.class查询数据时
  • 如果没有分页 可以通过List<User>>结构接收数据
  • 如果有分页了 那需要通过Page<List<User>>结构接收数据
  • 简单查询个部门列表,还要根据分不分页写两个接口吗

    7).数据加密
    对于需要加密的数据经常会遇到数字类型的ID
                                                     

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-jdbc生态的(No-ORM)DBUtil,没有繁琐的Service/Dao/Mapper及各种配置各种O,适合于抽象设计阶段,常用于动态结构的场景,如:可视化数据源、低代码后台、物联网数据处理、数据清洗、报表输出、运行时自定义表单、查询条件及数据结构等,只需要一个注解即可与springboot,mvc等框架项目完美整合。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助