Re: Create schema from EOModel programmatically
David Teran <[email protected]> Sun, 4 May 2003 22:39:38 +0200
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
Hi Stefan,
are you looking for something like this:
//get the JDBCAdaptor
EODatabaseContext dc =
EOUtilities.databaseContextForModelNamed(new EOEditingContext(),
"sss");
EOAdaptorContext ac = dc.adaptorContext();
JDBCAdaptor a = (JDBCAdaptor) ac.adaptor();
JDBCPlugIn plugin = a.plugIn();
EOSynchronizationFactory sf =
plugin.createSynchronizationFactory();
EOModel m = EOModelGroup.defaultGroup().modelNamed("sss");
NSMutableDictionary optionsCreate = new NSMutableDictionary();
optionsCreate.setObjectForKey("YES", "DropTablesKey");
optionsCreate.setObjectForKey("YES",
"DropPrimaryKeySupportKey");
optionsCreate.setObjectForKey("YES", "CreateTablesKey");
optionsCreate.setObjectForKey("YES",
"CreatePrimaryKeySupportKey");
optionsCreate.setObjectForKey("YES",
"PrimaryKeyConstraintsKey");
optionsCreate.setObjectForKey("YES",
"ForeignKeyConstraintsKey");
optionsCreate.setObjectForKey("NO", "CreateDatabaseKey");
optionsCreate.setObjectForKey("NO", "DropDatabaseKey");
String createStatements =
sf.schemaCreationScriptForEntities(m.entities(), optionsCreate);
?
cheers, David
On Sunday, May 4, 2003, at 09:50 Europe/Berlin, Stefan Apelt wrote:
>
> We use prototypes in the EOModel to be able to switch our model to
> different databases at app start. There is, however, a "default"
> configuration in the model (Openbase), so you can open and edit it.
>
> Because the model is under development/reorganisation we quite often
> have to recreate the database schema for all tables to reflect the
> changes. (Losing data is not an issue at this point as the database is
> nearly empty anyway.)
>
> To do this you have to close EOModeler, replace the
> "EOPrototypes.plist" with a saved file for the target database and
> replace the connection dictionary entry in "index.eomodeld" with the
> right entry for the target database. Then you start EOModeler again
> and press the "Generate SQL" button. As we currently support four
> databases this starts to be a lot of work.
>
> During runtime, the replacement is done automatically, no problem.
> What bothers me is how to do this "Generate SQL" stuff during runtime.
>
> Has anyone tried to do this in a small management application? Where
> should I start? I guess it is possible using plain JDBC SQL commands
> but I have not done anything in that direction yet.
>
> Any pointers are highly appreciated.
>
> --
> Regards,
> Stefan
>
> _______________________________________________
> EOF mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/eof
>
>
David Ter??n.vcf
(text/directory, 722 B) - not displayed