372876 - Dynamic Entities from Tables feature.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
index d602c6a..093e713 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
@@ -33,6 +33,9 @@
/** double quote */
public static final char QUOTE = '"';
+
+ /** XML double quote */
+ public static final String XML_QUOTE = """;
/** parenthesis */
public static final char OPEN_PARENTHESIS = '(';
@@ -5026,7 +5029,36 @@
writeCharOn(QUOTE, writer);
}
+ // ********** convert to XML string literal **********
+ public static String convertToXmlStringLiteral(String string) {
+ int len = string.length();
+ if (len == 0) {
+ return EMPTY_JAVA_STRING_LITERAL;
+ }
+ StringBuilder sb = new StringBuilder(len + 5);
+ convertToXmlStringLiteralOn_(string.toCharArray(), sb, len);
+ return sb.toString();
+ }
+
+ //TODO need to add the rest of the predifende entities to this switch (amp, apos, lt, and gt)
+ private static void convertToXmlStringLiteralOn_(char[] string, StringBuilder sb, int len) {
+ sb.ensureCapacity(sb.length() + len + 5);
+ sb.append(QUOTE);
+ for (char c : string) {
+ switch (c) {
+ case '"': // double-quote
+ sb.append(XML_QUOTE); //$NON-NLS-1$
+ break;
+ default:
+ sb.append(c);
+ break;
+ }
+ }
+ sb.append(QUOTE);
+ }
+
+
// ********** convenience **********
public static char[] convertToCharArray(StringBuffer sb) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF
index 0d561a5..1551672 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF
@@ -26,7 +26,8 @@
org.eclipse.ui.forms;bundle-version="[3.4.0,4.0.0)",
org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
org.eclipse.wst.common.frameworks.ui;bundle-version="[1.1.200,2.0.0)",
- org.eclipse.jpt.common.ui;bundle-version="[1.0.0,2.0.0)"
+ org.eclipse.jpt.common.ui;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.jpt.jpa.gen;bundle-version="[2.1.0, 3.0.0)"
Export-Package: org.eclipse.jpt.jpa.eclipselink.ui,
org.eclipse.jpt.jpa.eclipselink.ui.internal;x-internal:=true,
org.eclipse.jpt.jpa.eclipselink.ui.internal.commands;x-internal:=true,
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.properties b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.properties
index 617a1d6..20b4678 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.properties
@@ -25,6 +25,10 @@
eclipseLinkWizardCategoryName=EclipseLink
newEclipseLinkMappingFileWizardName=EclipseLink ORM Mapping File
newEclipseLinkJpaMappingFileWizardDesc=Create an EclipseLink ORM mapping file
+newDynamicEntityFromTableWizardName=Dynamic Entities from Tables
+newDynamicEntityFromTableWizardDesc=Create dynamic entities from database tables
+
+generateDynamicEntities=Generate Dynamic Entities from Tables...
convertJavaConverters=Java Converters...
jpaNode = JPA
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml
index de7c812..c5f39a2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml
@@ -76,6 +76,16 @@
<parameter name="jptartifact" value="true"/>
</class>
</wizard>
+
+ <wizard
+ category="org.eclipse.jpt.jpa/org.eclipse.jpt.jpa.eclipselink"
+ class="org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen.GenerateDynamicEntitiesFromSchemaWizard"
+ icon="platform:/plugin/org.eclipse.jpt.jpa.ui/icons/full/etool16/new_jpa_file_wiz.gif"
+ id="org.eclipse.jpt.jpa.eclipselink.ui.wizard.newDynamicEntitiesFromTables"
+ name="%newDynamicEntityFromTableWizardName">
+ <description>%newDynamicEntityFromTableWizardDesc</description>
+ <selection class="org.eclipse.core.resources.IResource"/>
+ </wizard>
</extension>
@@ -166,8 +176,16 @@
<command
id="org.eclipse.jpt.jpa.eclipselink.ui.persistentTypeAddVirtualAttribute"
name="%addVirtualAttribute"
- categoryId="org.eclipse.jpt.jpa.ui.jpaStructureViewCommands">
- </command>
+ categoryId="org.eclipse.jpt.jpa.ui.jpaStructureViewCommands"/>
+
+ <command
+ id="org.eclipse.jpt.jpa.eclipselink.ui.convertJavaConverters"
+ name="%convertJavaConverters"
+ categoryId="org.eclipse.jpt.jpa.ui.jpaMetadataConversionCommands"/>
+
+ <command
+ id="org.eclipse.jpt.jpa.eclipselink.ui.generateDynamicEntities"
+ name="%generateDynamicEntities"/>
</extension>
@@ -194,17 +212,54 @@
</and>
</activeWhen>
</handler>
- </extension>
-
+
+ <handler
+ commandId="org.eclipse.jpt.jpa.eclipselink.ui.convertJavaConverters"
+ class="org.eclipse.jpt.jpa.eclipselink.ui.internal.commands.JpaJavaConverterMetadataConversionHandler">
+ </handler>
+
+ <handler
+ commandId="org.eclipse.jpt.jpa.eclipselink.ui.generateDynamicEntities"
+ class="org.eclipse.jpt.jpa.eclipselink.ui.internal.commands.GenerateDynamicEntitiesHandler">
+ </handler>
+
+ </extension>
+
+
<!-- ***** menus ***** -->
- <extension
- point="org.eclipse.ui.menus">
-
- <!-- contributions to objects in the JPA structure view -->
+ <extension
+ point="org.eclipse.ui.menus">
+
+ <!-- contributions to the "JPA Tools" submenu -->
+ <menuContribution
+ locationURI="popup:org.eclipse.jpt.jpa.ui.menu.JpaTools?after=generate">
+
+ <command
+ commandId="org.eclipse.jpt.jpa.eclipselink.ui.generateDynamicEntities">
+ <visibleWhen>
+ <with
+ variable="selection">
+ <and>
+ <count value="1"/>
+ <iterate>
+ <adapt type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription">
+ <test
+ property="org.eclipse.jpt.jpa.core.jpaPlatformGroup"
+ value="eclipselink"/>
+ </adapt>
+ </iterate>
+ </and>
+ </with>
+ </visibleWhen>
+ </command>
+
+ </menuContribution>
+
+ <!-- contributions to objects in the JPA structure view -->
<menuContribution
locationURI="popup:org.eclipse.jpt.ui.jpaStructureView">
-
+
<command
commandId="org.eclipse.jpt.jpa.eclipselink.ui.persistentTypeAddVirtualAttribute">
<visibleWhen>
@@ -221,7 +276,7 @@
</extension>
- <extension
+ <extension
point="org.eclipse.ui.menus">
<!-- contributions to "Move to XML" submenu-->
@@ -256,25 +311,5 @@
</menuContribution>
</extension>
-
- <extension
- point="org.eclipse.ui.commands">
-
- <command
- id="org.eclipse.jpt.jpa.eclipselink.ui.convertJavaConverters"
- name="%convertJavaConverters"
- categoryId="org.eclipse.jpt.jpa.ui.jpaMetadataConversionCommands">
- </command>
-
- </extension>
-
- <extension
- point="org.eclipse.ui.handlers">
-
- <handler
- class="org.eclipse.jpt.jpa.eclipselink.ui.internal.commands.JpaJavaConverterMetadataConversionHandler"
- commandId="org.eclipse.jpt.jpa.eclipselink.ui.convertJavaConverters">
- </handler>
- </extension>
</plugin>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/property_files/eclipselink_ui_dynamic_entity_gen.properties b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/property_files/eclipselink_ui_dynamic_entity_gen.properties
new file mode 100644
index 0000000..1e9d36a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/property_files/eclipselink_ui_dynamic_entity_gen.properties
@@ -0,0 +1,13 @@
+###############################################################################
+# Copyright (c) 2012 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
+#
+# Contributors:
+# Oracle - initial API and implementation
+###############################################################################
+
+
+GenerateDynamicEntitiesWizard_generateEntities=Generate Dynamic Entities
+GenerateDynamicEntitiesWizard_defaultTablePage_domainJavaClass=Dynamic class defaults
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/commands/GenerateDynamicEntitiesHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/commands/GenerateDynamicEntitiesHandler.java
new file mode 100644
index 0000000..9dbb01f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/commands/GenerateDynamicEntitiesHandler.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen.GenerateDynamicEntitiesFromSchemaWizard;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+public class GenerateDynamicEntitiesHandler
+ extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ this.execute_(event);
+ return null;
+ }
+
+ private void execute_(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ JpaProject project = PlatformTools.getAdapter(selection.getFirstElement(), JpaProject.class);
+ GenerateDynamicEntitiesFromSchemaWizard wizard = new GenerateDynamicEntitiesFromSchemaWizard(project, selection);
+ WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShellChecked(event), wizard);
+ dialog.create();
+ int returnCode = dialog.open();
+ if (returnCode != Window.OK) {
+ return;
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicDefaultTableGenerationWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicDefaultTableGenerationWizardPage.java
new file mode 100644
index 0000000..8dd1866
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicDefaultTableGenerationWizardPage.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen;
+
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.DefaultTableGenerationWizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+
+public class DynamicDefaultTableGenerationWizardPage extends
+ DefaultTableGenerationWizardPage {
+
+ public DynamicDefaultTableGenerationWizardPage(JpaProject jpaProject) {
+ super(jpaProject);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+ Composite composite = new Composite(parent, SWT.NULL);
+ int nColumns= 4 ;
+ GridLayout layout = new GridLayout();
+ layout.numColumns = nColumns;
+ composite.setLayout(layout);
+ this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_CUSTOMIZE_DEFAULT_ENTITY_GENERATION);
+
+ defaultTableGenPanel = new DynamicTableGenPanel(composite, 4, true, this);
+ createDomainJavaClassesPropertiesGroup(composite, 4);
+
+ setControl(composite);
+
+ this.setPageComplete( true );
+ }
+
+ @Override
+ protected void createDomainJavaClassesPropertiesGroup(Composite composite, int columns) {
+ Group parent = new Group( composite, SWT.NONE);
+ parent.setText( JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_defaultTablePage_domainJavaClass);
+ parent.setLayout(new GridLayout( columns, false));
+ GridData layoutData = new GridData();
+ layoutData.horizontalSpan = columns;
+ layoutData.verticalAlignment = SWT.FILL;
+ layoutData.horizontalAlignment = SWT.FILL;
+ layoutData.grabExcessHorizontalSpace = true;
+ layoutData.grabExcessVerticalSpace = false;
+ parent.setLayoutData(layoutData);
+
+ createPackageControls(parent, columns);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicTableGenPanel.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicTableGenPanel.java
new file mode 100644
index 0000000..4acc359
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicTableGenPanel.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.JptUiEntityGenMessages;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.TableGenPanel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+
+
+public class DynamicTableGenPanel extends TableGenPanel {
+
+ public DynamicTableGenPanel(Composite parent, int columns , boolean isDefaultTable, WizardPage wizardPage){
+ super(parent, columns, isDefaultTable, wizardPage);
+ }
+
+ @Override
+ protected void createTableMappingPropertiesGroup(Composite composite, int columns) {
+ Group parent = new Group(composite, SWT.NONE );
+ parent.setText( JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_tableMapping);
+ parent.setLayout(new GridLayout(columns, false));
+ GridData layoutData = new GridData();
+ layoutData.horizontalSpan = columns;
+ layoutData.verticalAlignment = SWT.FILL;
+ layoutData.horizontalAlignment = SWT.FILL;
+ layoutData.grabExcessHorizontalSpace = true;
+ layoutData.grabExcessVerticalSpace = false;
+ parent.setLayoutData(layoutData);
+
+ createClassNameControl(parent, columns);
+
+ createIdGeneratorControls(parent, columns);
+
+ //AssociationFetch and CollectionType only available for default table generation
+ if ( isDefaultTable ) {
+ createAssociationFetchControls(parent, columns);
+ createCollectionTypeControls(parent, columns);
+ }
+ }
+
+ @Override
+ protected void updateAccessControls(){
+ //do nothing, not applicable for Dynamic
+ }
+
+ @Override
+ protected void updateGenerateOptionalAnnotationControls(){
+ //do nothing, not applicable for Dynamic
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicTablesAndColumnsCustomizationWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicTablesAndColumnsCustomizationWizardPage.java
new file mode 100644
index 0000000..0577d33
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicTablesAndColumnsCustomizationWizardPage.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen;
+
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.gen.internal.ORMGenColumn;
+import org.eclipse.jpt.jpa.gen.internal.ORMGenTable;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.ColumnGenPanel;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.TablesAndColumnsCustomizationWizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+public class DynamicTablesAndColumnsCustomizationWizardPage extends
+ TablesAndColumnsCustomizationWizardPage {
+
+ public DynamicTablesAndColumnsCustomizationWizardPage(JpaProject jpaProject, ResourceManager resourceManager) {
+ super(jpaProject, resourceManager);
+ }
+
+ @Override
+ protected void updateTabelGenDetail(ORMGenTable table) {
+ this.selectedTable = table;
+ if(tableGenDetatilGroup==null){
+ tableGenDetatilGroup = new Composite(detailPanel, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 4;
+ tableGenDetatilGroup.setLayout(gridLayout);
+
+ this.tableGenPanel = new DynamicTableGenPanel(tableGenDetatilGroup, 4 , false, this );
+
+ }
+ this.tableGenPanel.setORMGenTable(table);
+ this.tableGenPanel.updateControls();
+
+ this.detailPanelStatckLayout.topControl = tableGenDetatilGroup;
+ this.detailPanel.layout();
+
+ String baseClass = StringTools.stringIsEmpty(table.getExtends()) ? "" : table.getExtends();
+ setSuperClass(baseClass, true);
+ setSuperInterfaces(table.getImplements(), true);
+
+ detailPanel.getParent().layout();
+ }
+
+ @Override
+ protected void updateColumnGenDetail(ORMGenColumn column) {
+ if(columnGenDetatilGroup==null){
+ columnGenDetatilGroup = new Composite(detailPanel, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 4;
+ columnGenDetatilGroup.setLayout(gridLayout);
+ this.columnGenPanel = new ColumnGenPanel(columnGenDetatilGroup, 4, getCustomizer() , this, true);
+ }
+ columnGenPanel.setColumn(column);
+ this.detailPanelStatckLayout.topControl = columnGenDetatilGroup;
+ this.detailPanel.layout();
+ detailPanel.getParent().layout();
+ }
+
+ @Override
+ public boolean isDynamic(){
+ return true;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/GenerateDynamicEntitiesFromSchemaWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/GenerateDynamicEntitiesFromSchemaWizard.java
new file mode 100644
index 0000000..6892705
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/GenerateDynamicEntitiesFromSchemaWizard.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen;
+
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.db.ConnectionProfile;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.GenerateEntitiesFromSchemaWizard;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.TableAssociationsWizardPage;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.TablesSelectorWizardPage;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+public class GenerateDynamicEntitiesFromSchemaWizard extends GenerateEntitiesFromSchemaWizard
+ implements INewWizard {
+
+ public static final String HELP_CONTEXT_ID = JptJpaUiPlugin.PLUGIN_ID + ".GenerateEntitiesFromSchemaWizard"; //$NON-NLS-1$
+
+
+ public GenerateDynamicEntitiesFromSchemaWizard() {
+ super();
+ this.setWindowTitle(JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_generateEntities);
+ }
+
+ public GenerateDynamicEntitiesFromSchemaWizard( JpaProject jpaProject, IStructuredSelection selection) {
+ super(jpaProject, selection);
+ this.setWindowTitle(JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_generateEntities);
+ }
+
+ @Override
+ protected void addMainPages() {
+ this.tablesSelectorPage = new TablesSelectorWizardPage(this.jpaProject, this.resourceManager, true);
+ this.addPage(this.tablesSelectorPage);
+
+ this.tableAssociationsPage = new TableAssociationsWizardPage(this.jpaProject, this.resourceManager);
+ this.addPage(this.tableAssociationsPage);
+
+ this.defaultTableGenerationPage = new DynamicDefaultTableGenerationWizardPage(this.jpaProject);
+ this.addPage(this.defaultTableGenerationPage);
+ this.defaultTableGenerationPage.init(this.selection);
+
+ this.tablesAndColumnsCustomizationPage = new DynamicTablesAndColumnsCustomizationWizardPage(this.jpaProject, this.resourceManager);
+ this.addPage(this.tablesAndColumnsCustomizationPage);
+ this.tablesAndColumnsCustomizationPage.init(this.selection);
+ }
+
+ @Override
+ protected String getCustomizationFileName() {
+ ConnectionProfile profile = getProjectConnectionProfile();
+ String connection = profile == null ? "" : profile.getName();
+ String name = "org.eclipse.jpt.entitygen.dynamic" + (connection == null ? "" :connection.replace(' ', '-')); //$NON-NLS-1$
+ Schema schema = getDefaultSchema();
+ if ( schema!= null ) {
+ name += "." + schema.getName();//$NON-NLS-1$
+ }
+ return name.toLowerCase();
+ }
+
+ @Override
+ protected void scheduleGenerateEntitiesJob(
+ OverwriteConfirmer overwriteConfirmer) {
+ WorkspaceJob genEntitiesJob = new GenerateEntitiesJob(this.jpaProject, getCustomizer(), overwriteConfirmer, true);
+ genEntitiesJob.schedule();
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ super.init(workbench, selection);
+
+ this.setWindowTitle(JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_generateEntities);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/JptJpaEclipseLinkUiEntityGenMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/JptJpaEclipseLinkUiEntityGenMessages.java
new file mode 100644
index 0000000..2e220cf
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/JptJpaEclipseLinkUiEntityGenMessages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen;
+
+import org.eclipse.osgi.util.NLS;
+
+public class JptJpaEclipseLinkUiEntityGenMessages {
+ private static final String BUNDLE_NAME = "eclipselink_ui_dynamic_entity_gen"; //$NON-NLS-1$
+ private static final Class<?> BUNDLE_CLASS = JptJpaEclipseLinkUiEntityGenMessages.class;
+
+ public static String GenerateDynamicEntitiesWizard_generateEntities;
+
+ //Default table gen properties
+ public static String GenerateDynamicEntitiesWizard_defaultTablePage_domainJavaClass;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS);
+ }
+
+ private JptJpaEclipseLinkUiEntityGenMessages() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/BaseEntityGenCustomizer.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/BaseEntityGenCustomizer.java
index 6819f98..8e34042 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/BaseEntityGenCustomizer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/BaseEntityGenCustomizer.java
@@ -209,6 +209,39 @@
return buffer.toString();
}
+ public String genCascadesXml(AssociationRole role) {
+ List<String> cascades = StringUtil.strToList(role.getCascade(), ',', true/* trim */);
+ if (cascades == null) {
+ return ""; //$NON-NLS-1$
+ }
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0, n = cascades.size(); i < n; ++i) {
+ String cascade = cascades.get(i);
+ String enumStr;
+ if (cascade.equals(TagNames.ALL_CASCADE)) {
+ enumStr = "<cascade-all></cascade-all>"; //$NON-NLS-1$
+ }
+ else if (cascade.equals(TagNames.PERSIST_CASCADE)) {
+ enumStr = "<cascade-persist></cascade-persist>"; //$NON-NLS-1$
+ }
+ else if (cascade.equals(TagNames.MERGE_CASCADE)) {
+ enumStr = "<cascade-merge></cascade-merge>"; //$NON-NLS-1$
+ }
+ else if (cascade.equals(TagNames.REMOVE_CASCADE)) {
+ enumStr = "<cascade-remove></cascade-remove>"; //$NON-NLS-1$
+ }
+ else {
+ assert (cascade.equals(TagNames.REFRESH_CASCADE));
+ enumStr = "<cascade-refresh></cascade-refresh>"; //$NON-NLS-1$
+ }
+ if (i != 0) {
+ buffer.append("\n\t\t\t\t\t"); //$NON-NLS-1$
+ }
+ buffer.append(enumStr);
+ }
+ return buffer.toString();
+ }
+
/**
* Returns the fetch type annotation member value, or empty string if none.
* Empty string is returned instead of null because Velocity does not like
@@ -227,4 +260,19 @@
return "FetchType.EAGER"; //$NON-NLS-1$
}
}
+
+ @Override
+ public String genFetchXml(ORMGenTable table) {
+ String fetch = table.getDefaultFetch();
+ if (fetch == null || ORMGenTable.DEFAULT_FETCH.equals(fetch)) {
+ return ""; //$NON-NLS-1$
+ }
+ else if (fetch.equals(ORMGenTable.LAZY_FETCH)) {
+ return "LAZY"; //$NON-NLS-1$
+ }
+ else {
+ return "EAGER"; //$NON-NLS-1$
+ }
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java
index 55c53d4..5f647bb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java
@@ -350,6 +350,10 @@
public String genFetch(ORMGenTable table) {
return "";
}
+
+ public String genFetchXml(ORMGenTable table) {
+ return "";
+ }
/**
* Called when the table user selection is changed in the
* generation wizard.
@@ -533,6 +537,9 @@
public String convertToJavaStringLiteral(String s) {
return StringTools.convertToJavaStringLiteral(s);
}
+ public String convertToXmlStringLiteral(String s) {
+ return StringTools.convertToXmlStringLiteral(s);
+ }
/**
* Appends an annotation member name and value to an existing annotation.
*
@@ -562,6 +569,37 @@
}
return buffer.toString();
}
+
+ /**
+ * Appends an attribute name and value to an existing element.
+ *
+ * @param s The attribute key string.
+ *
+ * @param memberValue The attribute value, if null or empty strings then
+ * nothing is appened.
+ *
+ * @param whether to double quote the member value.
+ */
+ public String appendAttribute(String s, String memberName, String memberValue, boolean quote) {
+ if (memberValue == null || memberValue.length() == 0) {
+ return s;
+ }
+ StringBuffer buffer = new StringBuffer(s);
+ if (buffer.length() != 0) {
+ buffer.append(" ");
+ }
+ buffer.append(memberName);
+ buffer.append('=');
+ if (quote) {
+ buffer.append('"');
+ }
+ buffer.append(memberValue);
+ if (quote) {
+ buffer.append('"');
+ }
+ return buffer.toString();
+ }
+
public boolean isJDK1_5() {
return true;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java
index bcca94d..76b2a9c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java
@@ -211,7 +211,7 @@
return columnTypesMap;
}
- public String getSimplifiedColType(String fqtn ) {
+ public String getSimplifiedColType(String fqtn) {
HashMap<String, String> map = buildColumnTypesMap();
String typeName = map.get(fqtn);
if ( typeName != null ) {
@@ -745,7 +745,7 @@
public String getDefaultCollectionType() {
String cType = customized(DEFAULT_COLLECTION_TYPE);
if (cType == null) {
- cType = SET_COLLECTION_TYPE;
+ cType = LIST_COLLECTION_TYPE;
}
return cType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java
index 99905e1..b4c1f56 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java
@@ -15,6 +15,7 @@
import java.io.IOException;
import java.io.StringWriter;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -24,8 +25,10 @@
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.log.JdkLogChute;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -38,6 +41,7 @@
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
@@ -59,12 +63,17 @@
private final ORMGenCustomizer customizer;
private final OverwriteConfirmer overwriteConfirmer;
- public static void generate(JpaProject jpaProject, ORMGenCustomizer customizer, OverwriteConfirmer overwriteConfirmer, IProgressMonitor monitor) throws CoreException {
+ public static void generate(JpaProject jpaProject, ORMGenCustomizer customizer, OverwriteConfirmer overwriteConfirmer, IProgressMonitor monitor, boolean generateXml) throws CoreException {
SubMonitor sm = SubMonitor.convert(monitor, 20);
PackageGenerator generator = new PackageGenerator(jpaProject, customizer, overwriteConfirmer);
sm.worked(1);
try {
- generator.doGenerate(sm.newChild(19));
+ if (generateXml) {
+ generator.doXmlGenerate(sm.newChild(19));
+ }
+ else {
+ generator.doGenerate(sm.newChild(19));
+ }
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, JptJpaGenPlugin.PLUGIN_ID, JptGenMessages.Error_Generating_Entities, e));
}
@@ -89,9 +98,13 @@
protected void doGenerate(IProgressMonitor monitor) throws Exception {
generateInternal(monitor);
}
+
+ protected void doXmlGenerate(IProgressMonitor monitor) throws Exception {
+ generateXmlInternal(monitor);
+ }
protected void generateInternal(IProgressMonitor monitor) throws Exception {
- File templDir = prepareTemplatesFolder();
+ File templDir = prepareTemplatesFolder("templates/entities/"); //$NON-NLS-1$
List<String> genClasses = new java.util.ArrayList<String>();
List<String> tableNames = this.customizer.getGenTableNames();
@@ -161,14 +174,31 @@
resource.save();
}
- private File prepareTemplatesFolder() throws IOException, Exception,
+ //TODO can probably axe this method
+ protected void generateXmlInternal(IProgressMonitor monitor) throws Exception {
+ File templDir = prepareTemplatesFolder("templates/xml_entities/"); //$NON-NLS-1$
+
+ List<String> tableNames = this.customizer.getGenTableNames();
+
+ //TODO Need to fix progress monitor
+ SubMonitor sm = SubMonitor.convert(monitor, tableNames.size() + 2);
+
+ generateXmlMappingFile(tableNames, templDir.getAbsolutePath(), sm.newChild(1, SubMonitor.SUPPRESS_NONE));
+
+ if (sm.isCanceled()) {
+ return;
+ }
+
+ sm.worked(2);
+ }
+
+ private File prepareTemplatesFolder(String templatesPath) throws IOException, Exception,
CoreException {
//Prepare the Velocity template folder:
//If the plug-in is packaged as a JAR, we need extract the template
//folder into the plug-in state location. This is required by Velocity
//since we use included templates.
Bundle bundle = Platform.getBundle(JptJpaGenPlugin.PLUGIN_ID);
- String templatesPath = "templates/entities/"; //$NON-NLS-1$
Path path = new Path( templatesPath);
URL url = FileLocator.find(bundle, path, null);
if (url == null) {
@@ -322,4 +352,96 @@
}
return defaultSrcPath;
}
+
+ protected void generateXmlMappingFile(List<String> tableNames, String templateDirPath, IProgressMonitor monitor) throws Exception {
+
+ try {
+ IProject project = jpaProject.getProject();
+ IContainer container = ((ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class)).getDefaultResourceLocation();
+ IFile xmlFile = container.getFile(new Path("/eclipselink-orm.xml")); //$NON-NLS-1$
+
+ if (xmlFile.exists()) {
+ if (this.overwriteConfirmer != null && !this.overwriteConfirmer.overwrite(xmlFile.getName())) {
+ return;
+ }
+ }
+ //JdkLogChute in this version of Velocity not allow to set log level
+ //Workaround by preset the log level before Velocity is initialized
+ Logger logger = Logger.getLogger( LOGGER_NAME );
+ logger.setLevel( Level.SEVERE );
+
+ Properties vep = new Properties();
+ vep.setProperty("file.resource.loader.path", templateDirPath); //$NON-NLS-1$
+ vep.setProperty( JdkLogChute.RUNTIME_LOG_JDK_LOGGER, LOGGER_NAME );
+ VelocityEngine ve = new VelocityEngine();
+ ve.init(vep);
+
+ StringBuilder xmlFileContents = new StringBuilder();
+ xmlFileContents.append(generateXmlHeaderFooter(ve, "header.vm")); //$NON-NLS-1$
+ List<ORMGenTable> compositeKeyTables = new ArrayList<ORMGenTable>();
+
+ for (Iterator<String> names = tableNames.iterator(); names.hasNext();) {
+
+ ORMGenTable table = this.customizer.getTable(names.next());
+ String subTaskName = NLS.bind(JptGenMessages.EntityGenerator_taskName, table.getName());
+ SubMonitor sm = SubMonitor.convert(monitor, subTaskName, 10);
+
+ if (sm.isCanceled()) {
+ return;
+ }
+
+ xmlFileContents.append(generateXmlTypeMapping(table, ve, "main.xml.vm", sm.newChild(10))); //$NON-NLS-1$
+
+ if (table.isCompositeKey()) {
+ compositeKeyTables.add(table);
+ }
+ }
+
+ //Embeddables need to come after entities in the XML
+ for (ORMGenTable table : compositeKeyTables) {
+ SubMonitor sm = SubMonitor.convert(monitor, NLS.bind(JptGenMessages.EntityGenerator_taskName, table.getName()), 1);
+ if (table.isCompositeKey()) {
+ xmlFileContents.append(generateXmlTypeMapping(table, ve, "embeddable.vm", sm.newChild(1))); //$NON-NLS-1$
+ }
+ }
+
+ xmlFileContents.append(generateXmlHeaderFooter(ve, "footer.vm")); //$NON-NLS-1$
+
+ if(xmlFile.exists()){
+ byte[] content = xmlFileContents.toString().getBytes(xmlFile.getCharset());
+ xmlFile.setContents(new ByteArrayInputStream(content), false, true, null);
+ }
+ else {
+ byte[] content = xmlFileContents.toString().getBytes(xmlFile.getCharset());
+ createFile(xmlFile, new ByteArrayInputStream(content));
+ }
+
+ xmlFile.refreshLocal(1, null);
+
+ } catch (Throwable e) {
+ CoreException ce = new CoreException(new Status(IStatus.ERROR, JptJpaGenPlugin.PLUGIN_ID, JptGenMessages.Templates_notFound + "" + JptJpaGenPlugin.PLUGIN_ID , e) );//$NON-NLS-1$
+ JptJpaGenPlugin.logException( ce );
+ }
+ }
+
+ private String generateXmlHeaderFooter(VelocityEngine ve, String templateName) throws Exception{
+ StringWriter stringWriter = new StringWriter();
+ VelocityContext context = new VelocityContext();
+ ve.mergeTemplate(templateName, context, stringWriter);
+ return stringWriter.toString();
+ }
+
+
+ private String generateXmlTypeMapping(ORMGenTable table, VelocityEngine ve
+ , String templateName, IProgressMonitor monitor) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("table", table); //$NON-NLS-1$
+ context.put("customizer", getCustomizer()); //$NON-NLS-1$
+
+ StringWriter w = new StringWriter();
+ ve.mergeTemplate(templateName, context, w);
+
+ return w.toString();
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/basic.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/basic.vm
new file mode 100644
index 0000000..aa0639d
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/basic.vm
@@ -0,0 +1,4 @@
+
+ <basic name="${column.propertyName}" attribute-type="${column.propertyType}">
+#parse("column.vm")
+ </basic>
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/column.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/column.vm
new file mode 100644
index 0000000..3a4e351
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/column.vm
@@ -0,0 +1,29 @@
+###------------------------------------------------
+#macro( append $members $parameters )
+#if( $members == "")
+ #set( $members = $parameters )
+#else
+ #set( $members = "$members $parameters" )
+#end
+#end
+###------------------------------------------------
+#set ($DQ = '"')
+#set ($members = "")
+#if ( !$column.defaultname )
+ #append($members "name=$customizer.convertToXmlStringLiteral($column.name)" )
+#end
+#if (!$column.insertable)
+#append(${members} "insertable=${DQ}false${DQ}")
+#end
+#if (!$column.updateable)
+#append(${members} "updatable=${DQ}false${DQ}")
+#end
+#if( $members !="" )
+ <column $members/>
+#end
+#if ( $column.dataTypeLOB)
+ <lob/>
+#end
+#if ( $column.needMapTemporalType)
+ <temporal>$column.temporalType</temporal>
+#end
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/embeddable.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/embeddable.vm
new file mode 100644
index 0000000..4bcb6e8
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/embeddable.vm
@@ -0,0 +1,10 @@
+#### Embeddable ####
+ <embeddable class="${table.qualifiedCompositeKeyClassName}" access="VIRTUAL">
+#### Mappings ####
+ <attributes>
+#foreach ($column in $table.primaryKeyColumns)
+#parse("embeddedBasic.vm")
+#end
+
+ </attributes>
+ </embeddable>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/embeddedBasic.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/embeddedBasic.vm
new file mode 100644
index 0000000..aa0639d
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/embeddedBasic.vm
@@ -0,0 +1,4 @@
+
+ <basic name="${column.propertyName}" attribute-type="${column.propertyType}">
+#parse("column.vm")
+ </basic>
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/footer.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/footer.vm
new file mode 100644
index 0000000..702d9ad
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/footer.vm
@@ -0,0 +1,2 @@
+#### Closing tags ####
+</entity-mappings>
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/header.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/header.vm
new file mode 100644
index 0000000..aed7d68
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/header.vm
@@ -0,0 +1,4 @@
+#### Top-level ####
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings version="2.4" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd">
+## <package></package>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/id.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/id.vm
new file mode 100644
index 0000000..8dc87e2
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/id.vm
@@ -0,0 +1,26 @@
+ <id name="${column.propertyName}" attribute-type="${column.propertyType}">
+#parse("column.vm")
+#set ($idGenerator = $table.idGenerator)
+#if ($idGenerator == "auto")
+ #set ($generationType = "AUTO")
+#elseif ($idGenerator == "identity")
+ #set ($generationType = "IDENTITY")
+#elseif ($idGenerator == "sequence")
+ #set ($generationType = "SEQUENCE")
+#elseif ($idGenerator == "table")
+ #set ($generationType = "TABLE")
+#else
+ #set ($generationType = "")
+#end
+#if ($idGenerator == "sequence" )
+ #set ($generatorName = "${table.name.toUpperCase()}_${column.propertyName.toUpperCase()}_GENERATOR")
+ <generated-value strategy="$generationType" generator="$generatorName"/>
+ #if( $table.formattedSequence != "" )
+ <sequence-generator name="$generatorName" sequence-name="$table.formattedSequence"/>
+ #else
+ <sequence-generator name="$generatorName"/>
+ #end
+#elseif ($generationType != "")
+ <generated-value strategy="$generationType"/>
+#end
+ </id>
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/join.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/join.vm
new file mode 100644
index 0000000..487bbff
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/join.vm
@@ -0,0 +1,50 @@
+##macro joinColumn
+#macro (joinColumn $column $referencedColumn)
+ #set ($members = "name=$customizer.convertToJavaStringLiteral($column.joinColumnName)")
+ #if( !$referencedColumn.primaryKey || $referencedColumn.partOfCompositePrimaryKey )
+ #set ($members = "$members referencedColumnName=$customizer.convertToJavaStringLiteral($referencedColumn.name)")
+ #end
+<join-column $members/>
+#end
+##macro inverseJoinColumn
+#macro (inverseJoinColumn $column $referencedColumn)
+ #set ($members = "name=$customizer.convertToJavaStringLiteral($column.joinColumnName)")
+ #if( !$referencedColumn.primaryKey || $referencedColumn.partOfCompositePrimaryKey )
+ #set ($members = "$members referencedColumnName=$customizer.convertToJavaStringLiteral($referencedColumn.name)")
+ #end
+<inverse-join-column $members/>
+#end
+##
+##
+#### JoinTables
+#if ($role.association.joinTable)
+ #set ($joinTable = $role.association.joinTable)
+ <join-table name=$customizer.convertToJavaStringLiteral(${joinTable.joinTableAnnotationName})>
+ #foreach ($column in $role.referrerColumns)
+ #set ($referencedColumn = $role.getReferencedColumn(${column.name}))
+ ##$referencedColumn is the column in the join table
+ #joinColumn($referencedColumn $column)
+ #end
+ #foreach ($column in $role.referencedColumns)
+ #set ($referencedColumn = $role.getReferrerColumn(${column.name}))
+ ##$referencedColumn is the column in the join table
+#inverseJoinColumn($referencedColumn $column)
+ #end
+ </join-table>
+#### JoinColumn
+#else
+ #if ($role.referrerColumns.size() == 1)
+ #set ($column = $role.referrerColumns.get(0))
+ #set ($referencedColumn = $role.getReferencedColumn(${column.name}))
+ #set( $isDefaultJoinColumnName = $column.isDefaultJoinColumnName( ${role.propertyName}))
+ #if( ! $isDefaultJoinColumnName )
+#joinColumn($column $referencedColumn)
+ #end
+#### JoinColumns
+ #else
+ #foreach ($column in $role.referrerColumns)
+ #set ($referencedColumn = $role.getReferencedColumn(${column.name}))
+#joinColumn($column $referencedColumn)
+ #end
+ #end
+#end
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/main.xml.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/main.xml.vm
new file mode 100644
index 0000000..2cfdca2
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/main.xml.vm
@@ -0,0 +1,39 @@
+#### Entity ####
+ <entity class="${table.qualifiedClassName}" access="VIRTUAL">
+ #if(!$table.defaultname)
+ <table name=$customizer.convertToXmlStringLiteral(${table.name})/>
+ #end
+#### Mappings ####
+ <attributes>
+##Check for embedded-id
+#if ($table.compositeKey)
+ <embedded-id name="${table.compositeKeyPropertyName}" attribute-type="${table.qualifiedCompositeKeyClassName}"></embedded-id>
+#end
+#foreach ($column in $table.getSimpleColumns(true, true, false))
+#set ($mappingKind = $column.mappingKind)
+ #if ($mappingKind == "id")
+#parse("id.vm")
+ #elseif ($mappingKind == "basic")
+#parse("basic.vm")
+ #elseif ($mappingKind == "version")
+#parse("version.vm")
+ #end
+#end
+#foreach ($role in $table.associationRoles)
+ #if ($role.cardinality == "many-to-one")
+#parse("manyToOne.vm")
+ #end
+#end
+#foreach ($role in $table.associationRoles)
+ #if ($role.cardinality == "one-to-many")
+#parse("oneToMany.vm")
+ #end
+#end
+#foreach ($role in $table.associationRoles)
+ #if ($role.cardinality == "many-to-many")
+#parse("manyToMany.vm")
+ #end
+#end
+
+ </attributes>
+ </entity>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/manyToMany.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/manyToMany.vm
new file mode 100644
index 0000000..2ae266d
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/manyToMany.vm
@@ -0,0 +1,36 @@
+##included template. Generates the @ManyToMany annotation.
+##Assumes that the context has a "role" object representing the generated AssociationRole
+#set ($cascade=$customizer.genCascadesXml($role))
+#if ($role.association.bidirectional && !$role.isReferrerRole())##the owning side (either side for many-to-many)
+ #set ($members = $customizer.appendAttribute("", "name", $role.propertyName, true))
+ #set ($members = $customizer.appendAttribute($members, "mapped-by", $role.oppositeRole.propertyName, true))
+ #set ($members = $customizer.appendAttribute($members, "target-entity", $role.referencedTable.qualifiedClassName, true))
+ #set ($members = $customizer.appendAttribute($members, "attribute-type", $role.referencedTable.defaultCollectionType, true))
+ #if($customizer.genFetchXml($role.referrerTable)!="" && $customizer.genFetchXml($role.referrerTable)!="LAZY")
+ #set ($members = $customizer.appendAttribute($members, "fetch", $customizer.genFetchXml($role.referrerTable), true))
+ #end
+
+ <many-to-many $members>
+#if( $cascade!="")
+ <cascade>
+ $cascade
+ </cascade>
+#end
+ </many-to-many>
+#else
+ #set ($members = $customizer.appendAttribute("", "name", $role.propertyName, true))
+ #set ($members = $customizer.appendAttribute($members, "target-entity", $role.referencedTable.qualifiedClassName, true))
+ #set ($members = $customizer.appendAttribute($members, "attribute-type", $role.referencedTable.defaultCollectionType, true))
+ #if($customizer.genFetchXml($role.referrerTable)!="" && $customizer.genFetchXml($role.referrerTable)!="LAZY")
+ #set ($members = $customizer.appendAttribute($members, "fetch", $customizer.genFetchXml($role.referrerTable), true))
+ #end
+
+ <many-to-many $members>
+#parse("join.vm")
+#if( $cascade!="")
+ <cascade>
+ $cascade
+ </cascade>
+#end
+ </many-to-many>
+#end
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/manyToOne.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/manyToOne.vm
new file mode 100644
index 0000000..d1be6d5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/manyToOne.vm
@@ -0,0 +1,19 @@
+##included template. Generates the many-to-one element.
+##Assumes that the context has a "role" object representing the generated AssociationRole
+#set ($DQ = '"')
+#set ($members = "name=${DQ}$role.propertyName${DQ} target-entity=${DQ}$role.referencedTable.qualifiedClassName${DQ}")
+#if( $customizer.genFetchXml($role.referrerTable)!= "" && $customizer.genFetchXml($role.referrerTable)!= "EAGER")
+#set ($members = $customizer.appendAttribute($members, "fetch", $customizer.genFetchXml($role.referrerTable), true))
+#end
+
+ <many-to-one $members>
+#parse("join.vm")
+#set ($cascade=$customizer.genCascadesXml($role))
+#if( $cascade!="")
+ <cascade>
+ $cascade
+ </cascade>
+ </many-to-one>
+#else
+</many-to-one>
+#end
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/oneToMany.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/oneToMany.vm
new file mode 100644
index 0000000..f4d25b8
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/oneToMany.vm
@@ -0,0 +1,33 @@
+#set ($cascade=$customizer.genCascadesXml($role))
+#if ($role.association.bidirectional)
+ #set ($members = $customizer.appendAttribute("", "name", $role.propertyName, true))
+ #set ($members = $customizer.appendAttribute($members, "mapped-by", $role.oppositeRole.propertyName, true))
+ #set ($members = $customizer.appendAttribute($members, "target-entity", $role.referencedTable.qualifiedClassName, true))
+ #set ($members = $customizer.appendAttribute($members, "attribute-type", $role.referencedTable.defaultCollectionType, true))
+ #if($customizer.genFetchXml($role.referrerTable)!="" && $customizer.genFetchXml($role.referrerTable) !="LAZY")
+ #set ($members = $customizer.appendAttribute($members, "fetch", $customizer.genFetchXml($role.referrerTable), true))
+ #end
+
+ <one-to-many $members>
+#if( $cascade!="")
+ <cascade>
+ $cascade
+ </cascade>
+#end
+ </one-to-many>
+#else
+ #set ($members = $customizer.appendAttribute("", "name", $role.propertyName, true))
+ #set ($members = $customizer.appendAttribute($members, "target-entity", $role.referencedTable.qualifiedClassName, true))
+ #set ($members = $customizer.appendAttribute($members, "attribute-type", $role.referencedTable.defaultCollectionType, true))
+ #if($customizer.genFetchXml($role.referrerTable)!="" && $customizer.genFetchXml($role.referrerTable) !="LAZY")
+ #set ($members = $customizer.appendAttribute($members, "fetch", $customizer.genFetchXml($role.referrerTable), true))
+ #end
+ <one-to-many $members>
+#parse("join.vm")
+#if( $cascade!="")
+ <cascade>
+ $cascade
+ </cascade>
+#end
+ </one-to-many>
+#end
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/version.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/version.vm
new file mode 100644
index 0000000..f29548a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/xml_entities/version.vm
@@ -0,0 +1,3 @@
+ <version name="${column.propertyName}" attribute-type="${column.propertyType}">
+#parse("column.vm")
+ </version>
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
index 65eb7df..74a993e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
@@ -552,6 +552,7 @@
</menuContribution>
<!-- contributions to the "JPA Tools" submenu -->
+
<menuContribution
locationURI="popup:org.eclipse.jpt.jpa.ui.menu.JpaTools">
@@ -592,6 +593,9 @@
</visibleWhen>
</menu>
+ <separator
+ name="generate"/>
+
</menuContribution>
<!-- contributions to "Move to XML" submenu -->
@@ -1028,14 +1032,14 @@
label="%generateEntities"
class="org.eclipse.jpt.jpa.ui.internal.actions.GenerateEntitiesAction"
enablesFor="1"
- menubarPath="org.eclipse.jpt.jpa.ui.menu.JpaTools/content"/>
+ menubarPath="org.eclipse.jpt.jpa.ui.menu.JpaTools/generate"/>
<action
id="org.eclipse.jpt.jpa.ui.generateDDL"
label="%generateDDL"
class="org.eclipse.jpt.jpa.ui.internal.actions.GenerateDDLAction"
enablesFor="1"
- menubarPath="org.eclipse.jpt.jpa.ui.menu.JpaTools/content"/>
+ menubarPath="org.eclipse.jpt.jpa.ui.menu.JpaTools/generate"/>
</objectContribution>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
index 9463d75..8d7771e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
@@ -171,8 +171,8 @@
PersistenceItemLabelProviderFactory_persistenceLabel=Persistence
-OverwriteConfirmerDialog_title=Overwrite Existing Class
-OverwriteConfirmerDialog_text=Overwrite source code for the class ''{0}''?
+OverwriteConfirmerDialog_title=Overwrite Existing File
+OverwriteConfirmerDialog_text=Overwrite the existing file ''{0}''?
SelectJpaOrmMappingFileDialog_title=Mapping File
SelectJpaOrmMappingFileDialog_message=Choose a mapping file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties
index 342cb08..f657db2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties
@@ -52,8 +52,8 @@
GenerateEntitiesWizard_assocPage_delAssoc=Delete Selected Association
-GenerateEntitiesWizard_defaultTablePage_title=Customize Default Entity Generation
-GenerateEntitiesWizard_defaultTablePage_tableMapping=Table mapping
+GenerateEntitiesWizard_defaultTablePage_title=Customize Defaults
+GenerateEntitiesWizard_defaultTablePage_tableMapping=Mapping defaults
GenerateEntitiesWizard_defaultTablePage_domainJavaClass=Domain java class
GenerateEntitiesWizard_defaultTablePage_desc=Optionally customize aspects of entities that will be generated by default from database tables. A Java package should be specified.
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/ColumnGenPanel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/ColumnGenPanel.java
index 93c19cd..1dd842d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/ColumnGenPanel.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/ColumnGenPanel.java
@@ -13,7 +13,6 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.jpa.gen.internal.ORMGenColumn;
import org.eclipse.jpt.jpa.gen.internal.ORMGenCustomizer;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
@@ -40,7 +39,7 @@
*/
public class ColumnGenPanel
{
- WizardPage wizardPage ;
+ TablesAndColumnsCustomizationWizardPage wizardPage ;
Composite parent; //parent control with grid layout
int columns; //total columns in the parent composite
@@ -62,11 +61,14 @@
private ScopePanel mPropGetScopePanel;
private ScopePanel mPropSetScopePanel;
- public ColumnGenPanel(Composite parent, int columns, ORMGenCustomizer customizer, WizardPage wizardPage ) {
+ private boolean isDynamic;
+
+ public ColumnGenPanel(Composite parent, int columns, ORMGenCustomizer customizer, TablesAndColumnsCustomizationWizardPage wizardPage, boolean isDynamic) {
this.wizardPage = wizardPage;
this.customizer = customizer;
this.parent =parent;
this.columns = columns;
+ this.isDynamic = isDynamic;
initPanel();
}
@@ -107,11 +109,13 @@
mInsertableCheckBox.setSelection(mColumn.isInsertable());
- mPropGetScopePanel.enableComponents(isGenerated);
- mPropGetScopePanel.setScope(mColumn.getPropertyGetScope());
-
- mPropSetScopePanel.enableComponents( isGenerated );
- mPropSetScopePanel.setScope(mColumn.getPropertySetScope());
+ if(!this.isDynamic){
+ mPropGetScopePanel.enableComponents(isGenerated);
+ mPropGetScopePanel.setScope(mColumn.getPropertyGetScope());
+
+ mPropSetScopePanel.enableComponents( isGenerated );
+ mPropSetScopePanel.setScope(mColumn.getPropertySetScope());
+ }
if( mColumn.isPartOfCompositePrimaryKey()){
enableControls(false);
@@ -121,14 +125,17 @@
} catch (Exception e) {
JptJpaUiPlugin.log(e);
+ } finally {
+ mIsUpdatingControls = false;
}
-
- mIsUpdatingControls = false;
}
private void enableControls(boolean isGenerated) {
- Control[] controls = this.domainClassGroup.getChildren();
- for( Control c: controls){
- c.setEnabled( isGenerated );
+ Control[] controls;
+ if(!this.isDynamic) {
+ controls = this.domainClassGroup.getChildren();
+ for( Control c: controls){
+ c.setEnabled( isGenerated );
+ }
}
controls = this.columnMappingGroup.getChildren();
@@ -315,8 +322,9 @@
SWTUtil.fillColumns(mInsertableCheckBox ,4);
SWTUtil.createLabel(composite, 4,"");
-
- createJavaBeanPropertyControls(composite, columns);
+ if (!this.wizardPage.isDynamic()) {
+ createJavaBeanPropertyControls(composite, columns);
+ }
}
void createJavaBeanPropertyControls(Composite composite, int columns){
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
index 4283626..e9005e7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
@@ -66,11 +66,11 @@
private ORMGenCustomizer customizer;
- private TableGenPanel defaultTableGenPanel ;
+ protected TableGenPanel defaultTableGenPanel ;
private JpaEntityGenPreferencesManager prefrencesManager;
- protected DefaultTableGenerationWizardPage(JpaProject jpaProject) {
+ public DefaultTableGenerationWizardPage(JpaProject jpaProject) {
super(true, "DefaultTableGenerationWizardPage"); //$NON-NLS-1$
this.jpaProject = jpaProject;
setTitle(JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_title);
@@ -86,7 +86,7 @@
*
* @param selection used to initialize the fields
*/
- void init(IStructuredSelection selection) {
+ public void init(IStructuredSelection selection) {
IJavaElement jelem = null;
if ( selection!=null && selection.getFirstElement() instanceof IJavaElement ) {
jelem = (IJavaElement) selection.getFirstElement();
@@ -130,6 +130,7 @@
this.customizer = customizer;
this.defaultsTable = customizer.createGenTable(null);
this.defaultTableGenPanel.setORMGenTable(this.defaultsTable);
+ defaultTableGenPanel.updateControls();
//set the super class and implemented interfaces value
String baseClass = this.defaultsTable.getExtends() == null ?"" : this.defaultsTable.getExtends();
this.setSuperClass(baseClass, true);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
index 8936b10..a770ce1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
@@ -63,21 +63,21 @@
public static final String HELP_CONTEXT_ID = JptJpaUiPlugin.PLUGIN_ID + ".GenerateEntitiesFromSchemaWizard"; //$NON-NLS-1$
- private JpaProject jpaProject;
+ protected JpaProject jpaProject;
- private IStructuredSelection selection;
+ protected IStructuredSelection selection;
private ORMGenCustomizer customizer = null;
private PromptJPAProjectWizardPage projectPage;
- private TablesSelectorWizardPage tablesSelectorPage;
+ protected TablesSelectorWizardPage tablesSelectorPage;
- private TableAssociationsWizardPage tableAssociationsPage;
+ protected TableAssociationsWizardPage tableAssociationsPage;
- private DefaultTableGenerationWizardPage defaultTableGenerationPage;
+ protected DefaultTableGenerationWizardPage defaultTableGenerationPage;
- private TablesAndColumnsCustomizationWizardPage tablesAndColumnsCustomizationPage;
+ protected TablesAndColumnsCustomizationWizardPage tablesAndColumnsCustomizationPage;
protected final ResourceManager resourceManager;
@@ -108,8 +108,8 @@
addMainPages();
}
- private void addMainPages() {
- this.tablesSelectorPage = new TablesSelectorWizardPage(this.jpaProject, this.resourceManager);
+ protected void addMainPages() {
+ this.tablesSelectorPage = new TablesSelectorWizardPage(this.jpaProject, this.resourceManager, false);
this.addPage(this.tablesSelectorPage);
this.tableAssociationsPage = new TableAssociationsWizardPage(this.jpaProject, this.resourceManager);
@@ -211,29 +211,36 @@
overwriteConfirmer = new OverwriteConfirmer();
}
- WorkspaceJob genEntitiesJob = new GenerateEntitiesJob(this.jpaProject, getCustomizer(), overwriteConfirmer);
- genEntitiesJob.schedule();
+ scheduleGenerateEntitiesJob(overwriteConfirmer);
return true;
}
+
+ protected void scheduleGenerateEntitiesJob(
+ OverwriteConfirmer overwriteConfirmer) {
+ WorkspaceJob genEntitiesJob = new GenerateEntitiesJob(this.jpaProject, getCustomizer(), overwriteConfirmer, false);
+ genEntitiesJob.schedule();
+ }
// ********** generate entities job **********
- static class GenerateEntitiesJob extends WorkspaceJob {
+ public static class GenerateEntitiesJob extends WorkspaceJob {
final JpaProject jpaProject;
final ORMGenCustomizer customizer;
final OverwriteConfirmer confirmer;
- GenerateEntitiesJob(JpaProject jpaProject, ORMGenCustomizer customizer, OverwriteConfirmer confirmer) {
+ final boolean generateXml;
+ public GenerateEntitiesJob(JpaProject jpaProject, ORMGenCustomizer customizer, OverwriteConfirmer confirmer, boolean generateXml) {
super(JptUiMessages.EntitiesGenerator_jobName);
this.customizer = customizer;
this.jpaProject = jpaProject;
this.confirmer = confirmer;
+ this.generateXml = generateXml;
IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
this.setRule(ruleFactory.modifyRule(jpaProject.getProject()));
}
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
- PackageGenerator.generate(this.jpaProject,this.customizer, this.confirmer, monitor);
+ PackageGenerator.generate(this.jpaProject,this.customizer, this.confirmer, monitor, this.generateXml);
return Status.OK_STATUS;
}
}
@@ -244,7 +251,7 @@
// ********** overwrite confirmer **********
- static class OverwriteConfirmer implements org.eclipse.jpt.jpa.gen.internal.OverwriteConfirmer {
+ public static class OverwriteConfirmer implements org.eclipse.jpt.jpa.gen.internal.OverwriteConfirmer {
private boolean overwriteAll = false;
private boolean skipAll = false;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
index 57f31fe..bbeebf1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
@@ -21,7 +21,6 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -42,7 +41,7 @@
private static int PROJECT_NAME_COLUMN_INDEX = 0;
private final String helpContextId;
- protected PromptJPAProjectWizardPage( final String helpContextId ) {
+ public PromptJPAProjectWizardPage( final String helpContextId ) {
super(SELECT_PROJECT_PAGE_NAME);
setTitle( JptUiEntityGenMessages.GenerateEntitiesWizard_selectJPAProject );
setMessage( JptUiEntityGenMessages.GenerateEntitiesWizard_selectJPAProject_msg );
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java
index 51663f6..0fae1b1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java
@@ -96,7 +96,7 @@
protected final ResourceManager resourceManager;
- protected TableAssociationsWizardPage(JpaProject jpaProject, ResourceManager resourceManager) {
+ public TableAssociationsWizardPage(JpaProject jpaProject, ResourceManager resourceManager) {
super("Table Associations"); //$NON-NLS-1$
this.jpaProject = jpaProject;
this.resourceManager = resourceManager;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableGenPanel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableGenPanel.java
index 926e72b..06ab291 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableGenPanel.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableGenPanel.java
@@ -38,7 +38,7 @@
* table entity generation properties.
*
*/
-class TableGenPanel
+public class TableGenPanel
{
WizardPage wizardPage ;
@@ -64,7 +64,7 @@
private ORMGenTable mTable;
- private boolean isDefaultTable = false;
+ protected boolean isDefaultTable = false;
public TableGenPanel(Composite parent, int columns , boolean isDefaultTable, WizardPage wizardPage ){
super();
@@ -116,7 +116,7 @@
});
}
- private void createClassNameControl(Composite parent, int columns) {
+ protected void createClassNameControl(Composite parent, int columns) {
//Customize class name for specific table only
if ( !isDefaultTable ) {
SWTUtil.createLabel( parent, 1 , JptUiEntityGenMessages.GenerateEntitiesWizard_tablePanel_className );
@@ -152,7 +152,7 @@
}
}
- private void createAssociationFetchControls(Composite composite, int columns) {
+ protected void createAssociationFetchControls(Composite composite, int columns) {
SWTUtil.createLabel(composite, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_fetch );
Composite parent = new Composite( composite, SWT.NONE);
@@ -186,7 +186,7 @@
}
}
- private void createCollectionTypeControls(Composite composite, int columns) {
+ protected void createCollectionTypeControls(Composite composite, int columns) {
SWTUtil.createLabel(composite, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_collType );
Composite parent = new Composite( composite, SWT.NONE);
@@ -207,70 +207,24 @@
public void setORMGenTable(ORMGenTable table) {
- mTable = table;
+ this.mTable = table;
+ }
+
+ //should be called after setting the ORMGenTable
+ public void updateControls(){
isUpdatingControls = true;
try {
- //ClassNameField is not available for default table
- if(classNameField!= null )
- classNameField.setText( mTable.getClassName() );
-
- final List<String> schemes = this.mTable.getCustomizer().getAllIdGenerators();
- String[] values = new String[schemes.size()];
- schemes.toArray(values);
- idGeneratorCombo.setItems( values );
- String idGenerator = mTable.getIdGenerator();
- idGeneratorCombo.setText( idGenerator);
-
- boolean isSequence = this.mTable.getCustomizer().getSequenceIdGenerators().contains(idGenerator);
- String sequenceName = mTable.isDefaultsTable() ? mTable.getSequence() : mTable.getFormattedSequence();
- sequenceName = ( sequenceName == null ? "" : sequenceName );
- sequenceNameField.setText( sequenceName );
- if ( isSequence ) {
- sequenceNameField.setEnabled(true);
- sequenceNameNoteLabel.setEnabled(true);
- } else {
- sequenceNameField.setEnabled(false);
- sequenceNameNoteLabel.setEnabled(false);
- }
-
- String access = mTable.getAccess() ;
- if ( ORMGenTable.FIELD_ACCESS.equals( access ) ) {
- this.entityAccessField.setSelection( true );
- this.entityAccessProperty.setSelection( false );
- } else {
- this.entityAccessProperty.setSelection( true );
- this.entityAccessField.setSelection( false );
- }
-
- if (associationFetchLazy != null && associationFetchEager != null ) {
- String defaultFetch = mTable.getDefaultFetch();
- //reset all three buttons
- associationFetchDefault.setSelection(false);
- associationFetchEager.setSelection(false);
- associationFetchLazy.setSelection(false);
- if( ORMGenTable.DEFAULT_FETCH.equals( defaultFetch ) )
- associationFetchDefault.setSelection(true);
- else if( ORMGenTable.EAGER_FETCH.equals( defaultFetch ) )
- associationFetchEager.setSelection(true);
- else
- associationFetchLazy.setSelection(true);
- }
+ updateClassNameField();
+ udpateGeneratorControls();
+ updateAccessControls();
+ updateFetchControls();
//DefaultTable only
- if (collectionTypeList != null) {
- String cType = mTable.getDefaultCollectionType();
- if ( ORMGenTable.LIST_COLLECTION_TYPE.equals( cType ) ) {
- this.collectionTypeList.setSelection( true );
- this.collectionTypeSet.setSelection( false );
- } else {
- this.collectionTypeSet.setSelection( true );
- this.collectionTypeList.setSelection( false );
- }
-
- this.generateOptionalAnnotations.setSelection( mTable.isGenerateDDLAnnotations());
- }
+ updateCollectionTypeControls();
+ updateGenerateOptionalAnnotationControls();
+
} catch (Exception e) {
JptJpaUiPlugin.log(e);
@@ -279,7 +233,82 @@
isUpdatingControls = false;
}
- private void createIdGeneratorControls(Composite parent, int columns) {
+ private void updateCollectionTypeControls() {
+ if (collectionTypeList != null) {
+ String cType = this.mTable.getDefaultCollectionType();
+ if ( ORMGenTable.LIST_COLLECTION_TYPE.equals( cType ) ) {
+ this.collectionTypeList.setSelection( true );
+ this.collectionTypeSet.setSelection( false );
+ } else {
+ this.collectionTypeSet.setSelection( true );
+ this.collectionTypeList.setSelection( false );
+ }
+
+
+ }
+ }
+
+ protected void updateGenerateOptionalAnnotationControls(){
+ if (generateOptionalAnnotations != null){
+ this.generateOptionalAnnotations.setSelection( this.mTable.isGenerateDDLAnnotations());
+ }
+ }
+
+ private void updateFetchControls() {
+ if (associationFetchLazy != null && associationFetchEager != null ) {
+ String defaultFetch = this.mTable.getDefaultFetch();
+ //reset all three buttons
+ associationFetchDefault.setSelection(false);
+ associationFetchEager.setSelection(false);
+ associationFetchLazy.setSelection(false);
+ if( ORMGenTable.DEFAULT_FETCH.equals( defaultFetch ) )
+ associationFetchDefault.setSelection(true);
+ else if( ORMGenTable.EAGER_FETCH.equals( defaultFetch ) )
+ associationFetchEager.setSelection(true);
+ else
+ associationFetchLazy.setSelection(true);
+ }
+ }
+
+ protected void updateAccessControls() {
+ String access = this.mTable.getAccess() ;
+ if ( ORMGenTable.FIELD_ACCESS.equals( access ) ) {
+ this.entityAccessField.setSelection( true );
+ this.entityAccessProperty.setSelection( false );
+ } else {
+ this.entityAccessProperty.setSelection( true );
+ this.entityAccessField.setSelection( false );
+ }
+ }
+
+ private void udpateGeneratorControls() {
+ final List<String> schemes = this.mTable.getCustomizer().getAllIdGenerators();
+ String[] values = new String[schemes.size()];
+ schemes.toArray(values);
+ idGeneratorCombo.setItems( values );
+ String idGenerator = this.mTable.getIdGenerator();
+ idGeneratorCombo.setText( idGenerator);
+
+ boolean isSequence = this.mTable.getCustomizer().getSequenceIdGenerators().contains(idGenerator);
+ String sequenceName = this.mTable.isDefaultsTable() ? this.mTable.getSequence() : this.mTable.getFormattedSequence();
+ sequenceName = ( sequenceName == null ? "" : sequenceName );
+ sequenceNameField.setText( sequenceName );
+ if ( isSequence ) {
+ sequenceNameField.setEnabled(true);
+ sequenceNameNoteLabel.setEnabled(true);
+ } else {
+ sequenceNameField.setEnabled(false);
+ sequenceNameNoteLabel.setEnabled(false);
+ }
+ }
+
+ private void updateClassNameField() {
+ //ClassNameField is not available for default table
+ if(classNameField!= null )
+ classNameField.setText( this.mTable.getClassName() );
+ }
+
+ protected void createIdGeneratorControls(Composite parent, int columns) {
SWTUtil.createLabel(parent, 1, JptUiEntityGenMessages.GenerateEntitiesWizard_defaultTablePage_keyGen );
idGeneratorCombo = new Combo(parent,SWT.SINGLE | SWT.READ_ONLY);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java
index c2fc608..4916a46 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesAndColumnsCustomizationWizardPage.java
@@ -54,19 +54,19 @@
private TreeViewer tableColumnTreeViewer;
- private Composite detailPanel ;
- private StackLayout detailPanelStatckLayout;
- private Composite tableGenDetatilGroup;
- private ColumnGenPanel columnGenPanel;
- private Composite columnGenDetatilGroup;
- private TableGenPanel tableGenPanel;
- private ORMGenTable selectedTable;
+ protected Composite detailPanel ;
+ protected StackLayout detailPanelStatckLayout;
+ protected Composite tableGenDetatilGroup;
+ protected ColumnGenPanel columnGenPanel;
+ protected Composite columnGenDetatilGroup;
+ protected TableGenPanel tableGenPanel;
+ protected ORMGenTable selectedTable;
private ORMGenCustomizer customizer;
protected final ResourceManager resourceManager;
- protected TablesAndColumnsCustomizationWizardPage(JpaProject jpaProject, ResourceManager resourceManager) {
+ public TablesAndColumnsCustomizationWizardPage(JpaProject jpaProject, ResourceManager resourceManager) {
super(true, "TablesAndColumnsCustomizationWizardPage"); //$NON-NLS-1$
this.jpaProject = jpaProject;
this.resourceManager = resourceManager;
@@ -82,7 +82,7 @@
*
* @param selection used to initialize the fields
*/
- void init(IStructuredSelection selection) {
+ public void init(IStructuredSelection selection) {
if ( jpaProject != null ) {
IJavaElement jelem = this.jpaProject.getJavaProject();
initContainerPage(jelem);
@@ -174,13 +174,13 @@
}
}
- private void updateColumnGenDetail(ORMGenColumn column) {
+ protected void updateColumnGenDetail(ORMGenColumn column) {
if(columnGenDetatilGroup==null){
columnGenDetatilGroup = new Composite(detailPanel, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 4;
columnGenDetatilGroup.setLayout(gridLayout);
- this.columnGenPanel = new ColumnGenPanel(columnGenDetatilGroup, 4, getCustomizer() , this );
+ this.columnGenPanel = new ColumnGenPanel(columnGenDetatilGroup, 4, getCustomizer() , this, false);
}
columnGenPanel.setColumn(column);
this.detailPanelStatckLayout.topControl = columnGenDetatilGroup;
@@ -188,7 +188,7 @@
detailPanel.getParent().layout();
}
- private void updateTabelGenDetail(ORMGenTable table) {
+ protected void updateTabelGenDetail(ORMGenTable table) {
this.selectedTable = table;
if(tableGenDetatilGroup==null){
tableGenDetatilGroup = new Composite(detailPanel, SWT.NONE);
@@ -200,6 +200,7 @@
createDomainJavaClassesPropertiesGroup(tableGenDetatilGroup, 4 );
}
tableGenPanel.setORMGenTable(table);
+ tableGenPanel.updateControls();
this.detailPanelStatckLayout.topControl = tableGenDetatilGroup;
this.detailPanel.layout();
@@ -285,10 +286,15 @@
}
- private ORMGenCustomizer getCustomizer(){
+ protected ORMGenCustomizer getCustomizer(){
GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) this.getWizard();
return wizard.getCustomizer();
}
+
+ public boolean isDynamic() {
+ return false;
+ }
+
/**
* Content provider, and label provider for the DB Table/Column TreeViewer
*
@@ -337,7 +343,7 @@
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
public void dispose() {}
}
-
+
class TableColumnTreeLabelProvider extends LabelProvider{
@Override
@@ -388,4 +394,5 @@
protected final IWorkbenchHelpSystem getHelpSystem() {
return PlatformUI.getWorkbench().getHelpSystem();
}
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java
index 3a86ee2..4e3c1c0 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java
@@ -74,7 +74,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;
-class TablesSelectorWizardPage extends WizardPage {
+public class TablesSelectorWizardPage extends WizardPage {
private static final int TABLE_COLUMN_INDEX = 0;
@@ -82,6 +82,7 @@
private Schema schema;
private ORMGenCustomizer customizer;
private boolean updatePersistenceXml = true;
+ private boolean isDynamic;
private DatabaseGroup databaseGroup;
private CheckboxTableViewer tableTable;
@@ -95,12 +96,13 @@
// ********** constructors **********
- public TablesSelectorWizardPage(JpaProject jpaProject, ResourceManager resourceManager) {
+ public TablesSelectorWizardPage(JpaProject jpaProject, ResourceManager resourceManager, boolean isDynamic) {
super("TablesSelectorWizardPage"); //$NON-NLS-1$
this.jpaProject = jpaProject;
this.resourceManager = resourceManager;
this.schema = jpaProject.getDefaultDbSchema();
+ this.isDynamic = isDynamic;
this.setTitle(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_selectTable );
this.setMessage(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_chooseEntityTable );
}
@@ -166,8 +168,10 @@
this.createTablesSelectionControl(composite, nColumns);
- this.updatePersistenceXmlCheckBox = this.buildUpdatePersistenceXmlCheckBox(composite);
- this.fillColumns(this.updatePersistenceXmlCheckBox, 3);
+ if (!isDynamic) {
+ this.updatePersistenceXmlCheckBox = this.buildUpdatePersistenceXmlCheckBox(composite);
+ this.fillColumns(this.updatePersistenceXmlCheckBox, 3);
+ }
//Filler column
new Label( composite, SWT.NONE);
@@ -678,7 +682,7 @@
GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) getWizard();
this.customizer = wizard.createORMGenCustomizer(schema);
- if(this.tableTable!=null && this.updatePersistenceXmlCheckBox!=null && this.customizer != null) {
+ if(this.tableTable!=null && this.customizer != null) {
this.restoreWizardState();
}
this.doStatusUpdate();
@@ -686,7 +690,9 @@
private boolean restoreWizardState() {
boolean pageComplete = false;
- this.updatePersistenceXmlCheckBox.setSelection(this.customizer.updatePersistenceXml());
+ if (this.updatePersistenceXmlCheckBox != null){
+ this.updatePersistenceXmlCheckBox.setSelection(this.customizer.updatePersistenceXml());
+ }
List<String> preSelectedTableNames = this.customizer.getTableNames();
if(preSelectedTableNames!=null && preSelectedTableNames.size()>0) {
Set<String> set = new HashSet<String>();