Hibernate SVN: r10670 - trunk/Hibernate3/src/org/hibernate/util
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-31 16:30:15 -0500 (Tue, 31 Oct 2006)
New Revision: 10670
Modified:
trunk/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java
Log:
HHH-2202 Workaround Sybase weirdness
Modified: trunk/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java 2006-10-31 21:24:28 UTC (rev 10669)
+++ trunk/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java 2006-10-31 21:30:15 UTC (rev 10670)
@@ -20,13 +20,19 @@
if ( log.isWarnEnabled() ) {
try {
logWarnings( connection.getWarnings() );
- connection.clearWarnings();
}
catch (SQLException sqle) {
//workaround for WebLogic
log.debug("could not log warnings", sqle);
}
}
+ try {
+ //Sybase fail if we don't do that, sigh...
+ connection.clearWarnings();
+ }
+ catch (SQLException sqle) {
+ log.debug("could not clear warnings", sqle);
+ }
}
public static void logWarnings(SQLWarning warning) {
18 years, 1 month
Hibernate SVN: r10669 - branches/Branch_3_2/Hibernate3/src/org/hibernate/util
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-31 16:24:28 -0500 (Tue, 31 Oct 2006)
New Revision: 10669
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java
Log:
HHH-2202
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java 2006-10-31 15:34:22 UTC (rev 10668)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/util/JDBCExceptionReporter.java 2006-10-31 21:24:28 UTC (rev 10669)
@@ -20,13 +20,19 @@
if ( log.isWarnEnabled() ) {
try {
logWarnings( connection.getWarnings() );
- connection.clearWarnings();
}
catch (SQLException sqle) {
//workaround for WebLogic
log.debug("could not log warnings", sqle);
}
}
+ try {
+ //Sybase fail if we don't do that, sigh...
+ connection.clearWarnings();
+ }
+ catch (SQLException sqle) {
+ log.debug("could not clear warnings", sqle);
+ }
}
public static void logWarnings(SQLWarning warning) {
18 years, 1 month
Hibernate SVN: r10668 - branches/Branch_3_2/HibernateExt/tools/etc
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-31 10:34:22 -0500 (Tue, 31 Oct 2006)
New Revision: 10668
Modified:
branches/Branch_3_2/HibernateExt/tools/etc/hibernate.properties
Log:
update hibernate.properties
Modified: branches/Branch_3_2/HibernateExt/tools/etc/hibernate.properties
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/etc/hibernate.properties 2006-10-31 14:24:31 UTC (rev 10667)
+++ branches/Branch_3_2/HibernateExt/tools/etc/hibernate.properties 2006-10-31 15:34:22 UTC (rev 10668)
@@ -315,7 +315,7 @@
## specify a default schema and catalog for unqualified tablenames
-#hibernate.default_schema PUBLIC
+hibernate.default_schema PUBLIC
#hibernate.default_catalog PUBLIC
@@ -406,7 +406,7 @@
## choose a cache implementation
-hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider
+#hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.EmptyCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.TreeCacheProvider
18 years, 1 month
Hibernate SVN: r10667 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/tool/hbm2x java/org/hibernate/tool/hbm2x/doc java/org/hibernate/tool/hbm2x/pojo templates/doc templates/doc/entities
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-31 09:24:31 -0500 (Tue, 31 Oct 2006)
New Revision: 10667
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
branches/Branch_3_2/HibernateExt/tools/src/templates/doc/doc-style.css
branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
Log:
HBX-795 Entity docmentation is missing hiearchy information
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java 2006-10-31 14:21:49 UTC (rev 10666)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java 2006-10-31 14:24:31 UTC (rev 10667)
@@ -40,6 +40,11 @@
private static final String FILE_HIBERNATE_IMAGE = "doc/hibernate_logo.gif";
/**
+ * Extends Image.
+ */
+ private static final String FILE_EXTENDS_IMAGE = "doc/inherit.gif";
+
+ /**
* Main index page.
*/
private static final String FILE_INDEX = "doc/index.html";
@@ -289,6 +294,10 @@
DocFileManager.copy(FILE_HIBERNATE_IMAGE,
hibernateLogoDocFile.getFile() );
+ DocFile extendsImageDocFile = docFileManager.getExtendsImageDocFile();
+
+ DocFileManager.copy(FILE_EXTENDS_IMAGE, extendsImageDocFile.getFile());
+
DocFile mainIndexDocFile = docFileManager.getMainIndexDocFile();
DocFileManager.copy(FILE_INDEX, mainIndexDocFile.getFile() );
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java 2006-10-31 14:21:49 UTC (rev 10666)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java 2006-10-31 14:24:31 UTC (rev 10667)
@@ -45,6 +45,11 @@
* The Hibernate image.
*/
private DocFile hibernateImageDocFile;
+
+ /**
+ * The extends image.
+ */
+ private DocFile extendsImageDocFile;
/**
* The CSS stylesheet file.
@@ -159,6 +164,8 @@
hibernateImageDocFile = new DocFile("hibernate_logo.gif",
assetsDocFolder);
+
+ extendsImageDocFile = new DocFile("inherit.gif", assetsDocFolder);
cssStylesDocFile = new DocFile("doc-style.css", assetsDocFolder);
@@ -281,7 +288,17 @@
return hibernateImageDocFile;
}
+
+ /**
+ * Returns the DocFile for the extends Image.
+ *
+ * @return the value.
+ */
+ public DocFile getExtendsImageDocFile() {
+ return extendsImageDocFile;
+ }
+
/**
* Returns the DocFile for the main index.
*
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-10-31 14:21:49 UTC (rev 10666)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-10-31 14:24:31 UTC (rev 10667)
@@ -4,11 +4,9 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
@@ -489,5 +487,22 @@
return null;
}
}
+
+ public List getInheritanceHiearchy(POJOClass pc) {
+ if(pc.isSubclass()) {
+ List superClasses = new ArrayList();
+ POJOClass superClass = pc.getSuperClass();
+ while (superClass != null)
+ {
+ superClasses.add(superClass);
+ superClass = superClass.getSuperClass();
+ }
+
+ return superClasses;
+ } else {
+ return Collections.EMPTY_LIST;
+ }
+ }
+
}
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2006-10-31 14:21:49 UTC (rev 10666)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2006-10-31 14:24:31 UTC (rev 10667)
@@ -3,36 +3,36 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import java.util.StringTokenizer;
-import java.util.Set;
-import java.util.HashSet;
+import org.hibernate.cfg.Configuration;
import org.hibernate.id.MultipleHiLoPerTableGenerator;
import org.hibernate.id.PersistentIdentifierGenerator;
+import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Formula;
import org.hibernate.mapping.KeyValue;
+import org.hibernate.mapping.ManyToOne;
+import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Subclass;
+import org.hibernate.mapping.Table;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.mapping.Value;
-import org.hibernate.mapping.Collection;
-import org.hibernate.mapping.OneToMany;
-import org.hibernate.mapping.ManyToOne;
-import org.hibernate.mapping.Table;
import org.hibernate.tool.hbm2x.Cfg2JavaTool;
import org.hibernate.util.JoinedIterator;
import org.hibernate.util.StringHelper;
-import org.hibernate.cfg.Configuration;
public class EntityPOJOClass extends BasicPOJOClass {
@@ -786,8 +786,11 @@
}
public POJOClass getSuperClass(){
+ if (!isSubclass())
+ return null;
return new EntityPOJOClass(clazz.getSuperclass(),c2j);
}
+
public String toString() {
return getClass().getName() + "(" + (clazz==null?"<none>":clazz.getEntityName()) + ")";
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/doc/doc-style.css
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/doc/doc-style.css 2006-10-31 14:21:49 UTC (rev 10666)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/doc/doc-style.css 2006-10-31 14:24:31 UTC (rev 10667)
@@ -67,3 +67,39 @@
.HeaderLink {
text-decoration: none;
}
+
+/* entity hierarchy */
+
+.EntityHierarchy
+{
+ border: solid 1px #CCCCCC;
+ background: #F4F4F4;
+ padding: 5px;
+ font: bold 90% monospace;
+}
+
+.EntityHierarchy a
+{
+ font-weight: normal;
+}
+
+.EntityHierarchy ul
+{
+ margin: 0;
+ list-style: none;
+ padding-left: 0;
+}
+* html .EntityHierarchy ul /* ie6 only */
+{
+ margin-left: 0;
+}
+
+.EntityHierarchy ul.first
+{
+ padding-left: 15px;
+}
+
+.EntityHierarchy ul ul
+{
+ padding-left: 30px;
+}
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-10-31 14:21:49 UTC (rev 10666)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-10-31 14:24:31 UTC (rev 10667)
@@ -8,14 +8,28 @@
<BODY>
<H4>${class.packageName}</H4>
- <H3>Entity : ${class.getShortName()}</H3>
- <#if class.isInterface()>
- Interface Name :
- <#else>
- Class Name :
- </#if>
- ${class.qualifiedDeclarationName}
- <BR>
+ <H3>Entity ${class.getShortName()}</H3>
+
+ <div class="EntityHierarchy">
+ <ul>
+ <li>
+ <#assign superClasses=dochelper.getInheritanceHiearchy(class)>
+ <#list superClasses?reverse as superClass>
+ <#-- whitespace is significant here -->
+ <#if superClass_index gt 0><img src="${docFileManager.getRef(docFile, docFileManager.getExtendsImageDocFile())}" alt="extended by"/></#if><a href="${docFileManager.getRef(docFile, docFileManager.getEntityDocFileByDeclarationName(superClass))}">${superClass.qualifiedDeclarationName}</a>
+ <ul <#if superClass_index == 0>class="first"</#if>>
+ <li>
+ </#list>
+ <#-- whitespace is significant here -->
+ <#if class.subclass><img src="${docFileManager.getRef(docFile, docFileManager.getExtendsImageDocFile())}" alt="extended by"/></#if>${class.qualifiedDeclarationName}
+ <#list superClasses as superClass>
+ </li>
+ </ul>
+ </#list>
+ </li>
+ </ul>
+ </div>
+
<#if class.getMetaAsString("class-description")?has_content>
<HR>
<BR>
18 years, 1 month
Hibernate SVN: r10666 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-31 09:21:49 -0500 (Tue, 31 Oct 2006)
New Revision: 10666
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/QueryExporterTask.java
Log:
fix bug in <hql> were nested queries were ignored
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/QueryExporterTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/QueryExporterTask.java 2006-10-31 13:24:23 UTC (rev 10665)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/QueryExporterTask.java 2006-10-31 14:21:49 UTC (rev 10666)
@@ -28,7 +28,7 @@
for (Iterator iter = queries.iterator(); iter.hasNext();) {
HQL hql = (HQL) iter.next();
if(StringHelper.isNotEmpty(hql.query)) {
- queryStrings.add(query);
+ queryStrings.add(hql.query);
}
}
exporter.setQueries(queryStrings);
18 years, 1 month
Hibernate SVN: r10665 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/tool/hbm2x templates/doc/entities test/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-31 08:24:23 -0500 (Tue, 31 Oct 2006)
New Revision: 10665
Added:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/FileVisitor.java
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java
branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
Log:
HBX-791 Generic type information is hidden in hbm2doc
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java 2006-10-31 13:23:35 UTC (rev 10664)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java 2006-10-31 13:24:23 UTC (rev 10665)
@@ -123,12 +123,6 @@
* Doc File Manager.
*/
private DocFileManager docFileManager;
-
- /**
- * As of now we are not using generics. In future we may allow to pass one of the parameters in ant for generics
- */
- //TODO Should we allow user to make use of genrics?
- private boolean jdk5 = false;
/**
* Creates a new object.
@@ -270,7 +264,9 @@
protected void setupContext() {
- getProperties().put("jdk5", "" + useJdk5());
+ if(!getProperties().contains( "jdk5" )) {
+ getProperties().setProperty( "jdk5", "true" );
+ }
super.setupContext();
docHelper = new DocHelper( getConfiguration(), getCfg2JavaTool() );
docFileManager = new DocFileManager(docHelper, getOutputDirectory() );
@@ -619,13 +615,5 @@
public String getName() {
return "hbm2doc";
}
-
- public boolean useJdk5() {
- return jdk5;
- }
-
- public void setJdk5(boolean jdk5) {
- this.jdk5 = jdk5;
- }
-
+
}
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-10-31 13:23:35 UTC (rev 10664)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-10-31 13:24:23 UTC (rev 10665)
@@ -86,10 +86,10 @@
<TD WIDTH="14%" <#if (rowspan>0)>ROWSPAN="${rowspan}"</#if>>
<#if dochelper.getComponentPOJO(property)?exists>
<A HREF='${docFileManager.getRef(docFile, docFileManager.getEntityDocFileByDeclarationName(dochelper.getComponentPOJO(property)))}' TARGET="generalFrame">
- ${compoclass.getJavaTypeName(property, jdk5)?default(" ")}
+ ${compoclass.getJavaTypeName(property, jdk5)?html?default(" ")}
</A>
<#else>
- ${compoclass.getJavaTypeName(property, jdk5)?default(" ")}
+ ${compoclass.getJavaTypeName(property, jdk5)?html?default(" ")}
</#if>
</TD>
@@ -125,7 +125,7 @@
Column
</TD>
<TD WIDTH="14%">
- ${class.getJavaTypeName(propertyIdentifier, jdk5)?default(" ")}
+ ${class.getJavaTypeName(propertyIdentifier, jdk5)?html?default(" ")}
</TD>
<TD WIDTH="58%">
<#if class.hasFieldJavaDoc(propertyIdentifier)>
@@ -206,10 +206,10 @@
<TD WIDTH="14%" <#if (rowspan>0)>ROWSPAN="${rowspan}"</#if>>
<#if dochelper.getComponentPOJO(property)?exists>
<A HREF='${docFileManager.getRef(docFile, docFileManager.getEntityDocFileByDeclarationName(dochelper.getComponentPOJO(property)))}' TARGET="generalFrame">
- ${class.getJavaTypeName(property, jdk5)?default(" ")}
+ ${class.getJavaTypeName(property, jdk5)?html?default(" ")}
</A>
<#else>
- ${class.getJavaTypeName(property, jdk5)?default(" ")}
+ ${class.getJavaTypeName(property, jdk5)?html?default(" ")}
</#if>
</TD>
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-10-31 13:23:35 UTC (rev 10664)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-10-31 13:24:23 UTC (rev 10665)
@@ -1,9 +1,13 @@
package org.hibernate.tool.hbm2x;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
import java.util.Properties;
import org.hibernate.tool.NonReflectiveTestCase;
+import org.w3c.tidy.Tidy;
public class DocExporterTest extends NonReflectiveTestCase {
@@ -30,6 +34,7 @@
super.setUp();
DocExporter exporter = new DocExporter(getCfg(), getOutputDir() );
Properties properties = new Properties();
+ properties.put( "jdk5", "true"); // test generics
properties.put("dot.executable", System.getProperties().getProperty("dot.executable","dot.exe"));
exporter.setProperties( properties );
exporter.start();
@@ -61,7 +66,20 @@
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.dot"));
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.png"));
-
+ /* Tidy complains about valid html 4.x
+ final Tidy tidy = new Tidy();
+
+
+ new FileVisitor() {
+ protected void process(File dir) {
+ if(dir.isFile() && dir.getName().endsWith( ".html" )) {
+ testHtml( tidy, dir );
+ }
+
+ }
+ }.visit( getOutputDir() );*/
+
+
}
public void testCommentIncluded() {
@@ -71,5 +89,27 @@
assertNotNull(findFirstString("A unique customer comment!", tableFile));
}
+
+ public void testGenericsRenderedCorrectly() {
+// A unique customer comment!
+ File tableFile = new File(getOutputDir(), "entities/org/hibernate/tool/hbm2x/Customer.html");
+ assertFileAndExists(tableFile );
+
+ assertEquals("Generics syntax should not occur verbatim in html",null,findFirstString("List<", tableFile));
+ assertNotNull("Generics syntax occur verbatim in html",findFirstString("List<", tableFile));
+ }
+
+ private void testHtml(final Tidy tidy, File dir) {
+ try {
+ System.out.println("*****Parsing " + dir);
+ tidy.parse( new FileInputStream(dir), (OutputStream)null );
+ assertEquals(dir + "has errors ", 0, tidy.getParseErrors());
+ assertEquals(dir + "has warnings ", 0, tidy.getParseWarnings());
+ }
+ catch (FileNotFoundException e) {
+ fail();
+ }
+ }
+
}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/FileVisitor.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/FileVisitor.java 2006-10-31 13:23:35 UTC (rev 10664)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/FileVisitor.java 2006-10-31 13:24:23 UTC (rev 10665)
@@ -0,0 +1,21 @@
+package org.hibernate.tool.hbm2x;
+
+import java.io.File;
+
+public abstract class FileVisitor {
+
+
+ public void visit(File dir) {
+ process(dir);
+
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i=0; i<children.length; i++) {
+ visit(new File(dir, children[i]));
+ }
+ }
+ }
+
+ abstract protected void process(File dir);
+
+}
18 years, 1 month
Hibernate SVN: r10664 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-31 08:23:35 -0500 (Tue, 31 Oct 2006)
New Revision: 10664
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java
Log:
dont change case for strings that requires quoting
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java 2006-10-31 13:22:51 UTC (rev 10663)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java 2006-10-31 13:23:35 UTC (rev 10664)
@@ -30,10 +30,10 @@
private Connection connection;
private DatabaseMetaData metaData;
+
public void configure(ConnectionProvider provider, SQLExceptionConverter sec) {
this.provider = provider;
- this.sec = sec;
-
+ this.sec = sec;
}
@@ -134,7 +134,9 @@
public boolean needQuote(String name) {
- // TODO: use jdbc metadata to decide on this. but for now we just handle the most typical cases.
+ if(name==null) return false;
+
+ // TODO: use jdbc metadata to decide on this. but for now we just handle the most typical cases.
if(name.indexOf('-')>0) return true;
if(name.indexOf(' ')>0) return true;
return false;
@@ -142,6 +144,9 @@
protected String caseForSearch(String value) throws SQLException {
// TODO: handle quoted requests (just strip it ?)
+ if(needQuote(value)) {
+ return value;
+ }
if ( getMetaData().storesUpperCaseIdentifiers() ) {
return StringHelper.toUpperCase( value );
} else if( getMetaData().storesUpperCaseIdentifiers() ) {
18 years, 1 month
Hibernate SVN: r10663 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-31 08:22:51 -0500 (Tue, 31 Oct 2006)
New Revision: 10663
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java
Log:
remove bogus test code
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java 2006-10-31 13:21:53 UTC (rev 10662)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java 2006-10-31 13:22:51 UTC (rev 10663)
@@ -137,8 +137,7 @@
t.commit();
session.close();
-
- new StatisticsBrowser().showStatistics( sf.getStatistics(), true );
+
session = sf.openSession();
t = session.beginTransaction();
18 years, 1 month
Hibernate SVN: r10662 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-31 08:21:53 -0500 (Tue, 31 Oct 2006)
New Revision: 10662
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java
Log:
tx exceptions not properly handled
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java 2006-10-31 02:19:13 UTC (rev 10661)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java 2006-10-31 13:21:53 UTC (rev 10662)
@@ -61,11 +61,19 @@
}
transaction.commit();
} catch(HibernateException he) {
- if(transaction!=null) transaction.rollback();
+ if(transaction!=null) {
+ transaction.rollback();
+ }
+ throw new ExporterException("Error occured while trying to execute query", he);
} finally {
- session.close();
- session.getSessionFactory().close();
+ if(session!=null) {
+ session.close();
+ }
+ if(sessionFactory!=null) {
+ sessionFactory.close();
+ }
+
}
}
18 years, 1 month
Hibernate SVN: r10661 - in trunk/Hibernate3/src/org/hibernate: cfg mapping
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-30 21:19:13 -0500 (Mon, 30 Oct 2006)
New Revision: 10661
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java
trunk/Hibernate3/src/org/hibernate/mapping/Constraint.java
trunk/Hibernate3/src/org/hibernate/mapping/Index.java
trunk/Hibernate3/src/org/hibernate/mapping/Table.java
trunk/Hibernate3/src/org/hibernate/mapping/UniqueKey.java
Log:
HHH-2199 apply supportsNoNullUnique to UniqueKey
Modified: trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-10-31 02:18:40 UTC (rev 10660)
+++ trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-10-31 02:19:13 UTC (rev 10661)
@@ -800,7 +800,8 @@
Iterator subIter = table.getUniqueKeyIterator();
while ( subIter.hasNext() ) {
UniqueKey uk = (UniqueKey) subIter.next();
- script.add( uk.sqlCreateString( dialect, mapping, defaultCatalog, defaultSchema ) );
+ String constraintString = uk.sqlCreateString( dialect, mapping, defaultCatalog, defaultSchema );
+ if (constraintString != null) script.add( constraintString );
}
}
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Constraint.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Constraint.java 2006-10-31 02:18:40 UTC (rev 10660)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Constraint.java 2006-10-31 02:19:13 UTC (rev 10661)
@@ -11,6 +11,7 @@
/**
* A relational constraint.
+ *
* @author Gavin King
*/
public abstract class Constraint implements RelationalModel, Serializable {
@@ -22,63 +23,88 @@
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
+
public Iterator getColumnIterator() {
return columns.iterator();
}
+
public void addColumn(Column column) {
- if ( !columns.contains(column) ) columns.add(column);
+ if ( !columns.contains( column ) ) columns.add( column );
}
+
public void addColumns(Iterator columnIterator) {
while ( columnIterator.hasNext() ) {
Selectable col = (Selectable) columnIterator.next();
if ( !col.isFormula() ) addColumn( (Column) col );
}
}
+
/**
* @param column
* @return true if this constraint already contains a column with same name.
*/
public boolean containsColumn(Column column) {
- return columns.contains(column);
- }
+ return columns.contains( column );
+ }
+
public int getColumnSpan() {
return columns.size();
}
-
+
public Column getColumn(int i) {
- return (Column) columns.get(i);
+ return (Column) columns.get( i );
}
-
+
public Iterator columnIterator() {
return columns.iterator();
}
+
public Table getTable() {
return table;
}
+
public void setTable(Table table) {
this.table = table;
}
+ public boolean isGenerated(Dialect dialect) {
+ return true;
+ }
+
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
- return "alter table " + getTable().getQualifiedName(dialect, defaultCatalog, defaultSchema) + " drop constraint " + getName();
+ if ( isGenerated( dialect ) ) {
+ return "alter table " + getTable()
+ .getQualifiedName( dialect, defaultCatalog, defaultSchema ) + " drop constraint " + getName();
+ }
+ else {
+ return null;
+ }
}
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
- StringBuffer buf = new StringBuffer("alter table ")
- .append( getTable().getQualifiedName(dialect, defaultCatalog, defaultSchema) )
- .append( sqlConstraintString( dialect, getName(), defaultCatalog, defaultSchema ) );
- return buf.toString();
+ if ( isGenerated( dialect ) ) {
+ String constraintString = sqlConstraintString( dialect, getName(), defaultCatalog, defaultSchema );
+ StringBuffer buf = new StringBuffer( "alter table " )
+ .append( getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
+ .append( constraintString );
+ return buf.toString();
+ }
+ else {
+ return null;
+ }
}
-
+
public List getColumns() {
return columns;
}
- public abstract String sqlConstraintString(Dialect d, String constraintName, String defaultCatalog, String defaultSchema);
-
+ public abstract String sqlConstraintString(Dialect d, String constraintName, String defaultCatalog,
+ String defaultSchema);
+
public String toString() {
return getClass().getName() + '(' + getTable().getName() + getColumns() + ") as " + name;
}
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Index.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Index.java 2006-10-31 02:18:40 UTC (rev 10660)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Index.java 2006-10-31 02:19:13 UTC (rev 10661)
@@ -13,6 +13,7 @@
/**
* A relational table index
+ *
* @author Gavin King
*/
public class Index implements RelationalModel, Serializable {
@@ -20,107 +21,120 @@
private Table table;
private List columns = new ArrayList();
private String name;
-
- public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema)
+
+ public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema)
throws HibernateException {
return buildSqlCreateIndexString(
- dialect,
- getName(),
- getTable(),
- getColumnIterator(),
- false,
- defaultCatalog,
+ dialect,
+ getName(),
+ getTable(),
+ getColumnIterator(),
+ false,
+ defaultCatalog,
defaultSchema
- );
+ );
}
-
- public static String buildSqlDropIndexString(
- Dialect dialect,
- Table table,
- String name,
- String defaultCatalog,
- String defaultSchema
- ) {
- return "drop index " +
- StringHelper.qualify(
- table.getQualifiedName(dialect, defaultCatalog, defaultSchema),
- name
- );
- }
- public static String buildSqlCreateIndexString(
- Dialect dialect,
- String name,
- Table table,
- Iterator columns,
- boolean unique,
- String defaultCatalog,
- String defaultSchema
- ) {
- StringBuffer buf = new StringBuffer("create")
- .append( unique ? " unique" : "")
- .append(" index ")
- .append( dialect.qualifyIndexName() ? name : StringHelper.unqualify(name) )
- .append(" on ")
- .append( table.getQualifiedName(dialect, defaultCatalog, defaultSchema) )
- .append(" (");
- Iterator iter = columns;
- while ( iter.hasNext() ) {
- buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
- if ( iter.hasNext() ) buf.append(", ");
- }
- buf.append(")");
- return buf.toString();
- }
-
+ public static String buildSqlDropIndexString(
+ Dialect dialect,
+ Table table,
+ String name,
+ String defaultCatalog,
+ String defaultSchema
+ ) {
+ return "drop index " +
+ StringHelper.qualify(
+ table.getQualifiedName( dialect, defaultCatalog, defaultSchema ),
+ name
+ );
+ }
+
+ public static String buildSqlCreateIndexString(
+ Dialect dialect,
+ String name,
+ Table table,
+ Iterator columns,
+ boolean unique,
+ String defaultCatalog,
+ String defaultSchema
+ ) {
+ //TODO handle supportsNotNullUnique=false, but such a case does not exist in the wild so far
+ StringBuffer buf = new StringBuffer( "create" )
+ .append( unique ?
+ " unique" :
+ "" )
+ .append( " index " )
+ .append( dialect.qualifyIndexName() ?
+ name :
+ StringHelper.unqualify( name ) )
+ .append( " on " )
+ .append( table.getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
+ .append( " (" );
+ Iterator iter = columns;
+ while ( iter.hasNext() ) {
+ buf.append( ( (Column) iter.next() ).getQuotedName( dialect ) );
+ if ( iter.hasNext() ) buf.append( ", " );
+ }
+ buf.append( ")" );
+ return buf.toString();
+ }
+
+
// Used only in Table for sqlCreateString (but commented out at the moment)
public String sqlConstraintString(Dialect dialect) {
- StringBuffer buf = new StringBuffer(" index (");
+ StringBuffer buf = new StringBuffer( " index (" );
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
- buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
- if ( iter.hasNext() ) buf.append(", ");
+ buf.append( ( (Column) iter.next() ).getQuotedName( dialect ) );
+ if ( iter.hasNext() ) buf.append( ", " );
}
- return buf.append(')').toString();
+ return buf.append( ')' ).toString();
}
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
- return "drop index " +
- StringHelper.qualify(
- table.getQualifiedName(dialect, defaultCatalog, defaultSchema),
+ return "drop index " +
+ StringHelper.qualify(
+ table.getQualifiedName( dialect, defaultCatalog, defaultSchema ),
name
- );
+ );
}
public Table getTable() {
return table;
}
+
public void setTable(Table table) {
this.table = table;
}
+
public int getColumnSpan() {
return columns.size();
}
+
public Iterator getColumnIterator() {
return columns.iterator();
}
+
public void addColumn(Column column) {
- if ( !columns.contains(column) ) columns.add(column);
+ if ( !columns.contains( column ) ) columns.add( column );
}
+
public void addColumns(Iterator extraColumns) {
while ( extraColumns.hasNext() ) addColumn( (Column) extraColumns.next() );
}
+
/**
* @param column
* @return true if this constraint already contains a column with same name.
*/
public boolean containsColumn(Column column) {
- return columns.contains(column);
- }
-
+ return columns.contains( column );
+ }
+
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Table.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Table.java 2006-10-31 02:18:40 UTC (rev 10660)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Table.java 2006-10-31 02:19:13 UTC (rev 10661)
@@ -51,15 +51,15 @@
String referencedClassName;
List columns;
List referencedColumns;
-
+
ForeignKeyKey(List columns, String referencedClassName, List referencedColumns) {
this.referencedClassName = referencedClassName;
this.columns = new ArrayList();
this.columns.addAll( columns );
- if(referencedColumns!=null) {
+ if ( referencedColumns != null ) {
this.referencedColumns = new ArrayList();
- this.referencedColumns.addAll( referencedColumns );
- }
+ this.referencedColumns.addAll( referencedColumns );
+ }
else {
this.referencedColumns = CollectionHelper.EMPTY_LIST;
}
@@ -70,28 +70,33 @@
}
public boolean equals(Object other) {
- ForeignKeyKey fkk = ( ForeignKeyKey ) other;
+ ForeignKeyKey fkk = (ForeignKeyKey) other;
return fkk.columns.equals( columns ) &&
- fkk.referencedClassName.equals( referencedClassName ) && fkk.referencedColumns.equals( referencedColumns );
+ fkk.referencedClassName.equals( referencedClassName ) && fkk.referencedColumns
+ .equals( referencedColumns );
}
}
public Table() {
uniqueInteger = tableCounter++;
}
-
+
public Table(String name) {
this();
- setName(name);
+ setName( name );
}
public String getQualifiedName(Dialect dialect, String defaultCatalog, String defaultSchema) {
if ( subselect != null ) {
return "( " + subselect + " )";
}
- String quotedName = getQuotedName(dialect);
- String usedSchema = schema == null ? defaultSchema : getQuotedSchema(dialect);
- String usedCatalog = catalog == null ? defaultCatalog : catalog;
+ String quotedName = getQuotedName( dialect );
+ String usedSchema = schema == null ?
+ defaultSchema :
+ getQuotedSchema( dialect );
+ String usedCatalog = catalog == null ?
+ defaultCatalog :
+ catalog;
return qualify( usedCatalog, usedSchema, quotedName );
}
@@ -110,32 +115,36 @@
return name;
}
- /** returns quoted name as it would be in the mapping file. */
+ /**
+ * returns quoted name as it would be in the mapping file.
+ */
public String getQuotedName() {
return quoted ?
"`" + name + "`" :
name;
}
-
+
public String getQuotedName(Dialect dialect) {
return quoted ?
dialect.openQuote() + name + dialect.closeQuote() :
name;
}
- /** returns quoted name as it is in the mapping file. */
+ /**
+ * returns quoted name as it is in the mapping file.
+ */
public String getQuotedSchema() {
return schemaQuoted ?
"`" + schema + "`" :
schema;
}
-
+
public String getQuotedSchema(Dialect dialect) {
return schemaQuoted ?
dialect.openQuote() + schema + dialect.closeQuote() :
schema;
}
-
+
public void setName(String name) {
if ( name.charAt( 0 ) == '`' ) {
quoted = true;
@@ -157,7 +166,7 @@
return null;
}
- Column myColumn = ( Column ) columns.get( column.getCanonicalName() );
+ Column myColumn = (Column) columns.get( column.getCanonicalName() );
return column.equals( myColumn ) ?
myColumn :
@@ -169,11 +178,11 @@
for ( int i = 0; i < n - 1; i++ ) {
iter.next();
}
- return ( Column ) iter.next();
+ return (Column) iter.next();
}
public void addColumn(Column column) {
- Column old = ( Column ) getColumn( column );
+ Column old = (Column) getColumn( column );
if ( old == null ) {
columns.put( column.getCanonicalName(), column );
column.uniqueInteger = columns.size();
@@ -202,9 +211,9 @@
public Iterator getUniqueKeyIterator() {
return getUniqueKeys().values().iterator();
}
-
+
Map getUniqueKeys() {
- if ( uniqueKeys.size() > 1) {
+ if ( uniqueKeys.size() > 1 ) {
//deduplicate unique constraints sharing the same columns
//this is needed by Hibernate Annotations since it creates automagically
// unique constraints for the user
@@ -219,12 +228,13 @@
Iterator tempUks = finalUniqueKeys.entrySet().iterator();
while ( tempUks.hasNext() ) {
final UniqueKey currentUk = (UniqueKey) ( (Map.Entry) tempUks.next() ).getValue();
- if ( currentUk.getColumns().containsAll( columns ) && columns.containsAll( currentUk.getColumns() ) ) {
+ if ( currentUk.getColumns().containsAll( columns ) && columns
+ .containsAll( currentUk.getColumns() ) ) {
skip = true;
break;
}
}
- if (! skip) finalUniqueKeys.put(entry.getKey(), uk);
+ if ( !skip ) finalUniqueKeys.put( entry.getKey(), uk );
}
return finalUniqueKeys;
}
@@ -232,11 +242,11 @@
return uniqueKeys;
}
}
-
+
public void validateColumns(Dialect dialect, Mapping mapping, TableMetadata tableInfo) {
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
- Column col = ( Column ) iter.next();
+ Column col = (Column) iter.next();
ColumnMetadata columnInfo = tableInfo.getColumnMetadata( col.getName() );
@@ -244,21 +254,22 @@
throw new HibernateException( "Missing column: " + col.getName() );
}
else {
- final boolean typesMatch = col.getSqlType(dialect, mapping)
+ final boolean typesMatch = col.getSqlType( dialect, mapping )
.startsWith( columnInfo.getTypeName().toLowerCase() )
- || columnInfo.getTypeCode() == col.getSqlTypeCode(mapping);
+ || columnInfo.getTypeCode() == col.getSqlTypeCode( mapping );
if ( !typesMatch ) {
throw new HibernateException(
- "Wrong column type: " + col.getName() +
- ", expected: " + col.getSqlType(dialect, mapping)
- );
+ "Wrong column type: " + col.getName() +
+ ", expected: " + col.getSqlType( dialect, mapping )
+ );
}
}
}
-
+
}
- public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog, String defaultSchema)
+ public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog,
+ String defaultSchema)
throws HibernateException {
StringBuffer root = new StringBuffer( "alter table " )
@@ -269,7 +280,7 @@
Iterator iter = getColumnIterator();
List results = new ArrayList();
while ( iter.hasNext() ) {
- Column column = ( Column ) iter.next();
+ Column column = (Column) iter.next();
ColumnMetadata columnInfo = tableInfo.getColumnMetadata( column.getName() );
@@ -280,27 +291,27 @@
.append( column.getQuotedName( dialect ) )
.append( ' ' )
.append( column.getSqlType( dialect, p ) );
-
+
String defaultValue = column.getDefaultValue();
- if (defaultValue!=null) {
- alter.append( " default ").append(defaultValue);
-
+ if ( defaultValue != null ) {
+ alter.append( " default " ).append( defaultValue );
+
if ( column.isNullable() ) {
alter.append( dialect.getNullColumnString() );
}
else {
alter.append( " not null" );
}
-
+
}
-
- boolean useUniqueConstraint = column.isUnique() &&
- dialect.supportsUnique() &&
+
+ boolean useUniqueConstraint = column.isUnique() &&
+ dialect.supportsUnique() &&
( !column.isNullable() || dialect.supportsNotNullUnique() );
if ( useUniqueConstraint ) {
alter.append( " unique" );
}
-
+
if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
alter.append( " check(" )
.append( column.getCheckConstraint() )
@@ -319,9 +330,9 @@
return results.iterator();
}
-
+
public boolean hasPrimaryKey() {
- return getPrimaryKey()!=null;
+ return getPrimaryKey() != null;
}
public String sqlTemporaryTableCreateString(Dialect dialect, Mapping mapping) throws HibernateException {
@@ -330,8 +341,8 @@
.append( name )
.append( " (" );
Iterator itr = getColumnIterator();
- while( itr.hasNext() ) {
- final Column column = ( Column ) itr.next();
+ while ( itr.hasNext() ) {
+ final Column column = (Column) itr.next();
buffer.append( column.getQuotedName( dialect ) ).append( ' ' );
buffer.append( column.getSqlType( dialect, mapping ) );
if ( column.isNullable() ) {
@@ -352,20 +363,20 @@
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema)
throws HibernateException {
StringBuffer buf = new StringBuffer( "create table " )
- .append( getQualifiedName( dialect , defaultCatalog, defaultSchema ) )
+ .append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
.append( " (" );
- boolean identityColumn = idValue != null && idValue.isIdentityColumn(dialect);
+ boolean identityColumn = idValue != null && idValue.isIdentityColumn( dialect );
// Try to find out the name of the primary key to create it as identity if the IdentityGenerator is used
String pkname = null;
if ( hasPrimaryKey() && identityColumn ) {
- pkname = ( ( Column ) getPrimaryKey().getColumnIterator().next() ).getQuotedName( dialect );
+ pkname = ( (Column) getPrimaryKey().getColumnIterator().next() ).getQuotedName( dialect );
}
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
- Column col = ( Column ) iter.next();
+ Column col = (Column) iter.next();
buf.append( col.getQuotedName( dialect ) )
.append( ' ' );
@@ -383,20 +394,20 @@
buf.append( col.getSqlType( dialect, p ) );
String defaultValue = col.getDefaultValue();
- if (defaultValue!=null) {
- buf.append( " default ").append(defaultValue);
+ if ( defaultValue != null ) {
+ buf.append( " default " ).append( defaultValue );
}
-
+
if ( col.isNullable() ) {
buf.append( dialect.getNullColumnString() );
}
else {
buf.append( " not null" );
}
-
+
}
- boolean useUniqueConstraint = col.isUnique() &&
+ boolean useUniqueConstraint = col.isUnique() &&
( !col.isNullable() || dialect.supportsNotNullUnique() );
if ( useUniqueConstraint ) {
if ( dialect.supportsUnique() ) {
@@ -407,16 +418,16 @@
uk.addColumn( col );
}
}
-
+
if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
buf.append( " check (" )
.append( col.getCheckConstraint() )
.append( ")" );
}
-
+
String columnComment = col.getComment();
- if (columnComment!=null) {
- buf.append( dialect.getColumnComment(columnComment) );
+ if ( columnComment != null ) {
+ buf.append( dialect.getColumnComment( columnComment ) );
}
if ( iter.hasNext() ) {
@@ -426,15 +437,17 @@
}
if ( hasPrimaryKey() ) {
buf.append( ", " )
- .append( getPrimaryKey().sqlConstraintString( dialect ) );
+ .append( getPrimaryKey().sqlConstraintString( dialect ) );
}
if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
Iterator ukiter = getUniqueKeyIterator();
while ( ukiter.hasNext() ) {
- UniqueKey uk = ( UniqueKey ) ukiter.next();
- buf.append( ", " )
- .append( uk.sqlConstraintString( dialect ) );
+ UniqueKey uk = (UniqueKey) ukiter.next();
+ String constraint = uk.sqlConstraintString( dialect );
+ if ( constraint != null ) {
+ buf.append( ", " ).append( constraint );
+ }
}
}
/*Iterator idxiter = getIndexIterator();
@@ -447,17 +460,17 @@
Iterator chiter = checkConstraints.iterator();
while ( chiter.hasNext() ) {
buf.append( ", check (" )
- .append( chiter.next() )
- .append( ')' );
+ .append( chiter.next() )
+ .append( ')' );
}
}
-
+
buf.append( ')' );
if ( comment != null ) {
buf.append( dialect.getTableComment( comment ) );
}
-
+
return buf.append( dialect.getTableTypeString() ).toString();
}
@@ -466,7 +479,7 @@
if ( dialect.supportsIfExistsBeforeTableName() ) {
buf.append( "if exists " );
}
- buf.append( getQualifiedName( dialect , defaultCatalog, defaultSchema ) )
+ buf.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
.append( dialect.getCascadeConstraintsString() );
if ( dialect.supportsIfExistsAfterTableName() ) {
buf.append( " if exists" );
@@ -483,9 +496,9 @@
}
public Index getOrCreateIndex(String indexName) {
-
- Index index = ( Index ) indexes.get( indexName );
+ Index index = (Index) indexes.get( indexName );
+
if ( index == null ) {
index = new Index();
index.setName( indexName );
@@ -497,11 +510,11 @@
}
public Index getIndex(String indexName) {
- return ( Index ) indexes.get( indexName );
+ return (Index) indexes.get( indexName );
}
public Index addIndex(Index index) {
- Index current = ( Index ) indexes.get( index.getName() );
+ Index current = (Index) indexes.get( index.getName() );
if ( current != null ) {
throw new MappingException( "Index " + index.getName() + " already exists!" );
}
@@ -510,7 +523,7 @@
}
public UniqueKey addUniqueKey(UniqueKey uniqueKey) {
- UniqueKey current = ( UniqueKey ) uniqueKeys.get( uniqueKey.getName() );
+ UniqueKey current = (UniqueKey) uniqueKeys.get( uniqueKey.getName() );
if ( current != null ) {
throw new MappingException( "UniqueKey " + uniqueKey.getName() + " already exists!" );
}
@@ -528,9 +541,9 @@
public UniqueKey getUniqueKey(String keyName) {
return (UniqueKey) uniqueKeys.get( keyName );
}
-
+
public UniqueKey getOrCreateUniqueKey(String keyName) {
- UniqueKey uk = ( UniqueKey ) uniqueKeys.get( keyName );
+ UniqueKey uk = (UniqueKey) uniqueKeys.get( keyName );
if ( uk == null ) {
uk = new UniqueKey();
@@ -545,20 +558,21 @@
}
public ForeignKey createForeignKey(String keyName, List keyColumns, String referencedEntityName) {
- return createForeignKey(keyName, keyColumns, referencedEntityName, null);
+ return createForeignKey( keyName, keyColumns, referencedEntityName, null );
}
-
- public ForeignKey createForeignKey(String keyName, List keyColumns, String referencedEntityName, List referencedColumns) {
+
+ public ForeignKey createForeignKey(String keyName, List keyColumns, String referencedEntityName,
+ List referencedColumns) {
Object key = new ForeignKeyKey( keyColumns, referencedEntityName, referencedColumns );
- ForeignKey fk = ( ForeignKey ) foreignKeys.get( key );
+ ForeignKey fk = (ForeignKey) foreignKeys.get( key );
if ( fk == null ) {
fk = new ForeignKey();
if ( keyName != null ) {
fk.setName( keyName );
}
else {
- fk.setName( "FK" + uniqueColumnString( keyColumns.iterator(), referencedEntityName ) );
+ fk.setName( "FK" + uniqueColumnString( keyColumns.iterator(), referencedEntityName ) );
//TODO: add referencedClass to disambiguate to FKs on the same
// columns, pointing to different tables
}
@@ -575,11 +589,12 @@
fk.setName( keyName );
}
- return fk; }
+ return fk;
+ }
-
+
public String uniqueColumnString(Iterator iterator) {
- return uniqueColumnString(iterator, null);
+ return uniqueColumnString( iterator, null );
}
public String uniqueColumnString(Iterator iterator, String referencedEntityName) {
@@ -599,7 +614,7 @@
}
public void setSchema(String schema) {
- if ( schema!=null && schema.charAt( 0 ) == '`' ) {
+ if ( schema != null && schema.charAt( 0 ) == '`' ) {
schemaQuoted = true;
this.schema = schema.substring( 1, schema.length() - 1 );
}
@@ -631,7 +646,7 @@
public boolean isSchemaQuoted() {
return schemaQuoted;
}
-
+
public boolean isQuoted() {
return quoted;
}
@@ -658,14 +673,14 @@
public String toString() {
StringBuffer buf = new StringBuffer().append( getClass().getName() )
- .append('(');
+ .append( '(' );
if ( getCatalog() != null ) {
buf.append( getCatalog() + "." );
}
if ( getSchema() != null ) {
buf.append( getSchema() + "." );
}
- buf.append( getName() ).append(')');
+ buf.append( getName() ).append( ')' );
return buf.toString();
}
@@ -684,11 +699,11 @@
public boolean isAbstractUnionTable() {
return hasDenormalizedTables() && isAbstract;
}
-
+
public boolean hasDenormalizedTables() {
return hasDenormalizedTables;
}
-
+
void setHasDenormalizedTables() {
hasDenormalizedTables = true;
}
@@ -720,29 +735,29 @@
public Iterator sqlCommentStrings(Dialect dialect, String defaultCatalog, String defaultSchema) {
List comments = new ArrayList();
if ( dialect.supportsCommentOn() ) {
- String tableName = getQualifiedName( dialect , defaultCatalog, defaultSchema );
- if ( comment!=null ) {
+ String tableName = getQualifiedName( dialect, defaultCatalog, defaultSchema );
+ if ( comment != null ) {
StringBuffer buf = new StringBuffer()
- .append("comment on table ")
- .append( tableName )
- .append(" is '")
- .append(comment)
- .append("'");
+ .append( "comment on table " )
+ .append( tableName )
+ .append( " is '" )
+ .append( comment )
+ .append( "'" );
comments.add( buf.toString() );
}
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
Column column = (Column) iter.next();
String columnComment = column.getComment();
- if ( columnComment!=null ) {
+ if ( columnComment != null ) {
StringBuffer buf = new StringBuffer()
- .append("comment on column ")
- .append( tableName )
- .append('.')
- .append( column.getQuotedName(dialect) )
- .append(" is '")
- .append(columnComment)
- .append("'");
+ .append( "comment on column " )
+ .append( tableName )
+ .append( '.' )
+ .append( column.getQuotedName( dialect ) )
+ .append( " is '" )
+ .append( columnComment )
+ .append( "'" );
comments.add( buf.toString() );
}
}
Modified: trunk/Hibernate3/src/org/hibernate/mapping/UniqueKey.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/UniqueKey.java 2006-10-31 02:18:40 UTC (rev 10660)
+++ trunk/Hibernate3/src/org/hibernate/mapping/UniqueKey.java 2006-10-31 02:19:13 UTC (rev 10661)
@@ -9,48 +9,74 @@
/**
* A relational unique key constraint
+ *
* @author Gavin King
*/
public class UniqueKey extends Constraint {
public String sqlConstraintString(Dialect dialect) {
- StringBuffer buf = new StringBuffer("unique (");
+ StringBuffer buf = new StringBuffer( "unique (" );
Iterator iter = getColumnIterator();
+ boolean nullable = false;
while ( iter.hasNext() ) {
- buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
- if ( iter.hasNext() ) buf.append(", ");
+ Column column = (Column) iter.next();
+ if ( !nullable && column.isNullable() ) nullable = true;
+ buf.append( column.getQuotedName( dialect ) );
+ if ( iter.hasNext() ) buf.append( ", " );
}
- return buf.append(')').toString();
+ //do not add unique constraint on DB not supporting unique and nullable columns
+ return !nullable || dialect.supportsNotNullUnique() ?
+ buf.append( ')' ).toString() :
+ null;
}
- public String sqlConstraintString(Dialect dialect, String constraintName, String defaultCatalog, String defaultSchema) {
+ public String sqlConstraintString(Dialect dialect, String constraintName, String defaultCatalog,
+ String defaultSchema) {
StringBuffer buf = new StringBuffer(
- dialect.getAddPrimaryKeyConstraintString(constraintName)
- ).append('(');
+ dialect.getAddPrimaryKeyConstraintString( constraintName )
+ ).append( '(' );
Iterator iter = getColumnIterator();
+ boolean nullable = false;
while ( iter.hasNext() ) {
- buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
- if ( iter.hasNext() ) buf.append(", ");
+ Column column = (Column) iter.next();
+ if ( !nullable && column.isNullable() ) nullable = true;
+ buf.append( column.getQuotedName( dialect ) );
+ if ( iter.hasNext() ) buf.append( ", " );
}
- return StringHelper.replace( buf.append(')').toString(), "primary key", "unique" ); //TODO: improve this hack!
+ return !nullable || dialect.supportsNotNullUnique() ?
+ StringHelper.replace( buf.append( ')' ).toString(), "primary key", "unique" ) :
+ //TODO: improve this hack!
+ null;
}
-
+
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
- if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
- return super.sqlCreateString(dialect, p, defaultCatalog, defaultSchema);
- }
- else {
- return Index.buildSqlCreateIndexString(dialect, getName(), getTable(), getColumnIterator(), true, defaultCatalog, defaultSchema);
- }
- }
-
- public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
- if( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
- return super.sqlDropString(dialect, defaultCatalog, defaultSchema);
- }
- else {
- return Index.buildSqlDropIndexString(dialect, getTable(), getName(), defaultCatalog, defaultSchema);
- }
- }
-
+ if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
+ return super.sqlCreateString( dialect, p, defaultCatalog, defaultSchema );
+ }
+ else {
+ return Index.buildSqlCreateIndexString( dialect, getName(), getTable(), getColumnIterator(), true,
+ defaultCatalog, defaultSchema );
+ }
+ }
+
+ public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
+ if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
+ return super.sqlDropString( dialect, defaultCatalog, defaultSchema );
+ }
+ else {
+ return Index.buildSqlDropIndexString( dialect, getTable(), getName(), defaultCatalog, defaultSchema );
+ }
+ }
+
+ public boolean isGenerated(Dialect dialect) {
+ if ( dialect.supportsNotNullUnique() ) return true;
+ Iterator iter = getColumnIterator();
+ while ( iter.hasNext() ) {
+ if ( ( (Column) iter.next() ).isNullable() ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
}
18 years, 1 month