Intro - Part 1 - Part 2 - Part 3 - Part 4 Part 3: And now for some procedural SQLLet's capture what we defined in those separate java methods added in Part 2 in 1 PL-SQL function. Connect to your database.. with 'psql' and execute the 'create language' command to tell Postgresql to speak PL-SQL too (you only have to to do this once, maybe you already did so in the past).
Define the functionDon't quit that psql session yet, but copy/paste the following into it..
On successful creation of the function, psql will reply with 'CREATE FUNCTION'. Adapt the mlg fileRemove the functions getNextSequenceValue(), getMaxRank(), insertTask(), addNewTask() that we defined in previous section, and add the following:
Note the double square brackets used as delimiters for calling PL-SQL. You probably also noted the declaration of 'target postgresql': since some (but not all) JDBC code is different for the different target databases (postgresql and oracle) there has to be some way to tell the code-generator which database to target. For this, you add 'target postgresql' either to the method definition or to the class definition. In my projects I mostly put the definition at class level, because my code usually targets only 1 brand of database. Call upon amalegeni again to regenerate the bean(s) and service classes.
You know the drill now: hit the F5 button in Eclipse to refresh the src directory. Your Todo app is ready again.... so fire it up, and hit that 'Add' button. Source codeYour Todo.mlg looks a whole lot simpler now! |