Hi Rainer

thank you for your quick response; and you're very welcome with this spring example, I'm glad if can help.

My final goal was to create some kind of migration script to upgrade my db schema, because my app will contain some new features in next versions which will add tables and columns to the existing db schema. I want to compare two instances of DBDatabase and generate the sql ddl statements. So actually, I don't really need to add the table to the other db, but I want to create arbitary sql ddl statements (for DBTable, DBColumn, DBView...) using a different driver. This works with DBDatabse already, I can specify a DBDatabaseDriver there and the method will change the driver temporarily. Therefor I tried to either add the missing table from the one db to the other or to set the DBDatabaseDriver of the first db into the second, so I can use the second DB to create its table - but now with the driver from the first db...

I somehow got an evil workaround by serializing the two DBDatabses and while deserializing back, I inject my desired driver into the DBDatabases. So I end up with a clone of the db having my target driver attached.

Thank you four your help!
Eike

Rainer Döbele wrote:
Hi Eike,

first I want to thank you very much for your submission of the spring example.
Unfortunately I did not have the chance to look at it so far - but I am quite 
keen to do so.
I'll let you know when I have.

Now about your question:
A DBTable object may only belong to one database object just like an XMLElement 
belongs to its XMLDocument.
This assignment is usually performed on creation of the DBTable and there is no 
mechanism to change it.

Hence if you really need to need a copy of the table object of one database in 
another one you need to create a new instance of the table object.
Normally you would just create a instalce of the table like this:

    DBTable t = new DB1.SomeTable(db2);

If your code should be more generic then you might use something like:

    DBTable t = db1.getTable(...);
    t.getClass().getConstructor(DBDatabase.class).newInstance(new Object[] { 
db2 });

This assumes that the table has a constructor that takes the db as a parameter.

Hope this is what you need.
Otherwiese I would need to know what excatly you are trying to achieve with 
this.

Regards
Rainer


Eike Kettner wrote:
re: how to add a "foreign" table

Hello all,

I'm facing a problem that I want to add a table from one db to another
db. I have two DBDatabases and I like to add a table from DB1 to DB2,
something like this:


  DBDatabase db1 = ..
  DBDatabase db2 = ..

  DBTable table1 = db1.getTable(0);

  db2.addTable(table1);


actually, what i want is to create a table on DB2 that is present on
DB1, without too much coding ;-)

Thankful for any help!

Kind regards,
Eike


Reply via email to