JEQUEL - A Domain Specific Language for the Structured Query Language (SQL) embedded in Java                       JEQUEL
Main /

Historie von Main.JEQUEL

Einfache Korrekturen ausblenden - Änderungen im Wiki Quelltext

20.02.2008 00:30 Uhr von mh14 -
Zeilen 15-16 bearbeitet:

I couldn't bear it any longer. So after discussing the idea with my co-workers when leaving I used the spare spare time during my day of this week (after my family went to bed) to start writing an embedded DSL in Java to support the creation of sql query expression tree objects which can be rendered (e.g.) to SQL. The next day I got enthusiastic and excited support and was urged to publish it.

geändert zu:

I couldn't bear it any longer. So after discussing the idea with my co-workers when leaving I used the spare spare time during my day of this week (after my family went to bed) to start writing an embedded DSL in Java to support the creation of sql query expression tree objects which can be rendered (e.g.) to SQL. The next day I got enthusiastic and excited support and was urged to publish it. So, here it is. (Oct. 2007).

04.11.2007 02:54 Uhr von mh14 -
Zeile 5 bearbeitet:

How it all began

geändert zu:

How it all began

04.11.2007 02:54 Uhr von mh14 -
Zeile 84 bearbeitet:
  • Generation during build process, so all code referencing outdated structures won't compile
geändert zu:
  • Generation during build process (ant task), so all code referencing outdated structures won't compile
04.11.2007 02:51 Uhr von mh14 -
Zeilen 4-5 hinzugefügt:

How it all began

Zeilen 59-61 bearbeitet:

Advantages (also see Features):

geändert zu:

Main Points (also see Features):

IDE Support

Zeilen 67-80 bearbeitet:
  • Build Javadoc HTML API Documentation for generated Tables

  • Table declaration classes generated from Database Metadata
    • During build process, so all code referencing outdated structures won't compile
    • Documentation of Tables and Fields using JavaDoc from Database comments
    • Custom enhancers for Table Metadata before file creation possible
      • e.g. include information from ResourceBundles (Translations)
    • create database schema from manually written Table declarations
    • migrate database schemas

  • statements form expression tree
    • custom expressions possible for encapsulating subqueries, custom code, even with parameters
    • own keywords possible
geändert zu:

Expressions

  • build SQL expressions with statically typed java objects and methods
  • (named) parameter (prep.statement) integration
  • dynamic extension of queries
  • query(fragment) repositories
Zeilen 74-75 bearbeitet:
  • TODO: other target languages possible (ejbql, hibernateql, jdoql)
geändert zu:
  • TODO: Query Validation

Execution

  • execute using a fluent language
  • parameter support (either supplied with query or added before execution)
  • Spring JDBC API Support
  • Spring Extensions for additional Callbacks

MetaData Generation

  • Table classes generated from Database Metadata (including comments, relationship-references)
  • Generation during build process, so all code referencing outdated structures won't compile
  • Documentation of Tables and Fields using JavaDoc from Database comments
  • Custom enhancers for Table Metadata before file creation possible
    • e.g. include information from ResourceBundles (Translations)
03.11.2007 23:51 Uhr von mh14 -
Zeilen 32-56 bearbeitet:
geändert zu:

Simple Exampe with Execution, Parameters and BeanRowMapper

(:source lang=java :)

    interface ArticleBean {
        int getArticleNo();
        String getName();
    }

    public void testParameterExample() {
        final Sql sql = Select(ARTICLE.NAME, ARTICLE.ARTICLE_NO)
                .from(ARTICLE)
                .where(ARTICLE.OID.in(named("article_oid"))).toSql();
        assertEquals("select ARTICLE.NAME, ARTICLE.ARTICLE_NO from ARTICLE where ARTICLE.OID in (:article_oid)", sql.toString());

        final Collection<String> articleDesc = sql.executeOn(dataSource)
                .withParams("article_oid", Arrays.asList(10, 11, 12))
                .mapBeans(new BeanRowMapper<ArticleBean, String>() {
                    public String mapBean(final ArticleBean bean) {
                        return bean.getArticleNo() + "/" + bean.getName();
                    }
                });
        assertEquals(1, articleDesc.size());
        assertEquals("12345/Foobar", articleDesc.iterator().next());
    }

(:sourcend:)

31.10.2007 22:10 Uhr von mh14 -
Zeile 56 bearbeitet:

Frameworks Jequel uses and supports:

geändert zu:

Frameworks Jequel uses and supports:

31.10.2007 22:09 Uhr von mh14 -
Zeilen 15-16 bearbeitet:

Simple Example:

geändert zu:

Simple Example:

Zeile 33 bearbeitet:

Advantages (also see Features):

geändert zu:

Advantages (also see Features):

31.10.2007 22:09 Uhr von mh14 -
Zeile 57 hinzugefügt:
  • JUnit the first java xUnit testing framework
31.10.2007 22:08 Uhr von mh14 -
Zeile 59 hinzugefügt:
  • HSQLDB In memory database used for unit testing and examples
31.10.2007 22:07 Uhr von mh14 -
Zeilen 55-60 hinzugefügt:

Frameworks Jequel uses and supports:

  • Spring Framework the great framework integration layer and IOC container
  • Schema Crawler allows you to retrieve all database metadata as convenient POJOs
  • Apache Ant the first standard java build tool
  • Apache iBatis separating SQL to XML is one step in the right direction, I used their JPetStore database schema as example
24.10.2007 15:04 Uhr von mh14 -
Zeile 33 bearbeitet:

Advantages (by now):

geändert zu:

Advantages (also see Features):

24.10.2007 10:25 Uhr von mh14 -
24.10.2007 10:11 Uhr von mh14 -
Zeilen 2-3 bearbeitet:

Java Enabled QUEry Language

geändert zu:

Java Embedded QUEry Language

A Domain Specific Language for the Structured Query Language (SQL) embedded in Java

20.10.2007 18:27 Uhr von mh14 -
Zeilen 10-13 bearbeitet:

The SQL statements are just dumb, meaningless Java-String waiting to be executed to get a live.

I couldn't bear it any longer. So I used the spare spare time during my day of this week (after my family went to bed) to start writing an embedded DSL in Java to support the creation of sql query expression tree objects which can be rendered (e.g.) to SQL.

geändert zu:

The SQL statements are just dumb, meaningless Java Strings waiting to be executed to get a live.

I couldn't bear it any longer. So after discussing the idea with my co-workers when leaving I used the spare spare time during my day of this week (after my family went to bed) to start writing an embedded DSL in Java to support the creation of sql query expression tree objects which can be rendered (e.g.) to SQL. The next day I got enthusiastic and excited support and was urged to publish it.

20.10.2007 18:25 Uhr von mh14 -
Zeile 2 bearbeitet:
!! Java Enabled QUEry Language
geändert zu:

Java Enabled QUEry Language

20.10.2007 18:25 Uhr von mh14 -
Zeile 2 bearbeitet:

!! Java Enabled QUEry Language

geändert zu:
!! Java Enabled QUEry Language
20.10.2007 18:23 Uhr von mh14 -
20.10.2007 18:23 Uhr von mh14 -
Zeile 2 bearbeitet:
geändert zu:

!! Java Enabled QUEry Language

20.10.2007 14:57 Uhr von Array -
Zeilen 38-39 bearbeitet:
  • Javadoc Structures for generated Tables
geändert zu:
  • Build Javadoc HTML API Documentation for generated Tables
Zeile 42 bearbeitet:
  • Documentation of Tables and Fields using JavaDoc from Database domments
geändert zu:
  • Documentation of Tables and Fields using JavaDoc from Database comments
Zeile 44 bearbeitet:
  • e.g. include information from Resourcebundles
geändert zu:
  • e.g. include information from ResourceBundles (Translations)
20.10.2007 14:44 Uhr von Array -
Zeilen 34-38 bearbeitet:
  • Code Completion
  • Refactoring participation of Tables and Fields
  • On the fly spell checking and error
geändert zu:
  • Code Completion for Keywords, Tables and Fields
  • Refactoring participation of Tables and Fields, through the whole codebase (single source)
  • On the fly spell checking and error highlighting
  • Quick documentation Lookup
  • Javadoc Structures for generated Tables
  • Table declaration classes generated from Database Metadata
    • During build process, so all code referencing outdated structures won't compile
    • Documentation of Tables and Fields using JavaDoc from Database domments
    • Custom enhancers for Table Metadata before file creation possible
      • e.g. include information from Resourcebundles
    • create database schema from manually written Table declarations
    • migrate database schemas

  • statements form expression tree
    • custom expressions possible for encapsulating subqueries, custom code, even with parameters
    • own keywords possible

  • rendering of syntax tree to SQL
    • TODO: other target languages possible (ejbql, hibernateql, jdoql)
20.10.2007 14:30 Uhr von Array -
Zeilen 1-38 hinzugefügt:

JEQUEL

After dealing with DSL theoretically for a while, this is my second experiment with implementing an embedded DSL in Java.

When looking at the code after a big refactoring at work I could still see lots of SQL contained in Java Strings. Although already using Spring NamedParameterJdbcTemplate and so getting very readable prepared statements, containing them in String form is very stupid.

You won't get IDE support in writing it, you have no code completion, error reporting or refactoring. There is no documentation to quickly look up while writing it. It is not possible to catch syntax errors until the code is executed against the database (hopefully in an unit test).

The SQL statements are just dumb, meaningless Java-String waiting to be executed to get a live.

I couldn't bear it any longer. So I used the spare spare time during my day of this week (after my family went to bed) to start writing an embedded DSL in Java to support the creation of sql query expression tree objects which can be rendered (e.g.) to SQL.

Simple Example:

(:source lang=java :)

    public void testSimpleSql() {
        final SqlString sql =
                select(ARTICLE.OID)
                        .from(ARTICLE, ARTICLE_COLOR)
                        .where(ARTICLE.OID.eq(ARTICLE_COLOR.ARTICLE_OID)
                                .and(ARTICLE.ARTICLE_NO.is_not(NULL)));

        assertEquals("select ARTICLE.OID" +
                     " from ARTICLE, ARTICLE_COLOR" +
                     " where ARTICLE.OID = ARTICLE_COLOR.ARTICLE_OID" +
                     " and ARTICLE.ARTICLE_NO is not NULL", sql.toString());
    }

(:sourcend:)

Advantages (by now):

  • Syntax highlighting
  • Code Completion
  • Refactoring participation of Tables and Fields
  • On the fly spell checking and error
edit SideBar
Page last modified on 20.02.2008 00:30 Uhr
Bearbeiten - Historie - Druckansicht