Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320150 - Improve Extendability of the SQL Query Source Writer
Summary: Improve Extendability of the SQL Query Source Writer
Status: RESOLVED FIXED
Alias: None
Product: Data Tools
Classification: Tools
Component: ModelBase (show other bugs)
Version: 1.8   Edit
Hardware: PC Windows Server 2003
: P3 normal (vote)
Target Milestone: 1.8.1   Edit
Assignee: Brian Payton CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-16 20:01 EDT by Linda Chan CLA
Modified: 2010-08-10 20:57 EDT (History)
1 user (show)

See Also:
lchan: review? (bpayton)


Attachments
Proposed Patch (4.60 KB, text/plain)
2010-07-16 20:01 EDT, Linda Chan CLA
no flags Details
Revised patch (15.95 KB, patch)
2010-07-23 22:59 EDT, Linda Chan CLA
no flags Details | Diff
Revised Patch (15.38 KB, patch)
2010-07-29 14:50 EDT, Linda Chan CLA
no flags Details | Diff
Patch for plugin o.e.d.modelbase.sql.query (49.29 KB, patch)
2010-07-29 16:55 EDT, Brian Payton CLA
no flags Details | Diff
Patch for plugin o.e.d.modelbase.sql.query (87.54 KB, patch)
2010-07-29 23:37 EDT, Brian Payton CLA
no flags Details | Diff
Further Update to call #appendOperator (1.64 KB, patch)
2010-08-02 19:24 EDT, Linda Chan CLA
no flags Details | Diff
Another patch for plugin o.e.d.modelbase.sql.query (183.14 KB, patch)
2010-08-04 18:41 EDT, Brian Payton CLA
no flags Details | Diff
Fix calls to #appendSpace(sb, SPACE) (1.88 KB, patch)
2010-08-05 19:08 EDT, Linda Chan CLA
no flags Details | Diff
Refactoring in #appendSQLForTableInDatabase(TableInDatabase, StringBuffer) (1.43 KB, patch)
2010-08-05 23:42 EDT, Linda Chan CLA
no flags Details | Diff
Refactoring in #appendSQLForTableInDatabase and for OrderByResultColumn (2.58 KB, patch)
2010-08-06 15:48 EDT, Linda Chan CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Linda Chan CLA 2010-07-16 20:01:51 EDT
Created attachment 174550 [details]
Proposed Patch

The schema of the extension point org.eclipse.datatools.modelbase.sql.query.sourceWriterExtension has incorrect base class value in the 2 class attributes.
See attached patch for the fix.

Separately, it would be nice for the default SQLQuerySourceWriter to let an ISQLObjectNameHelper, if available, to determine the SQL format of the table name written in the generated SQL query text.  See patch for enhanced implementation.
Comment 1 Linda Chan CLA 2010-07-23 22:59:10 EDT
Created attachment 175123 [details]
Revised patch

Further refactoring to allow an extended SQLQuerySourceWriter to override the call to StatementHelper#convertCatalogIdentifierToSQLFormat.
Comment 2 Linda Chan CLA 2010-07-29 14:50:41 EDT
Created attachment 175521 [details]
Revised Patch

Removed the prior changes to use ISQLObjectNameHelper.
The only source changes left in this patch is the extraction to the call of StatementHelper#convertCatalogIdentifierToSQLFormat into a protected method.
This will hopefully expedite the review process.
Comment 3 Brian Payton CLA 2010-07-29 16:53:35 EDT
Hi Linda, I took this opportunity to clean up the methods in the SQLQuerySourceWriter that are being changed.  Over time I've been trying to make the class easier to subclass.  For example, I've been changing sb.append(xxx) method calls to appendYyyy(sb, xxx), so that extenders can get control when each language element is written out (for example, to change the case of some language elements).  I added appendDataTypeName, appendFunctionName, appendIdentifier methods.  I've also been refactoring the code to make it easier to debug by splitting up nested method calls.
Comment 4 Brian Payton CLA 2010-07-29 16:55:03 EDT
Created attachment 175529 [details]
Patch for plugin o.e.d.modelbase.sql.query

Linda, please try out this patch to make sure I didn't mess anything up.  I ran all the parser JUnit test cases, and they ran OK.
Comment 5 Linda Chan CLA 2010-07-29 18:18:27 EDT
(In reply to comment #4)

Brian,
The additional re-factoring is a great idea.  The latest patch seems to work fine for me too.  Thanks.
Comment 6 Linda Chan CLA 2010-07-29 21:23:15 EDT
Brian,
I find that the new method #appendOperator(StringBuffer sb, String oper) is not called.  Shouldn't it be called by #appendSpecificSQL(ValueExpressionCombinedOperator op, StringBuffer sb) ?
Comment 7 Brian Payton CLA 2010-07-29 23:33:37 EDT
I added appendOperator quite a while ago, not sure why I didn't use it yet.  I'll do some more updates.
Comment 8 Brian Payton CLA 2010-07-29 23:37:02 EDT
Created attachment 175536 [details]
Patch for plugin o.e.d.modelbase.sql.query

OK, I started going through and converting all the appendSpecificSQL methods to use the override-able appendXxxx methods.  I converted a lot of them, but there's a lot left to do still.  I'm going to go ahead and check in the fix, and carry on refactoring the methods later.
Comment 9 Brian Payton CLA 2010-07-29 23:44:29 EDT
Checked in fix, tagged to v201007301145.
Comment 10 Linda Chan CLA 2010-08-02 19:24:41 EDT
Created attachment 175735 [details]
Further Update to call #appendOperator

The attached patch changes the #appendSpecificSQL(ValueExpressionCombinedOperator , StringBuffer) method to call #appendOperator for the combined operator string.
Comment 11 Linda Chan CLA 2010-08-02 19:27:52 EDT
Brian,
This additional patch adds re-factoring of #appendSpecificSQL(ValueExpressionCombinedOperator, StringBuffer) to call #appendOperator.
Comment 12 Brian Payton CLA 2010-08-04 18:41:31 EDT
Created attachment 175899 [details]
Another patch for plugin o.e.d.modelbase.sql.query

Sorry, was going through the code refactoring all the sb.append method calls, and got tired before reaching that one.

With this patch I've completed the refactoring and other code cleanup.
Comment 13 Brian Payton CLA 2010-08-04 18:47:11 EDT
Checked in patch, tagged to v201008050645.

Let me know if you see any problems.
Comment 14 Linda Chan CLA 2010-08-05 19:08:25 EDT
Created attachment 175991 [details]
Fix calls to #appendSpace(sb, SPACE)

Brian,
I found a few of these calls are now made: appendSpace(sbSelect, SPACE),
which led to adding 32 spaces.
These were probably typos from recent re-factoring.
See patch that identifies those calls.
Comment 15 Brian Payton CLA 2010-08-05 19:45:03 EDT
Thanks, I was trying to watch out for those, but I must have been getting sleepy.  (It's pretty tedious going through all that code.)  It's annoying that the char ' ' is accepted as a integer argument.  It's a legacy of Java's "C" roots, I think.
Comment 16 Brian Payton CLA 2010-08-05 21:27:39 EDT
Checked in fix, tagged to v201008060930.
Comment 17 Linda Chan CLA 2010-08-05 23:42:02 EDT
Created attachment 175997 [details]
Refactoring in #appendSQLForTableInDatabase(TableInDatabase, StringBuffer)

Just a bit more re-factoring...
This patch makes separate calls to #appendIdentifier for the table qualifier and table name, so that the DOT separator is handled by #appendSymbol.
Comment 18 Linda Chan CLA 2010-08-06 15:48:22 EDT
Created attachment 176065 [details]
Refactoring in #appendSQLForTableInDatabase and for OrderByResultColumn

Brian,
Including another minor re-factoring for
#appendSpecificSQL(OrderByResultColumn, StringBuffer)
Comment 19 Brian Payton CLA 2010-08-09 18:58:58 EDT
OK, I applied the patch from 2010-08-06 with the refactoring of appendSQLforTableInDatabase and appendSpecificSQL(OrderByResultColumn..., tagged to v201008100700.
Comment 20 Brian Payton CLA 2010-08-10 20:57:33 EDT
Resolving as fixed.