prepare release 2.4.4 Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/83302f08 Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/83302f08 Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/83302f08
Branch: refs/heads/master Commit: 83302f0838c04027f034ca99d960d156a1cb16d0 Parents: 46d3e32 Author: Rainer Döbele <[email protected]> Authored: Thu Aug 6 13:26:12 2015 +0200 Committer: Rainer Döbele <[email protected]> Committed: Thu Aug 6 13:26:12 2015 +0200 ---------------------------------------------------------------------- CHANGELOG.txt | 19 + empire-db-eclipse-codegen/.gitignore | 3 + empire-db-eclipse-codegen/META-INF/MANIFEST.MF | 30 + empire-db-eclipse-codegen/build.properties | 30 + empire-db-eclipse-codegen/lib/.gitignore | 8 + empire-db-eclipse-codegen/lib/readme.txt | 24 + empire-db-eclipse-codegen/plugin.xml | 76 +++ empire-db-eclipse-codegen/pom.xml | 86 +++ .../apache/empire/db/eclipse/CodeGenConfig.java | 574 +++++++++++++++++++ .../org/apache/empire/db/eclipse/Plugin.java | 190 ++++++ .../apache/empire/db/eclipse/PluginConsts.java | 47 ++ .../db/eclipse/handler/ConfigDialogHandler.java | 48 ++ .../empire/db/eclipse/model/ConfigFile.java | 64 +++ .../db/eclipse/model/JdbcDriverClass.java | 39 ++ .../db/eclipse/service/ConfigFileService.java | 38 ++ .../eclipse/service/ConfigFileServiceImpl.java | 234 ++++++++ .../db/eclipse/service/MessageService.java | 26 + .../db/eclipse/service/MessageServiceImpl.java | 52 ++ .../db/eclipse/ui/ClassParameterPage.java | 272 +++++++++ .../db/eclipse/ui/ConfigurationDialog.java | 293 ++++++++++ .../empire/db/eclipse/ui/DBTablesDialog.java | 350 +++++++++++ .../apache/empire/db/eclipse/ui/INavigator.java | 46 ++ .../org/apache/empire/db/eclipse/ui/IPage.java | 30 + .../apache/empire/db/eclipse/ui/MainPage.java | 305 ++++++++++ .../apache/empire/db/eclipse/ui/Navigator.java | 145 +++++ .../org/apache/empire/db/eclipse/ui/Page.java | 51 ++ .../empire/db/eclipse/ui/SchemaOptionsPage.java | 241 ++++++++ .../db/eclipse/util/SWTResourceManager.java | 455 +++++++++++++++ .../src/main/resources/defaultConfig.xml | 84 +++ .../src/main/resources/icons/addButton.png | Bin 0 -> 366 bytes .../src/main/resources/icons/check_all.gif | Bin 0 -> 344 bytes .../src/main/resources/icons/db_element.gif | Bin 0 -> 959 bytes .../src/main/resources/icons/deleteButton.png | Bin 0 -> 582 bytes .../src/main/resources/icons/empire-db-logo.gif | Bin 0 -> 12167 bytes .../src/main/resources/icons/empire_db_icon.png | Bin 0 -> 581 bytes .../src/main/resources/icons/folder.gif | Bin 0 -> 219 bytes .../src/main/resources/icons/logo.png | Bin 0 -> 5482 bytes .../src/main/resources/icons/save.png | Bin 0 -> 550 bytes .../src/main/resources/icons/testConnection.gif | Bin 0 -> 920 bytes .../src/main/resources/icons/uncheck_all.gif | Bin 0 -> 148 bytes .../main/resources/lang/messages_en.properties | 141 +++++ .../src/main/resources/templates/BaseRecord.vm | 41 ++ .../src/main/resources/templates/BaseTable.vm | 31 + .../src/main/resources/templates/BaseView.vm | 31 + .../src/main/resources/templates/Database.vm | 136 +++++ .../src/main/resources/templates/Record.vm | 66 +++ .../src/main/resources/templates/Table.vm | 76 +++ .../src/main/resources/templates/View.vm | 68 +++ .../empire-db-example-basic/.gitignore | 1 + .../empire-db-example-basic/pom.xml | 1 + .../empire-db-example-jsf2/.gitignore | 1 + .../empire-db-example-struts2-cxf/.gitignore | 1 + .../empire-db-example-struts2/.gitignore | 1 + empire-db-examples/pom.xml | 10 - empire-db-maven-plugin/pom.xml | 4 +- pom.xml | 28 +- 56 files changed, 4482 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/CHANGELOG.txt ---------------------------------------------------------------------- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 811bb52..9d53398 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,6 +5,25 @@ For more Information about a particular issue please visit https://issues.apache.org/jira/browse/EMPIREDB -------------- +Release 2.4.4: +-------------- +** Improvement + EMPIREDB-221 Allow batch execution through JDBC executeBatch + EMPIREDB-220 Allow override of fraction digits on JSF input tag + EMPIREDB-219 Added source code for Eclipse-Code-Generation-Plugin + EMPIREDB-217 Consistency check for data model defintion vs deployed data model + +** Bugfix + EMPIREDB-218 Missing reserved keywords in DBDatabaseDriverMySQL + EMPIREDB-216 Reserved words as colum names not correctly escaped/quoted for derby + EMPIREDB-215 Sequence generation and use for HSql to not agree in using toUpperCase + EMPIREDB-214 SQLServer - wrong 'alterColumnPhrase' + EMPIREDB-212 MySQL Nested Union bad syntax + EMPIREDB-210 Wrong Java Type in Records for BLOB Columns + EMPIREDB-209 Using a reserved word as a column alias in a select statement. + EMPIREDB-208 Decimal fields don't support scales above 9 + +-------------- Release 2.4.3: -------------- ** Improvement http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/.gitignore ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/.gitignore b/empire-db-eclipse-codegen/.gitignore new file mode 100644 index 0000000..ddd6d6d --- /dev/null +++ b/empire-db-eclipse-codegen/.gitignore @@ -0,0 +1,3 @@ +/.settings/ +/.classpath +/.project http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/META-INF/MANIFEST.MF ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/META-INF/MANIFEST.MF b/empire-db-eclipse-codegen/META-INF/MANIFEST.MF new file mode 100644 index 0000000..328a0a3 --- /dev/null +++ b/empire-db-eclipse-codegen/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Empire-db eclipse code generator +Bundle-SymbolicName: org.apache.empire.db.eclipse;singleton:=true +Bundle-Version: 1.0.0 +Bundle-ClassPath: ., + lib/commons-beanutils-1.8.3.jar, + lib/commons-logging-1.1.1.jar, + lib/commons-io-1.4.jar, + lib/empire-db-2.4.3.jar, + lib/empire-db-codegen-2.4.3.jar, + lib/slf4j-api-1.6.1.jar, + lib/slf4j-log4j12-1.6.1.jar, + lib/log4j-1.2.16.jar +Bundle-Activator: org.apache.empire.db.eclipse.Plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.ui.workbench, + org.eclipse.swt, + org.eclipse.core.resources, + org.apache.empire.db.eclipse +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: icons, + lang, + org.apache.empire.db.eclipse, + org.apache.empire.db.eclipse.handler, + org.apache.empire.db.eclipse.service, + org.apache.empire.db.eclipse.ui, + org.apache.empire.db.eclipse.util http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/build.properties ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/build.properties b/empire-db-eclipse-codegen/build.properties new file mode 100644 index 0000000..75ab60b --- /dev/null +++ b/empire-db-eclipse-codegen/build.properties @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version +# 2.0 (the "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 Unless required by +# applicable law or agreed to in writing, software distributed under the +# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for +# the specific language governing permissions and limitations under the +# License. +bin.includes = META-INF/,\ + plugin.xml,\ + .,\ + lib/commons-beanutils-1.8.3.jar,\ + lib/commons-logging-1.1.1.jar,\ + lib/commons-io-1.4.jar,\ + lib/empire-db-2.4.3.jar,\ + lib/empire-db-codegen-2.4.3.jar,\ + lib/slf4j-api-1.6.1.jar,\ + lib/slf4j-log4j12-1.6.1.jar,\ + lib/log4j-1.2.16.jar,\ + src/main/resources/ +jre.compilation.profile = J2SE-1.6 +src.includes = lib/,\ + src/main/ +source.. = src/main/java/,\ + src/main/resources/ http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/lib/.gitignore ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/lib/.gitignore b/empire-db-eclipse-codegen/lib/.gitignore new file mode 100644 index 0000000..156fd81 --- /dev/null +++ b/empire-db-eclipse-codegen/lib/.gitignore @@ -0,0 +1,8 @@ +/commons-beanutils-1.8.3.jar +/commons-io-1.4.jar +/commons-logging-1.1.1.jar +/empire-db-2.4.3.jar +/empire-db-codegen-2.4.3.jar +/log4j-1.2.16.jar +/slf4j-api-1.6.1.jar +/slf4j-log4j12-1.6.1.jar http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/lib/readme.txt ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/lib/readme.txt b/empire-db-eclipse-codegen/lib/readme.txt new file mode 100644 index 0000000..558439b --- /dev/null +++ b/empire-db-eclipse-codegen/lib/readme.txt @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version +# 2.0 (the "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 Unless required by +# applicable law or agreed to in writing, software distributed under the +# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for +# the specific language governing permissions and limitations under the +# License. + +In order to compile in Eclipse please copy the following files into this folder: + + commons-beanutils-1.8.3.jar, + commons-logging-1.1.1.jar, + commons-io-1.4.jar, + empire-db-2.4.3.jar, + empire-db-codegen-2.4.3.jar, + slf4j-api-1.6.1.jar, + slf4j-log4j12-1.6.1.jar, + log4j-1.2.16.jar http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/plugin.xml ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/plugin.xml b/empire-db-eclipse-codegen/plugin.xml new file mode 100644 index 0000000..9af512a --- /dev/null +++ b/empire-db-eclipse-codegen/plugin.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> + <!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version + 2.0 (the "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. + --> +<?eclipse version="3.4"?> +<plugin id="empire-db-eclipse-plugin" version="1.0.0" name="Empire-db Eclipse Plugin"> +<extension + point="org.eclipse.ui.handlers"> + <handler + class="org.apache.empire.db.eclipse.handler.ConfigDialogHandler" + commandId="codegen.commands.configDialogHandler"> + </handler> +</extension> + +<extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:org.eclipse.jdt.ui.PackageExplorer"> + <command + commandId="codegen.commands.configDialogHandler" + icon="src/main/resources/icons/empire_db_icon.png" + id="org.empire.codegen.menus.packageExplorer.configCommand" + label="EmpireDB Tool" + tooltip=""> + <visibleWhen + checkEnabled="false"> + <with + variable="selection"> + <iterate + ifEmpty="false" + operator="or"> + <instanceof + value="org.eclipse.core.resources.IProject"> + </instanceof> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> + <menuContribution + locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu"> + <command + commandId="codegen.commands.configDialogHandler" + icon="src/main/resources/icons/empire_db_icon.png" + id="org.empire.codegen.menus.projectExplorer.configCommand" + label="EmpireDB Tool" + tooltip=""> + <visibleWhen + checkEnabled="false"> + <with + variable="selection"> + <iterate + ifEmpty="false" + operator="or"> + <instanceof + value="org.eclipse.core.resources.IProject"> + </instanceof> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> +</extension> +</plugin> http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/pom.xml ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/pom.xml b/empire-db-eclipse-codegen/pom.xml new file mode 100644 index 0000000..58cc2e3 --- /dev/null +++ b/empire-db-eclipse-codegen/pom.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?> + <!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version + 2.0 (the "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>empire-db-parent</artifactId> + <groupId>org.apache.empire-db</groupId> + <version>2.4.4-SNAPSHOT</version> + </parent> + <artifactId>empire-db-eclipse-codegen</artifactId> + <name>Empire db eclipse codegen</name> + <packaging>eclipse-plugin</packaging> + + <properties> + <tycho-version>0.16.0</tycho-version> + </properties> + + <repositories> + <repository> + <id>luna</id> + <url>http://download.eclipse.org/releases/luna</url> + <layout>p2</layout> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.empire-db</groupId> + <artifactId>empire-db</artifactId> + </dependency> + <dependency> + <groupId>org.apache.empire-db</groupId> + <artifactId>empire-db-codegen</artifactId> + </dependency> + <!-- use log4j for logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </dependency> + <!-- commons --> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.4</version> + </dependency> + </dependencies> + + <build> + <plugins> + <!-- Eclipse --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-eclipse-plugin</artifactId> + <configuration> + <pde>true</pde> + </configuration> + </plugin> + <!-- enable tycho build extension --> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-maven-plugin</artifactId> + <version>${tycho-version}</version> + <extensions>true</extensions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/CodeGenConfig.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/CodeGenConfig.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/CodeGenConfig.java new file mode 100644 index 0000000..e57a6c0 --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/CodeGenConfig.java @@ -0,0 +1,574 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.empire.exceptions.ItemNotFoundException; +import org.apache.empire.exceptions.ObjectNotValidException; +import org.apache.empire.xml.XMLConfiguration; +import org.apache.empire.xml.XMLUtil; +import org.apache.log4j.xml.DOMConfigurator; +import org.slf4j.Logger; +import org.w3c.dom.Element; + +@XmlRootElement +public class CodeGenConfig extends XMLConfiguration { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(CodeGenConfig.class); + + // the logging configuration root node name + private final String loggingNodeName = "log4j:configuration"; + + private String configTitle; + + private String jdbcType; + + private String jdbcClass; + + private String jdbcURL; + + private String jdbcServer; + + private String jdbcPort; + + private String jdbcSID; + + private String jdbcUser; + + private String jdbcPwd; + + // generation options + /** + * name of the database catalog (may be null) + */ + private String dbCatalog = null; + + /** + * name of the database schema (may be null) + */ + private String dbSchema = null; + + /** + * name of the table pattern (may be null) + */ + private String dbTablePattern = null; + /** + * Name of the timestamp column used for optimistic locking (may be null) + * e.g. "UPDATE_TIMESTAMP"; + */ + private String timestampColumn = null; + + /** + * name of the target folder + */ + private String targetFolder; + + /** + * name of the template folder + */ + private String templateFolder = "configuration\\org.apache.empire\\templates\\"; + + /** + * name of the target package + */ + private String packageName; + + /** + * name of the table target package + */ + private String tablePackageName; + + /** + * name of the record target package + */ + private String recordPackageName; + + /** + * name of the view target package + */ + private String viewPackageName; + + /** + * Target name of the generated database class. This class extends + * DBDatabase. + */ + private String dbClassName; + + /** + * Target name of the generated table class. This class extends DBTable and + * is the base class for all generated individual table classes. + */ + private String tableBaseName; + + /** + * Target name of the generated view class. This class extends DBView and is + * the base class for all generated individual view classes. + */ + private String viewBaseName; + + /** + * Target name of the generated record class. This is a template class that + * extends DBRecord as follows:<br/> + * + * <pre> + * XXRecord<T extends XXTable> extends DBRecord + * </pre> + * + * <br/> + */ + private String recordBaseName; + + /** + * Prefix used for table member declarations + */ + private String tableNamePrefix = ""; + + /** + * Prefix used for view member declarations + */ + private String viewNamePrefix = ""; + + /** + * Prefix used for column member declarations + */ + private String columnNamePrefix = ""; + + /** + * Prefix used for generating table class names.<br/> + * The Table name is appended after the prefix starting with captial letter + * followed by lower case letters.<br/> + * Occurrence an of underscore indicates a new word which will again start + * with a capital letter.<br/> + * e.g.<br/> + * <ul> + * <li>Table "names" -> Class "XXNames"</li> + * <li>Table "flight_bookings" -> Class "XXFlightBookings"</li> + * </ul> + * Where XX is the prefix. + */ + private String tableClassPrefix = ""; + + /** + * Suffix used for generating table class names.<br/> + * The Table name is appended before the suffix starting with captial letter + * followed by lower case letters.<br/> + * Occurrence an of underscore indicates a new word which will again start + * with a capital letter.<br/> + * e.g.<br/> + * <ul> + * <li>Table "names" -> Class "NamesTable"</li> + * <li>Table "flight_bookings" -> Class "FlightBookingsTable"</li> + * </ul> + * Where "Table" is the suffix. + */ + private String tableClassSuffix = ""; + + /** + * Prefix used for generating view class names.<br/> + * The Table name is appended after the prefix starting with captial letter + * followed by lower case letters.<br/> + * Occurrence an of underscore indicates a new word which will again start + * with a capital letter.<br/> + * See naming of table classes above. + */ + private String viewClassPrefix = ""; + + /** + * Suffix used for generating view class names.<br/> + * The View name is appended before the suffix starting with captial letter + * followed by lower case letters.<br/> + * Occurrence an of underscore indicates a new word which will again start + * with a capital letter.<br/> + * e.g.<br/> + * <ul> + * <li>View "names" -> Class "NamesView"</li> + * <li>View "flight_bookings" -> Class "FlightBookingsView"</li> + * </ul> + * Where "View" is the suffix. + */ + private String viewClassSuffix = ""; + + /** + * if TRUE table classes should be declared as inner classes of DBDatabase. + * <br/> + * if FALSE table classes should be declared as top level classes. + */ + private boolean nestTables = false; + + /** + * if TRUE view classes should be declared as inner classes of DBDatabase. + * <br/> + * if FALSE view classes should be declared as top level classes. + */ + private boolean nestViews = false; + + /** + * if TRUE record classes should have a getter and setter for each field. + * <br/> + * Otherwise getters / setters are omitted. + */ + private boolean createRecordProperties; + + /** + * true if names of tables and views should not be camel-cased + */ + private boolean preserverCharacterCase = false; + + /** + * true if names of foreign-key-relations should be preserved + */ + private boolean preserveRelationNames = false; + + /** + * Initialize the configuration. + * + * @param filename + * the file to read + */ + public void init(String filename) { + // Read the properties file + super.init(filename, false); + + // Init Logging + initLogging(); + + // Reader Provider Properties + readProperties(this, "properties"); + } + + /** + * Init logging using Log4J's DOMConfigurator + * + * @return + */ + private void initLogging() { + // Get configuration root node + Element rootNode = getRootNode(); + if (rootNode == null) { + throw new ObjectNotValidException(getClass().getName()); + } + // Find log configuration node + Element loggingNode = XMLUtil.findFirstChild(rootNode, this.loggingNodeName); + if (loggingNode == null) { // log configuration node not found + CodeGenConfig.log.error("Log configuration node {} has not been found. Logging has not been configured.", + this.loggingNodeName); + throw new ItemNotFoundException(this.loggingNodeName); + } + // Init Log4J + DOMConfigurator.configure(loggingNode); + // done + CodeGenConfig.log.info("Logging sucessfully configured from node {}.", this.loggingNodeName); + } + + public String getJdbcClass() { + return this.jdbcClass; + } + + public void setJdbcClass(String jdbcClass) { + this.jdbcClass = jdbcClass; + } + + public String getJdbcURL() { + return this.jdbcURL; + } + + public void setJdbcURL(String jdbcURL) { + this.jdbcURL = jdbcURL; + } + + public String getJdbcUser() { + return this.jdbcUser; + } + + public void setJdbcUser(String jdbcUser) { + this.jdbcUser = jdbcUser; + } + + public String getJdbcPwd() { + return this.jdbcPwd; + } + + public void setJdbcPwd(String jdbcPwd) { + this.jdbcPwd = jdbcPwd; + } + + // ------- generation options ------- + + public String getDbCatalog() { + if(this.dbCatalog == "") { + this.dbCatalog = null; + } + return this.dbCatalog; + } + + public void setDbCatalog(String dbCatalog) { + this.dbCatalog = dbCatalog; + } + + public String getDbSchema() { + if(this.dbSchema == "") { + this.dbSchema = null; + } + return this.dbSchema; + } + + public void setDbSchema(String dbSchema) { + this.dbSchema = dbSchema; + } + + public String getDbTablePattern() { + return this.dbTablePattern; + } + + public void setDbTablePattern(String dbTablePattern) { + this.dbTablePattern = dbTablePattern; + } + + public String getTimestampColumn() { + return this.timestampColumn; + } + + public void setTimestampColumn(String timestampColumn) { + this.timestampColumn = timestampColumn; + } + + public String getTargetFolder() { + return this.targetFolder; + } + + public void setTargetFolder(String targetFolder) { + this.targetFolder = targetFolder; + } + + public String getTemplateFolder() { + return this.templateFolder; + } + + public void setTemplateFolder(String templateFolder) { + this.templateFolder = templateFolder; + } + + public String getPackageName() { + return this.packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getTablePackageName() { + return fallback(this.tablePackageName, "tables"); + } + + public void setTablePackageName(String tablePackageName) { + this.tablePackageName = tablePackageName; + } + + public String getRecordPackageName() { + return fallback(this.recordPackageName, "records"); + } + + public void setRecordPackageName(String recordPackageName) { + this.recordPackageName = recordPackageName; + } + + public String getViewPackageName() { + return fallback(this.viewPackageName, "views"); + } + + public void setViewPackageName(String viewPackageName) { + this.viewPackageName = viewPackageName; + } + + public String getDbClassName() { + return this.dbClassName; + } + + public void setDbClassName(String dbClassName) { + this.dbClassName = dbClassName; + } + + public String getTableBaseName() { + return this.tableBaseName; + } + + public void setTableBaseName(String tableBaseName) { + this.tableBaseName = tableBaseName; + } + + public String getViewBaseName() { + return this.viewBaseName; + } + + public void setViewBaseName(String viewBaseName) { + this.viewBaseName = viewBaseName; + } + + public String getRecordBaseName() { + return this.recordBaseName; + } + + public void setRecordBaseName(String recordBaseName) { + this.recordBaseName = recordBaseName; + } + + public String getTableNamePrefix() { + return this.tableNamePrefix; + } + + public void setTableNamePrefix(String tableNamePrefix) { + this.tableNamePrefix = tableNamePrefix; + } + + public String getTableClassPrefix() { + return this.tableClassPrefix; + } + + public void setTableClassPrefix(String tableClassPrefix) { + this.tableClassPrefix = tableClassPrefix; + } + + public String getTableClassSuffix() { + return this.tableClassSuffix; + } + + public void setTableClassSuffix(String tableClassSuffix) { + this.tableClassSuffix = tableClassSuffix; + } + + public String getViewNamePrefix() { + return this.viewNamePrefix; + } + + public void setViewNamePrefix(String viewNamePrefix) { + this.viewNamePrefix = viewNamePrefix; + } + + public String getViewClassPrefix() { + return this.viewClassPrefix; + } + + public void setViewClassPrefix(String viewClassPrefix) { + this.viewClassPrefix = viewClassPrefix; + } + + public String getViewClassSuffix() { + return this.viewClassSuffix; + } + + public void setViewClassSuffix(String viewClassSuffix) { + this.viewClassSuffix = viewClassSuffix; + } + + public String getColumnNamePrefix() { + return this.columnNamePrefix; + } + + public void setColumnNamePrefix(String columnNamePrefix) { + this.columnNamePrefix = columnNamePrefix; + } + + public boolean isNestTables() { + return this.nestTables; + } + + public void setNestTables(boolean nestTables) { + this.nestTables = nestTables; + } + + public boolean isNestViews() { + return this.nestViews; + } + + public void setNestViews(boolean nestViews) { + this.nestViews = nestViews; + } + + public boolean isCreateRecordProperties() { + return this.createRecordProperties; + } + + public void setCreateRecordProperties(boolean createRecordProperties) { + this.createRecordProperties = createRecordProperties; + } + + public boolean isPreserverCharacterCase() { + return this.preserverCharacterCase; + } + + public void setPreserverCharacterCase(boolean preserverCharacterCase) { + this.preserverCharacterCase = preserverCharacterCase; + } + + public boolean isPreserveRelationNames() { + return this.preserveRelationNames; + } + + public void setPreserveRelationNames(boolean preserveRelationNames) { + this.preserveRelationNames = preserveRelationNames; + } + + private String fallback(String packageName, String defaultSubpackage) { + String pkg = packageName; + if (pkg == null && this.packageName != null) { + pkg = this.packageName + "." + defaultSubpackage; + } + return pkg; + } + + public String getConfigTitle() { + return this.configTitle; + } + + public void setConfigTitle(String configTitle) { + this.configTitle = configTitle; + } + + public String getJdbcType() { + return this.jdbcType; + } + + public void setJdbcType(String jdbcType) { + this.jdbcType = jdbcType; + } + + public String getJdbcServer() { + return this.jdbcServer; + } + + public void setJdbcServer(String jdbcServer) { + this.jdbcServer = jdbcServer; + } + + public String getJdbcPort() { + return this.jdbcPort; + } + + public void setJdbcPort(String jdbcPort) { + this.jdbcPort = jdbcPort; + } + + public String getJdbcSID() { + return this.jdbcSID; + } + + public void setJdbcSID(String jdbcSID) { + this.jdbcSID = jdbcSID; + } +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/Plugin.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/Plugin.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/Plugin.java new file mode 100644 index 0000000..905cfef --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/Plugin.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import org.apache.commons.io.FileUtils; +import org.apache.empire.db.eclipse.model.JdbcDriverClass; +import org.apache.empire.db.eclipse.service.ConfigFileService; +import org.apache.empire.db.eclipse.service.ConfigFileServiceImpl; +import org.apache.empire.db.eclipse.service.MessageService; +import org.apache.empire.db.eclipse.service.MessageServiceImpl; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The activator class controls the plug-in life cycle + */ +public class Plugin extends AbstractUIPlugin +{ + private static final Logger log = LoggerFactory.getLogger(Plugin.class); + // The shared instance + private static Plugin plugin; + + private final MessageService messageService; + + private final ConfigFileService configFileService; + + private final Map<String, JdbcDriverClass> driverClasses; + + /** + * The constructor + */ + public Plugin() + { + this.messageService = new MessageServiceImpl(Locale.ENGLISH); + // check config dir + File checkConfigDir = new File(PluginConsts.CONFIG_DIR_PATH, PluginConsts.CONFIG_DIR); + if (!checkConfigDir.exists()) + { + checkConfigDir.mkdirs(); + } + // check default config file + checkConfigFile(PluginConsts.DEFAULT_CONFIG_FILE); + // check database generation templates + checkConfigFile(PluginConsts.TEMPLATE_BASE_RECORD); + checkConfigFile(PluginConsts.TEMPLATE_BASE_TABLE); + checkConfigFile(PluginConsts.TEMPLATE_BASE_VIEW); + checkConfigFile(PluginConsts.TEMPLATE_DATABASE); + checkConfigFile(PluginConsts.TEMPLATE_RECORD); + checkConfigFile(PluginConsts.TEMPLATE_TABLE); + checkConfigFile(PluginConsts.TEMPLATE_VIEW); + + this.configFileService = new ConfigFileServiceImpl(checkConfigDir); + this.driverClasses = new HashMap<String, JdbcDriverClass>(); + this.driverClasses.put("Oracle", new JdbcDriverClass("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@%s:%s:%s")); + this.driverClasses.put("Microsoft SQL Server", new JdbcDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver", + "jdbc:sqlserver://%s:%s;databaseName=%s")); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) + throws Exception + { + Plugin.log.debug("Start empire-db-codegen plugin"); + super.start(context); + Plugin.plugin = this; + + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) + throws Exception + { + Plugin.log.debug("Stop empire-db-codegen plugin"); + Plugin.plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Plugin getInstance() + { + return Plugin.plugin; + } + + public MessageService getMessageService() + { + return this.messageService; + } + + public ConfigFileService getConfigFileService() + { + return this.configFileService; + } + + public Map<String, JdbcDriverClass> getDriverClasses() + { + return this.driverClasses; + } + + public String[] getDriverClassNames() + { + String[] driverClassNames = new String[this.driverClasses.size() + 1]; + driverClassNames[0] = " "; + int i = 1; + for (String key : this.driverClasses.keySet()) + { + driverClassNames[i] = key; + i++; + } + return driverClassNames; + } + + public Connection getJDBCConnection(String connectionType, String jdbcServer, String jdbcPort, String jdbcDatabase, String jdbcUser, + String jdbcPwd) + throws SQLException + { + JdbcDriverClass jdbcDriverClass = this.driverClasses.get(connectionType); + String jdbcClass = jdbcDriverClass.getJdbcClass(); + String jdbcURL = String.format(jdbcDriverClass.getJdbcUrl(), jdbcServer, jdbcPort, jdbcDatabase); + Plugin.log.info("Connecting to Database'" + jdbcURL + "' / User=" + jdbcUser); + Connection conn = null; + try + { + Class.forName(jdbcClass).newInstance(); + } + catch (Exception ex) + { + throw new SQLException("Could not load database driver: " + jdbcClass); + } + conn = DriverManager.getConnection(jdbcURL, jdbcUser, jdbcPwd); + Plugin.log.info("Connected successfully"); + return conn; + } + + private void checkConfigFile(String filename) + { + File configFile = new File(PluginConsts.CONFIG_DIR_PATH, filename); + if (!configFile.exists()) + { + URL inputUrl = Plugin.class.getClassLoader().getResource(filename); + try + { + FileUtils.copyURLToFile(inputUrl, configFile); + } + catch (IOException e) + { + Plugin.log.error("Could not copy resoucres file in configuration directory! %s", e.getMessage()); + } + } + } +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/PluginConsts.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/PluginConsts.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/PluginConsts.java new file mode 100644 index 0000000..479cbc5 --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/PluginConsts.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse; + +public class PluginConsts +{ + // The plug-in ID + public static final String PLUGIN_ID = "empire-db-eclipse-codegen"; + + public static int BUTTON_NEXT_ID = 2; + + public static int BUTTON_PREVIOUS_ID = 3; + + public static int BUTTON_OK = 4; + + public static int BUTTON_CANCEL = 5; + + public static final String CONFIG_DIR_PATH = "configuration/org.apache.empire"; + + public static final String CONFIG_DIR = "config"; + + public static final String DEFAULT_CONFIG_FILE = "defaultConfig.xml"; + + public static final String TEMPLATE_BASE_RECORD = "templates/BaseRecord.vm"; + public static final String TEMPLATE_BASE_TABLE = "templates/BaseTable.vm"; + public static final String TEMPLATE_BASE_VIEW = "templates/BaseView.vm"; + public static final String TEMPLATE_DATABASE = "templates/Database.vm"; + public static final String TEMPLATE_RECORD = "templates/Record.vm"; + public static final String TEMPLATE_TABLE = "templates/Table.vm"; + public static final String TEMPLATE_VIEW = "templates/View.vm"; +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/handler/ConfigDialogHandler.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/handler/ConfigDialogHandler.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/handler/ConfigDialogHandler.java new file mode 100644 index 0000000..da36e1d --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/handler/ConfigDialogHandler.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.handler; + +import org.apache.empire.db.codegen.CodeGenerator; +import org.apache.empire.db.eclipse.Plugin; +import org.apache.empire.db.eclipse.ui.ConfigurationDialog; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.window.Window; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.handlers.HandlerUtil; + +public class ConfigDialogHandler extends AbstractHandler +{ + public Object execute(ExecutionEvent event) + throws ExecutionException + { + // loads the configurations + Plugin.getInstance().getConfigFileService().refreshConfigList(); + // create new window + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + ConfigurationDialog dialog = new ConfigurationDialog(window.getShell()); + if (dialog.open() == Window.OK) + { + // start the class cration + CodeGenerator.main(new String[] { dialog.getConfigFileAbsolutPath() }); + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/ConfigFile.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/ConfigFile.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/ConfigFile.java new file mode 100644 index 0000000..a810733 --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/ConfigFile.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.model; + +import org.apache.empire.db.eclipse.CodeGenConfig; + +public class ConfigFile { + + private String uuid; + + private String filename; + + private CodeGenConfig codeGenConfig; + + public ConfigFile(CodeGenConfig codeGenConfig) { + this.codeGenConfig = codeGenConfig; + } + + public ConfigFile(String filename, String uuid, CodeGenConfig pluginCodeGenConfig) { + this.filename = filename; + this.uuid = uuid; + this.codeGenConfig = pluginCodeGenConfig; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getUuid() { + return uuid; + } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public CodeGenConfig getCodeGenConfig() { + return codeGenConfig; + } + + public void setCodeGenConfig(CodeGenConfig codeGenConfig) { + this.codeGenConfig = codeGenConfig; + } +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/JdbcDriverClass.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/JdbcDriverClass.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/JdbcDriverClass.java new file mode 100644 index 0000000..52451a0 --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/model/JdbcDriverClass.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.model; + +public class JdbcDriverClass { + + private final String jdbcClass; + + private final String jdbcUrl; + + public JdbcDriverClass(String jdbcClass, String jdbcUrl) { + this.jdbcClass = jdbcClass; + this.jdbcUrl = jdbcUrl; + } + + public String getJdbcClass() { + return jdbcClass; + } + + public String getJdbcUrl() { + return jdbcUrl; + } +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileService.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileService.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileService.java new file mode 100644 index 0000000..11ccea4 --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileService.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.service; + +import org.apache.empire.db.eclipse.model.ConfigFile; + +public interface ConfigFileService +{ + public boolean saveConfig(ConfigFile config); + + public ConfigFile getConfig(String configTitle); + + public boolean deleteConfig(String uuid); + + public void refreshConfigList(); + + public String[] getConfigTitles(); + + public ConfigFile getDefaultConfig(); + + public String getConfigFilePath(String uuid); +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileServiceImpl.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileServiceImpl.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileServiceImpl.java new file mode 100644 index 0000000..bbc8b7f --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/ConfigFileServiceImpl.java @@ -0,0 +1,234 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.service; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.empire.commons.StringUtils; +import org.apache.empire.db.eclipse.CodeGenConfig; +import org.apache.empire.db.eclipse.Plugin; +import org.apache.empire.db.eclipse.PluginConsts; +import org.apache.empire.db.eclipse.model.ConfigFile; +import org.apache.empire.db.eclipse.model.JdbcDriverClass; +import org.apache.empire.xml.XMLWriter; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class ConfigFileServiceImpl implements ConfigFileService +{ + private Map<String, ConfigFile> configurationgs; + + private final File directory; + + public ConfigFileServiceImpl(File configDir) + { + this.directory = configDir; + } + + public boolean saveConfig(ConfigFile config) + { + ConfigFile configFile = this.configurationgs.get(config.getUuid()); + if (configFile == null) + { + configFile = config; + configFile.setFilename(config.getCodeGenConfig().getConfigTitle() + "_" + Calendar.getInstance().getTimeInMillis() + + ".xml"); + configFile.setUuid(UUID.randomUUID().toString()); + this.configurationgs.put(configFile.getUuid(), configFile); + } + else + { + configFile.setCodeGenConfig(config.getCodeGenConfig()); + } + try + { + File file = new File(this.directory, configFile.getFilename()); + if (!file.exists()) + { + file.createNewFile(); + } + // build url string + CodeGenConfig pluginConfig = configFile.getCodeGenConfig(); + if (!StringUtils.isEmpty(pluginConfig.getJdbcType())) + { + JdbcDriverClass driver = Plugin.getInstance().getDriverClasses().get(pluginConfig.getJdbcType()); + pluginConfig.setJdbcURL(String.format(driver.getJdbcUrl(), pluginConfig.getJdbcServer(), pluginConfig.getJdbcPort(), + pluginConfig.getJdbcSID())); + pluginConfig.setJdbcClass(driver.getJdbcClass()); + } + else + { + pluginConfig.setJdbcURL(""); + } + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.newDocument(); + Element configElement = document.createElement("config"); + document.appendChild(configElement); + // Marshal the Object to a Document + JAXBContext jc = JAXBContext.newInstance(CodeGenConfig.class); + Marshaller marshaller = jc.createMarshaller(); + marshaller.marshal(pluginConfig, configElement); + document.renameNode(configElement.getFirstChild(), configElement.getFirstChild().getNamespaceURI(), "properties"); + configElement.appendChild(createLogginNode(document)); + XMLWriter writer = new XMLWriter(new FileOutputStream(file)); + writer.print(document); + } + catch (Exception e) + { + return false; + } + return true; + } + + private Element createLogginNode(Document document) + { + Element log4j = document.createElement("log4j:configuration"); + log4j.setAttribute("xmlns:log4j", "http://jakarta.apache.org/log4j/"); + Element appender = document.createElement("appender"); + appender.setAttribute("name", "default"); + appender.setAttribute("class", "org.apache.log4j.ConsoleAppender"); + Element layout = document.createElement("layout"); + layout.setAttribute("class", "org.apache.log4j.PatternLayout"); + Element param = document.createElement("param"); + param.setAttribute("name", "ConversionPattern"); + param.setAttribute("value", "%-5p [%d{yyyy/MM/dd HH:mm}]: %m at %l %n"); + layout.appendChild(param); + appender.appendChild(layout); + log4j.appendChild(appender); + + Element logger = document.createElement("logger"); + logger.setAttribute("name", "org.apache.empire.commons"); + logger.setAttribute("additivity", "false"); + Element level = document.createElement("level"); + level.setAttribute("value", "warn"); + Element loggerAppender = document.createElement("appender-ref"); + loggerAppender.setAttribute("ref", "default"); + logger.appendChild(level); + logger.appendChild(loggerAppender); + log4j.appendChild(logger); + + Element root = document.createElement("root"); + Element priority = document.createElement("priority"); + priority.setAttribute("value", "info"); + Element rootAppender = document.createElement("appender-ref"); + rootAppender.setAttribute("ref", "default"); + root.appendChild(priority); + root.appendChild(rootAppender); + log4j.appendChild(root); + + return log4j; + } + + public ConfigFile getConfig(String configTitle) + { + for (ConfigFile configFile : this.configurationgs.values()) + { + if (configFile.getCodeGenConfig().getConfigTitle().equals(configTitle)) + { + return configFile; + } + } + return null; + } + + public boolean deleteConfig(String uuid) + { + ConfigFile configFile = this.configurationgs.get(uuid); + if (configFile == null) + { + return false; + } + File file = new File(this.directory, configFile.getFilename()); + boolean deleted = file.delete(); + if (deleted) + { + this.configurationgs.remove(configFile); + } + return deleted; + } + + public void refreshConfigList() + { + File[] files = this.directory.listFiles(); + this.configurationgs = new HashMap<String, ConfigFile>(); + if (files != null) + { + for (File file : files) + { + if (file.isFile()) + { + CodeGenConfig config = new CodeGenConfig(); + try + { + config.init(file.getAbsolutePath()); + } + catch (Exception e) + { + continue; + } + String uuid = UUID.randomUUID().toString(); + this.configurationgs.put(uuid, new ConfigFile(file.getName(), uuid, config)); + } + } + } + } + + public String[] getConfigTitles() + { + List<String> configTitles = new ArrayList<String>(); + for (ConfigFile configFile : this.configurationgs.values()) + { + configTitles.add(configFile.getCodeGenConfig().getConfigTitle()); + } + Collections.sort(configTitles); + return configTitles.toArray(new String[configTitles.size()]); + } + + public ConfigFile getDefaultConfig() + { + CodeGenConfig defaultConfig = new CodeGenConfig(); + File file = new File(PluginConsts.CONFIG_DIR_PATH, PluginConsts.DEFAULT_CONFIG_FILE); + defaultConfig.init(file.getAbsolutePath()); + return new ConfigFile(defaultConfig); + } + + public String getConfigFilePath(String uuid) + { + ConfigFile config = this.configurationgs.get(uuid); + if (config == null) + { + return null; + } + return new File(new File(PluginConsts.CONFIG_DIR_PATH, PluginConsts.CONFIG_DIR), config.getFilename()).getAbsolutePath(); + } +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageService.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageService.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageService.java new file mode 100644 index 0000000..b76fb2f --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageService.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.service; + +public interface MessageService +{ + String resolveMessageKey(String key); + + String resolveMessageKey(String key, Object... params); +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageServiceImpl.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageServiceImpl.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageServiceImpl.java new file mode 100644 index 0000000..1cc4dc8 --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/service/MessageServiceImpl.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.service; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; + +public class MessageServiceImpl implements MessageService +{ + private final Locale locale; + + public static List<Locale> supportedLocales = new ArrayList<Locale>(); + + static + { + MessageServiceImpl.supportedLocales.add(Locale.ENGLISH); + } + + public MessageServiceImpl(Locale locale) + { + this.locale = locale; + } + + public String resolveMessageKey(String key) + { + return ResourceBundle.getBundle("lang.messages", this.locale).getString(key); + } + + public String resolveMessageKey(String key, Object... params) + { + return MessageFormat.format(resolveMessageKey(key), params); + } +} http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ClassParameterPage.java ---------------------------------------------------------------------- diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ClassParameterPage.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ClassParameterPage.java new file mode 100644 index 0000000..1660b62 --- /dev/null +++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ClassParameterPage.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.empire.db.eclipse.ui; + +import org.apache.empire.db.eclipse.CodeGenConfig; +import org.apache.empire.db.eclipse.Plugin; +import org.apache.empire.db.eclipse.util.SWTResourceManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class ClassParameterPage extends Page +{ + private final Text ctlDbClassName; + private final Text ctlTableBaseName; + private final Text ctlViewBaseName; + private final Text ctlRecordBaseName; + private final Text ctlTableNamePrefix; + private final Text ctlTableClassPrefix; + private final Text ctlTableClassSuffix; + private final Text ctlViewNamePrefix; + private final Text ctlViewClassPrefix; + private final Text ctlViewClassSuffix; + private final Text ctlColumnNamePrefix; + private final Label lblClassParameter; + private final Label lblTableBaseName; + private final Label lblViewBaseName; + private final Label lblRecordBaseName; + private final Label lblDbClassName; + + private final Button ctlNestTables; + private final Button ctlNestViews; + private final Button ctlCreateRecordProperties; + private final Button ctlPreserverCharCase; + private final Button ctlPreserveRelationNames; + + public ClassParameterPage(Composite parent, int style) + { + super(parent, style); + + this.lblDbClassName = new Label(this, SWT.NONE); + this.lblDbClassName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbClassName")); + this.lblDbClassName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbClassName")); + this.lblDbClassName.setBounds(15, 50, 145, 17); + + this.ctlDbClassName = new Text(this, SWT.BORDER); + this.ctlDbClassName.setBounds(185, 47, 250, 21); + this.ctlDbClassName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbClassName")); + + this.lblClassParameter = new Label(this, SWT.NONE); + this.lblClassParameter.setAlignment(SWT.CENTER); + this.lblClassParameter.setText(Plugin.getInstance().getMessageService().resolveMessageKey("classParameter")); + this.lblClassParameter.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.BOLD)); + this.lblClassParameter.setBounds(0, 10, 418, 21); + + this.lblTableBaseName = new Label(this, SWT.NONE); + this.lblTableBaseName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("tableBaseName")); + this.lblTableBaseName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableBaseName")); + this.lblTableBaseName.setBounds(15, 76, 145, 17); + + this.ctlTableBaseName = new Text(this, SWT.BORDER); + this.ctlTableBaseName.setBounds(185, 73, 250, 21); + this.ctlTableBaseName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableBaseName")); + + this.lblViewBaseName = new Label(this, SWT.NONE); + this.lblViewBaseName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("viewBaseName")); + this.lblViewBaseName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewBaseName")); + this.lblViewBaseName.setBounds(15, 102, 145, 17); + + this.ctlViewBaseName = new Text(this, SWT.BORDER); + this.ctlViewBaseName.setBounds(185, 99, 250, 21); + this.ctlViewBaseName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewBaseName")); + + this.lblRecordBaseName = new Label(this, SWT.NONE); + this.lblRecordBaseName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("recordBaseName")); + this.lblRecordBaseName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.recordBaseName")); + this.lblRecordBaseName.setBounds(15, 128, 145, 17); + + this.ctlRecordBaseName = new Text(this, SWT.BORDER); + this.ctlRecordBaseName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.recordBaseName")); + this.ctlRecordBaseName.setBounds(185, 125, 250, 21); + + Label lblTableNamePrefix = new Label(this, SWT.NONE); + lblTableNamePrefix.setText(Plugin.getInstance().getMessageService().resolveMessageKey("tableNamePrefix")); + lblTableNamePrefix.setBounds(15, 154, 145, 17); + lblTableNamePrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableNamePrefix")); + + this.ctlTableNamePrefix = new Text(this, SWT.BORDER); + this.ctlTableNamePrefix.setBounds(185, 151, 250, 21); + this.ctlTableNamePrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableNamePrefix")); + + Label lblTableClassPrefix = new Label(this, SWT.NONE); + lblTableClassPrefix.setText(Plugin.getInstance().getMessageService().resolveMessageKey("tableClassPrefix")); + lblTableClassPrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableClassPrefix")); + lblTableClassPrefix.setBounds(15, 180, 145, 17); + + this.ctlTableClassPrefix = new Text(this, SWT.BORDER); + this.ctlTableClassPrefix.setBounds(185, 177, 250, 21); + this.ctlTableClassPrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableClassPrefix")); + + Label lblTableClassSuffix = new Label(this, SWT.NONE); + lblTableClassSuffix.setText(Plugin.getInstance().getMessageService().resolveMessageKey("tableClassSuffix")); + lblTableClassSuffix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableClassSuffix")); + lblTableClassSuffix.setBounds(15, 206, 145, 17); + + this.ctlTableClassSuffix = new Text(this, SWT.BORDER); + this.ctlTableClassSuffix.setBounds(185, 203, 250, 21); + this.ctlTableClassSuffix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tableClassSuffix")); + + Label lblViewNamePrefix = new Label(this, SWT.NONE); + lblViewNamePrefix.setText(Plugin.getInstance().getMessageService().resolveMessageKey("viewNamePrefix")); + lblViewNamePrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewNamePrefix")); + lblViewNamePrefix.setBounds(15, 232, 145, 17); + + this.ctlViewNamePrefix = new Text(this, SWT.BORDER); + this.ctlViewNamePrefix.setBounds(185, 229, 250, 21); + this.ctlViewNamePrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewNamePrefix")); + + Label lblViewClassPrefix = new Label(this, SWT.NONE); + lblViewClassPrefix.setText(Plugin.getInstance().getMessageService().resolveMessageKey("viewClassPrefix")); + lblViewClassPrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewClassPrefix")); + lblViewClassPrefix.setBounds(15, 258, 145, 17); + + this.ctlViewClassPrefix = new Text(this, SWT.BORDER); + this.ctlViewClassPrefix.setBounds(185, 255, 250, 21); + this.ctlViewClassPrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewClassPrefix")); + + Label lblViewClassSuffix = new Label(this, SWT.NONE); + lblViewClassSuffix.setText(Plugin.getInstance().getMessageService().resolveMessageKey("viewClassSuffix")); + lblViewClassSuffix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewClassSuffix")); + lblViewClassSuffix.setBounds(15, 285, 145, 17); + + this.ctlViewClassSuffix = new Text(this, SWT.BORDER); + this.ctlViewClassSuffix.setBounds(185, 282, 250, 21); + this.ctlViewClassSuffix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewClassSuffix")); + + Label lblColumnNamePrefix = new Label(this, SWT.NONE); + lblColumnNamePrefix.setText(Plugin.getInstance().getMessageService().resolveMessageKey("columnNamePrefix")); + lblColumnNamePrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.columnNamePrefix")); + lblColumnNamePrefix.setBounds(15, 312, 145, 17); + + this.ctlColumnNamePrefix = new Text(this, SWT.BORDER); + this.ctlColumnNamePrefix.setBounds(185, 309, 250, 21); + this.ctlColumnNamePrefix.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.columnNamePrefix")); + + Group grpFlag = new Group(this, SWT.NONE); + grpFlag.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD)); + grpFlag.setText(Plugin.getInstance().getMessageService().resolveMessageKey("flagGroup")); + grpFlag.setBounds(5, 335, 440, 144); + + this.ctlNestTables = new Button(grpFlag, SWT.CHECK); + this.ctlNestTables.setBounds(180, 22, 93, 16); + + Label lblNestTables = new Label(grpFlag, SWT.NONE); + lblNestTables.setBounds(10, 23, 156, 15); + lblNestTables.setText(Plugin.getInstance().getMessageService().resolveMessageKey("nestTables")); + + Label lblNestViews = new Label(grpFlag, SWT.NONE); + lblNestViews.setText(Plugin.getInstance().getMessageService().resolveMessageKey("nestViews")); + lblNestViews.setBounds(10, 45, 156, 15); + + this.ctlNestViews = new Button(grpFlag, SWT.CHECK); + this.ctlNestViews.setBounds(180, 44, 93, 16); + + Label lblCreateRecordProperties = new Label(grpFlag, SWT.NONE); + lblCreateRecordProperties.setText(Plugin.getInstance().getMessageService().resolveMessageKey("createRecordProperties")); + lblCreateRecordProperties.setBounds(10, 67, 156, 15); + + this.ctlCreateRecordProperties = new Button(grpFlag, SWT.CHECK); + this.ctlCreateRecordProperties.setBounds(180, 66, 93, 16); + + Label lblPreserverCharCase = new Label(grpFlag, SWT.NONE); + lblPreserverCharCase.setText(Plugin.getInstance().getMessageService().resolveMessageKey("preserverCharCase")); + lblPreserverCharCase.setBounds(10, 89, 156, 15); + + this.ctlPreserverCharCase = new Button(grpFlag, SWT.CHECK); + this.ctlPreserverCharCase.setBounds(180, 88, 93, 16); + + Label lblPreserveRelationNames = new Label(grpFlag, SWT.NONE); + lblPreserveRelationNames.setText(Plugin.getInstance().getMessageService().resolveMessageKey("preserveRelationNames")); + lblPreserveRelationNames.setBounds(10, 111, 156, 15); + + this.ctlPreserveRelationNames = new Button(grpFlag, SWT.CHECK); + this.ctlPreserveRelationNames.setBounds(180, 110, 93, 16); + } + + public void save(CodeGenConfig config) + { + config.setDbClassName(this.ctlDbClassName.getText()); + config.setTableBaseName(this.ctlTableBaseName.getText()); + config.setViewBaseName(this.ctlViewBaseName.getText()); + config.setRecordBaseName(this.ctlRecordBaseName.getText()); + config.setTableNamePrefix(this.ctlTableNamePrefix.getText()); + config.setTableClassPrefix(this.ctlTableClassPrefix.getText()); + config.setTableClassSuffix(this.ctlTableClassSuffix.getText()); + config.setViewClassPrefix(this.ctlViewClassPrefix.getText()); + config.setViewClassSuffix(this.ctlViewClassSuffix.getText()); + config.setColumnNamePrefix(this.ctlColumnNamePrefix.getText()); + config.setNestTables(this.ctlNestTables.getSelection()); + config.setNestViews(this.ctlNestViews.getSelection()); + config.setCreateRecordProperties(this.ctlCreateRecordProperties.getSelection()); + config.setPreserverCharacterCase(this.ctlPreserverCharCase.getSelection()); + config.setPreserveRelationNames(this.ctlPreserveRelationNames.getSelection()); + } + + public void load(CodeGenConfig config) + { + setControlText(this.ctlDbClassName, config.getDbClassName()); + setControlText(this.ctlTableBaseName, config.getTableBaseName()); + setControlText(this.ctlViewBaseName, config.getViewBaseName()); + setControlText(this.ctlRecordBaseName, config.getRecordBaseName()); + setControlText(this.ctlTableNamePrefix, config.getTableNamePrefix()); + setControlText(this.ctlTableClassPrefix, config.getTableClassPrefix()); + setControlText(this.ctlTableClassSuffix, config.getTableClassSuffix()); + setControlText(this.ctlViewClassPrefix, config.getViewClassPrefix()); + setControlText(this.ctlViewClassSuffix, config.getViewClassSuffix()); + setControlText(this.ctlColumnNamePrefix, config.getColumnNamePrefix()); + this.ctlNestTables.setSelection(config.isNestTables()); + this.ctlNestViews.setSelection(config.isNestViews()); + this.ctlCreateRecordProperties.setSelection(config.isCreateRecordProperties()); + this.ctlPreserverCharCase.setSelection(config.isPreserverCharacterCase()); + this.ctlPreserveRelationNames.setSelection(config.isPreserveRelationNames()); + } + + @Override + public void setEnabled(boolean enabled) + { + this.ctlDbClassName.setEnabled(enabled); + this.ctlTableBaseName.setEnabled(enabled); + this.ctlViewBaseName.setEnabled(enabled); + this.ctlRecordBaseName.setEnabled(enabled); + this.ctlTableNamePrefix.setEnabled(enabled); + this.ctlTableClassPrefix.setEnabled(enabled); + this.ctlTableClassSuffix.setEnabled(enabled); + this.ctlViewNamePrefix.setEnabled(enabled); + this.ctlViewClassPrefix.setEnabled(enabled); + this.ctlViewClassSuffix.setEnabled(enabled); + this.ctlColumnNamePrefix.setEnabled(enabled); + this.ctlNestTables.setEnabled(enabled); + this.ctlNestViews.setEnabled(enabled); + this.ctlCreateRecordProperties.setEnabled(enabled); + this.ctlPreserverCharCase.setEnabled(enabled); + this.ctlPreserveRelationNames.setEnabled(enabled); + } + + public boolean checkRequiredFields() + { + return checkControlFilled(this.ctlDbClassName, this.lblDbClassName.getText()) + && checkControlFilled(this.ctlTableBaseName, this.lblTableBaseName.getText()) + && checkControlFilled(this.ctlViewBaseName, this.lblViewBaseName.getText()) + && this.checkControlFilled(this.ctlRecordBaseName, this.lblRecordBaseName.getText()); + } +}
