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;
}