Hibernate SVN: r10771 - in branches/Branch_3_2/HibernateExt/tools: lib lib/testlibs src/java/org/hibernate/tool/ant src/java/org/hibernate/tool/ide/formatting src/test/org/hibernate/tool/ant src/testsupport src/testsupport/formatting
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-08 07:00:28 -0500 (Wed, 08 Nov 2006)
New Revision: 10771
Added:
branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.core.runtime_3.2.0.v20060603.jar
branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.equinox.common_3.2.0.v20060603.jar
branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.jdt.core_3.2.0.v_671.jar
branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.text_3.2.0.v20060605-1400.jar
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JavaFormatterTask.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/formatting/JavaFormatter.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java
branches/Branch_3_2/HibernateExt/tools/src/testsupport/emptyconfig.properties
branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/Simple5One.java
branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/SimpleOne.java
branches/Branch_3_2/HibernateExt/tools/src/testsupport/javaformattest-build.xml
Removed:
branches/Branch_3_2/HibernateExt/tools/lib/testlibs/org.eclipse.jdt.core_3.1.0.jar
Log:
HBX-811 eclipse code formatter ant task
Added: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.core.runtime_3.2.0.v20060603.jar
===================================================================
(Binary files differ)
Property changes on: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.core.runtime_3.2.0.v20060603.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.equinox.common_3.2.0.v20060603.jar
===================================================================
(Binary files differ)
Property changes on: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.equinox.common_3.2.0.v20060603.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.jdt.core_3.2.0.v_671.jar
===================================================================
(Binary files differ)
Property changes on: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.jdt.core_3.2.0.v_671.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.text_3.2.0.v20060605-1400.jar
===================================================================
(Binary files differ)
Property changes on: branches/Branch_3_2/HibernateExt/tools/lib/org.eclipse.text_3.2.0.v20060605-1400.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: branches/Branch_3_2/HibernateExt/tools/lib/testlibs/org.eclipse.jdt.core_3.1.0.jar
===================================================================
(Binary files differ)
Added: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JavaFormatterTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JavaFormatterTask.java 2006-11-08 12:00:23 UTC (rev 10770)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JavaFormatterTask.java 2006-11-08 12:00:28 UTC (rev 10771)
@@ -0,0 +1,119 @@
+package org.hibernate.tool.ant;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+
+import org.eclipse.jdt.internal.core.util.Util;
+import org.hibernate.tool.hbm2x.ExporterException;
+import org.hibernate.tool.ide.formatting.JavaFormatter;
+
+public class JavaFormatterTask extends Task {
+
+ private List fileSets = new ArrayList();
+ private boolean failOnError;
+ private File configurationFile;
+
+ public void addConfiguredFileSet(FileSet fileSet) {
+ fileSets.add(fileSet);
+ }
+
+ public void setConfigurationFile(File configurationFile) {
+ this.configurationFile = configurationFile;
+ }
+
+ private Properties readConfig(File cfgfile) throws IOException {
+ BufferedInputStream stream = null;
+ try {
+ stream = new BufferedInputStream(new FileInputStream(cfgfile));
+ final Properties settings = new Properties();
+ settings.load(stream);
+ return settings;
+ } catch (IOException e) {
+ throw e;
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+
+ }
+ }
+ }
+ }
+
+
+ public void execute() throws BuildException {
+
+ Map settings = null;
+ if(configurationFile!=null) {
+ try {
+ settings = readConfig( configurationFile );
+ }
+ catch (IOException e) {
+ throw new BuildException("Could not read configurationfile " + configurationFile, e);
+ }
+ }
+
+ File[] files = getFiles();
+
+ if(files.length>0) {
+
+ JavaFormatter formatter = new JavaFormatter(settings);
+
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+ getProject().log(this, "Formatting " + file, Project.MSG_INFO);
+ try {
+ boolean ok = formatter.formatFile( file );
+ if(!ok) {
+ getProject().log(this, "Formatting failed - skipping " + file, Project.MSG_WARN);
+ }
+ } catch(ExporterException ee) {
+ if(failOnError) {
+ throw new BuildException("Formatting failed on " + file, ee);
+ } else {
+ getProject().log(this, "Formatting failed on " + file + ", " + ee.getLocalizedMessage(), Project.MSG_ERR);
+ }
+ }
+ }
+ }
+
+ }
+
+ private File[] getFiles() {
+
+ List files = new LinkedList();
+ for ( Iterator i = fileSets.iterator(); i.hasNext(); ) {
+
+ FileSet fs = (FileSet) i.next();
+ DirectoryScanner ds = fs.getDirectoryScanner( getProject() );
+
+ String[] dsFiles = ds.getIncludedFiles();
+ for (int j = 0; j < dsFiles.length; j++) {
+ File f = new File(dsFiles[j]);
+ if ( !f.isFile() ) {
+ f = new File( ds.getBasedir(), dsFiles[j] );
+ }
+
+ files.add( f );
+ }
+ }
+
+ return (File[]) files.toArray(new File[files.size()]);
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/formatting/JavaFormatter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/formatting/JavaFormatter.java 2006-11-08 12:00:23 UTC (rev 10770)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/formatting/JavaFormatter.java 2006-11-08 12:00:28 UTC (rev 10771)
@@ -0,0 +1,90 @@
+package org.hibernate.tool.ide.formatting;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.formatter.CodeFormatter;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.text.edits.TextEdit;
+import org.hibernate.tool.hbm2x.ExporterException;
+
+
+public class JavaFormatter {
+
+ private CodeFormatter codeFormatter;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ //DefaultCodeFormatter.USE_NEW_FORMATTER = true;
+ HashMap hashMap = new HashMap();
+ hashMap.put( JavaCore.COMPILER_SOURCE, "1.5");
+ hashMap.put( JavaCore.COMPILER_COMPLIANCE, "1.5");
+ hashMap.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.5");
+ final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(hashMap);
+
+ //new JavaFormatter().formatFile(new File("c:/temp/SomeJava.java"), codeFormatter);
+
+ }
+
+ public JavaFormatter(Map settings) {
+ if(settings==null) {
+ // if no settings run with jdk 5 as default
+ settings = new HashMap();
+ settings.put( JavaCore.COMPILER_SOURCE, "1.5");
+ settings.put( JavaCore.COMPILER_COMPLIANCE, "1.5");
+ settings.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.5");
+ }
+
+ this.codeFormatter = ToolFactory.createCodeFormatter(settings);
+ }
+
+ /**
+ * Throws exception if not possible to read or write the file.
+ * Returns true if formatting went ok; returns false if the formatting could not finish because of errors in the input.
+ *
+ * @param file
+ * @param codeFormatter
+ * @return
+ */
+ public boolean formatFile(File file) throws ExporterException {
+ IDocument doc = new Document();
+ try {
+ String contents = new String(org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(file, null));
+ doc.set(contents);
+ TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, null);
+ if (edit != null) {
+ edit.apply(doc);
+ } else {
+ return false; // most likely syntax errror
+ }
+
+ // write the file
+ final BufferedWriter out = new BufferedWriter(new FileWriter(file));
+ try {
+ out.write(doc.get());
+ out.flush();
+ } finally {
+ try {
+ out.close();
+ } catch (IOException e) {
+ /* ignore */
+ }
+ }
+ return true;
+ } catch (IOException e) {
+ throw new ExporterException("Could not format " + file, e);
+ } catch (BadLocationException e) {
+ throw new ExporterException("Could not format " + file, e);
+ }
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java 2006-11-08 12:00:23 UTC (rev 10770)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java 2006-11-08 12:00:28 UTC (rev 10771)
@@ -0,0 +1,115 @@
+/*
+ * Created on 13-Feb-2005
+ *
+ */
+package org.hibernate.tool.ant;
+
+import java.io.File;
+import java.util.HashMap;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.formatter.CodeFormatter;
+import org.hibernate.tool.ide.formatting.JavaFormatter;
+
+/**
+ * @author max
+ *
+ */
+public class JavaFormatterTest extends BuildFileTestCase {
+
+
+
+ public JavaFormatterTest(String name) {
+ super(name);
+ }
+
+ protected void tearDown() throws Exception {
+ executeTarget( "cleanup" );
+ System.out.println(getLog());
+ super.tearDown();
+ }
+ protected void setUp() throws Exception {
+ configureProject("src/testsupport/javaformattest-build.xml");
+ }
+
+ public void testJava() {
+
+ executeTarget("prepare");
+
+ File file = new File(project.getProperty( "build.dir" ), "formatting/SimpleOne.java");
+ assertFileAndExists( file );
+ long before = file.lastModified();
+
+ JavaFormatter formatter = new JavaFormatter(null);
+ formatter.formatFile( file );
+
+ assertTrue( before!=file.lastModified() );
+
+ }
+
+ public void testJavaJdk5() {
+
+ executeTarget("prepare");
+
+ File file = new File(project.getProperty( "build.dir" ), "formatting/Simple5One.java");
+ assertFileAndExists( file );
+ long before = file.lastModified();
+
+ JavaFormatter formatter = new JavaFormatter(new HashMap());
+ assertFalse("formatting should fail when using zero settings", formatter.formatFile( file ));
+
+ assertTrue( before==file.lastModified() );
+
+ executeTarget("prepare");
+ formatter = new JavaFormatter(null);
+ assertTrue("formatting should pass when using default settings", formatter.formatFile( file ));
+
+ assertTrue( before<file.lastModified() );
+ }
+ public void testAntxDestDir() {
+
+ executeTarget("prepare");
+
+ File file = new File(project.getProperty( "build.dir" ), "formatting/SimpleOne.java");
+ assertFileAndExists( file );
+ long before = file.lastModified();
+ executeTarget("fileset");
+ System.out.println(getLog());
+ assertTrue( before!=file.lastModified() );
+
+
+ }
+
+ public void testConfig() {
+
+ executeTarget("prepare");
+
+ File jdk5file = new File(project.getProperty( "build.dir" ), "formatting/Simple5One.java");
+ File jdkfile = new File(project.getProperty( "build.dir" ), "formatting/SimpleOne.java");
+ assertFileAndExists( jdkfile );
+ long jdk5before = jdk5file.lastModified();
+ long before = jdkfile.lastModified();
+
+ executeTarget("configtest");
+ System.out.println(getLog());
+ assertEquals("jdk5 should fail since config is not specifying jdk5",jdk5before, jdk5file.lastModified() );
+ assertTrue(before<jdkfile.lastModified());
+
+ executeTarget("noconfigtest");
+ System.out.println(getLog());
+ assertTrue(jdk5before<jdk5file.lastModified() );
+ assertTrue(before<jdk5file.lastModified());
+
+
+ }
+
+
+ public static Test suite() {
+ return new TestSuite(JavaFormatterTest.class);
+ }
+
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/testsupport/emptyconfig.properties
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/emptyconfig.properties 2006-11-08 12:00:23 UTC (rev 10770)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/emptyconfig.properties 2006-11-08 12:00:28 UTC (rev 10771)
@@ -0,0 +1 @@
+## this file is intentionally left blank
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/Simple5One.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/Simple5One.java 2006-11-08 12:00:23 UTC (rev 10770)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/Simple5One.java 2006-11-08 12:00:28 UTC (rev 10771)
@@ -0,0 +1,9 @@
+package formatting;
+
+@Override // intentional that his will give compile error.
+public
+ class
+ Simple5One {
+
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/SimpleOne.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/SimpleOne.java 2006-11-08 12:00:23 UTC (rev 10770)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/formatting/SimpleOne.java 2006-11-08 12:00:28 UTC (rev 10771)
@@ -0,0 +1,8 @@
+package formatting;
+
+public
+ class
+ SimpleOne {
+
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/testsupport/javaformattest-build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/javaformattest-build.xml 2006-11-08 12:00:23 UTC (rev 10770)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/javaformattest-build.xml 2006-11-08 12:00:28 UTC (rev 10771)
@@ -0,0 +1,68 @@
+<project name="javaformattest">
+ <property name="hibernate-core.jar" location="../../../../hibernate-3.1/hibernate3.jar" />
+ <property name="hibernate-core.home" location="../../../../hibernate3" />
+ <property name="hibernate-core.lib.dir" location="${hibernate-core.home}/lib" />
+ <property name="build.dir" location="../../build/javaformattest" />
+ <property file="../../etc/hibernate.properties" />
+
+
+
+ <path id="tasks.classpath">
+ <pathelement path="../../build/eclipse" />
+ <pathelement path="../../build/classes" />
+
+ <fileset dir="${hibernate-core.lib.dir}">
+ <include name="**/*.jar" />
+ </fileset>
+
+ <pathelement location="${hibernate-core.jar}" />
+ <pathelement path="../../lib/freemarker.jar" />
+
+ <fileset dir="../../lib">
+ <include name="**/*eclipse*.jar" />
+ </fileset>
+ <pathelement path="${hibernate-core.home}\jdbc\hsqldb.jar" />
+ </path>
+
+ <target name="cleanup">
+ <delete dir="${build.dir}"/>
+ </target>
+
+ <target name="prepare">
+ <copy todir="${build.dir}">
+ <fileset dir="." includes="formatting/**/*.java"/>
+ </copy>
+ </target>
+
+ <target name="fileset">
+ <taskdef name="javaformatter" classname="org.hibernate.tool.ant.JavaFormatterTask" classpathref="tasks.classpath"/>
+
+ <javaformatter> <!-- config, failonerror, destdir -->
+ <fileset dir="${build.dir}">
+ <include name="formatting/**/*.java"/>
+ </fileset>
+ </javaformatter>
+ </target>
+
+ <target name="configtest">
+ <taskdef name="javaformatter" classname="org.hibernate.tool.ant.JavaFormatterTask" classpathref="tasks.classpath"/>
+
+ <javaformatter configurationfile="emptyconfig.properties"> <!-- config, failonerror, destdir -->
+ <fileset dir="${build.dir}">
+ <include name="formatting/**/*.java"/>
+ </fileset>
+ </javaformatter>
+ </target>
+
+ <target name="noconfigtest">
+ <taskdef name="javaformatter" classname="org.hibernate.tool.ant.JavaFormatterTask" classpathref="tasks.classpath"/>
+
+ <javaformatter> <!-- config, failonerror, destdir -->
+ <fileset dir="${build.dir}">
+ <include name="formatting/**/*.java"/>
+ </fileset>
+ </javaformatter>
+ </target>
+
+
+</project>
18 years, 2 months
Hibernate SVN: r10769 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-08 06:58:44 -0500 (Wed, 08 Nov 2006)
New Revision: 10769
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java
Log:
move methods up
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java 2006-11-08 11:58:22 UTC (rev 10768)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java 2006-11-08 11:58:44 UTC (rev 10769)
@@ -48,7 +48,11 @@
}
- static protected void assertFileAndExists(File file) {
+ protected String findFirstString(String string, File file) {
+ return TestHelper.findFirstString(string, file);
+ }
+
+ protected void assertFileAndExists(File file) {
assertTrue(file + " does not exist", file.exists() );
assertTrue(file + " not a file", file.isFile() );
assertTrue(file + " does not have any contents", file.length()>0);
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2006-11-08 11:58:22 UTC (rev 10768)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2006-11-08 11:58:44 UTC (rev 10769)
@@ -176,9 +176,6 @@
return cfg;
}
- protected String findFirstString(String string, File file) {
- return TestHelper.findFirstString(string, file);
- }
public Configuration getConfiguration() {
return getCfg();
18 years, 2 months
Hibernate SVN: r10768 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-08 06:58:22 -0500 (Wed, 08 Nov 2006)
New Revision: 10768
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
Log:
HBX-810 Remove redundant generation of @Column default values in annotation codegen
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java 2006-11-08 06:55:52 UTC (rev 10767)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java 2006-11-08 11:58:22 UTC (rev 10768)
@@ -413,21 +413,8 @@
Column column = (Column) selectable;
annotations.append( "@" + importType("javax.persistence.Column") + "(name=\"" ).append( column.getName() ).append( "\"" );
- if(column.isUnique()) {
- annotations.append( ", unique=" ).append( column.isUnique() );
- }
- if(!column.isNullable()) {
- annotations.append( ", nullable=" ).append( column.isNullable() );
- }
+ appendCommonColumnInfo( annotations, column, insertable, updatable );
- if(!insertable) {
- annotations.append( ", insertable=" ).append( insertable );
- }
-
- if(!updatable) {
- annotations.append( ", updatable=" ).append( updatable );
- }
-
if (column.getPrecision() != Column.DEFAULT_PRECISION) {
annotations.append( ", precision=" ).append( column.getPrecision() );
}
@@ -440,16 +427,36 @@
- String sqlType = column.getSqlType();
- if ( StringHelper.isNotEmpty( sqlType ) ) {
- annotations.append( ", columnDefinition=\"" ).append( sqlType ).append( "\"" );
- }
+
//TODO support secondary table
annotations.append( ")" );
}
}
+ protected void appendCommonColumnInfo(StringBuffer annotations, Column column, boolean insertable, boolean updatable) {
+ if(column.isUnique()) {
+ annotations.append( ", unique=" ).append( column.isUnique() );
+ }
+ if(!column.isNullable()) {
+ annotations.append( ", nullable=" ).append( column.isNullable() );
+ }
+
+ if(!insertable) {
+ annotations.append( ", insertable=" ).append( insertable );
+ }
+
+ if(!updatable) {
+ annotations.append( ", updatable=" ).append( updatable );
+ }
+
+ String sqlType = column.getSqlType();
+ if ( StringHelper.isNotEmpty( sqlType ) ) {
+ annotations.append( ", columnDefinition=\"" ).append( sqlType ).append( "\"" );
+ }
+
+ }
+
public Iterator getToStringPropertiesIterator() {
Iterator iter = getAllPropertiesIterator();
return getToStringPropertiesIterator( iter );
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-11-08 06:55:52 UTC (rev 10767)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2006-11-08 11:58:22 UTC (rev 10768)
@@ -376,17 +376,10 @@
else {
Column column = (Column) selectable;
annotations.append("@").append( importType("javax.persistence.JoinColumn") )
- .append("(name=\"" ).append( column.getName() ).append( "\"" )
+ .append("(name=\"" ).append( column.getName() ).append( "\"" );
//TODO handle referenced column name, this is a hard one
//.append(", referencedColumnName=")
- .append( ", unique=" ).append( column.isUnique() )
- .append( ", nullable=" ).append( column.isNullable() )
- .append( ", insertable=" ).append( insertable )
- .append( ", updatable=" ).append( updatable );
- String sqlType = column.getSqlType();
- if ( StringHelper.isNotEmpty( sqlType ) ) {
- annotations.append( ", columnDefinition=\"" ).append( sqlType ).append( "\"" );
- }
+ appendCommonColumnInfo(annotations, column, insertable, updatable);
//TODO support secondary table
annotations.append( ")" );
}
18 years, 2 months
Hibernate SVN: r10767 - in branches/Lucene_Integration/HibernateExt/metadata/src: java/org/hibernate/search/annotations java/org/hibernate/search/bridge java/org/hibernate/search/bridge/builtin java/org/hibernate/search/engine test/org/hibernate/search/test/bridge
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-11-08 01:55:52 -0500 (Wed, 08 Nov 2006)
New Revision: 10767
Added:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/annotations/Resolution.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayFieldBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayString2FieldBridgeAdaptor.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/BigDecimalBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/BigIntegerBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/DateBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/DoubleBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/FloatBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/IntegerBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/LongBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/NumberBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/ShortBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/StringBridge.java
Removed:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigDecimalBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigIntegerBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DateBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DoubleBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/FloatBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IdFieldBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IntegerBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/LongBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/NumberBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/Resolution.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2IdFieldBridgeAdaptor.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringImplBridge.java
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/annotations/DateBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BridgeFactory.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/Cloud.java
Log:
rename to @DateField.resolution
move Resolution into annotations
move built-in bridge into bridge.builtin
clean separation between OneWay and TwoWay bridges
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/annotations/DateBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/annotations/DateBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/annotations/DateBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -7,7 +7,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.hibernate.search.bridge.Resolution;
+import org.hibernate.search.annotations.Resolution;
/**
* Defines the temporal resolution of a given field
@@ -19,6 +19,7 @@
@Target( {ElementType.FIELD, ElementType.METHOD} )
@Documented
//TODO allow pattern like yyyyMMdd?
+//TODO allow base timezone?
public @interface DateBridge {
- Resolution value();
+ Resolution resolution();
}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/annotations/Resolution.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/Resolution.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/Resolution.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/annotations/Resolution.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,17 @@
+//$Id: $
+package org.hibernate.search.annotations;
+
+/**
+ * Date indexing resolution
+ *
+ * @author Emmanuel Bernard
+ */
+public enum Resolution {
+ YEAR,
+ MONTH,
+ DAY,
+ HOUR,
+ MINUTE,
+ SECOND,
+ MILLISECOND
+}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigDecimalBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigDecimalBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigDecimalBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,18 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import java.math.BigDecimal;
-
-import org.hibernate.util.StringHelper;
-
-/**
- * Map a BigDecimal element
- *
- * @author Emmanuel Bernard
- */
-public class BigDecimalBridge extends NumberBridge {
- public Object stringToObject(String stringValue) {
- if ( StringHelper.isEmpty( stringValue ) ) return null;
- return new BigDecimal( stringValue );
- }
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigIntegerBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigIntegerBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigIntegerBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,18 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import java.math.BigInteger;
-
-import org.hibernate.util.StringHelper;
-
-/**
- * Map a BigInteger element
- *
- * @author Emmanuel Bernard
- */
-public class BigIntegerBridge extends NumberBridge {
- public Object stringToObject(String stringValue) {
- if ( StringHelper.isEmpty( stringValue ) ) return null;
- return new BigInteger( stringValue );
- }
-}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BridgeFactory.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BridgeFactory.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BridgeFactory.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -8,6 +8,17 @@
import java.util.Map;
import org.hibernate.HibernateException;
+import org.hibernate.AssertionFailure;
+import org.hibernate.search.bridge.builtin.DateBridge;
+import org.hibernate.search.bridge.builtin.FloatBridge;
+import org.hibernate.search.bridge.builtin.LongBridge;
+import org.hibernate.search.bridge.builtin.BigIntegerBridge;
+import org.hibernate.search.bridge.builtin.StringBridge;
+import org.hibernate.search.bridge.builtin.IntegerBridge;
+import org.hibernate.search.bridge.builtin.BigDecimalBridge;
+import org.hibernate.search.bridge.builtin.DoubleBridge;
+import org.hibernate.search.bridge.builtin.ShortBridge;
+import org.hibernate.search.annotations.Resolution;
import org.hibernate.annotations.Parameter;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XMember;
@@ -21,33 +32,37 @@
private BridgeFactory() {
}
- public static final IdFieldBridge DOUBLE = new String2IdFieldBridgeAdaptor( new DoubleBridge() );
+ public static final TwoWayFieldBridge DOUBLE = new TwoWayString2FieldBridgeAdaptor( new DoubleBridge() );
- public static final IdFieldBridge FLOAT = new String2IdFieldBridgeAdaptor( new FloatBridge() );
+ public static final TwoWayFieldBridge FLOAT = new TwoWayString2FieldBridgeAdaptor( new FloatBridge() );
- public static final IdFieldBridge INTEGER = new String2IdFieldBridgeAdaptor( new IntegerBridge() );
+ public static final TwoWayFieldBridge SHORT = new TwoWayString2FieldBridgeAdaptor( new ShortBridge() );
- public static final IdFieldBridge LONG = new String2IdFieldBridgeAdaptor( new LongBridge() );
+ public static final TwoWayFieldBridge INTEGER = new TwoWayString2FieldBridgeAdaptor( new IntegerBridge() );
- public static final IdFieldBridge BIG_INTEGER = new String2IdFieldBridgeAdaptor( new BigIntegerBridge() );
+ public static final TwoWayFieldBridge LONG = new TwoWayString2FieldBridgeAdaptor( new LongBridge() );
- public static final IdFieldBridge BIG_DECIMAL = new String2IdFieldBridgeAdaptor( new BigDecimalBridge() );
+ public static final TwoWayFieldBridge BIG_INTEGER = new TwoWayString2FieldBridgeAdaptor( new BigIntegerBridge() );
- public static final IdFieldBridge STRING = new String2IdFieldBridgeAdaptor( new StringImplBridge() );
+ public static final TwoWayFieldBridge BIG_DECIMAL = new TwoWayString2FieldBridgeAdaptor( new BigDecimalBridge() );
- public static final FieldBridge DATE_YEAR;
- public static final FieldBridge DATE_MONTH;
- public static final FieldBridge DATE_DAY;
- public static final FieldBridge DATE_HOUR;
- public static final FieldBridge DATE_MINUTE;
- public static final FieldBridge DATE_SECOND;
- public static final IdFieldBridge DATE_MILLISECOND;
+ public static final TwoWayFieldBridge STRING = new TwoWayString2FieldBridgeAdaptor( new StringBridge() );
+ public static final FieldBridge DATE_YEAR = new String2FieldBridgeAdaptor( DateBridge.DATE_YEAR );
+ public static final FieldBridge DATE_MONTH = new String2FieldBridgeAdaptor( DateBridge.DATE_MONTH );
+ public static final FieldBridge DATE_DAY = new String2FieldBridgeAdaptor( DateBridge.DATE_DAY );
+ public static final FieldBridge DATE_HOUR = new String2FieldBridgeAdaptor( DateBridge.DATE_HOUR );
+ public static final FieldBridge DATE_MINUTE = new String2FieldBridgeAdaptor( DateBridge.DATE_MINUTE );
+ public static final FieldBridge DATE_SECOND = new String2FieldBridgeAdaptor( DateBridge.DATE_SECOND );
+ public static final TwoWayFieldBridge DATE_MILLISECOND = new TwoWayString2FieldBridgeAdaptor( DateBridge.DATE_MILLISECOND );
+
static {
builtInBridges.put( Double.class.getName(), DOUBLE );
builtInBridges.put( double.class.getName(), DOUBLE );
builtInBridges.put( Float.class.getName(), FLOAT );
builtInBridges.put( float.class.getName(), FLOAT );
+ builtInBridges.put( Short.class.getName(), SHORT );
+ builtInBridges.put( short.class.getName(), SHORT );
builtInBridges.put( Integer.class.getName(), INTEGER );
builtInBridges.put( int.class.getName(), INTEGER );
builtInBridges.put( Long.class.getName(), LONG );
@@ -56,13 +71,6 @@
builtInBridges.put( BigDecimal.class.getName(), BIG_DECIMAL );
builtInBridges.put( String.class.getName(), STRING );
- DATE_YEAR = org.hibernate.search.bridge.DateBridge.DATE_YEAR;
- DATE_MONTH = org.hibernate.search.bridge.DateBridge.DATE_MONTH;
- DATE_DAY = org.hibernate.search.bridge.DateBridge.DATE_DAY;
- DATE_HOUR = org.hibernate.search.bridge.DateBridge.DATE_HOUR;
- DATE_MINUTE = org.hibernate.search.bridge.DateBridge.DATE_MINUTE;
- DATE_SECOND = org.hibernate.search.bridge.DateBridge.DATE_SECOND;
- DATE_MILLISECOND = org.hibernate.search.bridge.DateBridge.DATE_MILLISECOND;
builtInBridges.put( Date.class.getName(), DATE_MILLISECOND );
}
@@ -77,9 +85,12 @@
if ( FieldBridge.class.isAssignableFrom( impl ) ) {
bridge = (FieldBridge) instance;
}
- else if ( StringBridge.class.isAssignableFrom( impl ) ) {
- bridge = new String2IdFieldBridgeAdaptor( (StringBridge) instance );
+ else if ( org.hibernate.search.bridge.TwoWayStringBridge.class.isAssignableFrom( impl ) ) {
+ bridge = new TwoWayString2FieldBridgeAdaptor( (org.hibernate.search.bridge.TwoWayStringBridge) instance );
}
+ else if ( org.hibernate.search.bridge.StringBridge.class.isAssignableFrom( impl ) ) {
+ bridge = new String2FieldBridgeAdaptor( (org.hibernate.search.bridge.StringBridge) instance );
+ }
if ( bridgeAnn.params().length > 0 && ParameterizedBridge.class.isAssignableFrom( impl ) ) {
Map params = new HashMap( bridgeAnn.params().length );
for ( Parameter param : bridgeAnn.params() ) {
@@ -94,8 +105,8 @@
}
}
else if ( member.isAnnotationPresent( org.hibernate.search.annotations.DateBridge.class ) ) {
- Resolution resolution = member.getAnnotation( org.hibernate.search.annotations.DateBridge.class ).value();
- bridge = org.hibernate.search.bridge.DateBridge.getDateField( resolution );
+ Resolution resolution = member.getAnnotation( org.hibernate.search.annotations.DateBridge.class ).resolution();
+ bridge = getDateField( resolution );
}
else {
//find in built-ins
@@ -107,4 +118,24 @@
return bridge;
}
+ public static FieldBridge getDateField(Resolution resolution) {
+ switch (resolution) {
+ case YEAR:
+ return DATE_YEAR;
+ case MONTH:
+ return DATE_MONTH;
+ case DAY:
+ return DATE_DAY;
+ case HOUR:
+ return DATE_HOUR;
+ case MINUTE:
+ return DATE_MINUTE;
+ case SECOND:
+ return DATE_SECOND;
+ case MILLISECOND:
+ return DATE_MILLISECOND;
+ default:
+ throw new AssertionFailure( "Unknown Resolution: " + resolution );
+ }
+ }
}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DateBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DateBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DateBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,132 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import java.text.ParseException;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Map;
-
-import org.apache.lucene.document.DateTools;
-import org.hibernate.AssertionFailure;
-import org.hibernate.HibernateException;
-import org.hibernate.util.StringHelper;
-
-/**
- * Bridge a java.util.Date to a String, truncated to the resolution
- * Date are stored GMT based
- * <p/>
- * ie
- * Resolution.YEAR: yyyy
- * Resolution.MONTH: yyyyMM
- * Resolution.DAY: yyyyMMdd
- * Resolution.HOUR: yyyyMMddHH
- * Resolution.MINUTE: yyyyMMddHHmm
- * Resolution.SECOND: yyyyMMddHHmmss
- * Resolution.MILLISECOND: yyyyMMddHHmmssSSS
- *
- * @author Emmanuel Bernard
- */
-public class DateBridge implements StringBridge, ParameterizedBridge {
-
- public static final String2FieldBridgeAdaptor DATE_YEAR =
- new String2FieldBridgeAdaptor( new DateBridge( Resolution.YEAR ) );
- public static final String2FieldBridgeAdaptor DATE_MONTH =
- new String2FieldBridgeAdaptor( new DateBridge( Resolution.MONTH ) );
- public static final String2FieldBridgeAdaptor DATE_DAY =
- new String2FieldBridgeAdaptor( new DateBridge( Resolution.DAY ) );
- public static final String2FieldBridgeAdaptor DATE_HOUR =
- new String2FieldBridgeAdaptor( new DateBridge( Resolution.HOUR ) );
- public static final String2FieldBridgeAdaptor DATE_MINUTE =
- new String2FieldBridgeAdaptor( new DateBridge( Resolution.MINUTE ) );
- public static final String2FieldBridgeAdaptor DATE_SECOND =
- new String2FieldBridgeAdaptor( new DateBridge( Resolution.SECOND ) );
- public static final String2IdFieldBridgeAdaptor DATE_MILLISECOND =
- new String2IdFieldBridgeAdaptor( new DateBridge( Resolution.MILLISECOND ) );
-
- DateTools.Resolution resolution;
-
- public DateBridge() {
- }
-
- public DateBridge(Resolution resolution) {
- setResolution( resolution );
- }
-
- public Object stringToObject(String stringValue) {
- if ( StringHelper.isEmpty( stringValue ) ) return null;
- try {
- return DateTools.stringToDate( stringValue );
- }
- catch (ParseException e) {
- throw new HibernateException( "Unable to parse into date: " + stringValue, e );
- }
- }
-
- public String objectToString(Object object) {
- return object != null ?
- DateTools.dateToString( (Date) object, resolution ) :
- null;
- }
-
- public void setParameterValues(Map parameters) {
- Object resolution = parameters.get( "resolution" );
- Resolution hibResolution;
- if ( resolution instanceof String ) {
- hibResolution = Resolution.valueOf( ( (String) resolution ).toUpperCase( Locale.ENGLISH ) );
- }
- else {
- hibResolution = (Resolution) resolution;
- }
- setResolution( hibResolution );
- }
-
- private void setResolution(Resolution hibResolution) {
- switch (hibResolution) {
- case YEAR:
- this.resolution = DateTools.Resolution.YEAR;
- break;
- case MONTH:
- this.resolution = DateTools.Resolution.MONTH;
- break;
- case DAY:
- this.resolution = DateTools.Resolution.DAY;
- break;
- case HOUR:
- this.resolution = DateTools.Resolution.HOUR;
- break;
- case MINUTE:
- this.resolution = DateTools.Resolution.MINUTE;
- break;
- case SECOND:
- this.resolution = DateTools.Resolution.SECOND;
- break;
- case MILLISECOND:
- this.resolution = DateTools.Resolution.MILLISECOND;
- break;
- default:
- throw new AssertionFailure( "Unknown Resolution: " + hibResolution );
-
- }
- }
-
- public static String2FieldBridgeAdaptor getDateField(Resolution resolution) {
- switch (resolution) {
- case YEAR:
- return DATE_YEAR;
- case MONTH:
- return DATE_MONTH;
- case DAY:
- return DATE_DAY;
- case HOUR:
- return DATE_HOUR;
- case MINUTE:
- return DATE_MINUTE;
- case SECOND:
- return DATE_SECOND;
- case MILLISECOND:
- return DATE_MILLISECOND;
- default:
- throw new AssertionFailure( "Unknown Resolution: " + resolution );
- }
- }
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DoubleBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DoubleBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DoubleBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,16 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import org.hibernate.util.StringHelper;
-
-/**
- * Map a double element
- *
- * @author Emmanuel Bernard
- */
-public class DoubleBridge extends NumberBridge {
- public Object stringToObject(String stringValue) {
- if ( StringHelper.isEmpty( stringValue ) ) return null;
- return new Double( stringValue );
- }
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/FloatBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/FloatBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/FloatBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,16 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import org.hibernate.util.StringHelper;
-
-/**
- * Map a float element
- *
- * @author Emmanuel Bernard
- */
-public class FloatBridge extends NumberBridge {
- public Object stringToObject(String stringValue) {
- if ( StringHelper.isEmpty( stringValue ) ) return null;
- return new Float( stringValue );
- }
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IdFieldBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IdFieldBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IdFieldBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,29 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import org.apache.lucene.document.Document;
-
-/**
- * Any bridge expected to process a document id should implement this interface
- *
- * @author Emmanuel Bernard
- */
-//FIXME rework the interface inheritance there are some common concepts with StringBridge
-public interface IdFieldBridge extends FieldBridge {
- /**
- * build the element from the Document
- * This method is called when the bridge is used on a document id, If the Bridge is not expected to
- * support document id, this method should raise an exception
- * The return value is the Entity id
- *
- * @param name field name
- * @param document document
- */
- Object get(String name, Document document);
-
- /**
- * convert the object representation to a String
- * The return String must not be null, it can be empty though
- */
- String objectToString(Object object);
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IntegerBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IntegerBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IntegerBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,16 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import org.hibernate.util.StringHelper;
-
-/**
- * Map an integer element
- *
- * @author Emmanuel Bernard
- */
-public class IntegerBridge extends NumberBridge {
- public Object stringToObject(String stringValue) {
- if ( StringHelper.isEmpty( stringValue ) ) return null;
- return new Integer( stringValue );
- }
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/LongBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/LongBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/LongBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,16 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import org.hibernate.util.StringHelper;
-
-/**
- * Map a long element
- *
- * @author Emmanuel Bernard
- */
-public class LongBridge extends NumberBridge {
- public Object stringToObject(String stringValue) {
- if ( StringHelper.isEmpty( stringValue ) ) return null;
- return new Long( stringValue );
- }
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/NumberBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/NumberBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/NumberBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,13 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-/**
- * @author Emmanuel Bernard
- */
-public abstract class NumberBridge implements StringBridge {
- public String objectToString(Object object) {
- return object != null ?
- object.toString() :
- null;
- }
-}
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/Resolution.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/Resolution.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/Resolution.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,17 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-/**
- * Date indexing resolution
- *
- * @author Emmanuel Bernard
- */
-public enum Resolution {
- YEAR,
- MONTH,
- DAY,
- HOUR,
- MINUTE,
- SECOND,
- MILLISECOND
-}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2FieldBridgeAdaptor.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -11,7 +11,7 @@
* @author Emmanuel Bernard
*/
public class String2FieldBridgeAdaptor implements FieldBridge {
- protected StringBridge stringBridge;
+ private StringBridge stringBridge;
public String2FieldBridgeAdaptor(StringBridge stringBridge) {
this.stringBridge = stringBridge;
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2IdFieldBridgeAdaptor.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2IdFieldBridgeAdaptor.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2IdFieldBridgeAdaptor.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,26 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-
-/**
- * Bridge to use a StringBridge as a IdFieldBridge
- *
- * @author Emmanuel Bernard
- */
-public class String2IdFieldBridgeAdaptor extends String2FieldBridgeAdaptor implements IdFieldBridge {
-
- public String2IdFieldBridgeAdaptor(StringBridge stringBridge) {
- super( stringBridge );
- }
-
- public String objectToString(Object object) {
- return stringBridge.objectToString( object );
- }
-
- public Object get(String name, Document document) {
- Field field = document.getField( name );
- return stringBridge.stringToObject( field.stringValue() );
- }
-}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -2,18 +2,13 @@
package org.hibernate.search.bridge;
/**
- * Transform an object into a stirng representation and vice versa
+ * Transform an object into a string representation
*
* @author Emmanuel Bernard
*/
public interface StringBridge {
+
/**
- * Convert the string representation to an object
- * FIXME: This operation might not always be possible
- */
- Object stringToObject(String stringValue);
-
- /**
* convert the object representation to a String
* The return String must not be null, it can be empty though
*/
Deleted: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringImplBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringImplBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringImplBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -1,17 +0,0 @@
-//$Id: $
-package org.hibernate.search.bridge;
-
-/**
- * Map a string element
- *
- * @author Emmanuel Bernard
- */
-public class StringImplBridge implements StringBridge {
- public Object stringToObject(String stringValue) {
- return stringValue;
- }
-
- public String objectToString(Object object) {
- return (String) object;
- }
-}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayFieldBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IdFieldBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IdFieldBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayFieldBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,32 @@
+//$Id: $
+package org.hibernate.search.bridge;
+
+import org.apache.lucene.document.Document;
+
+/**
+ * A FieldBrige able to convert the index representation back into an object without losing information
+ *
+ * Any bridge expected to process a document id should implement this interface
+ * EXPERIMENTAL Consider this interface as private
+ *
+ * @author Emmanuel Bernard
+ */
+//FIXME rework the interface inheritance there are some common concepts with StringBridge
+public interface TwoWayFieldBridge extends FieldBridge {
+ /**
+ * build the element object from the Document
+ *
+ * The return value is the Entity id
+ *
+ * @param name field name
+ * @param document document
+ */
+ Object get(String name, Document document);
+
+ /**
+ * convert the object representation to a String
+ * The return String must not be null, it can be empty though
+ * EXPERIMENTAL API subject to change in the future
+ */
+ String objectToString(Object object);
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayString2FieldBridgeAdaptor.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2IdFieldBridgeAdaptor.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/String2IdFieldBridgeAdaptor.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayString2FieldBridgeAdaptor.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,30 @@
+//$Id: $
+package org.hibernate.search.bridge;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+
+/**
+ * Bridge to use a TwoWayStringBridge as a TwoWayFieldBridge
+ *
+ * @author Emmanuel Bernard
+ */
+//TODO use Generics to avoid double declaration of stringBridge
+public class TwoWayString2FieldBridgeAdaptor extends String2FieldBridgeAdaptor implements TwoWayFieldBridge {
+
+ private TwoWayStringBridge stringBridge;
+
+ public TwoWayString2FieldBridgeAdaptor(TwoWayStringBridge stringBridge) {
+ super( stringBridge );
+ this.stringBridge = stringBridge;
+ }
+
+ public String objectToString(Object object) {
+ return stringBridge.objectToString( object );
+ }
+
+ public Object get(String name, Document document) {
+ Field field = document.getField( name );
+ return stringBridge.stringToObject( field.stringValue() );
+ }
+}
Added: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/TwoWayStringBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,18 @@
+//$Id: $
+package org.hibernate.search.bridge;
+
+/**
+ * StringBridge allowing a translation from the String back to the Object
+ * objectToString( stringToObject( string ) ) and stringToObject( objectToString( object ) )
+ * should be "idempotent". More precisely,
+ *
+ * objectToString( stringToObject( string ) ).equals(string) for string not null
+ * stringToObject( objectToString( object ) ).equals(object) for object not null
+ * @author Emmanuel Bernard
+ */
+public interface TwoWayStringBridge extends StringBridge {
+ /**
+ * Convert the string representation to an object
+ */
+ Object stringToObject(String stringValue);
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/BigDecimalBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigDecimalBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigDecimalBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/BigDecimalBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,18 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import java.math.BigDecimal;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Map a BigDecimal element
+ *
+ * @author Emmanuel Bernard
+ */
+public class BigDecimalBridge extends NumberBridge {
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ return new BigDecimal( stringValue );
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/BigIntegerBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigIntegerBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/BigIntegerBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/BigIntegerBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,18 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import java.math.BigInteger;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Map a BigInteger element
+ *
+ * @author Emmanuel Bernard
+ */
+public class BigIntegerBridge extends NumberBridge {
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ return new BigInteger( stringValue );
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/DateBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DateBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DateBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/DateBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,111 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.lucene.document.DateTools;
+import org.hibernate.AssertionFailure;
+import org.hibernate.HibernateException;
+import org.hibernate.search.bridge.StringBridge;
+import org.hibernate.search.bridge.ParameterizedBridge;
+import org.hibernate.search.bridge.String2FieldBridgeAdaptor;
+import org.hibernate.search.annotations.Resolution;
+import org.hibernate.search.bridge.TwoWayString2FieldBridgeAdaptor;
+import org.hibernate.search.bridge.TwoWayStringBridge;
+import org.hibernate.util.StringHelper;
+
+/**
+ * Bridge a java.util.Date to a String, truncated to the resolution
+ * Date are stored GMT based
+ * <p/>
+ * ie
+ * Resolution.YEAR: yyyy
+ * Resolution.MONTH: yyyyMM
+ * Resolution.DAY: yyyyMMdd
+ * Resolution.HOUR: yyyyMMddHH
+ * Resolution.MINUTE: yyyyMMddHHmm
+ * Resolution.SECOND: yyyyMMddHHmmss
+ * Resolution.MILLISECOND: yyyyMMddHHmmssSSS
+ *
+ * @author Emmanuel Bernard
+ */
+//TODO split into StringBridge and TwoWayStringBridge?
+public class DateBridge implements TwoWayStringBridge, ParameterizedBridge {
+
+ public static final TwoWayStringBridge DATE_YEAR = new DateBridge( Resolution.YEAR );
+ public static final TwoWayStringBridge DATE_MONTH = new DateBridge( Resolution.MONTH );
+ public static final TwoWayStringBridge DATE_DAY = new DateBridge( Resolution.DAY );
+ public static final TwoWayStringBridge DATE_HOUR = new DateBridge( Resolution.HOUR );
+ public static final TwoWayStringBridge DATE_MINUTE = new DateBridge( Resolution.MINUTE );
+ public static final TwoWayStringBridge DATE_SECOND = new DateBridge( Resolution.SECOND );
+ public static final TwoWayStringBridge DATE_MILLISECOND = new DateBridge( Resolution.MILLISECOND );
+
+ DateTools.Resolution resolution;
+
+ public DateBridge() {
+ }
+
+ public DateBridge(Resolution resolution) {
+ setResolution( resolution );
+ }
+
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ try {
+ return DateTools.stringToDate( stringValue );
+ }
+ catch (ParseException e) {
+ throw new HibernateException( "Unable to parse into date: " + stringValue, e );
+ }
+ }
+
+ public String objectToString(Object object) {
+ return object != null ?
+ DateTools.dateToString( (Date) object, resolution ) :
+ null;
+ }
+
+ public void setParameterValues(Map parameters) {
+ Object resolution = parameters.get( "resolution" );
+ Resolution hibResolution;
+ if ( resolution instanceof String ) {
+ hibResolution = Resolution.valueOf( ( (String) resolution ).toUpperCase( Locale.ENGLISH ) );
+ }
+ else {
+ hibResolution = (Resolution) resolution;
+ }
+ setResolution( hibResolution );
+ }
+
+ private void setResolution(Resolution hibResolution) {
+ switch (hibResolution) {
+ case YEAR:
+ this.resolution = DateTools.Resolution.YEAR;
+ break;
+ case MONTH:
+ this.resolution = DateTools.Resolution.MONTH;
+ break;
+ case DAY:
+ this.resolution = DateTools.Resolution.DAY;
+ break;
+ case HOUR:
+ this.resolution = DateTools.Resolution.HOUR;
+ break;
+ case MINUTE:
+ this.resolution = DateTools.Resolution.MINUTE;
+ break;
+ case SECOND:
+ this.resolution = DateTools.Resolution.SECOND;
+ break;
+ case MILLISECOND:
+ this.resolution = DateTools.Resolution.MILLISECOND;
+ break;
+ default:
+ throw new AssertionFailure( "Unknown Resolution: " + hibResolution );
+
+ }
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/DoubleBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DoubleBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/DoubleBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/DoubleBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Map a double element
+ *
+ * @author Emmanuel Bernard
+ */
+public class DoubleBridge extends NumberBridge {
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ return new Double( stringValue );
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/FloatBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/FloatBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/FloatBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/FloatBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Map a float element
+ *
+ * @author Emmanuel Bernard
+ */
+public class FloatBridge extends NumberBridge {
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ return new Float( stringValue );
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/IntegerBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IntegerBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/IntegerBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/IntegerBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Map an integer element
+ *
+ * @author Emmanuel Bernard
+ */
+public class IntegerBridge extends NumberBridge {
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ return new Integer( stringValue );
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/LongBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/LongBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/LongBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/LongBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Map a long element
+ *
+ * @author Emmanuel Bernard
+ */
+public class LongBridge extends NumberBridge {
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ return new Long( stringValue );
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/NumberBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/NumberBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/NumberBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/NumberBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import org.hibernate.search.bridge.StringBridge;
+import org.hibernate.search.bridge.TwoWayStringBridge;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class NumberBridge implements TwoWayStringBridge {
+ public String objectToString(Object object) {
+ return object != null ?
+ object.toString() :
+ null;
+ }
+}
Added: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/ShortBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/ShortBridge.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/ShortBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Map a short element
+ *
+ * @author Emmanuel Bernard
+ */
+public class ShortBridge extends NumberBridge {
+ public Object stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
+ return new Short( stringValue );
+ }
+}
Copied: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/StringBridge.java (from rev 10742, branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringImplBridge.java)
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/StringImplBridge.java 2006-11-07 01:03:16 UTC (rev 10742)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/bridge/builtin/StringBridge.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -0,0 +1,18 @@
+//$Id: $
+package org.hibernate.search.bridge.builtin;
+
+
+/**
+ * Map a string element
+ *
+ * @author Emmanuel Bernard
+ */
+public class StringBridge implements org.hibernate.search.bridge.TwoWayStringBridge {
+ public Object stringToObject(String stringValue) {
+ return stringValue;
+ }
+
+ public String objectToString(Object object) {
+ return (String) object;
+ }
+}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/search/engine/DocumentBuilder.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -25,7 +25,7 @@
import org.hibernate.search.annotations.Unstored;
import org.hibernate.search.bridge.BridgeFactory;
import org.hibernate.search.bridge.FieldBridge;
-import org.hibernate.search.bridge.IdFieldBridge;
+import org.hibernate.search.bridge.TwoWayFieldBridge;
import org.hibernate.search.event.FullTextEventListener;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.util.BinderHelper;
@@ -71,7 +71,7 @@
private final Analyzer analyzer;
private Float idBoost;
public static final String CLASS_FIELDNAME = "_hibernate_class";
- private IdFieldBridge idBridge;
+ private TwoWayFieldBridge idBridge;
private Set<Class> mappedSubclasses = new HashSet<Class>();
private ReflectionManager reflectionManager;
@@ -112,8 +112,8 @@
idKeywordName = name;
idBoost = getBoost( member );
FieldBridge fieldBridge = BridgeFactory.guessType( member );
- if ( fieldBridge instanceof IdFieldBridge ) {
- idBridge = (IdFieldBridge) fieldBridge;
+ if ( fieldBridge instanceof TwoWayFieldBridge ) {
+ idBridge = (TwoWayFieldBridge) fieldBridge;
}
else {
throw new HibernateException(
@@ -152,8 +152,8 @@
}
idKeywordName = BinderHelper.getAttributeName( member, documentIdAnn.name() );
FieldBridge fieldBridge = BridgeFactory.guessType( member );
- if ( fieldBridge instanceof IdFieldBridge ) {
- idBridge = (IdFieldBridge) fieldBridge;
+ if ( fieldBridge instanceof TwoWayFieldBridge ) {
+ idBridge = (TwoWayFieldBridge) fieldBridge;
}
else {
throw new HibernateException(
@@ -287,7 +287,7 @@
}
}
- public IdFieldBridge getIdBridge() {
+ public TwoWayFieldBridge getIdBridge() {
return idBridge;
}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/Cloud.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/Cloud.java 2006-11-08 04:52:08 UTC (rev 10766)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/search/test/bridge/Cloud.java 2006-11-08 06:55:52 UTC (rev 10767)
@@ -11,7 +11,7 @@
import org.hibernate.search.annotations.Text;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.FieldBridge;
-import org.hibernate.search.bridge.Resolution;
+import org.hibernate.search.annotations.Resolution;
import org.hibernate.annotations.Parameter;
/**
@@ -161,7 +161,7 @@
}
@Keyword
- @DateBridge( Resolution.YEAR )
+ @DateBridge( resolution = Resolution.YEAR )
public Date getDateYear() {
return dateYear;
}
@@ -171,7 +171,7 @@
}
@Keyword
- @DateBridge( Resolution.MONTH )
+ @DateBridge( resolution = Resolution.MONTH )
public Date getDateMonth() {
return dateMonth;
}
@@ -181,7 +181,7 @@
}
@Keyword
- @DateBridge( Resolution.DAY )
+ @DateBridge( resolution = Resolution.DAY )
public Date getDateDay() {
return dateDay;
}
@@ -191,7 +191,7 @@
}
@Keyword
- @DateBridge( Resolution.HOUR )
+ @DateBridge( resolution = Resolution.HOUR )
public Date getDateHour() {
return dateHour;
}
@@ -202,7 +202,7 @@
@Keyword
- @DateBridge( Resolution.MINUTE )
+ @DateBridge( resolution = Resolution.MINUTE )
public Date getDateMinute() {
return dateMinute;
}
@@ -212,7 +212,7 @@
}
@Keyword
- @DateBridge( Resolution.SECOND )
+ @DateBridge( resolution = Resolution.SECOND )
public Date getDateSecond() {
return dateSecond;
}
@@ -222,7 +222,7 @@
}
@Keyword
- @DateBridge( Resolution.MILLISECOND )
+ @DateBridge( resolution = Resolution.MILLISECOND )
public Date getDateMillisecond() {
return dateMillisecond;
}
18 years, 2 months
Hibernate SVN: r10766 - trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-11-07 23:52:08 -0500 (Tue, 07 Nov 2006)
New Revision: 10766
Modified:
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
Log:
more test
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-11-08 04:30:27 UTC (rev 10765)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-11-08 04:52:08 UTC (rev 10766)
@@ -8,6 +8,7 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
import org.hibernate.test.annotations.TestCase;
/**
@@ -408,6 +409,7 @@
s.clear();
atm = (Atmosphere) s.get( Atmosphere.class, atm.id );
+ assertTrue( ! Hibernate.isInitialized( atm.composition ) );
assertEquals( 1, atm.composition.size() );
assertEquals( o2.name, atm.composition.keySet().iterator().next().name );
tx.rollback();
18 years, 2 months
Hibernate SVN: r10765 - in trunk/Hibernate3: src/org/hibernate/loader src/org/hibernate/loader/hql src/org/hibernate/param src/org/hibernate/tool/hbm2ddl test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 23:30:27 -0500 (Tue, 07 Nov 2006)
New Revision: 10765
Modified:
trunk/Hibernate3/src/org/hibernate/loader/Loader.java
trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
trunk/Hibernate3/src/org/hibernate/param/ParameterSpecification.java
trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java
trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
hhh-2207 : mysql + limit + offset + parameters
Modified: trunk/Hibernate3/src/org/hibernate/loader/Loader.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/loader/Loader.java 2006-11-08 04:30:04 UTC (rev 10764)
+++ trunk/Hibernate3/src/org/hibernate/loader/Loader.java 2006-11-08 04:30:27 UTC (rev 10765)
@@ -1559,7 +1559,10 @@
col += bindLimitParameters( st, col, selection );
}
- if ( !useLimit ) setMaxRows( st, selection );
+ if ( !useLimit ) {
+ setMaxRows( st, selection );
+ }
+
if ( selection != null ) {
if ( selection.getTimeout() != null ) {
st.setQueryTimeout( selection.getTimeout().intValue() );
@@ -1582,8 +1585,13 @@
}
/**
- * Some dialect-specific LIMIT clauses require the maximium last row number,
- * others require the maximum returned row count.
+ * Some dialect-specific LIMIT clauses require the maximium last row number
+ * (aka, first_row_number + total_row_count), while others require the maximum
+ * returned row count (the total maximum number of rows to return).
+ *
+ * @param selection The selection criteria
+ * @param dialect The dialect
+ * @return The appropriate value to bind into the limit clause.
*/
private static int getMaxOrLimit(final RowSelection selection, final Dialect dialect) {
final int firstRow = getFirstRow( selection );
@@ -1597,13 +1605,22 @@
}
/**
- * Bind parameters needed by the dialect-specific LIMIT clause
+ * Bind parameter values needed by the dialect-specific LIMIT clause.
+ *
+ * @param statement The statement to which to bind limit param values.
+ * @param index The bind position from which to start binding
+ * @param selection The selection object containing the limit information.
+ * @return The number of parameter values bound.
+ * @throws java.sql.SQLException Indicates problems binding parameter values.
*/
- private int bindLimitParameters(final PreparedStatement st, final int index, final RowSelection selection)
- throws SQLException {
-
+ private int bindLimitParameters(
+ final PreparedStatement statement,
+ final int index,
+ final RowSelection selection) throws SQLException {
Dialect dialect = getFactory().getDialect();
- if ( !dialect.supportsVariableLimit() ) return 0;
+ if ( !dialect.supportsVariableLimit() ) {
+ return 0;
+ }
if ( !hasMaxRows( selection ) ) {
throw new AssertionFailure( "no max results set" );
}
@@ -1611,59 +1628,98 @@
int lastRow = getMaxOrLimit( selection, dialect );
boolean hasFirstRow = firstRow > 0 && dialect.supportsLimitOffset();
boolean reverse = dialect.bindLimitParametersInReverseOrder();
- if ( hasFirstRow ) st.setInt( index + ( reverse ? 1 : 0 ), firstRow );
- st.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow );
+ if ( hasFirstRow ) {
+ statement.setInt( index + ( reverse ? 1 : 0 ), firstRow );
+ }
+ statement.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow );
return hasFirstRow ? 2 : 1;
}
/**
* Use JDBC API to limit the number of rows returned by the SQL query if necessary
*/
- private void setMaxRows(final PreparedStatement st, final RowSelection selection)
- throws SQLException {
+ private void setMaxRows(
+ final PreparedStatement st,
+ final RowSelection selection) throws SQLException {
if ( hasMaxRows( selection ) ) {
st.setMaxRows( selection.getMaxRows().intValue() + getFirstRow( selection ) );
}
}
+ /**
+ * Bind all parameter values into the prepared statement in preparation
+ * for execution.
+ *
+ * @param statement The JDBC prepared statement
+ * @param queryParameters The encapsulation of the parameter values to be bound.
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ */
protected int bindParameterValues(
- PreparedStatement st,
+ PreparedStatement statement,
QueryParameters queryParameters,
- int col,
+ int startIndex,
SessionImplementor session) throws SQLException {
- col += bindPositionalParameters( st, queryParameters, col, session );
- col += bindNamedParameters( st, queryParameters.getNamedParameters(), col, session );
- return col;
+ int span = 0;
+ span += bindPositionalParameters( statement, queryParameters, startIndex, session );
+ span += bindNamedParameters( statement, queryParameters.getNamedParameters(), startIndex + span, session );
+ return span;
}
/**
- * Bind positional parameter values to the <tt>PreparedStatement</tt>
- * (these are parameters specified by a JDBC-style ?).
+ * Bind positional parameter values to the JDBC prepared statement.
+ * <p/>
+ * Postional parameters are those specified by JDBC-style ? parameters
+ * in the source query. It is (currently) expected that these come
+ * before any named parameters in the source query.
+ *
+ * @param statement The JDBC prepared statement
+ * @param queryParameters The encapsulation of the parameter values to be bound.
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
*/
protected int bindPositionalParameters(
- final PreparedStatement st,
+ final PreparedStatement statement,
final QueryParameters queryParameters,
- final int start,
+ final int startIndex,
final SessionImplementor session) throws SQLException, HibernateException {
final Object[] values = queryParameters.getFilteredPositionalParameterValues();
final Type[] types = queryParameters.getFilteredPositionalParameterTypes();
int span = 0;
for ( int i = 0; i < values.length; i++ ) {
- types[i].nullSafeSet( st, values[i], start + span, session );
+ types[i].nullSafeSet( statement, values[i], startIndex + span, session );
span += types[i].getColumnSpan( getFactory() );
}
return span;
}
/**
- * Bind named parameters to the <tt>PreparedStatement</tt>. This has an empty
- * implementation on this superclass and should be implemented by subclasses
- * (queries) which allow named parameters.
+ * Bind named parameters to the JDBC prepared statement.
+ * <p/>
+ * This is a generic implementation, the problem being that in the
+ * general case we do not know enough information about the named
+ * parameters to perform this in a complete manner here. Thus this
+ * is generally overridden on subclasses allowing named parameters to
+ * apply the specific behavior. The most usual limitation here is that
+ * we need to assume the type span is always one...
+ *
+ * @param statement The JDBC prepared statement
+ * @param namedParams A map of parameter names to values
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
*/
protected int bindNamedParameters(
- final PreparedStatement ps,
+ final PreparedStatement statement,
final Map namedParams,
- final int start,
+ final int startIndex,
final SessionImplementor session) throws SQLException, HibernateException {
if ( namedParams != null ) {
// assumes that types are all of span 1
@@ -1679,10 +1735,10 @@
log.debug(
"bindNamedParameters() " +
typedval.getValue() + " -> " + name +
- " [" + ( locs[i] + start ) + "]"
+ " [" + ( locs[i] + startIndex ) + "]"
);
}
- typedval.getType().nullSafeSet( ps, typedval.getValue(), locs[i] + start, session );
+ typedval.getType().nullSafeSet( statement, typedval.getValue(), locs[i] + startIndex, session );
}
result += locs.length;
}
Modified: trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2006-11-08 04:30:04 UTC (rev 10764)
+++ trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2006-11-08 04:30:27 UTC (rev 10765)
@@ -488,20 +488,31 @@
return queryTranslator.getParameterTranslations().getNamedParameterSqlLocations( name );
}
+ /**
+ * We specifically override this method here, because in general we know much more
+ * about the parameters and their appropriate bind positions here then we do in
+ * our super because we track them explciitly here through the ParameterSpecification
+ * interface.
+ *
+ * @param queryParameters The encapsulation of the parameter values to be bound.
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ */
protected int bindParameterValues(
- PreparedStatement st,
- QueryParameters queryParameters,
- int startPosition,
- SessionImplementor session) throws SQLException {
- int position = startPosition;
- position = bindFilterParameterValues( st, queryParameters, position, session );
+ final PreparedStatement statement,
+ final QueryParameters queryParameters,
+ final int startIndex,
+ final SessionImplementor session) throws SQLException {
+ int position = bindFilterParameterValues( statement, queryParameters, startIndex, session );
List parameterSpecs = queryTranslator.getSqlAST().getWalker().getParameters();
Iterator itr = parameterSpecs.iterator();
while ( itr.hasNext() ) {
ParameterSpecification spec = ( ParameterSpecification ) itr.next();
- position += spec.bind( st, queryParameters, session, position );
+ position += spec.bind( statement, queryParameters, session, position );
}
- return position;
+ return position - startIndex;
}
private int bindFilterParameterValues(
Modified: trunk/Hibernate3/src/org/hibernate/param/ParameterSpecification.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/param/ParameterSpecification.java 2006-11-08 04:30:04 UTC (rev 10764)
+++ trunk/Hibernate3/src/org/hibernate/param/ParameterSpecification.java 2006-11-08 04:30:27 UTC (rev 10765)
@@ -24,12 +24,29 @@
* @param position The position from which to start binding value(s).
*
* @return The number of sql bind positions "eaten" by this bind operation.
+ * @throws java.sql.SQLException Indicates problems performing the JDBC biind operation.
*/
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position) throws SQLException;
+ /**
+ * Get the type which we are expeting for a bind into this parameter based
+ * on translated contextual information.
+ *
+ * @return The expected type.
+ */
public Type getExpectedType();
+ /**
+ * Injects the expected type. Called during translation.
+ *
+ * @param expectedType The type to expect.
+ */
public void setExpectedType(Type expectedType);
+ /**
+ * Render this parameter into displayable info (for logging, etc).
+ *
+ * @return The displayable info.
+ */
public String renderDisplayInfo();
}
Modified: trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-11-08 04:30:04 UTC (rev 10764)
+++ trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-11-08 04:30:27 UTC (rev 10765)
@@ -311,8 +311,7 @@
try {
SQLWarning warnings = statement.getWarnings();
if ( warnings != null) {
- JDBCExceptionReporter.logWarnings( warnings );
- connectionHelper.getConnection().clearWarnings();
+ JDBCExceptionReporter.logAndClearWarnings( connectionHelper.getConnection() );
}
}
catch( SQLException sqle ) {
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-11-08 04:30:04 UTC (rev 10764)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-11-08 04:30:27 UTC (rev 10765)
@@ -90,7 +90,21 @@
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
+ public void testSimpleSelectWithLimitAndOffset() throws Exception {
+ if ( ! ( getDialect().supportsLimit() && getDialect().supportsLimitOffset() ) ) {
+ reportSkip( "dialect does not support offset and limit combo", "limit and offset combination" );
+ return;
+ }
+ // just checking correctness of param binding code...
+ Session session = openSession();
+ session.createQuery( "from Animal" )
+ .setFirstResult( 2 )
+ .setMaxResults( 1 )
+ .list();
+ session.close();
+ }
+
public void testSelectAndResultColumnReferences() {
Session s = openSession();
s.beginTransaction();
18 years, 2 months
Hibernate SVN: r10764 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/loader src/org/hibernate/loader/hql src/org/hibernate/param src/org/hibernate/tool/hbm2ddl test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 23:30:04 -0500 (Tue, 07 Nov 2006)
New Revision: 10764
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/Loader.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/param/ParameterSpecification.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
hhh-2207 : mysql + limit + offset + parameters
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/Loader.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/Loader.java 2006-11-08 00:08:19 UTC (rev 10763)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/Loader.java 2006-11-08 04:30:04 UTC (rev 10764)
@@ -1557,7 +1557,10 @@
col += bindLimitParameters( st, col, selection );
}
- if ( !useLimit ) setMaxRows( st, selection );
+ if ( !useLimit ) {
+ setMaxRows( st, selection );
+ }
+
if ( selection != null ) {
if ( selection.getTimeout() != null ) {
st.setQueryTimeout( selection.getTimeout().intValue() );
@@ -1585,8 +1588,13 @@
}
/**
- * Some dialect-specific LIMIT clauses require the maximium last row number,
- * others require the maximum returned row count.
+ * Some dialect-specific LIMIT clauses require the maximium last row number
+ * (aka, first_row_number + total_row_count), while others require the maximum
+ * returned row count (the total maximum number of rows to return).
+ *
+ * @param selection The selection criteria
+ * @param dialect The dialect
+ * @return The appropriate value to bind into the limit clause.
*/
private static int getMaxOrLimit(final RowSelection selection, final Dialect dialect) {
final int firstRow = getFirstRow( selection );
@@ -1600,13 +1608,22 @@
}
/**
- * Bind parameters needed by the dialect-specific LIMIT clause
+ * Bind parameter values needed by the dialect-specific LIMIT clause.
+ *
+ * @param statement The statement to which to bind limit param values.
+ * @param index The bind position from which to start binding
+ * @param selection The selection object containing the limit information.
+ * @return The number of parameter values bound.
+ * @throws java.sql.SQLException Indicates problems binding parameter values.
*/
- private int bindLimitParameters(final PreparedStatement st, final int index, final RowSelection selection)
- throws SQLException {
-
+ private int bindLimitParameters(
+ final PreparedStatement statement,
+ final int index,
+ final RowSelection selection) throws SQLException {
Dialect dialect = getFactory().getDialect();
- if ( !dialect.supportsVariableLimit() ) return 0;
+ if ( !dialect.supportsVariableLimit() ) {
+ return 0;
+ }
if ( !hasMaxRows( selection ) ) {
throw new AssertionFailure( "no max results set" );
}
@@ -1614,62 +1631,99 @@
int lastRow = getMaxOrLimit( selection, dialect );
boolean hasFirstRow = firstRow > 0 && dialect.supportsLimitOffset();
boolean reverse = dialect.bindLimitParametersInReverseOrder();
- if ( hasFirstRow ) st.setInt( index + ( reverse ? 1 : 0 ), firstRow );
- st.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow );
+ if ( hasFirstRow ) {
+ statement.setInt( index + ( reverse ? 1 : 0 ), firstRow );
+ }
+ statement.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow );
return hasFirstRow ? 2 : 1;
}
/**
* Use JDBC API to limit the number of rows returned by the SQL query if necessary
*/
- private void setMaxRows(final PreparedStatement st, final RowSelection selection)
- throws SQLException {
+ private void setMaxRows(
+ final PreparedStatement st,
+ final RowSelection selection) throws SQLException {
if ( hasMaxRows( selection ) ) {
st.setMaxRows( selection.getMaxRows().intValue() + getFirstRow( selection ) );
}
}
+ /**
+ * Bind all parameter values into the prepared statement in preparation
+ * for execution.
+ *
+ * @param statement The JDBC prepared statement
+ * @param queryParameters The encapsulation of the parameter values to be bound.
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ */
protected int bindParameterValues(
- PreparedStatement st,
+ PreparedStatement statement,
QueryParameters queryParameters,
- int col,
+ int startIndex,
SessionImplementor session) throws SQLException {
- col += bindPositionalParameters( st, queryParameters, col, session );
- col += bindNamedParameters( st, queryParameters.getNamedParameters(), col, session );
- return col;
+ int span = 0;
+ span += bindPositionalParameters( statement, queryParameters, startIndex, session );
+ span += bindNamedParameters( statement, queryParameters.getNamedParameters(), startIndex + span, session );
+ return span;
}
/**
- * Bind positional parameter values to the <tt>PreparedStatement</tt>
- * (these are parameters specified by a JDBC-style ?).
+ * Bind positional parameter values to the JDBC prepared statement.
+ * <p/>
+ * Postional parameters are those specified by JDBC-style ? parameters
+ * in the source query. It is (currently) expected that these come
+ * before any named parameters in the source query.
+ *
+ * @param statement The JDBC prepared statement
+ * @param queryParameters The encapsulation of the parameter values to be bound.
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
*/
protected int bindPositionalParameters(
- final PreparedStatement st,
+ final PreparedStatement statement,
final QueryParameters queryParameters,
- final int start,
+ final int startIndex,
final SessionImplementor session) throws SQLException, HibernateException {
-
final Object[] values = queryParameters.getFilteredPositionalParameterValues();
final Type[] types = queryParameters.getFilteredPositionalParameterTypes();
int span = 0;
for ( int i = 0; i < values.length; i++ ) {
- types[i].nullSafeSet( st, values[i], start + span, session );
+ types[i].nullSafeSet( statement, values[i], startIndex + span, session );
span += types[i].getColumnSpan( getFactory() );
}
return span;
}
/**
- * Bind named parameters to the <tt>PreparedStatement</tt>. This has an empty
- * implementation on this superclass and should be implemented by subclasses
- * (queries) which allow named parameters.
+ * Bind named parameters to the JDBC prepared statement.
+ * <p/>
+ * This is a generic implementation, the problem being that in the
+ * general case we do not know enough information about the named
+ * parameters to perform this in a complete manner here. Thus this
+ * is generally overridden on subclasses allowing named parameters to
+ * apply the specific behavior. The most usual limitation here is that
+ * we need to assume the type span is always one...
+ *
+ * @param statement The JDBC prepared statement
+ * @param namedParams A map of parameter names to values
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
*/
- protected int bindNamedParameters(final PreparedStatement ps,
- final Map namedParams,
- final int start,
- final SessionImplementor session)
- throws SQLException, HibernateException {
-
+ protected int bindNamedParameters(
+ final PreparedStatement statement,
+ final Map namedParams,
+ final int startIndex,
+ final SessionImplementor session) throws SQLException, HibernateException {
if ( namedParams != null ) {
// assumes that types are all of span 1
Iterator iter = namedParams.entrySet().iterator();
@@ -1684,10 +1738,10 @@
log.debug(
"bindNamedParameters() " +
typedval.getValue() + " -> " + name +
- " [" + ( locs[i] + start ) + "]"
+ " [" + ( locs[i] + startIndex ) + "]"
);
}
- typedval.getType().nullSafeSet( ps, typedval.getValue(), locs[i] + start, session );
+ typedval.getType().nullSafeSet( statement, typedval.getValue(), locs[i] + startIndex, session );
}
result += locs.length;
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2006-11-08 00:08:19 UTC (rev 10763)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2006-11-08 04:30:04 UTC (rev 10764)
@@ -478,21 +478,31 @@
return queryTranslator.getParameterTranslations().getNamedParameterSqlLocations( name );
}
-
+ /**
+ * We specifically override this method here, because in general we know much more
+ * about the parameters and their appropriate bind positions here then we do in
+ * our super because we track them explciitly here through the ParameterSpecification
+ * interface.
+ *
+ * @param queryParameters The encapsulation of the parameter values to be bound.
+ * @param startIndex The position from which to start binding parameter values.
+ * @param session The originating session.
+ * @return The number of JDBC bind positions actually bound during this method execution.
+ * @throws SQLException Indicates problems performing the binding.
+ */
protected int bindParameterValues(
- PreparedStatement st,
- QueryParameters queryParameters,
- int startPosition,
- SessionImplementor session) throws SQLException {
- int position = startPosition;
- position = bindFilterParameterValues( st, queryParameters, position, session );
+ final PreparedStatement statement,
+ final QueryParameters queryParameters,
+ final int startIndex,
+ final SessionImplementor session) throws SQLException {
+ int position = bindFilterParameterValues( statement, queryParameters, startIndex, session );
List parameterSpecs = queryTranslator.getSqlAST().getWalker().getParameters();
Iterator itr = parameterSpecs.iterator();
while ( itr.hasNext() ) {
ParameterSpecification spec = ( ParameterSpecification ) itr.next();
- position += spec.bind( st, queryParameters, session, position );
+ position += spec.bind( statement, queryParameters, session, position );
}
- return position;
+ return position - startIndex;
}
private int bindFilterParameterValues(
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/param/ParameterSpecification.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/param/ParameterSpecification.java 2006-11-08 00:08:19 UTC (rev 10763)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/param/ParameterSpecification.java 2006-11-08 04:30:04 UTC (rev 10764)
@@ -24,12 +24,29 @@
* @param position The position from which to start binding value(s).
*
* @return The number of sql bind positions "eaten" by this bind operation.
+ * @throws java.sql.SQLException Indicates problems performing the JDBC biind operation.
*/
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position) throws SQLException;
+ /**
+ * Get the type which we are expeting for a bind into this parameter based
+ * on translated contextual information.
+ *
+ * @return The expected type.
+ */
public Type getExpectedType();
+ /**
+ * Injects the expected type. Called during translation.
+ *
+ * @param expectedType The type to expect.
+ */
public void setExpectedType(Type expectedType);
+ /**
+ * Render this parameter into displayable info (for logging, etc).
+ *
+ * @return The displayable info.
+ */
public String renderDisplayInfo();
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-11-08 00:08:19 UTC (rev 10763)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-11-08 04:30:04 UTC (rev 10764)
@@ -308,7 +308,7 @@
statement.executeUpdate( sql );
SQLWarning warnings = statement.getWarnings();
if ( warnings != null) {
- JDBCExceptionReporter.logWarnings( warnings );
+ JDBCExceptionReporter.logAndClearWarnings( connectionHelper.getConnection() );
}
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-11-08 00:08:19 UTC (rev 10763)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-11-08 04:30:04 UTC (rev 10764)
@@ -90,7 +90,21 @@
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
+ public void testSimpleSelectWithLimitAndOffset() throws Exception {
+ if ( ! ( getDialect().supportsLimit() && getDialect().supportsLimitOffset() ) ) {
+ reportSkip( "dialect does not support offset and limit combo", "limit and offset combination" );
+ return;
+ }
+ // just checking correctness of param binding code...
+ Session session = openSession();
+ session.createQuery( "from Animal" )
+ .setFirstResult( 2 )
+ .setMaxResults( 1 )
+ .list();
+ session.close();
+ }
+
public void testJPAPositionalParameterList() {
Session s = openSession();
s.beginTransaction();
18 years, 2 months
Hibernate SVN: r10763 - branches/Branch_3_2/Hibernate3/lib
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-11-07 19:08:19 -0500 (Tue, 07 Nov 2006)
New Revision: 10763
Removed:
branches/Branch_3_2/Hibernate3/lib/ehcache-1.2.jar
Log:
Max forgot to get rid of the old ehcache (conflicts arised)
Deleted: branches/Branch_3_2/Hibernate3/lib/ehcache-1.2.jar
===================================================================
(Binary files differ)
18 years, 2 months
Hibernate SVN: r10762 - trunk/Hibernate3/test/org/hibernate/test
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 19:03:56 -0500 (Tue, 07 Nov 2006)
New Revision: 10762
Modified:
trunk/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
added OpsSuite to AllTests
Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-11-08 00:03:29 UTC (rev 10761)
+++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-11-08 00:03:56 UTC (rev 10762)
@@ -4,9 +4,11 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
+
import org.hibernate.dialect.Dialect;
import org.hibernate.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest;
import org.hibernate.test.abstractembeddedcomponents.propertyref.AbstractComponentPropertyRefTest;
+import org.hibernate.test.any.AnyTypeTest;
import org.hibernate.test.array.ArrayTest;
import org.hibernate.test.ast.ASTIteratorTest;
import org.hibernate.test.ast.ASTUtilTest;
@@ -93,10 +95,7 @@
import org.hibernate.test.onetomany.OneToManyTest;
import org.hibernate.test.onetoone.joined.OneToOneTest;
import org.hibernate.test.onetooneformula.OneToOneFormulaTest;
-import org.hibernate.test.ops.CreateTest;
-import org.hibernate.test.ops.GetLoadTest;
-import org.hibernate.test.ops.MergeTest;
-import org.hibernate.test.ops.SaveOrUpdateTest;
+import org.hibernate.test.ops.OpsSuite;
import org.hibernate.test.optlock.OptimisticLockTest;
import org.hibernate.test.ordered.OrderByTest;
import org.hibernate.test.orphan.OrphanIdRollbackTest;
@@ -131,7 +130,6 @@
import org.hibernate.test.version.db.DbVersionTest;
import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
import org.hibernate.test.where.WhereTest;
-import org.hibernate.test.any.AnyTypeTest;
/**
* @author Gavin King
@@ -172,10 +170,7 @@
*/
public static Test suite() {
TestSuite suite = new TestSuite("New tests suite");
- suite.addTest( GetLoadTest.suite() );
- suite.addTest( CreateTest.suite() );
- suite.addTest( SaveOrUpdateTest.suite() );
- suite.addTest( MergeTest.suite() );
+ suite.addTest( OpsSuite.suite() );
suite.addTest( NaturalIdTest.suite() );
suite.addTest( ComponentTest.suite() );
suite.addTest( ProxyTest.suite() );
18 years, 2 months