Code Generator for Eclipse Code
Brought to you by:
hotzst
--- a/trunk/ch.sahits.codegen.java.datatools/src/ch/sahits/codegen/java/internal/wizards/DTPConnectionDefinitionPage.java +++ b/trunk/ch.sahits.codegen.java.datatools/src/ch/sahits/codegen/java/internal/wizards/DTPConnectionDefinitionPage.java @@ -5,7 +5,6 @@ import java.util.Properties; import java.util.Vector; -<<<<<<< .working import org.eclipse.datatools.connectivity.IConnectionProfile; import org.eclipse.datatools.modelbase.sql.tables.Table; import org.eclipse.swt.SWT; @@ -15,30 +14,13 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -======= -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.modelbase.sql.tables.Table; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; ->>>>>>> .merge-right.r899 import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -<<<<<<< .working import ch.sahits.codegen.help.ISahitsHelpSystem; import ch.sahits.codegen.i18n.DatatoolsMessages; -import ch.sahits.codegen.java.wizards.DTPConnection; -======= -import ch.sahits.codegen.help.ISahitsHelpSystem; -import ch.sahits.codegen.i18n.DatatoolsMessages; ->>>>>>> .merge-right.r1041 import ch.sahits.codegen.java.wizards.DTPConnection; import ch.sahits.codegen.model.IBasicDBConnectionModelGenerator; import ch.sahits.codegen.ui.internal.wizards.BasicCodeGenWizard; @@ -51,15 +33,7 @@ * @author Andi Hotz * @since 1.1.0 */ -<<<<<<< .working -<<<<<<< .working public final class DTPConnectionDefinitionPage extends BasicDBDefinitionPage { -======= -public class DTPConnectionDefinitionPage extends BasicDBDefinitionPage { -======= -public final class DTPConnectionDefinitionPage extends BasicDBDefinitionPage { ->>>>>>> .merge-right.r2453 ->>>>>>> .merge-right.r899 /** Input field for the user name. * The input is optional if the user name was not supplied * with the configuration @@ -75,48 +49,23 @@ /** Input field for the schema/owner name */ private Combo comboSchema; /** Input field for table name */ -<<<<<<< .working private Combo comboTable; /** Helper instance to encapsule DTP functionality */ private DTPConnection helper=null; -<<<<<<< .working /** This holds the name of the connection profile selected */ private String connectionProfile=null; -======= - private Combo comboTable; - /** Helper instance to encapsule DTP functionality */ - private DTPConnection helper=null; ->>>>>>> .merge-right.r899 -======= - /** This holds the name of the connection profile selected */ - private String connectionProfile=null; ->>>>>>> .merge-right.r2453 /** * Constructor for creating this page. This constructor is used through reflection * @param pageTitle title of the page * @param caller calling wizard * @param imageURL URL to the header image */ -<<<<<<< .working public DTPConnectionDefinitionPage(String pageTitle, BasicCodeGenWizard caller, String imageURL) { -======= - public DTPConnectionDefinitionPage(String pageTitle, - BasicCodeGenWizard caller, String imageURL) { ->>>>>>> .merge-right.r1041 super(pageTitle,caller); -<<<<<<< .working setTitle(DatatoolsMessages.DTPConnectionDefinitionPage_0); setDescription(DatatoolsMessages.DTPConnectionDefinitionPage_1); setPageHeaderURL(imageURL); -======= - setTitle(DatatoolsMessages.DTPConnectionDefinitionPage_0); - setDescription(DatatoolsMessages.DTPConnectionDefinitionPage_1); -<<<<<<< .working ->>>>>>> .merge-right.r1041 -======= - setPageHeaderURL(imageURL); ->>>>>>> .merge-right.r2453 setImage(); } @@ -125,17 +74,8 @@ * @param enable or disable the field */ @Override -<<<<<<< .working -<<<<<<< .working protected final void enableTableName(boolean enable) { comboTable.setEnabled(enable); -======= - protected void enableTableName(boolean enable) { -======= - protected final void enableTableName(boolean enable) { ->>>>>>> .merge-right.r2453 - comboTable.setEnabled(enable); ->>>>>>> .merge-right.r899 } @@ -150,56 +90,25 @@ public List<String> getDataBaseProducts() { return DTPConnection.getRegisteredConnectionProfiles(); } -<<<<<<< .working /** * Create a model generation instance for datatools * The return object implements two subinterfaces of {@link IBasicDBConnectionModelGenerator} * that implement two different init methods * @param connectionProfileName profile name */ -======= - /** - * Create a model generation instance for datatools - * The return object implements two subinterfaces of {@link IBasicDBConnectionModelGenerator} - * that implement two different init methods - * @param connectionProfileName profile name - */ ->>>>>>> .merge-right.r1041 - @Override -<<<<<<< .working -<<<<<<< .working + @Override public IBasicDBConnectionModelGenerator getModelGenerator(String connectionProfileName) { IConnectionProfile profile = DTPConnection.getProfile(connectionProfileName); return new DTPConnectionModelGenerator(profile,getSchema(),getTableName(),getUserName(),getPassword()); -======= - public IDBConnectionModelGenerator getModelGenerator(String connectionProfileName) { -======= - public IBasicDBConnectionModelGenerator getModelGenerator(String connectionProfileName) { ->>>>>>> .merge-right.r2453 - IConnectionProfile profile = DTPConnection.getProfile(connectionProfileName); - return new DTPConnectionModelGenerator(profile,getSchema(),getTableName(),getUserName(),getPassword()); ->>>>>>> .merge-right.r1041 - } - -<<<<<<< .working + } + /** * Initialize the fields based on the selected database * connection profile * @param profileName name of the database connection profile. * @param testNeeded flag indicating that a test is needed */ -======= - /** - * Initialize the fields based on the selected database - * connection profile - * @param profileName name of the database connection profile. - * @param testNeeded flag indicating that a test is needed - */ ->>>>>>> .merge-right.r899 - @Override -<<<<<<< .working -<<<<<<< .working -<<<<<<< .working + @Override public void initData(String profileName,boolean testNeeded) { initConnectionTestNeeded(testNeeded); if (profileName==null || profileName.trim().equals("")){ //$NON-NLS-1$ @@ -238,61 +147,12 @@ txtPassword.setText(pwd); } } -======= - protected void initData(String product) { - if (product==null || product.trim().equals("")){ -======= - public void initData(String product) { - if (product==null || product.trim().equals("")){ //$NON-NLS-1$ -======= - public void initData(String profileName,boolean testNeeded) { - initConnectionTestNeeded(testNeeded); - if (profileName==null || profileName.trim().equals("")){ //$NON-NLS-1$ ->>>>>>> .merge-right.r2453 ->>>>>>> .merge-right.r1041 - initEmpty(); - } - if (helper==null){ - helper = new DTPConnection(profileName); - } - IConnectionProfile profile = helper.getConnectionProfile(profileName); - if (profile==null){ - initEmpty(); - } else { - setDbProduct(helper.getVenorNameUpperCase(profile)); - setHost(helper.getHost(profile)); - setPort(helper.getPortNumber(profile)); - setDbName(helper.getDatabase(profile)); - initDataBaseConnections(); - for (int i = 0; i < comboName.getItemCount(); i++) { - String s = comboName.getItem(i); - if (s.equals(profileName)){ - comboName.select(i); - break; - } - } - Properties baseProp =profile.getBaseProperties(); - final String pwd = baseProp.getProperty("org.eclipse.datatools.connectivity.db.password"); //$NON-NLS-1$ - final String user = baseProp.getProperty("org.eclipse.datatools.connectivity.db.username"); //$NON-NLS-1$ - setConnectionProfile(profileName); - initSchemas(profile); - if (user!=null && !user.trim().equals("")){ //$NON-NLS-1$ - setUser(user); - txtUserName.setText(user); - } - if (pwd!=null && !pwd.trim().equals("")){ //$NON-NLS-1$ - setPasswd(pwd); - txtPassword.setText(pwd); - } - } ->>>>>>> .merge-right.r899 } /** * Initialize the page with empty data */ @Override protected void initEmpty() { -<<<<<<< .working txtUserName.setText(""); //$NON-NLS-1$ txtPassword.setText(""); //$NON-NLS-1$ initDataBaseConnections(); @@ -341,7 +201,6 @@ } if (comboTable.getItemCount()==1){ comboTable.select(0); -<<<<<<< .working setTableName(comboTable.getItem(0)); } } @@ -359,67 +218,6 @@ v.add(t.getName()); } return v; -======= - txtUserName.setText(""); //$NON-NLS-1$ - txtPassword.setText(""); //$NON-NLS-1$ - initDataBaseConnections(); - } - /** - * Initialize the dropdown with the connection profiles - */ - private void initDataBaseConnections() { - List<String> profileNames = DTPConnection.getRegisteredConnectionProfiles(); - for (Iterator<String> iterator = profileNames.iterator(); iterator.hasNext();) { - String name = iterator.next(); - comboName.add(name); - } - } - /** - * Initialize the dropdown with the schema definitions - */ - private void initSchemas(IConnectionProfile profile){ - List<String> schemas = helper.getOwner(profile); - for (Iterator<String> iterator = schemas.iterator(); iterator.hasNext();) { - String name = iterator.next(); - comboSchema.add(name); - } - if (comboSchema.getItemCount()==1){ - comboSchema.select(0); - } - } - /** - * Initialize the dropdown with the table definitions - * @param profile Connection profile - * @param schemaName name of the schema - */ - private void initTables(IConnectionProfile profile, String schemaName){ - List<String> tables = getTables(profile, schemaName); - for (Iterator<String> iterator = tables.iterator(); iterator.hasNext();) { - String name = iterator.next(); - comboTable.add(name); - } - if (comboTable.getItemCount()==1){ - comboTable.select(0); -======= - setTableName(comboTable.getItem(0)); ->>>>>>> .merge-right.r2453 - } - } - /** - * Retrieve the tables of a schema - * @param profile Connection profile - * @param schemaName name of the schema - * @return List of table names with empty entry - */ - public List<String> getTables(IConnectionProfile profile, String schemaName){ - List<Table> l = helper.getTable(profile, schemaName); - Vector<String> v = new Vector<String>(); - for (Iterator<Table> iterator2 = l.iterator(); iterator2.hasNext();) { - Table t = iterator2.next(); - v.add(t.getName()); - } - return v; ->>>>>>> .merge-right.r899 } /** @@ -442,18 +240,11 @@ return true; } -<<<<<<< .working /** * @param name the dbName to set */ -======= - /** - * @param name the dbName to set - */ ->>>>>>> .merge-right.r899 @Override public void setDbName(String name) { -<<<<<<< .working this.dbName = name; if (name!=null && !name.trim().equals("")){ //$NON-NLS-1$ for (int i = 0; i < comboName.getItemCount(); i++) { @@ -463,29 +254,12 @@ } } } -======= - this.dbName = name; - if (name!=null && !name.trim().equals("")){ //$NON-NLS-1$ - for (int i = 0; i < comboName.getItemCount(); i++) { - if (comboName.getItem(i).equals(name)){ - comboName.select(i); - break; - } - } - } ->>>>>>> .merge-right.r899 - } - -<<<<<<< .working + } + /** * Empty implementation since the host is not of interest * @param _host the host to set */ -======= - /** - * @param _host the host to set - */ ->>>>>>> .merge-right.r899 @Override public void setHost(String _host) { // empty implementation since the host is not of interest @@ -496,30 +270,14 @@ */ @Override public void setPasswd(String _passwd) { -<<<<<<< .working -<<<<<<< .working //txtPassword.setText(_passwd); this.passwd = _passwd; -======= - txtPassword.setText(_passwd); -======= - //txtPassword.setText(_passwd); ->>>>>>> .merge-right.r2453 - this.passwd = _passwd; ->>>>>>> .merge-right.r899 - } - -<<<<<<< .working + } + /** * Empty implementation since the port is not of interest * @param _port the port number to set */ -======= - /** - * Empty implementation since the port is not of interest - * @param _port the port number to set - */ ->>>>>>> .merge-right.r899 @Override public void setPort(String _port) { // empty implementation since the port is not of interest @@ -530,7 +288,6 @@ */ @Override public void setSchema(String _schema) { -<<<<<<< .working this.schema = _schema; if (_schema!=null && !_schema.trim().equals("")){ //$NON-NLS-1$ for (int i = 0; i < comboSchema.getItemCount(); i++) { @@ -540,33 +297,14 @@ } } } -======= - this.schema = _schema; - if (_schema!=null && !_schema.trim().equals("")){ //$NON-NLS-1$ - for (int i = 0; i < comboSchema.getItemCount(); i++) { - if (comboSchema.getItem(i).equals(_schema)){ - comboSchema.select(i); - break; - } - } - } ->>>>>>> .merge-right.r899 - } - -<<<<<<< .working + } + /** * Set the name of the table * @param name table name */ -======= - /** - * Set the name of the table - * @param name table name - */ ->>>>>>> .merge-right.r899 @Override public void setTableName(String name) { -<<<<<<< .working this.tableName = name; if (name!=null && !name.trim().equals("")){ //$NON-NLS-1$ for (int i = 0; i < comboTable.getItemCount(); i++) { @@ -576,17 +314,6 @@ } } } -======= - this.tableName = name; - if (name!=null && !name.trim().equals("")){ //$NON-NLS-1$ - for (int i = 0; i < comboTable.getItemCount(); i++) { - if (comboTable.getItem(i).equals(name)){ - comboTable.select(i); - break; - } - } - } ->>>>>>> .merge-right.r899 } /** @@ -594,17 +321,8 @@ */ @Override public void setUser(String _user) { -<<<<<<< .working -<<<<<<< .working //txtUserName.setText(_user); this.user = _user; -======= - txtUserName.setText(_user); -======= - //txtUserName.setText(_user); ->>>>>>> .merge-right.r2453 - this.user = _user; ->>>>>>> .merge-right.r899 } /** @@ -613,47 +331,27 @@ */ @Override public void showSchema(boolean show) { -<<<<<<< .working // empty implementation since the schema is always shown } -======= - // empty implementation since the schema is always shown ->>>>>>> .merge-right.r899 /** * Create the input part for the port number * Empty implementation since the port is not of interest * @param container parent container */ @Override -<<<<<<< .working protected final void creatInputPort(Composite container) { // no implementation since the port number is not needed } -<<<<<<< .working /** * Create the input field for the host * Empty implementation since the host is not of interest * @param container parent container */ -======= - /** - * Create the input part for the port number - * @param container parent container - */ ->>>>>>> .merge-right.r899 - @Override -<<<<<<< .working + @Override protected final void createHostInput(Composite container) { // no implementation since the port number is not needed -======= - protected void creatInputPort(Composite container) { -======= - protected final void creatInputPort(Composite container) { ->>>>>>> .merge-right.r2453 - // no implementation since the port number is not needed ->>>>>>> .merge-right.r899 } /** * Create the input dropdown list for the database selection @@ -690,21 +388,11 @@ } }); } -<<<<<<< .working /** * Create the input field for the password * @param container parent container */ -======= - /** - * Create the input field for the host - * Empty implementation since the host is not of interest - * @param container parent container - */ ->>>>>>> .merge-right.r899 - @Override -<<<<<<< .working -<<<<<<< .working + @Override protected final void createInputPassword(Composite container) { txtPassword = new Text(container,SWT.BORDER | SWT.PASSWORD); GridData gd = new GridData(GridData.FILL_HORIZONTAL); @@ -765,24 +453,13 @@ dialogChanged(); } }); -======= - protected void createHostInput(Composite container) { -======= - protected final void createHostInput(Composite container) { ->>>>>>> .merge-right.r2453 - // no implementation since the port number is not needed ->>>>>>> .merge-right.r899 - } - /** - * Create the input dropdown list for the database selection - */ + } + /** * Create the input field for the user name * @param container parent container */ @Override -<<<<<<< .working -<<<<<<< .working protected final void createInputUserName(Composite container) { txtUserName = new Text(container,SWT.BORDER | SWT.SINGLE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); @@ -796,56 +473,12 @@ } }); } -======= - protected void createInputDatabaseName(Composite container) { -======= - protected final void createInputDatabaseName(Composite container) { ->>>>>>> .merge-right.r2453 - comboName = new Combo(container,SWT.DROP_DOWN); - comboName.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - String selection = comboName.getItem(comboName.getSelectionIndex()); - if (selection==null || selection.equals("")){ //$NON-NLS-1$ - setDbName(null); - // Update the UI - comboSchema.removeAll(); - comboSchema.setEnabled(false); - comboTable.removeAll(); - comboTable.setEnabled(false); - helper=null; - } else { - //setDbName(selection); - // update the owner drop down - helper=new DTPConnection(selection); - connectionProfile=selection; - IConnectionProfile profile = helper.getConnectionProfile(connectionProfile); - setDbProduct(helper.getVenorNameUpperCase(profile)); - setHost(helper.getHost(profile)); - setPort(helper.getPortNumber(profile)); - setDbName(helper.getDatabase(profile)); - initSchemas(profile); - comboSchema.setEnabled(true); - } - dialogChanged(); - } - }); } ->>>>>>> .merge-right.r899 - -<<<<<<< .working + /** * Set the control up with the layout and the input fields * @param composite parent container */ -======= - /** - * Create the input field for the password - * @param container parent container - */ ->>>>>>> .merge-right.r899 - @Override -<<<<<<< .working -<<<<<<< .working + @Override public final void createControl(Composite composite) { Composite container = new Composite(composite, SWT.NULL); container.setFont(composite.getFont()); @@ -864,116 +497,35 @@ createSaveButton(container); -======= - protected void createInputPassword(Composite container) { -======= - protected final void createInputPassword(Composite container) { ->>>>>>> .merge-right.r2453 - txtPassword = new Text(container,SWT.BORDER | SWT.PASSWORD); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - txtPassword.setLayoutData(gd); - txtPassword.setToolTipText(DatatoolsMessages.DTPConnectionDefinitionPage_5); - txtPassword.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - setPasswd(txtPassword.getText()); - setConnectionTestedFalse(); - dialogChanged(); - } - - }); ->>>>>>> .merge-right.r899 dialogChanged(); setControl(container); } - /** - * Create the input dropdown list for the schema/owner - */ + /** * Create the input fields for the database name * @param container */ @Override -<<<<<<< .working -<<<<<<< .working protected final void createName(Composite container) { Label label = new Label(container,SWT.NULL); label.setText(DatatoolsMessages.DTPConnectionDefinitionPage_7); createInputDatabaseName(container); -======= - protected void createInputSchema(Composite container) { -======= - protected final void createInputSchema(Composite container) { ->>>>>>> .merge-right.r2453 - comboSchema = new Combo(container,SWT.DROP_DOWN); - comboSchema.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - String selection = comboSchema.getItem(comboSchema.getSelectionIndex()); - if (selection==null || selection.equals("")){ //$NON-NLS-1$ - setSchema(null); - // Update the UI - comboTable.removeAll(); - comboTable.setEnabled(false); - } else { - setSchema(selection); - // update the table drop down - IConnectionProfile profile = helper.getConnectionProfile(connectionProfile); - initTables(profile, selection); - comboTable.setEnabled(true); - } - dialogChanged(); - } - }); ->>>>>>> .merge-right.r899 - } - /** - * Create the input dropdown list for the tables - */ + } + /** * Don't check the database name * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#checkDBName() */ @Override -<<<<<<< .working -<<<<<<< .working protected final boolean checkDBName() { return true; -======= - protected void createInputTableName(Composite container) { -======= - protected final void createInputTableName(Composite container) { ->>>>>>> .merge-right.r2453 - comboTable = new Combo(container,SWT.DROP_DOWN); - comboTable.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - String selection = comboTable.getItem(comboTable.getSelectionIndex()); - if (selection==null || selection.equals("")){ //$NON-NLS-1$ - setTableName(null); - // Update the UI - } else { - setTableName(selection); - // update the field definition drop down - } - dialogChanged(); - } - }); ->>>>>>> .merge-right.r899 - } - -<<<<<<< .working + } + /** * Don't check the host name * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#checkHost() */ -======= - /** - * Create the input field for the user name - * @param container parent container - */ ->>>>>>> .merge-right.r899 - @Override -<<<<<<< .working + @Override protected final boolean checkHost() { return true; } @@ -1025,7 +577,6 @@ * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#getPort() */ @Override -<<<<<<< .working public String getPort() { return "0"; //$NON-NLS-1$ } @@ -1131,64 +682,8 @@ public String getConnectionDriver() { DTPConnection conn = new DTPConnection(getConnectionProfile()); return conn.getDriverClass(); -======= - protected void createInputUserName(Composite container) { -======= - protected final void createInputUserName(Composite container) { ->>>>>>> .merge-right.r2453 - txtUserName = new Text(container,SWT.BORDER | SWT.SINGLE); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - txtUserName.setLayoutData(gd); - txtUserName.setToolTipText(DatatoolsMessages.DTPConnectionDefinitionPage_6); - txtUserName.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - setUser(txtUserName.getText()); - setConnectionTestedFalse(); - dialogChanged(); - } - }); - } - - /** - * Set the control up with the layout and the input fields - * @param composite parent container - */ - @Override - public final void createControl(Composite composite) { - Composite container = new Composite(composite, SWT.NULL); - container.setFont(composite.getFont()); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int nColumns = 2; - layout.numColumns = nColumns; - layout.verticalSpacing = 9; - createName(container); - createUser(container); - createPassword(container); - createTableName(container); - createSchemaName(container); - - createConnectionButton(container); - ->>>>>>> .merge-right.r899 - createSaveButton(container); - - dialogChanged(); - setControl(container); - } - - /** - * Create the input fields for the database name - * @param container - */ - @Override - protected final void createName(Composite container) { - Label label = new Label(container,SWT.NULL); - label.setText(DatatoolsMessages.DTPConnectionDefinitionPage_7); - createInputDatabaseName(container); - } - -<<<<<<< .working + } + /** * Retrieved the default connection URL of a database product * @return connection URL @@ -1201,190 +696,4 @@ -======= - /** - * Don't check the database name - * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#checkDBName() - */ - @Override - protected final boolean checkDBName() { - return true; - } - - /** - * Don't check the host name - * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#checkHost() - */ - @Override - protected final boolean checkHost() { - return true; - } - - /** - * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#checkPassword() - */ - @Override - protected final boolean checkPassword() { - if (helper==null || connectionProfile==null){ - return true; // cannot check - } - Properties baseProp = helper.getConnectionProfile(connectionProfile).getBaseProperties(); - String pwd = baseProp.getProperty("org.eclipse.datatools.connectivity.db.password"); //$NON-NLS-1$ - if (pwd!=null){ - return super.checkPassword(); - } - return true; - } - - /** - * Don't check the port number - * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#checkPort() - */ - @Override - protected final boolean checkPort() { - return true; - } - - /** - * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#checkUserName() - */ - @Override - protected final boolean checkUserName() { - if (helper==null || connectionProfile==null){ - return true; // cannot check - } - IConnectionProfile prof = helper.getConnectionProfile(connectionProfile); - Properties baseProp = prof.getBaseProperties(); - String user = baseProp.getProperty("org.eclipse.datatools.connectivity.db.username"); //$NON-NLS-1$ - if (user!=null){ - return super.checkUserName(); - } - return true; - } - - /** - * Since the port is never set and null may lead to an exception return null - * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#getPort() - */ - @Override - public String getPort() { - return "0"; //$NON-NLS-1$ - } - - /** - * @param connectionProfile the connectionProfile to set - */ - private void setConnectionProfile(String connectionProfile) { - this.connectionProfile = connectionProfile; - } - - /** - * @return the connectionProfile - */ - private String getConnectionProfile() { - return connectionProfile; - } - - /** - * Retrieve the load message - * @return Pleas wait message - */ - @Override - public String getLoadMessage() { - return DatatoolsMessages.DTPConnectionDefinitionPage_9; - } - - /** - * Indicates if there is a message for the call of {@link #getDataBaseProducts()} - * since this method may take some time - * @return true - */ - @Override - public boolean hasLoadMessage() { - return true; - } - /** - * Compute the context help string for the current selection - * @return Context-ID - * @since 1.1.0 - */ - protected String getHelpContext(){ - String prefix=ISahitsHelpSystem.PLUGIN_ID+"."; //$NON-NLS-1$ - String postfix= "DTPConnectionDefinitionPage"; //$NON-NLS-1$ - return prefix+postfix; - } - - /** - * Make sure that the database product is not null - * @see ch.sahits.codegen.wizards.BasicDBDefinitionPage#testConnection() - */ - @Override - protected void testConnection() { - DTPConnectionModelGenerator generator = new DTPConnectionModelGenerator(helper.getConnectionProfile(),getSchema(),getTableName(),getUserName(),getPassword()); - String errorCode = generator.testConnection(); - if (errorCode==null ){ - setConnectionTestedTrue(); - dialogChanged(); - } else { - updateStatus(errorCode); - } - } - - - - /** - * Initialize the values and the text fields - * Since {@link #initData(String, boolean)} resets the combos they must - * be initialized anew. - * @param dbName database connection profile name - * @param tableName Table name - * @param host host name - * @param port port number - * @param user database user - * @param password user's password - * @param schema schema - * @since 1.1.1 - */ - public void init(String dbName,String tableName,String host,String port,String user, String password,String schema){ - setDbName(dbName); - IConnectionProfile profile = helper.getConnectionProfile(getConnectionProfile()); - initSchemas(profile); - comboName.select(comboName.indexOf(dbName)); - setSchema(schema); - initTables(profile, schema); - comboSchema.select(comboSchema.indexOf(schema)); - setTableName(tableName); - comboTable.select(comboTable.indexOf(tableName)); - enableTableName(true); - setHost(host); - setPort(port); - setUser(user); - txtUserName.setText(user); - setPasswd(password); - txtPassword.setText(password); - } - - /** - * Retrieve the JDBC driver class for the connection - * @return fully qualified driver class name - */ - @Override - public String getConnectionDriver() { - DTPConnection conn = new DTPConnection(getConnectionProfile()); - return conn.getDriverClass(); - } - - /** - * Retrieved the default connection URL of a database product - * @return connection URL - */ - @Override - public String getConnectionURL() { - DTPConnection conn = new DTPConnection(getConnectionProfile()); - return conn.getConnectionURL(); - } - - - ->>>>>>> .merge-right.r1041 }
--- a/trunk/ch.sahits.codegen.java.datatools/src/ch/sahits/codegen/java/internal/wizards/DTPConnectionModelGenerator.java +++ b/trunk/ch.sahits.codegen.java.datatools/src/ch/sahits/codegen/java/internal/wizards/DTPConnectionModelGenerator.java @@ -1,46 +1,21 @@ package ch.sahits.codegen.java.internal.wizards; -<<<<<<< .working import java.math.BigInteger; import java.sql.Blob; import java.sql.Connection; import java.sql.Date; import java.sql.ResultSet; -======= -import java.math.BigInteger; -import java.sql.Blob; -import java.sql.Connection; -import java.sql.Date; -<<<<<<< .working ->>>>>>> .merge-right.r1041 -======= -import java.sql.ResultSet; ->>>>>>> .merge-right.r2453 import java.sql.SQLException; -<<<<<<< .working -<<<<<<< .working import java.sql.Statement; -======= -import java.sql.Statement; ->>>>>>> .merge-right.r2453 import java.sql.Time; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Vector; -======= -import java.sql.Time; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; -import java.util.Vector; ->>>>>>> .merge-right.r1041 import org.eclipse.core.runtime.IStatus; import org.eclipse.datatools.connectivity.IConnection; import org.eclipse.datatools.connectivity.IConnectionProfile; -<<<<<<< .working -<<<<<<< .working import org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnectionFactory; import org.eclipse.datatools.modelbase.sql.constraints.Index; import org.eclipse.datatools.modelbase.sql.constraints.IndexMember; @@ -56,63 +31,23 @@ import org.eclipse.datatools.modelbase.sql.datatypes.NumericalDataType; import org.eclipse.datatools.modelbase.sql.datatypes.RowDataType; import org.eclipse.datatools.modelbase.sql.datatypes.TimeDataType; -======= -======= -import org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnectionFactory; ->>>>>>> .merge-right.r2453 -import org.eclipse.datatools.modelbase.sql.constraints.Index; -import org.eclipse.datatools.modelbase.sql.constraints.IndexMember; -import org.eclipse.datatools.modelbase.sql.datatypes.BinaryStringDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.BooleanDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.CharacterStringDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.DataType; -import org.eclipse.datatools.modelbase.sql.datatypes.DateDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.ExactNumericDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.FixedPrecisionDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.IntegerDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.NumberDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.NumericalDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.RowDataType; -import org.eclipse.datatools.modelbase.sql.datatypes.TimeDataType; ->>>>>>> .merge-right.r1041 import org.eclipse.datatools.modelbase.sql.schema.Database; import org.eclipse.datatools.modelbase.sql.tables.Column; import org.eclipse.datatools.modelbase.sql.tables.Table; import org.eclipse.emf.common.util.EList; import org.eclipse.osgi.util.NLS; -<<<<<<< .working -<<<<<<< .working import ch.sahits.codegen.ui.Logging; import ch.sahits.codegen.i18n.DatatoolsMessages; -======= -import ch.sahits.codegen.core.Logging; -======= -import ch.sahits.codegen.ui.Logging; ->>>>>>> .merge-right.r2453 -import ch.sahits.codegen.i18n.DatatoolsMessages; ->>>>>>> .merge-right.r1041 import ch.sahits.codegen.java.model.IDBConnectionModelGenerator; import ch.sahits.codegen.java.wizards.DTPConnection; -<<<<<<< .working -<<<<<<< .working import ch.sahits.codegen.model.IGeneralDBConnectionModelGenerator; import ch.sahits.model.db.DataBaseTableField; import ch.sahits.model.db.DataBaseTableIndex; import ch.sahits.model.db.EDBIndexConstrains; -======= -======= -import ch.sahits.codegen.model.IGeneralDBConnectionModelGenerator; ->>>>>>> .merge-right.r2453 - -import ch.sahits.model.db.DataBaseTableField; -import ch.sahits.model.db.DataBaseTableIndex; -import ch.sahits.model.db.EDBIndexConstrains; ->>>>>>> .merge-right.r1041 import ch.sahits.model.java.db.DataBaseTable; -<<<<<<< .working /** * This model generation implements the generation of a model based on datatools connection * @author Andi Hotz @@ -120,15 +55,6 @@ */ public class DTPConnectionModelGenerator extends DTPConnection implements IDBConnectionModelGenerator,IGeneralDBConnectionModelGenerator { private Logging logger = new Logging(); -======= -/** - * This model generation implements the generation of a model based on datatools connection - * @author Andi Hotz - * @since 1.1.0 - */ -public class DTPConnectionModelGenerator extends DTPConnection implements IDBConnectionModelGenerator,IGeneralDBConnectionModelGenerator { - private Logging logger = new Logging(); ->>>>>>> .merge-right.r1041 /** Name of the table */ private String tableName=null; /** Database user name */ @@ -167,7 +93,6 @@ * @return {@link DataBaseTable} model for the selected table */ public DataBaseTable generateModel() { -<<<<<<< .working try { testConnection(); } catch (Exception e) { @@ -268,146 +193,6 @@ v.add(dbti); } return v; -======= - try { - testConnection(); - } catch (Exception e) { - logger.log(e); - } - DataBaseTable dbt = new DataBaseTable("",table.getName(),table.getSchema().getName(),packageName,className); //$NON-NLS-1$ - dbt.setDbName(db.getName()); - dbt.setPassword(password); - dbt.setUserName(userName); - List<DataBaseTableField> dbtfs = getColumns(); - for (Iterator<DataBaseTableField> iterator = dbtfs.iterator(); iterator.hasNext();) { - DataBaseTableField dbtf = iterator.next(); - dbt.add(dbtf); - - } - List<DataBaseTableIndex> dbtis = getIndices(dbt); - for (Iterator<DataBaseTableIndex> iterator = dbtis.iterator(); iterator.hasNext();) { - DataBaseTableIndex dbti = iterator.next(); - dbt.add(dbti); - } - return dbt; - } - /** - * Retrieve the column data from the table - * @return List of Fields - */ - @SuppressWarnings("unchecked") - private List<DataBaseTableField> getColumns() { - Vector<DataBaseTableField> v = new Vector<DataBaseTableField>(); - EList l = table.getColumns(); - for (Iterator iterator = l.iterator(); iterator.hasNext();) { - Column col = (Column) iterator.next(); - String name = col.getName(); - DataType type = col.getDataType(); - DataBaseTableField dbtf = new DataBaseTableField(name,convert2JavaType(type),col.isNullable(),isAutGenKey(name)); - v.add(dbtf); - } - return v; ->>>>>>> .merge-right.r1041 - } - - /** - * Convert the datatype to a Java type - * @param type - * @return class representing the data type - */ - @SuppressWarnings("unchecked") - private Class convert2JavaType(DataType type){ - if (type instanceof BooleanDataType){ - return Boolean.class; - } - if (type instanceof BinaryStringDataType){ - return Blob.class; - } - if (type instanceof CharacterStringDataType){ - return String.class; - } - if (type instanceof DateDataType){ - return Date.class; - } - if (type instanceof ExactNumericDataType || - type instanceof FixedPrecisionDataType || - type instanceof NumberDataType || - type instanceof NumericalDataType){ - return Double.class; - } - if (type instanceof IntegerDataType){ - return Integer.class; - } - if (type instanceof RowDataType){ - return BigInteger.class; - } - if (type instanceof TimeDataType){ - return Time.class; - } - throw new RuntimeException(NLS.bind(DatatoolsMessages.DTPConnectionModelGenerator_0, type.getClass().getName())); - } - - /** - * Check if the field is an auto generated key field - * @param fieldName name of the fiedl to be checked - * @return true if the field is an auto generated key - * @since 1.2.0 - */ - private boolean isAutGenKey(String fieldName){ - IConnection conn = new JDBCConnectionFactory().createConnection(profile, userName, password); - Connection c = (Connection) conn.getRawConnection(); - try { - if (c.getMetaData().supportsGetGeneratedKeys()){ - Statement stmt = c.createStatement(); - String sql = "select "+fieldName+" from "+tableName; //$NON-NLS-1$ //$NON-NLS-2$ - ResultSet rs = stmt.executeQuery(sql); - stmt.close(); - if (rs.isBeforeFirst()){ - if (rs.next()){ - return rs.getMetaData().isAutoIncrement(1); - } - } - } else { - return false; - } - } catch (SQLException e) { - logger.logWarning(e); - return false; - } - return false; - } - /** - * Retrieve the column data from the table - * @param dbt table instance - * @return List of Fields - */ - @SuppressWarnings("unchecked") - private List<DataBaseTableIndex> getIndices(DataBaseTable dbt) { - Vector<DataBaseTableIndex> v = new Vector<DataBaseTableIndex>(); - EList l = table.getIndex(); - for (Iterator iterator = l.iterator(); iterator.hasNext();) { - Index index = (Index) iterator.next(); - String name = index.getName(); - DataBaseTableIndex dbti = new DataBaseTableIndex(name); - EList l2 = index.getMembers(); - for (Iterator iterator2 = l2.iterator(); iterator2.hasNext();) { - IndexMember member = (IndexMember) iterator2.next(); - Column col = member.getColumn(); - String name2 = col.getName(); - DataBaseTableField field = dbt.findField(name2); - dbti.addField(field); - } - if (index.isUnique()){ - dbti.setIndexConstrains(EDBIndexConstrains.UNIQUE); - } else if (!index.getForeignKey().isEmpty()){ - dbti.setIndexConstrains(EDBIndexConstrains.FOREIGN_KEY); - } else { - dbti.setIndexConstrains(EDBIndexConstrains.NONE); - } - dbti.setTable(dbt); - v.add(dbti); - } - return v; } /**