Author: vyemialyanchyk
Date: 2010-09-10 11:00:21 -0400 (Fri, 10 Sep 2010)
New Revision: 24873
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactoryStrings.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenJpa_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenProps_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenReveng_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGen_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
Log:
https://jira.jboss.org/browse/JBIDE-6703 - fixed
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -39,7 +39,7 @@
<attribute name="update" gui-name="schemaUpdate"
default="false"/>
<attribute name="drop" gui-name="drop"
default="false"/>
<attribute name="create" gui-name="create"
default="true"/>
- <attribute name="outputfilename" gui-name="outputfilename"
default=""/>
+ <attribute name="outputfilename" gui-name="outputFileName"
default=""/>
<attribute name="delimiter" gui-name="delimiter"
default=";"/>
<attribute name="format" gui-name="format"
default="false"/>
<attribute name="haltonerror" gui-name="haltonerror"
default="false"/>
@@ -52,4 +52,11 @@
<attribute name="jdk5" gui-name="jdk5"
default="false"/>
<attribute name="ejb3" gui-name="ejb3"
default="false"/>
</task>
+ <task name="query" id="org.hibernate.tools.query">
+ <attribute name="destfile" gui-name="outputFileName"
default=""/>
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ <subtag name="hql" gui-name="query_string"
default=""/>
+ </task>
</ant-tasks>
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -619,6 +619,27 @@
type="boolean"
value="false"/>
</exporter>
+ <exporter
+ classname="org.hibernate.tool.hbm2x.QueryExporter"
+ description="HQL Query Execution Exporter"
+ icon="icons/images/hql_editor_connect.gif"
+ id="org.hibernate.tools.query">
+ <property
+ description="Output directory"
+ name="outputdir"
+ type="directory"
+ value=""/>
+ <property
+ description="File name"
+ name="outputFileName"
+ type="string"
+ value=""/>
+ <property
+ description="Query"
+ name="query_string"
+ type="string"
+ value=""/>
+ </exporter>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2010-09-10
15:00:21 UTC (rev 24873)
@@ -25,6 +25,7 @@
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.tool.hbm2x.GenericExporter;
import org.hibernate.tool.hbm2x.Hbm2DDLExporter;
+import org.hibernate.tool.hbm2x.QueryExporter;
import org.hibernate.util.StringHelper;
/**
@@ -289,6 +290,14 @@
//avoid users to delete their databases with a single click
ddlExporter.setExport(Boolean.getBoolean(extract.getProperty(ExporterFactoryStrings.EXPORTTODATABASE)));
}
+ // special handling for QueryExporter
+ if (exporterId.equals("org.hibernate.tools.query")) { //$NON-NLS-1$
+ QueryExporter queryExporter = (QueryExporter) exporter;
+ List<String> queryStrings = new ArrayList<String>();
+ queryStrings.add(extract.getProperty(ExporterFactoryStrings.QUERY_STRING));
+ queryExporter.setQueries(queryStrings);
+ queryExporter.setFilename(extract.getProperty(ExporterFactoryStrings.OUTPUTFILENAME));
+ }
return exporter;
}
@@ -335,5 +344,19 @@
extract.put(ExporterFactoryStrings.EXPORTTODATABASE,
props.getProperty(ExporterFactoryStrings.EXPORTTODATABASE, Boolean.toString(false)));
props.remove(ExporterFactoryStrings.EXPORTTODATABASE);
}
+ // special handling for QueryExporter
+ if (exporterId.equals("org.hibernate.tools.query")) { //$NON-NLS-1$
+ String tmp;
+ if (props.containsKey(ExporterFactoryStrings.QUERY_STRING)) {
+ tmp = props.getProperty(ExporterFactoryStrings.QUERY_STRING, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.QUERY_STRING, tmp);
+ props.remove(ExporterFactoryStrings.QUERY_STRING);
+ }
+ if (props.containsKey(ExporterFactoryStrings.OUTPUTFILENAME)) {
+ tmp = props.getProperty(ExporterFactoryStrings.OUTPUTFILENAME, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.OUTPUTFILENAME, tmp);
+ props.remove(ExporterFactoryStrings.OUTPUTFILENAME);
+ }
+ }
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactoryStrings.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactoryStrings.java 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactoryStrings.java 2010-09-10
15:00:21 UTC (rev 24873)
@@ -23,4 +23,6 @@
public static final String TEMPLATE_NAME = "template_name"; //$NON-NLS-1$
public static final String FOR_EACH = "for_each"; //$NON-NLS-1$
public static final String EXPORTTODATABASE = "exportToDatabase";
//$NON-NLS-1$
+ public static final String QUERY_STRING = "query_string"; //$NON-NLS-1$
+ public static final String OUTPUTFILENAME = "outputFileName"; //$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-09-10
15:00:21 UTC (rev 24873)
@@ -19,7 +19,9 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
@@ -303,6 +305,8 @@
//
Map<String, Map<String, AttributeDescription>> exportersDescr =
ExportersXMLAttributeDescription.getExportersDescription();
+ Map<String, Set<String>> exportersSetSubTags =
+ ExportersXMLAttributeDescription.getExportersSetSubTags();
//
Properties globalProps = new Properties();
// obligatory global properties
@@ -323,6 +327,11 @@
if (attributesDescrGui == null) {
attributesDescrGui = new TreeMap<String, AttributeDescription>();
}
+ // mapping: guiName -> set of sub tags
+ Set<String> setSubTags = exportersSetSubTags.get(expName);
+ if (setSubTags == null) {
+ setSubTags = new TreeSet<String>();
+ }
// construct new mapping: name -> AttributeDescription
Map<String, AttributeDescription> attributesDescrAnt = new TreeMap<String,
AttributeDescription>();
for (AttributeDescription ad : attributesDescrGui.values()) {
@@ -365,7 +374,12 @@
if (val == null || 0 == val.toString().compareTo(ad.defaultValue)) {
continue;
}
- exporter.addAttribute(ad.name, val.toString());
+ if (setSubTags.contains(ad.guiName)) {
+ Element subTag = exporter.addElement(ad.name);
+ subTag.addText(val.toString());
+ } else {
+ exporter.addAttribute(ad.name, val.toString());
+ }
}
for (Object obj : list2Remove) {
expProps.remove(obj);
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java 2010-09-10
15:00:21 UTC (rev 24873)
@@ -17,7 +17,9 @@
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import org.dom4j.Document;
import org.dom4j.DocumentException;
@@ -47,12 +49,14 @@
}
private static Map<String, Map<String, AttributeDescription>>
mapExporter2AttributeDescr = null;
+ private static Map<String, Set<String>> mapExporter2SetSubTags = null;
private static void initExportersDescriptionmap() {
if (mapExporter2AttributeDescr != null) {
return;
}
mapExporter2AttributeDescr = new TreeMap<String, Map<String,
AttributeDescription>>();
+ mapExporter2SetSubTags = new TreeMap<String, Set<String>>();
Document doc = getDocument();
if (doc == null) {
return;
@@ -73,9 +77,21 @@
ad.defaultValue = elAttribute.attributeValue("default"); //$NON-NLS-1$
attributes.put(ad.guiName, ad);
}
+ Set<String> subtags = new TreeSet<String>();
+ itAttribute = elTask.elementIterator("subtag"); //$NON-NLS-1$
+ while (itAttribute.hasNext()) {
+ Element elAttribute = (Element)itAttribute.next();
+ AttributeDescription ad = new AttributeDescription();
+ ad.name = elAttribute.attributeValue("name"); //$NON-NLS-1$
+ ad.guiName = elAttribute.attributeValue("gui-name"); //$NON-NLS-1$
+ ad.defaultValue = elAttribute.attributeValue("default"); //$NON-NLS-1$
+ attributes.put(ad.guiName, ad);
+ subtags.add(ad.guiName);
+ }
//String taskId = elTask.attributeValue("id"); //$NON-NLS-1$
String taskName = elTask.attributeValue("name"); //$NON-NLS-1$
mapExporter2AttributeDescr.put(taskName, attributes);
+ mapExporter2SetSubTags.put(taskName, subtags);
}
}
@@ -91,6 +107,13 @@
res.putAll(mapExporter2AttributeDescr);
return res;
}
+
+ public static Map<String, Set<String>> getExportersSetSubTags() {
+ initExportersDescriptionmap();
+ Map<String, Set<String>> res = new TreeMap<String,
Set<String>>();
+ res.putAll(mapExporter2SetSubTags);
+ return res;
+ }
private static Document getDocument() {
File resourceFile = null;
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -16,6 +16,11 @@
<classpath>
<path location="${build.dir}"/>
</classpath>
+ <query>
+ <hql>from testQuery</hql>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </query>
<hbm2doc>
<property key="ejb3" value="false"/>
<property key="jdk5" value="false"/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenJpa_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenJpa_test1.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenJpa_test1.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -17,6 +17,11 @@
<classpath>
<path location="${build.dir}"/>
</classpath>
+ <query>
+ <hql>from testQuery</hql>
+ <property key="ejb3" value="true"/>
+ <property key="jdk5" value="true"/>
+ </query>
<hbm2doc>
<property key="ejb3" value="true"/>
<property key="jdk5" value="true"/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -7,6 +7,11 @@
<classpath>
<path location="${build.dir}"/>
</classpath>
+ <query>
+ <hql>from testQuery</hql>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </query>
<hbm2doc>
<property key="ejb3" value="false"/>
<property key="jdk5" value="false"/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenProps_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenProps_test1.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenProps_test1.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -8,6 +8,11 @@
<classpath>
<path location="${build.dir}"/>
</classpath>
+ <query>
+ <hql>from testQuery</hql>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </query>
<hbm2doc>
<property key="ejb3" value="false"/>
<property key="jdk5" value="false"/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenReveng_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenReveng_test1.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenReveng_test1.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -8,6 +8,11 @@
<classpath>
<path location="${build.dir}"/>
</classpath>
+ <query>
+ <hql>from testQuery</hql>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </query>
<hbm2doc>
<property key="ejb3" value="false"/>
<property key="jdk5" value="false"/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGen_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGen_test1.xml 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGen_test1.xml 2010-09-10
15:00:21 UTC (rev 24873)
@@ -10,6 +10,11 @@
<classpath>
<path location="${build.dir}"/>
</classpath>
+ <query>
+ <hql>from testQuery</hql>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </query>
<hbm2doc>
<property key="ejb3" value="false"/>
<property key="jdk5" value="false"/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java 2010-09-10
14:43:40 UTC (rev 24872)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java 2010-09-10
15:00:21 UTC (rev 24873)
@@ -62,6 +62,9 @@
public static final String HBMTEMPLATE0 = "hbm2java"; //$NON-NLS-1$
public static final String HBMTEMPLATE0_PROPERTIES =
HibernateLaunchConstants.ATTR_EXPORTERS
+ '.' + HBMTEMPLATE0 + ".properties"; //$NON-NLS-1$
+ public static final String HBMTEMPLATE1 = "query"; //$NON-NLS-1$
+ public static final String HBMTEMPLATE1_PROPERTIES =
HibernateLaunchConstants.ATTR_EXPORTERS
+ + '.' + HBMTEMPLATE1 + ".properties"; //$NON-NLS-1$
public static final String OUTDIR_PATH = "outputdir/test".replace('/',
IPath.SEPARATOR); //$NON-NLS-1$
public class TestConsoleConfigPref extends TestConsoleConfigurationPreferences {
@@ -404,7 +407,10 @@
expProps2.put(ExporterFactoryStrings.OUTPUTDIR, OUTDIR_PATH);
expProps2.put(CodeGenerationStrings.DESTDIR, OUTDIR_PATH + "_test_suffix");
//$NON-NLS-1$
expProps2.put("keyXXX", "valueYYY"); //$NON-NLS-1$ //$NON-NLS-2$
+ Map<String, String> expProps3 = new HashMap<String, String>();
+ expProps3.put(ExporterFactoryStrings.QUERY_STRING, "from testQuery");
//$NON-NLS-1$
testLaunchConfigAttr.put(HBMTEMPLATE0_PROPERTIES, expProps2);
+ testLaunchConfigAttr.put(HBMTEMPLATE1_PROPERTIES, expProps3);
testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, reveng);
testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
true);
TestLaunchConfig testLaunchConfig = new TestLaunchConfig(testLaunchConfigAttr);