[ 
https://issues.apache.org/jira/browse/METAMODEL-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13876863#comment-13876863
 ] 

Kasper Sørensen commented on METAMODEL-12:
------------------------------------------

We could have some real usages of this issue so I am finding it interesting to 
dive into and maybe elaborate a bit.

One important question is: How would a developer use this functionality. Would 
it require an interface change or can it simply be some kind of non-breaking 
addition? A couple of non-breaking ideas that come into mind could be:

 * A new DataContext implementation that wraps an underlying DataContext, but 
in the case of executeUpdate intercepts the updates and writes to a .sql file. 
Pseudo code:
{code}
UpdateableDataContext dataContext = ...
UpdateableDataContext wrapper = new SqlFileWriterDataContext(dataContext, new 
File("my_script.sql"));
wrapper.executeUpdate(new UpdateScript() {
  public void run(UpdateCallback cb) {
    // actual script contents omitted in this example
  }
});
{code}
 * A implementation of UpdateScript that handles a similar interception scheme. 
Pseudo code:
{code}
UpdateableDataContext dataContext = ...
dataContext.executeUpdate(new SqlFileUpdateScript(new File("my_script.sql")) {
  public void runInternal(UpdateCallback cb) {
    // actual script contents omitted in this example
  }
});
{code}

I think I like the second option a bit better. And I think it would be possible 
to implement simply by implementing and making the UpdateScript.run(...) method 
final, and make sure the UpdateCallback gets replaced/decorated and then a new 
abstract method gets called (in the example called 'runInternal').

> Write update script to .sql file
> --------------------------------
>
>                 Key: METAMODEL-12
>                 URL: https://issues.apache.org/jira/browse/METAMODEL-12
>             Project: Metamodel
>          Issue Type: New Feature
>            Reporter: Kasper Sørensen
>            Assignee: Henry Saputra
>            Priority: Minor
>
> It would be great with a feature to write datacontext updates to a .sql 
> script file instead of performing them directly. This will allow database 
> users to inspect the updates in a text editor and then execute it.
> Also for situations where the user only has read-only access to the database 
> - it might be an option to send it to the DBA and have him execute it.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to