Skip to content

icuter/jsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSQL

License

MIT licensed.

Abstract

Welcome to JSQL. It's a lightweight JDBC DSL framework, JSQL means Just SQL and without ORM configuration. It is a framework which is convenience and easy to use, just like sql syntax that you feel free to write SQL as usual and makes Java SQL development more easier.

If you are a Java developer searching for the jdbc framework satisfy functions as connection pool, super lightweight orm and want to write sql like java code programing, then I suggest you could try to use JSQL framework for jdbc operation.

JSQL for Reasons:

  • No SQL string and keep your code graceful
  • No ORM bean code generation mass your git control
  • Provide ExecutorPool/ConnectionPool for jdbc connection pooling without DBCP dependencies

Requirements

  • JDK6 or higher

Features

  1. Connection/JdbcExecutor pool
  2. SQL syntax like builder
  3. Transaction
  4. Support customizing dialects
  5. Pagination
  6. Jdbc executor for query, update or batch update
  7. Super lightweight ORM
  8. Against SQL inject
  9. Logging ability

Support Databases

  1. Cubrid
  2. SQLite
  3. DB2
  4. Derby (EmbeddedDerby/NetworkDerby)
  5. H2
  6. MariaDB
  7. MySQL
  8. Oracle
  9. PostgreSQL
  10. SQLServer2012(version >= 2012)

Quick Start

Maven dependency

<!-- for jdk1.8+ -->
<dependency>
  <groupId>cn.icuter</groupId>
  <artifactId>jsql</artifactId>
  <version>1.1.2</version>
</dependency>

<!-- for jdk1.6+ -->
<dependency>
  <groupId>cn.icuter</groupId>
  <artifactId>jsql-jdk1.6</artifactId>
  <version>1.1.2</version>
</dependency>

Examples

Auto Commit

JSQLDataSource dataSource = JSQLDataSource.newDataSourceBuilder()
                            .url("jdbcUrl").user("jsql").password("pass").build();
List<Map<String, Object>> list = dataSource.select()
                                           .from("table")
                                           .where().eq("name", "jsql")
                                           .execQuery();
SQL: select * from table where name = ?
Value: [jsql]

Transaction

JSQLDataSource dataSource = JSQLDataSource.newDataSourceBuilder()
                            .url("jdbcUrl").user("jsql").password("pass").build();
dataSource.transaction(tx -> {
    tx.insert("table")
      .values(Cond.eq("col1", "val1"), Cond.eq("col2", 102),Cond.eq("col3", "val3"))
      .execUpdate();
    // if exception thrown will call tx.rollback()
    // tx.commit(); // auto commit if transaction ended
});
SQL: insert into table(col1,col2,col3) values(?,?,?)
VALUE: ["val1", 102, "val3"]

Using standalone Transaction to control commit or rollback operation as your favour

JSQLDataSource dataSource = JSQLDataSource.newDataSourceBuilder()
                            .url("jdbcUrl").user("jsql").password("pass").build();
TransactionDataSource tx = dataSource.transaction();
tx.insert("table")
  .values(Cond.eq("col1", "val1"), Cond.eq("col2", 102),Cond.eq("col3", "val3"))
  .execUpdate();
tx.close(); // auto commit
SQL: insert into table(col1,col2,col3) values(?,?,?)
VALUE: ["val1", 102, "val3"]

NOTE

Above examples are using JSQLDataSource inner Connection pool to execute SQL generated by JSQL.

Documents

Find more documentation here.

  1. DataSource
  2. JDBC Connection Pool
  3. Transaction
  4. SQL Builder
  5. Condition
  6. DB Dialect
  7. ORM
  8. SQL Executor
  9. Logging Customization

Release Notes

1.1.2

performance

  • remove Injection's read lock and add snapshot root node for improvement

features

  • use builder patterns to create JSQLDatasource more easier

others

  • update checkstyle version
  • simplify Test Unit Exception checking with Lamda

1.1.1

bug fixes

  • fix ReentrantLock.lock() prior to try-finally block
  • fix bugs which have been detected by FindBugs tools

performance

  • optimize scheduled task checking and invalidation

1.1.0

bug fixes

  • fix fields injection

performance

  • optimize injection checking
  • avoid inflating schedule tasks

1.0.9

bug fixes

  • fix idle object schedule thread can't shutdown immediately

1.0.8

features

  • support validating field name and table name injection

1.0.7

bug fixes

  • fix NPE while checking idle object

1.0.6

bug fixes

  • fix top-select in SelectBuilder.select

features

  • support transaction in JSQLDataSource
  • support insert... select... syntax
  • support Driver properties when getting Connection from Driver

1.0.4

bug fixes

  • fix pool configuration

features

  • execute builder directly in JSQLDataSource
  • refactor Connection object idle timeout validation

jsql-jdk1.6 missing this version

1.0.3

breaks

  • Remove Builder.union and Builder.unionAll operation

bug fixes

  • fix OracleDialect invalid table alias name format
  • fix DB2Dialect invalid table alias name format

features

  • Add builder as Condition value
  • Add UnionSelectBuilder for union/unionAll operation

jsql-jdk1.6 missing this version