Formatting SQL statements in pureQuery Java source code

You can format SQL statements that are string literals in pureQuery Java™ source code to improve their readability. All SQL statements in pureQuery code are embedded in quotation marks.

The SQL statements are formatted by keyword and indentation. Each SQL keyword starts on a new line. To remain consistent with Eclipse Java formatting, after the SQL is separated into multiple lines, each string is embedded in quotation marks. To concatenate the lines, a plus sign is inserted at the beginning of each continuation line.

For example, the following Java code shows an unformatted SQL statement with pureQuery annotation in the Java editor:

Unformatted SQL in pureQuery Java code

The following code shows the SQL statement after formatting:

Formatted SQL in pureQuery Java code

You can format the pureQuery SQL statements in a .java file that is open in the Java editor. You can also format the pureQuery SQL statements in a .java file from the Package Explorer.

You can format valid pureQuery SQL statements of any length. The only requirement is that the query parser is able to parse the SQL successfully.

Whenever you generate pureQuery code, the SQL in the generated code is formatted automatically during code generation.

The Eclipse Java formatter overwrites pureQuery SQL formatting. Any time the Java code is formatted, such as when you manually format the code with Ctrl+Shift+F in the Java editor, each SQL statement reverts to an unformatted state. Each statement wraps to the maximum line length that is specified in the selected profile in the Java Formatter preferences. If you want to view the pureQuery SQL statements with formatting, you must format the SQL statements again.


Feedback