HasorDB is a fully functional database access tool

HasorDB is a fully functional database access tool

2022-09-05 0 554
Resource Number 38208 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

The HasorDB recommended in this issue is a full-featured database access tool that provides object mapping, rich type handling, dynamic SQL, stored procedures, built-in pagination dialects of 20+, support for nested transactions, multiple data sources, condition constructors, POST strategies, and multiple statements/results.

4d5dad793b5b41b7b126faccab25c398noop.image_

introduce

HasorDB is a full-featured database access tool that provides object mapping, rich type handling, dynamic SQL, stored procedures, built-in pagination dialects of 20+, support for nested transactions, multiple data sources, conditional constructors, POST policies, and multiple statements/results. And compatible with Spring and MyBatis usage. It does not rely on any other framework, so it can be easily integrated with any framework for use.

function characteristics

Familiar way

  • JdbcTemplate interface method (highly compatible with Spring JDBC)Mapper file format (highly compatible with MyBatis)LambdaTemplate (highly similar to MyBatis Plus, jOOQ, and BeetlSQL)@Insert, @ Update, @ Delete, @ Query, @ Callable annotations (similar to JPA)

transaction support

  • Supports 5 transaction isolation levels and 7 transaction propagation behaviors (the same as Spring tx)Provide TransactionTemplate and TransactionManager interface with declarative transaction control capability (same usage as Spring)

Featured advantages

  • Support pagination queries and provide multiple database dialects (20+)Support Insert strategy (Into, Update, IGNORE)More comprehensive TypeHandler options (MyBatis 40+, HasorDB 60+)Mapper XML supports multiple statements and multiple results

    Provide a unique @ {xxx, expr, xxxxx} rule extension mechanism to make dynamic SQL simpler

    Support stored procedures

    Supports time types in JDBC 4.2 and Java 8

    Support multiple data sources

quick start

Introducing Dependency

<dependency>
  <groupId>net.hasor</groupId>
  <artifactId>hasor-db</artifactId>
  <version>4.3.0</version><!-- Check out the latest version:https://mvnrepository.com/artifact/net.hasor/hasor-db -->
</dependency>

Introduce database drivers, such as MySQL drivers

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.22</version>
</dependency>

Using HasorDB does not rely on database connection pools, but having a database connection pool is standard for most projects. We use Alibaba’s Druid here

<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>druid</artifactId>
  <version>1.1.23</version>
</dependency>

Finally, prepare a database table and initialize some data (CreateDB. sql file)

drop table if exists `test_user`;
create table `test_user` (
    `id`          int(11) auto_increment,
    `name`        varchar(255),
    `age`         int,
    `create_time` datetime,
    primary key (`id`)
);

insert into `test_user` values (1, 'mali', 26, now());
insert into `test_user` values (2, 'dative', 32, now());
insert into `test_user` values (3, 'jon wes', 41, now());
insert into `test_user` values (4, 'mary', 66, now());
insert into `test_user` values (5, 'matt', 25, now());

Using DAO

Using DAO can inherit the BaseMapper<T>generic DAO interface to complete some basic operations, still taking single table CRUD as an example

/Some interfaces of DAO need to recognize the ID attribute, so it is necessary to mark them on the DTO object with the @ Column annotation


@Table(mapUnderscoreToCamelCase = true)
public class TestUser {
@Column(primary = true)
private Integer id;
private String name;
private Integer age;
private Date createTime;

// getters and setters omitted
}

//Creating a data source data mining tutorial
DataSource dataSource = DsUtils.dsMySql();
//Create a universal DAO
DalSession session = new DalSession(dataSource);
BaseMapper<TestUser> baseMapper = session.createBaseMapper(TestUser.class);
// Initialize some data
baseMapper.template().loadSQL(“CreateDB.sql”);

// Query data
List<TestUser> dtoList = baseMapper.query().queryForList();
PrintUtils.printObjectList(dtoList);

// Insert new data
TestUser newUser = new TestUser();
newUser.setName(“new User”);
newUser.setAge(33);
newUser.setCreateTime(new Date());
int result = baseMapper.insert(newUser);

//Update, update the name from mali to mala.
TestUser sample = baseMapper.queryById(1);
sample.setName(“mala”);
int result = baseMapper.updateById(sample);

// Delete data with ID 2.
int result = baseMapper.deleteById(2);

Using Mapper

The best place for unified management of SQL is still the Mapper file, and HasorDB’s Mapper file is highly compatible with MyBatis, with extremely low learning costs

//Use @ RefMapper annotation to link Mapper files with interface classes (inheriting BaseMapper is optional)


@RefMapper("/mapper/quick_dao3/TestUserMapper.xml")
public interface TestUserDAO extends BaseMapper<TestUser> {
public int insertUser(@Param("name") String name, @Param("age") int age);

public int updateAge(@Param(“id”) int userId, @Param(“age”) int newAge);

public int deleteByAge(@Param(“age”) int age);

public List<TestUser> queryByAge(@Param(“beginAge”) int beginAge, @Param(“endAge”) int endAge);
}

To better understand and use HasorDB’s Mapper file, it is recommended to add DTD for validation. In addition, HasorDB is compatible with MyBatis3’s DTD and is compatible with the vast majority of MyBatis projects

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//hasor.net//DTD Mapper 1.0//EN" "https://www.hasor.net/schema/hasordb-mapper.dtd">
<mapper namespace="net.hasor.db.example.quick.dao3.TestUserDAO">
  <resultMap id="testuser_resultMap" type="net.hasor.db.example.quick.dao3.TestUser">
    <id column="id" property="id"/>
    <result column="name" property="name"/>
    <result column="age" property="age"/>
    <result column="create_time" property="createTime"/>
  </resultMap>
  
  <sql id="testuser_columns">
    name,age,create_time
  </sql>
  
  <insert id="insertUser">
    insert into `test_user` (
      <include refid="testuser_columns"/>
    ) values (
      #{name}, #{age}, now()
    )
  </insert>
  
  <update id="updateAge">
    update `test_user` set age = #{age} where id = #{id}
  </update>
  
  <delete id="deleteByAge"><![CDATA[
    delete from `test_user` where age > #{age}
  ]]></delete>
  
  <select id="queryByAge" resultMap="testuser_resultMap">
    select id,<include refid="testuser_columns"/>
    from `test_user`
    where  #{beginAge} < age and age < #{endAge}
  </select>
</mapper>

Using Transactions

HasorDB provides three ways to use transactions, namely:

  • Declarative transactions implement transaction control by calling the TransactionManager interface.
  • Template transactions are controlled through the TransactionTemplate interface.
  • Annotation transaction, annotation transaction control based on @ Transaction (under development…)
资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code HasorDB is a fully functional database access tool https://ictcoder.com/kyym/hasordb-is-a-fully-functional-database-access-tool.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service