SQL was never meant to be abstracted. To be confined in the narrow boundaries of heavy mappers, hiding the beauty and simplicity of relational data. SQL was never meant to be object-oriented. SQL was never meant to be anything other than… SQL!
翻译过来就是说:
SQL 从来就不是抽象的.被限制在mappers 的狭窄的区域中,被隐藏了数据关联的美丽和简单
SQL 从来就不是面向对象的.
SQL 从来就不是任何东西, 除了 SQL!
好吧这么一看,喷了很多框架啊,哈哈哈开发者个性我喜欢
jOOQ 的不同
jOOQ has originally been created as a library for complete abstraction of JDBC and all database interaction. Various best practices that are frequently encountered in pre-existing software products are applied to this library. This includes:
- Typesafe database object referencing through generated schema, table, column, record, procedure, type, dao, pojo artefacts (see the chapter about code generation) 通过生成的模式、表、列、记录、过程、类型、dao和pojo构件引用类型安全数据库对象
- Typesafe SQL construction / SQL building through a complete querying DSL API modelling SQL as a domain specific language in Java (see the chapter about the query DSL API) 类型安全SQL构建/ SQL构建通过一个完整的查询DSL API建模的SQL
- Convenient query execution through an improved API for result fetching (see the chapters about the various types of data fetching) 通过改进的用于结果获取的API方便地执行查询
- SQL dialect abstraction and SQL clause emulation to improve cross-database compatibility and to enable missing features in simpler databases (see the chapter about SQL dialects) SQL方言抽象和SQL子句模拟,以提高跨数据库兼容性,并在更简单的数据库中启用缺少的特性
- SQL logging and debugging using jOOQ as an integral part of your development process (see the chapters about logging) SQL日志记录和调试
Effectively, jOOQ was originally designed to replace any other database abstraction framework short of the ones handling connection pooling (and more sophisticated transaction management) 实际上,jOOQ最初的设计是为了取代除处理连接池之外的任何其他数据库抽象框架
好,很棒
使用 jOOQ 的几种方式
- Using Hibernate for 70% of the queries (i.e. CRUD) and jOOQ for the remaining 30% where SQL is really needed
- Using jOOQ for SQL building and JDBC for SQL execution
- Using jOOQ for SQL building and Spring Data for SQL execution
- Using jOOQ without the source code generator to build the basis of a framework for dynamic
<generator> <!-- The default code generator. You can override this one, to generate your own code style. Supported generators: - org.jooq.util.JavaGenerator - org.jooq.util.ScalaGenerator Defaults to org.jooq.util.JavaGenerator --> <name>org.jooq.util.JavaGenerator</name>
<database> <!-- The database type. The format here is: org.util.[database].[database]Database --> <name>org.jooq.util.mysql.MySQLDatabase</name>
<!-- The database schema (or in the absence of schema support, in your RDBMS this can be the owner, user, database name) to be generated --> <inputSchema>library</inputSchema>
<!-- All elements that are generated from your schema (A Java regular expression. Use the pipe to separate several expressions) Watch out for case-sensitivity. Depending on your database, this might be important! --> <includes>.*</includes>
<!-- All elements that are excluded from your schema (A Java regular expression. Use the pipe to separate several expressions). Excludes match before includes, i.e. excludes have a higher priority --> <excludes></excludes> </database>
<target> <!-- The destination package of your generated classes (within the destination directory) --> <!-- 生成的包名,生成的类在此包下 --> <packageName>zone.yiqing.learnjooq.generated</packageName>
<!-- The destination directory of your generated classes. Using Maven directory layout here --> <!-- 输出的目录 --> <directory>/Users/yiqing/Documents/programming/projects/learn-jooq/src/main/java</directory> </target> </generator> </configuration>
// Connection is the only JDBC resource that we need // PreparedStatement and ResultSet are handled by jOOQ, internally try (Connectionconn= DriverManager.getConnection(url, userName, password)) { // ... } // For the sake of this tutorial, let's keep exception handling simple catch (Exception e) { e.printStackTrace(); } }
}
查询
使用 jOOQ 的 DSL 构建一个简单查询
1 2
DSLContextcreate= DSL.using(conn, SQLDialect.MYSQL); Result<Record> result = create.select().from(AUTHOR).fetch();