Java的ORM框架 jOOQ 1.6.8 發布

jopen 13年前發布 | 12K 次閱讀 Java ORM

jOOQ 高效的合并了復雜SQL、類型安全、源碼生成、Active Records、存儲過程以及高級數據類型的 Java 類庫。

示例代碼:

Result<Record> result =
create.select(FIRST_NAME, LAST_NAME, create.count())
      .from(AUTHOR)
      .join(BOOK).on(Author.ID.equal(Book.AUTHOR_ID))
      .where(LANGUAGE.equal("DE"))
      .and(PUBLISHED.greaterThan(parseDate('2008-01-01')))
      .groupBy(FIRST_NAME, LAST_NAME)
      .having(create.count().greaterThan(5))
      .orderBy(LAST_NAME.asc().nullsFirst())
      .limit(2)
      .offset(1)
      .forUpdate()
      .of(FIRST_NAME, LAST_NAME)
      .fetch();

jOOQ 1.6.8 發布了,該版本重新設計了存儲過程和函數 API 。
項目地址: http://sourceforge.net/apps/trac/jooq

What's jOOQ

jOOQ stands for Java Object Oriented Querying. It combines these essential features:

  • Code Generation:
    jOOQ generates a simple Java representation of your database schema. Every table, view, stored procedure, enum, UDT is a class.

  • Active records:
    jOOQ implements an easy-to-use active record pattern. It is NOT an OR-mapper, but provides a 1:1 mapping between tables/views and classes. Between columns and members.

  • Typesafe SQL:
    jOOQ allows for writing compile-time typesafe querying using its built-in DSL.

  • SQL standard:
    jOOQ supports all standard SQL language features including the more complex UNION's, nested SELECTs, joins, aliasing

  • Vendor-specific feature support:
    jOOQ encourages the use of vendor-specific extensions such as stored procedures, UDT's and ARRAY's, recursive queries, and many more.

How does jOOQ help you?

  • Your database always comes FIRST! That's where the real schema is, not in your Java code or some XML mapping file.
  • Your schema is generated in Java. You can use auto-completion in your IDE!
  • Your "value objects" or "data transfer objects" are generated too. This keeps things DRY
  • Your Java code won't compile anymore when you modify your schema. That means less runtime errors.
  • You and your DBA can be friends again because you have full control over your SQL.
  • You can port your SQL to a new database. jOOQ will generate SQL that works on any database.
  • You won't have syntax errors in your query.
  • You won't forget to bind variables correctly. No SQL injection, either.
  • You can forget about JDBC's verbosity (especially useful when dealing with UDTs, ARRAYs and stored procedures).

Or in short:

  • You can be productive again!

When to use jOOQ

  • When you love your RDBMS of choice, including all its vendor-specific features.
  • When you love control over your code.
  • When you love the relational data model (read this interesting article).
  • When you love SQL.
  • When you love stored procedures.
  • When you love both OLAP and OLTP

When not to use jOOQ

On the other hand, many people like the ease of use of Hibernate or other products, when it comes to simply persisting any domain model in any database. You should not use jOOQ...

  • When you don't care about your database (or "persistence" as you would probably call it).
  • When you don't really need SQL.
  • When you want to map your object-oriented domain model to a database and not vice versa.
  • When your schema changes more frequently than you can re-deploy jOOQ-generated source code.
  • When you need to write DDL statements. jOOQ only supports DML statements.

What databases are supported

Every RDMBS out there has its own little specialties. We consider those specialties as much as possible, while trying to standardise the behaviour in jOOQ. In order to increase the quality of jOOQ, we run unit tests for syntax and variable binding verification, as well as integration tests for any of these databases:

  • DB2 9.7 (v9.7 is strongly recommended. we have known issues such as #172 for v9.5)
  • Derby 10.8
  • H2 1.3.155
  • HSQLDB 2.2.1
  • Ingres 10.1.0
  • MySQL 5.1.41 and 5.5.8
  • Oracle XE 10.2.0.1.0
  • PostGreSQL 9.0
  • SQLite with inofficial JDBC driver v056
  • SQL Server 2008 R8
  • Sybase Adaptive Server Enterprise 15.5
  • Sybase SQL Anywhere 12

Please report any issues you might have with other database versions.

Planned (Contributions and suggestions welcome!):

Other requirements

  • jOOQ runs with Java 1.6+

License

jOOQ is licensed under the Apache Software License 2.0

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!