125 Star 398 Fork 94

drinkjava2 / jSqlBox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README_ENG.md 6.38 KB
一键复制 编辑 原始数据 按行查看 历史
drinkjava2 提交于 2022-04-07 01:04 . 5.0.13.jre8 release

jsqlbox-logo

Java persistence tool Java

maven code style

Intro

jSqlBox is a DAO tool based on Apache-commons-DbUtils core.

Advantages

  • Excellent architecture: Modular architecture, each module can be separated from jSqlBox alone.
  • Cross-database: Based on jDialects, support pagination、functions translating, and DDL output for more than 70 kinds of databases.
  • Small size: All dependent packages total about 500k.
  • Compatible with DbUtils: Inherited from DbUtils, the original DbUtils-based project can be seamlessly upgrade to jSqlBox.
  • Multiple SQL methods: Inline method, template method, DataMapper, ActiveRecord, chaining, query, etc.
  • A number of technical innovations: Inline writing, multi-line text support, NoSQL query, ActiveRecord, and SqlMapper fit.
  • Dynamic Configuration: In addition to support annotation configuration, jSqlBox also supports dynamic configuration changes at runtime.
  • No session design: Sessionless, a truly lightweight tool
  • Comes with declarative transaction: based on the independent declarative transaction tool jTransactions, and can be configured as a Spring transaction.
  • Smooth learning curve: Modular learning, understanding of the various sub-modules, to master the jSqlBox, jSqlBox main body only more ~30 classes.

Documentation

Chinese中文 | English User Manual | JavaDoc

Download

Maven site

<dependency>
   <groupId>com.github.drinkjava2</groupId>
   <artifactId>jsqlbox</artifactId>
   <version>5.0.13.jre8</version> <!--Or newest version-->
</dependency> 

First Example

pom.xml:
    <dependency>
      <groupId>com.github.drinkjava2</groupId>
       <artifactId>jsqlbox</artifactId> 
       <version>5.0.13.jre8</version> <!-- Java8 -->
    </dependency>

    <dependency>
      <groupId>com.h2database</groupId> <!--H2 database->
      <artifactId>h2</artifactId>  
      <version>1.3.176</version>
    </dependency>

And create below java file in Eclipse or Idea:

import javax.sql.DataSource;
import org.h2.jdbcx.JdbcConnectionPool;
import static com.github.drinkjava2.jsqlbox.DB.*;
import com.github.drinkjava2.jdialects.annotation.jdia.UUID25;
import com.github.drinkjava2.jdialects.annotation.jpa.Id;
import com.github.drinkjava2.jsqlbox.ActiveEntity;
import com.github.drinkjava2.jsqlbox.DB;
import com.github.drinkjava2.jsqlbox.DbContext;

public class HelloWorld implements ActiveEntity<HelloWorld> {
  @Id
  @UUID25
  private String id;
  private String name;
  public String getId() {return id;}
  public void setId(String id) {this.id = id;}
  public String getName() {return name;}
  public HelloWorld setName(String name) {this.name = name;return this;}

    public static void main(String[] args) {
     DataSource ds = JdbcConnectionPool  
                     .create("jdbc:h2:mem:demo;MODE=MYSQL;TRACE_LEVEL_SYSTEM_OUT=0", "sa", "");
     DbContext ctx = new DbContext(ds);
     ctx.setAllowShowSQL(true); 
     DbContext.setGlobalDbContext(ctx);  
     ctx.quiteExecute(ctx.toDropAndCreateDDL(HelloWorld.class));  
     ctx.tx(() -> { 
        HelloWorld h = new HelloWorld().setName("Foo").insert().putField("name", "Hello jSqlBox").update();
        System.out.println(DB.qryString("select name from HelloWorld where name like", que("H%"),
					" or name=", que("1"), " or name =", que("2")));
        h.delete(); 
     });
     ctx.executeDDL(ctx.toDropDDL(HelloWorld.class)); 
   }
}

Below is the log output:

SQL: drop table HelloWorld if exists
PAR: []
SQL: create table HelloWorld ( id varchar(250),name varchar(250), primary key (id))
PAR: []
SQL: insert into HelloWorld (name, id)  values(?,?)
PAR: [Foo, emeai4bfdsciufuuteb9a7nmo]
SQL: update HelloWorld set name=?  where id=?
PAR: [Hello jSqlBox, emeai4bfdsciufuuteb9a7nmo]
SQL: select name from HelloWorld where name like? or name=? or name =?
PAR: [H%, 1, 2]
SQL: delete from HelloWorld where id=? 
PAR: [emeai4bfdsciufuuteb9a7nmo]
SQL: drop table HelloWorld if exists
PAR: []

More documents please see wiki.

Demo

Related Other Projects

Futures

Welcome post issue or submit PR, to help improve jSqlBox

License

Apache 2.0

About Me

Github
码云

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/drinkjava2/jsqlbox.git
git@gitee.com:drinkjava2/jsqlbox.git
drinkjava2
jsqlbox
jSqlBox
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891