Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [dtp-dev] Generating DDL from SQL Model


Hi Alex,

Here is a working code snippet and the resulting output:

Code:

            DatabaseDefinitionRegistry dbDefinitionRegistry = RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry();
                DatabaseDefinition genericDBDefinition = dbDefinitionRegistry.getDefinition("Generic JDBC","1.0");
                DDLGenerator gdg = genericDBDefinition.getDDLGenerator();
               
                SQLSchemaFactory sqlSchemaFactory = SQLSchemaFactory.eINSTANCE;
                Database myDatabase = sqlSchemaFactory.createDatabase();
                myDatabase.setVendor("Generic JDBC");
                myDatabase.setVersion("1.0");
               
                Schema mySchema = sqlSchemaFactory.createSchema();
                Table myTable = SQLTablesFactory.eINSTANCE.createPersistentTable() ;
                myTable.setName("MyTable");
                Column column =        SQLTablesFactory.eINSTANCE.createColumn();
                column.setName("COL1");

                // set DataType
         PredefinedDataType predefineDatatype = genericDBDefinition.getPredefinedDataType("CHAR");
                column.setDataType(predefineDatatype);
               
                myTable.getColumns().add(column);
                mySchema.getTables().add(myTable);
                myDatabase.getSchemas().add(mySchema);
               
               
                // pass schema to DDLGen
                String[] test =        gdg.generateDDL(new SQLObject[]{(SQLObject)mySchema}, new
                NullProgressMonitor());
                System.out.println(test[0]);


Output:

CREATE TABLE MyTable (
                COL1 CHAR(32) NOT NULL
        )


Larry Dunnell
RAD Data Tools, DB2 Tooling,  Eclipse WTP Project and Eclipse DTP Project
IBM DB2 Information Management Software




"Black, Alex BGI UK" <Alex.Black@xxxxxxxxxxxxxxxxxx>
Sent by: dtp-dev-bounces@xxxxxxxxxxx

03/22/2007 11:08 AM

Please respond to
DTP development mailing list <dtp-dev@xxxxxxxxxxx>

To
<dtp-dev@xxxxxxxxxxx>
cc
Subject
[dtp-dev] Generating DDL from SQL Model





Hi Guys,

I have been trying to generate DDL with this simple code but I keep
hitting a brick wall, any help would be appreciated:

SQLSchemaFactory sqlSchemaFactory = SQLSchemaFactory.eINSTANCE;

Schema mySchema = sqlSchemaFactory.createSchema(); Table myTable =
SQLTablesFactory.eINSTANCE.createPersistentTable() ;
myTable.setName("MyTable"); Column column =
SQLTablesFactory.eINSTANCE.createColumn();

//set DataType
DataType dataType =
SQLDataTypesFactory.eINSTANCE.createBinaryStringDataType();
column.setDataType(dataType);
myTable.getColumns().add(column);
mySchema.getTables().add(myTable);


//pass schema to DDLGen
GenericDdlGenerator gdg = new GenericDdlGenerator(); String[] test =
gdg.generateDDL(new SQLObject[]{(SQLObject)mySchema}, new
NullProgressMonitor()); System.out.println(test);

I have been told not to instantiate the GenericDdlGenerator in this
manner, how else would do this?

Many thanks,
Alex

--

This message and any attachments are confidential, proprietary, and may be privileged.  If this message was misdirected, Barclays Global Investors (BGI) does not waive any confidentiality or privilege.  If you are not the intended recipient, please notify us immediately and destroy the message without disclosing its contents to anyone.  Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized.  The views and opinions expressed in this e-mail message are the author's own and may not reflect the views and opinions of BGI, unless the author is authorized by BGI to express such views or opinions on its behalf.  All email sent to or from this address is subject to electronic storage and review by BGI.  Although BGI operates anti-virus programs, it does not accept responsibility for any damage whatsoever caused by viruses being passed.

--

Barclays Global Investors Limited is authorized and regulated by The Financial Services Authority. Registered in England. Registered No:796793. Registered Office: 1 Churchill Place, London E14 5HP.
_______________________________________________
dtp-dev mailing list
dtp-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dtp-dev


Back to the top