Formatted SQL logging

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Oct 04 2010 - 19:53:53 UTC

  • Next message: Andrus Adamchik: "Re: Build failed in Hudson: Cayenne-trunk » h2,JDK 1.5 (latest),Ubuntu #372"

    Just I applied CAY-1486 patch, switching static QueryLogger to a DI-based approach. Part of that was changing QueryFormatter to a more OO approach (a special subclass FormattedCommonsJdbcEventLogger instead of if/else in the static logger).

    I noticed that formatting algorithm adds a bunch of unneeded line breaks sometimes. All examples are from running 3.1 tutorial with FormattedCommonsJdbcEventLogger, which is achieved with code similar to this:

    ServerRuntime cayenneRuntime = new ServerRuntime(
     "cayenne-UntitledDomain.xml", new Module() {
         public void configure(Binder binder) {
           JdbcEventLogger logger = new FormattedCommonsJdbcEventLogger();
           QueryLogger.setLogger(logger);
           binder.bind(JdbcEventLogger.class).toInstance(logger);
         }
    });

    Examples:

    1. (an empty line before WHERE)

    INFO: SELECT t0.GALLERY_ID,
             t0.NAME,
             t0.ARTIST_ID,
             t0.ID
    FROM PAINTING t0 JOIN ARTIST t1 ON (
            t0.ARTIST_ID = t1.ID)
             
    WHERE t1.DATE_OF_BIRTH < ?
     [bind: 1->DATE_OF_BIRTH:'1910-01-01 00:00:00.04']

    2. (an empty line before VALUES, 2 empty lines after the last parenthesis)

    INFO: INSERT INTO PAINTING (
            ARTIST_ID,
             GALLERY_ID,
             ID,
             NAME)

    VALUES (
            ?,
             ?,
             ?,
             ?)

    3. (an empty line after WHERE, also lie break between DELETE and FROM seems unneeded)

    INFO: DELETE
    FROM ARTIST
    WHERE ID = ?



    This archive was generated by hypermail 2.0.0 : Mon Oct 04 2010 - 19:54:23 UTC