All Projects → michaelliao → warpdb

michaelliao / warpdb

Licence: Apache-2.0 license
DSL-driven RDBMS interface for Java.

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to warpdb

java
📚 Recursos para aprender Java
Stars: ✭ 31 (-57.53%)
Mutual labels:  jdbc
database-metadata-bind
A library for binding information from java.sql.DatabaseMetadata
Stars: ✭ 17 (-76.71%)
Mutual labels:  jdbc
mydataharbor
🇨🇳 MyDataHarbor是一个致力于解决任意数据源到任意数据源的分布式、高扩展性、高性能、事务级的数据同步中间件。帮助用户可靠、快速、稳定的对海量数据进行准实时增量同步或者定时全量同步,主要定位是为实时交易系统服务,亦可用于大数据的数据同步(ETL领域)。
Stars: ✭ 28 (-61.64%)
Mutual labels:  jdbc
dogETL
A lib to transform data from jdbc,csv,json to ecah other.
Stars: ✭ 15 (-79.45%)
Mutual labels:  jdbc
komapper
Kotlin SQL Mapper
Stars: ✭ 28 (-61.64%)
Mutual labels:  jdbc
sqlite-jna
Java wrapper and Jdbc driver for SQLite using JNA or Bridj or JNR or JNI or JavaCPP.
Stars: ✭ 20 (-72.6%)
Mutual labels:  jdbc
java-notes
Complete Java Note for colleges in Nepal.
Stars: ✭ 30 (-58.9%)
Mutual labels:  jdbc
spring-data-jdbc-repository
Spring Data JDBC generic DAO implementation in Java (more up-to-date fork)
Stars: ✭ 123 (+68.49%)
Mutual labels:  jdbc
HiveJdbcStorageHandler
No description or website provided.
Stars: ✭ 21 (-71.23%)
Mutual labels:  jdbc
oracle-jdbc-tester
A simple command line Java application to test JDBC connection to Oracle database
Stars: ✭ 37 (-49.32%)
Mutual labels:  jdbc
implyr
SQL backend to dplyr for Impala
Stars: ✭ 74 (+1.37%)
Mutual labels:  jdbc
WarpUI
A warp UI and world UI teleportation plugin that supports rotation and pitch.
Stars: ✭ 14 (-80.82%)
Mutual labels:  warp
JDBCManager
一款操作数据库的小工具
Stars: ✭ 13 (-82.19%)
Mutual labels:  jdbc
wasp
WASP is a framework to build complex real time big data applications. It relies on a kind of Kappa/Lambda architecture mainly leveraging Kafka and Spark. If you need to ingest huge amount of heterogeneous data and analyze them through complex pipelines, this is the framework for you.
Stars: ✭ 19 (-73.97%)
Mutual labels:  jdbc
jdk-source-code-reading
JDK source code reading
Stars: ✭ 19 (-73.97%)
Mutual labels:  jdbc
warpy
A command-line program to get WARP+ as WireGuard written in python
Stars: ✭ 57 (-21.92%)
Mutual labels:  warp
itstack-naive-chat-server
💞 《服务端》| 服务端同样使用Netty4.x作为socket的通信框架,同时在服务端使用Layui作为管理后台的页面,并且我们的服务端采用偏向于DDD领域驱动设计的方式与Netty集合,以此来达到我们的框架结构整洁干净易于扩展。同时我们的通信协议也是在服务端进行定义的,并对外提供可引入的Jar包,这样来保证客户端与服务端共同协议下进行通信。
Stars: ✭ 21 (-71.23%)
Mutual labels:  jdbc
jTDS
jTDS JDBC Driver
Stars: ✭ 67 (-8.22%)
Mutual labels:  jdbc
migrate-Java-EE-app-to-azure
Migrate an existing Java EE workload to Azure
Stars: ✭ 12 (-83.56%)
Mutual labels:  jdbc
tekniq
A framework designed around Kotlin providing Restful HTTP Client, JDBC DSL, Loading Cache, Configurations, Validations, and more
Stars: ✭ 31 (-57.53%)
Mutual labels:  jdbc

warpdb

DSL-driven RDBMS interface for Java:

DEMO

Status:

Maven Status

Github Workflow

Design principles

  • JPA-annotation based configuration.
  • DSL-style API reads like English.
  • Support raw SQL for very complex query.
  • No "attach/dettach".
  • All entities are simple POJOs without proxy-ing.

Database Support

  • MySQL 5.x

Configuration

Maven dependency:

<dependency>
    <groupId>com.itranswarp</groupId>
    <artifactId>warpdb</artifactId>
    <version>5.0.4</version>
</dependency>

Warpdb is built on top of Spring-JDBC. JdbcTemplate or DataSource is required when build warpdb instance:

<bean class="com.itranswarp.warpdb.WarpDb" init-method="init">
    <property name="basePackages">
        <list>
            <value>com.test.product.model</value>
            <value>com.test.order.model</value>
        </list>
    </property>
    <property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>

Or using data source:

<bean class="com.itranswarp.warpdb.WarpDb" init-method="init">
    <property name="basePackages">
        <list>
            <value>com.test.product.model</value>
            <value>com.test.order.model</value>
        </list>
    </property>
    <property name="dataSource" ref="dataSource" />
</bean>

Basic Usage

Fully JPA Annotation Support

Entities are configured with JPA annotation:

@Entity
@Table(name="user")
public class User {
    @Id
    String id;

    @Column(nullable=false)
    String name;
}

Query

Query by primary key:

// get user, or throw EntityNotFoundException if not found:
User user = warpdb.get(User.class, "123");

// get user, or return null if not found:
User another = warpdb.fetch(User.class, "456");

You have to provide multiple values if multiple id columns are defined:

Product p = warpdb.get(Product.class, "p123", "c456);

Warpdb supports criteria query and raw SQL query, both are type-safe:

List<User> users = warpdb.from(User.class)
        .where("name=?", "bob")
        .orderBy("updatedAt").desc()
        .list();

Get first result or null if not found:

User user = warpdb.from(User.class)
        .where("name=?", "bob")
        .orderBy("updatedAt").desc()
        .first();

Query for update:

User user = warpdb.selectForUpdate()
        .where("id=?", 123)
        .first();

Using raw SQL:

List<User> users = warpdb.query("select * from User order by name limit 100");

Paged Query

Warpdb supports paged query by specify page index and page size:

// page 3, 10 items per page:
PagedResults<User> pr = warpdb.from(User.class)
        .orderBy("updatedAt")
        .list(3, 10);
System.out.println(pr.page.pageIndex); // 3
System.out.println(pr.page.itemsPerPage); // 10
System.out.println(pr.page.totalPages); // 92
System.out.println(pr.page.totalItems); // 912
List<User> list = pr.results; // current page items

A paged query will generate 2 SQLs when execute list(pageIndex, pageSize):

SELECT COUNT(*) FROM User;
SELECT * FROM User ORDER BY updatedAt limit 20, 10

Insert

Using insert() to insert one or more entities:

User user = new User();
user.setId(...);
user.setName(...);
Product product = new Product();
product.setId(...);
product.setName(...);
warpdb.insert(user, product);

Batch insert

Using insert(List<T>) to do batch save entities.

Update

Using update() to update one or more entities:

User user = ...
user.setName(...);
Product product = ...
product.setName(...);
warpdb.update(user, product);

Batch update

Using update(List<T>) to do batch update entities.

Remove

Using remove() to remove one or more entities:

User user = ...
Product product = ...
warpdb.remove(user, product);

Batch remove

Using remove(List<T>) to do batch remove entities.

Misc

Enum Support

Enum is stored as VARCHAR(50) in database:

@Entity
public class User {
    RoleEnum role;
}

Attribute Converter

Values used in Java and db can be converted by attribute converter:

@Entity
public class User {
    // stored as "DATE" in db:
    @Convert(converter = LocalDateConverter.class)
    @Column(columnDefinition = "date")
    public LocalDate birth;
}

Listeners

Listeners must be added as entity method with annotation PostLoad, PrePersist, PostPersist, PreUpdate, PostUpdate, PreRemove, PostRemove:

@Entity
public class User {
    @Id
    String id;

    long createdAt;

    @PrePersist()
    public void prePersist() {
        if (this.id == null) {
            this.id = nextId();
        }
        this.createdAt = System.currentTimeMillis();
    }
}

Schema Export

Using getDDL() to export schema:

String ddl = warpdb.getDDL();

or get schema for one entity:

String ddl = warpdb.getDDL(User.class);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].