Created
March 8, 2016 20:44
-
-
Save krisrice/ce9f5eb290a203ef1c12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fatFinger = [ { bad:"form", good:"from"}, | |
{ bad:"hwere", good:"where"}, | |
{ bad:"dula", good:"dual"} | |
]; | |
// SQLCL's Command Registry | |
var CommandRegistry = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandRegistry"); | |
// CommandListener for creating any new command | |
var CommandListener = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandListener") | |
// Broke the .js out from the Java.extend to be easier to read | |
var cmd = {}; | |
// Called to attempt to handle any command | |
cmd.handle = function (conn,ctx,cmd) { | |
return false; | |
} | |
// fired before ANY command | |
cmd.begin = function (conn,ctx,cmd) { | |
for(var i = 0; i < fatFinger.length; i++) { | |
var w = fatFinger[i]; | |
if ( cmd.getSql().trim().indexOf(" "+ w.bad +" ") >0 ) { | |
ctx.write("\n***Mispelled "+ w.bad +" again. AUTOCORRECTING ***\n"); | |
cmd.setSql(cmd.getSql().replace(" "+ w.bad +" ", " "+ w.good +" /* AUTO CORRECTED */ ")); | |
} | |
} | |
} | |
// fired after ANY Command | |
cmd.end = function (conn,ctx,cmd) { | |
} | |
// Actual Extend of the Java CommandListener | |
var AutoCorrectCommand = Java.extend(CommandListener, { | |
handleEvent: cmd.handle , | |
beginEvent: cmd.begin , | |
endEvent: cmd.end | |
}); | |
// Registering the new Command | |
CommandRegistry.addForAllStmtsListener(AutoCorrectCommand.class); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment