db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guido Schreuder <g.schreu...@xs4all.nl>
Subject Re: Preventing tables from being dropped
Date Tue, 24 Apr 2007 10:38:18 GMT
Hi Tom,

Yep, that'll work, i was thinking along the same line already

thanks,
Guido

On Sat, 2007-04-14 at 16:58 -0700, Thomas Dudziak wrote:
> Hi Guido
> 
> On 4/12/07, Guido Schreuder <g.schreuder@xs4all.nl> wrote:
> > I am looking for a way to prevent tables from being dropped when
> > executing Platform.alterTables(Database, boolean)
> >
> > The reason for this is that my model is iteratively constructed without
> > prior knowledge of the final model. Currently this will lead to
> > "unknown" tables being dropped, causing data to be lost.
> >
> > An option like would be welcome, but maybe being able to somehow
> > decorate the SqlBuilder and/or ModelComparator might yield a more
> > flexible solution. Although the latter would probably not be trivial.
> 
> Unfortunately, you can't at the moment, at least not out of the box
> (but a feature request in JIRA would be appreciated).
> However, you might be able to achieve what you want by using a
> modified version of e.g. the
> PlatformImplBase#getAlterTablesSql(Connection, String, String,
> String[], Database, CreationParameters) method. More precisely, if you
> do the following:
> 
> String   sql          = null;
> Database currentModel = readModelFromDatabase(connection,
> desiredModel.getName(), catalog, schema, tableTypes);
> 
> // Filter the read model here so that only relevant tables are in the
> currentModel
> 
> try
> {
>     StringWriter buffer = new StringWriter();
> 
>     getSqlBuilder().setWriter(buffer);
>     getSqlBuilder().alterDatabase(currentModel, desiredModel, params);
>     sql = buffer.toString();
> }
> catch (IOException ex)
> {
>     // won't happen because we're using a string writer
> }
> return sql;
> 
> 
> The alterTables is nothing more than a wrapper around getAlterTablesSql:
> 
> Connection connection = borrowConnection();
> 
> try
> {
>     return getAlterTablesSql(...);
> }
> finally
> {
>     returnConnection(connection);
> }
> 
> hope that helps,
> Tom
> 


Mime
View raw message