jade-all

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

Categories

Categories

JADE General Purpose Libraries Utility
GroupId

GroupId

com.github.leixuan6
ArtifactId

ArtifactId

jade-all
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

jade-all
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

https://github.com/LeiXuan6/jade-all

Download jade-all

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.leixuan6/jade-all/ -->
<dependency>
    <groupId>com.github.leixuan6</groupId>
    <artifactId>jade-all</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.leixuan6/jade-all/
implementation 'com.github.leixuan6:jade-all:1.0.3'
// https://jarcasting.com/artifacts/com.github.leixuan6/jade-all/
implementation ("com.github.leixuan6:jade-all:1.0.3")
'com.github.leixuan6:jade-all:jar:1.0.3'
<dependency org="com.github.leixuan6" name="jade-all" rev="1.0.3">
  <artifact name="jade-all" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.leixuan6', module='jade-all', version='1.0.3')
)
libraryDependencies += "com.github.leixuan6" % "jade-all" % "1.0.3"
[com.github.leixuan6/jade-all "1.0.3"]

Dependencies

compile (6)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.5
org.slf4j : log4j-over-slf4j jar 1.7.5
ch.qos.logback : logback-core jar 1.0.13
ch.qos.logback : logback-classic jar 1.0.13
org.apache.commons : commons-dbcp2 jar 2.2.0
mysql : mysql-connector-java jar 5.1.6

test (1)

Group / Artifact Type Version
junit : junit jar 3.8.1

Project Modules

There are no modules declared in this project.

jade-all

Jade,是Java应用程序访问Mysql数据库的一个小框架.

数据库访问流程图


     ,---------------.          ,---.                                           ,----.             ,----------.
     |JavaApplication|          |DAO|                                           |Jade|             |DataServer|
     `-------+-------'          `-+-'                                           `-+--'             `----+-----'
             |                    |                                               |                     |      
             |<------------------>|                                               |                     |      
             |                    |                                               |                     |      
             |                    |        1.Implement jdade specification        |                     |      
             |                    |----------------------------------------------->                     |      
             |                    |                                               |                     |      
             |                    |                                               | 2.Commit sql request|      
             |                    |                                               | -------------------->      
             |                    |                                               |                     |      
             |                    |                                               |   3.Return result   |      
             |                    |                                               | <- - - - - - - - - -       
             |                    |                                               |                     |      
             |                    |4.To convert a database object to a Java object|                     |      
             |                    | according to the DAO specification            |                     |      
             |                    |<- - - - - - - - - - - - - - - - - - - - - - - -                     |      
     ,-------+-------.          ,-+-.                                           ,-+--.             ,----+-----.
     |JavaApplication|          |DAO|                                           |Jade|             |DataServer|
     `---------------'          `---'                                           `----'             `----------'

工程依赖

  • JDK1.7或更高版本
  • Maven3.x
  • MySql数据库服务器

简单调用示例

  • 添加如下依赖:
    <dependency>
        <groupId>com.github.leixuan6</groupId>
        <artifactId>jade-all</artifactId>
        <version>1.0.3</version>
    </dependency>
  • 设置src/main/resource/db.properties文件
    
    driverClassName=com.mysql.jdbc.Driver
    url=jdbc:mysql://127.0.0.1/jade?characterEncoding=UTF-8
    username=root
    password=123456
    maxTotal=1
    maxIdle=1
    maxWait=-1
    
    		
  • 应用层实现DAO规范
  • 调用JadeBootstrap.start方法,传入的路径参数。Jade扫描这个路径下的DAO,Jade会注册这些DAO服务
  • 具体参考org.jade.example目录下的例子

实现Jade的DAO规范


@DAO
public interface AccountDAO {

	@SQL(val = "Select * from Account ", type = SQLType.SELECT)
	Account query();
	
	@SQL(val = "Select * from Account ", type = SQLType.SELECT)
	List queryList();

	@SQL(val="Select * from Account Where id = ?",type = SQLType.SELECT)
	Account queryById(int id);
	
	@SQL(val="Select * from Account Where id =? and name =?",type = SQLType.SELECT)
	Account queryById2(int id, String name);
	
	@SQL(val="Delete From Account where id = ?",type=SQLType.INSERT)
	int deleteById(int id);

	@SQL(val="Update Account set name = ? where id = ?",type = SQLType.UPDATE)
	int updateById(int id,String name);
	
	@SQL(val="Insert into Account()Values(?,?)",type = SQLType.INSERT)
	int insert(int id, String name);
}

Java对象,实现getset方法


public class Account {
	private int id;

	private String name;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Account [id=" + id + ", name=" + name + "]";
	}
}

测试增删改查


public class JadeTest {
	public static void main(String[] args) {
		JadeBootstrap.start("org.jade");
		AccountDAO dao = JadeDAOService.getDao(AccountDAO.class);
		dao.deleteById(1);
		dao.insert(1, "test");
		dao.query();
		dao.queryById(1);
		dao.queryById2(1, "test");
		dao.updateById(1, "test2");
		
	}
}

Versions

Version
1.0.3