Skip to content

Commit

Permalink
HSEARCH-3609 Move binder references out of @ValueBridgeRef and @Ident…
Browse files Browse the repository at this point in the history
…ifierBridgeRef to different annotations

Now that some bridges can only be referenced by their binder, this makes
more sense.
  • Loading branch information
yrodiere committed Jul 12, 2019
1 parent 6c40bae commit 3374cb9
Show file tree
Hide file tree
Showing 24 changed files with 224 additions and 82 deletions.
Expand Up @@ -83,12 +83,12 @@ public void successfulBuilding() {
.binder( StartupStubBridge.binder( TYPE_BRIDGE_COUNTER_KEYS ) )
.property( "id" )
.documentId()
.identifierBridge( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.identifierBinder( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.property( "text" )
.binder( StartupStubBridge.binder( PROPERTY_BRIDGE_COUNTER_KEYS ) )
.genericField( "otherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME );
} );

Expand Down Expand Up @@ -131,12 +131,12 @@ public void failingRoutingKeyBinding() {
.binder( StartupStubBridge.binder( TYPE_BRIDGE_COUNTER_KEYS ) )
.property( "id" )
.documentId()
.identifierBridge( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.identifierBinder( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.property( "text" )
.binder( StartupStubBridge.binder( PROPERTY_BRIDGE_COUNTER_KEYS ) )
.genericField( "otherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME );
typeContext.routingKeyBinder( new FailingBinder() );
} );
Expand Down Expand Up @@ -166,12 +166,12 @@ public void failingTypeBinding() {
.routingKeyBinder( StartupStubBridge.binder( ROUTING_KEY_BRIDGE_COUNTER_KEYS ) )
.property( "id" )
.documentId()
.identifierBridge( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.identifierBinder( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.property( "text" )
.binder( StartupStubBridge.binder( PROPERTY_BRIDGE_COUNTER_KEYS ) )
.genericField( "otherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME );
typeContext.binder( new FailingBinder() );
} );
Expand Down Expand Up @@ -203,11 +203,11 @@ public void failingIdentifierBinding() {
.binder( StartupStubBridge.binder( PROPERTY_BRIDGE_COUNTER_KEYS ) )
.genericField( "otherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME )
.property( "id" )
.documentId()
.identifierBridge( new FailingBinder() )
.identifierBinder( new FailingBinder() )
);

// We must have instantiated objects...
Expand Down Expand Up @@ -235,11 +235,11 @@ public void failingPropertyBinding() {
.binder( StartupStubBridge.binder( TYPE_BRIDGE_COUNTER_KEYS ) )
.property( "id" )
.documentId()
.identifierBridge( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.identifierBinder( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.property( "text" )
.genericField( "otherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME )
.binder( new FailingBinder() )
);
Expand Down Expand Up @@ -268,15 +268,15 @@ public void failingValueBinding() {
.routingKeyBinder( StartupStubBridge.binder( ROUTING_KEY_BRIDGE_COUNTER_KEYS ) )
.binder( StartupStubBridge.binder( TYPE_BRIDGE_COUNTER_KEYS ) )
.property( "id" )
.documentId().identifierBridge( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.documentId().identifierBinder( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.property( "text" )
.binder( StartupStubBridge.binder( PROPERTY_BRIDGE_COUNTER_KEYS ) )
.genericField( "otherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME )
.genericField( "yetAnotherText" )
.valueBridge( new FailingBinder() )
.valueBinder( new FailingBinder() )
.withExtractor( StartupStubContainerExtractor.NAME )
);

Expand Down Expand Up @@ -305,16 +305,16 @@ public void failingContainerExtractorBuilding() {
.routingKeyBinder( StartupStubBridge.binder( ROUTING_KEY_BRIDGE_COUNTER_KEYS ) )
.binder( StartupStubBridge.binder( TYPE_BRIDGE_COUNTER_KEYS ) )
.property( "id" )
.documentId().identifierBridge( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.documentId().identifierBinder( StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS ) )
.property( "text" )
.binder( StartupStubBridge.binder( PROPERTY_BRIDGE_COUNTER_KEYS ) )
.genericField( "otherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME )
.genericField( "yetAnotherText" )
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractors( ContainerExtractorPath.explicitExtractors( Arrays.asList(
StartupStubContainerExtractor.NAME, // The first one succeeds, but...
FailingContainerExtractor.NAME // This one fails.
Expand Down Expand Up @@ -382,13 +382,13 @@ public void configure(BeanConfigurationContext context) {
.binder( StartupStubBridge.binder( TYPE_BRIDGE_COUNTER_KEYS ) )
.routingKeyBinder( StartupStubBridge.binder( ROUTING_KEY_BRIDGE_COUNTER_KEYS ) )
.property( "id" )
.documentId().identifierBridge(
.documentId().identifierBinder(
StartupStubBridge.binder( Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS )
)
.property( "text" )
.genericField()
// The extractor returns type Object, not String
.valueBridge( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.valueBinder( StartupStubBridge.binder( Object.class, VALUE_BRIDGE_COUNTER_KEYS ) )
.withExtractor( StartupStubContainerExtractor.NAME )
.property( "embedded" )
.associationInverseSide(
Expand Down
Expand Up @@ -9,6 +9,7 @@
import java.lang.invoke.MethodHandles;

import org.hibernate.search.mapper.pojo.bridge.IdentifierBridge;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBinderRef;
import org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeFromDocumentIdentifierContext;
import org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeToDocumentIdentifierContext;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
Expand Down Expand Up @@ -198,7 +199,8 @@ public void error_definingBothBridgeReferenceAndBinderReference() {
class IndexedEntity {
Object id;
@DocumentId(
identifierBridge = @IdentifierBridgeRef(name = "foo", binderName = "bar")
identifierBridge = @IdentifierBridgeRef(name = "foo"),
identifierBinder = @IdentifierBinderRef(name = "bar")
)
public Object getId() {
return id;
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.search.mapper.javabean.JavaBeanMapping;
import org.hibernate.search.mapper.javabean.session.SearchSession;
import org.hibernate.search.mapper.pojo.bridge.ValueBridge;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBinderRef;
import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
Expand Down Expand Up @@ -254,7 +255,8 @@ class IndexedEntity {
Integer id;
@DocumentId
@GenericField(
valueBridge = @ValueBridgeRef(name = "foo", binderName = "bar")
valueBridge = @ValueBridgeRef(name = "foo"),
valueBinder = @ValueBinderRef(name = "bar")
)
public Integer getId() {
return id;
Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.search.mapper.javabean.JavaBeanMapping;
import org.hibernate.search.mapper.pojo.bridge.ValueBridge;
import org.hibernate.search.mapper.pojo.bridge.binding.ValueBindingContext;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBinderRef;
import org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.ValueBinder;
import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext;
import org.hibernate.search.mapper.javabean.session.SearchSession;
Expand Down Expand Up @@ -268,7 +269,7 @@ public Integer getId() {
}

@FullTextField(analyzer = ANALYZER_NAME,
valueBridge = @ValueBridgeRef(binderType = ValidTypeBridge.ExplictFieldTypeBinder.class))
valueBinder = @ValueBinderRef(type = ValidTypeBridge.ExplictFieldTypeBinder.class))
public WrappedValue getWrap() {
return wrap;
}
Expand Down Expand Up @@ -362,7 +363,7 @@ public Integer getId() {
}

@FullTextField(analyzer = ANALYZER_NAME,
valueBridge = @ValueBridgeRef(binderType = InvalidTypeBridge.ExplictFieldTypeBinder.class))
valueBinder = @ValueBinderRef(type = InvalidTypeBridge.ExplictFieldTypeBinder.class))
public WrappedValue getWrap() {
return wrap;
}
Expand Down
Expand Up @@ -601,7 +601,7 @@ public IndexedEmbeddedLevel1 getLevel1() {
.binder( StartupStubBridge.binder( filteredOutBridgeCounterKeys ) )
.genericField( "level1IncludedField" )
.genericField( "filteredOut" )
.valueBridge( StartupStubBridge.binder( String.class, filteredOutBridgeCounterKeys ) );
.valueBinder( StartupStubBridge.binder( String.class, filteredOutBridgeCounterKeys ) );
} )
.setup();
backendMock.verifyExpectationsMet();
Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.search.mapper.javabean.JavaBeanMapping;
import org.hibernate.search.mapper.pojo.bridge.ValueBridge;
import org.hibernate.search.mapper.pojo.bridge.binding.ValueBindingContext;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBinderRef;
import org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.ValueBinder;
import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext;
import org.hibernate.search.mapper.javabean.session.SearchSession;
Expand Down Expand Up @@ -237,7 +238,7 @@ public Integer getId() {
}

@KeywordField(normalizer = NORMALIZER_NAME,
valueBridge = @ValueBridgeRef(binderType = ValidTypeBridge.ExplictFieldTypeBinder.class))
valueBinder = @ValueBinderRef(type = ValidTypeBridge.ExplictFieldTypeBinder.class))
public WrappedValue getWrap() {
return wrap;
}
Expand Down Expand Up @@ -334,7 +335,7 @@ public Integer getId() {
}

@KeywordField(normalizer = NORMALIZER_NAME,
valueBridge = @ValueBridgeRef(binderType = InvalidTypeBridge.ExplictFieldTypeBinder.class))
valueBinder = @ValueBinderRef(type = InvalidTypeBridge.ExplictFieldTypeBinder.class))
public WrappedValue getWrap() {
return wrap;
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper;
import org.hibernate.search.mapper.pojo.bridge.ValueBridge;
import org.hibernate.search.mapper.pojo.bridge.binding.ValueBindingContext;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBinderRef;
import org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.ValueBinder;
import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
Expand Down Expand Up @@ -238,7 +239,7 @@ public Integer getId() {
return id;
}

@ScaledNumberField(decimalScale = 3, valueBridge = @ValueBridgeRef(binderType = ValidTypeBridge.ExplictFieldTypeBinder.class))
@ScaledNumberField(decimalScale = 3, valueBinder = @ValueBinderRef(type = ValidTypeBridge.ExplictFieldTypeBinder.class))
public WrappedValue getWrap() {
return wrap;
}
Expand Down Expand Up @@ -298,7 +299,7 @@ public Integer getId() {
return id;
}

@ScaledNumberField(decimalScale = 3, valueBridge = @ValueBridgeRef(binderType = InvalidTypeBridge.ExplictFieldTypeBinder.class))
@ScaledNumberField(decimalScale = 3, valueBinder = @ValueBinderRef(type = InvalidTypeBridge.ExplictFieldTypeBinder.class))
public WrappedValue getWrap() {
return wrap;
}
Expand Down
Expand Up @@ -10,8 +10,8 @@
import javax.persistence.Entity;

import org.hibernate.annotations.Type;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBinderRef;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBridgeRef;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.integrationtest.showcase.library.bridge.ISBNBridge;
import org.hibernate.search.integrationtest.showcase.library.usertype.ISBNUserType;
Expand All @@ -29,7 +29,7 @@ public class Book extends Document<BookCopy> {

@Basic
@Type(type = ISBNUserType.NAME)
@GenericField(valueBridge = @ValueBridgeRef(binderType = ISBNBridge.Binder.class))
@GenericField(valueBinder = @ValueBinderRef(type = ISBNBridge.Binder.class))
private ISBN isbn;

public Book() {
Expand Down
@@ -0,0 +1,47 @@
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.mapper.pojo.bridge.mapping.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.IdentifierBinder;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;

/**
* References the identifier binder to use for a {@link DocumentId}.
* <p>
* Either a bridge or a binder can be referenced, but never both.
* References can use either a name, a type, or both.
*/
@Documented
@Target({}) // Only used as a component in other annotations
@Retention(RetentionPolicy.RUNTIME)
public @interface IdentifierBinderRef {

/**
* Reference an identifier binder by its bean name.
* @return The bean name of the identifier binder.
*/
String name() default "";

/**
* Reference an identifier binder by its type.
* @return The type of the identifier binder.
*/
Class<? extends IdentifierBinder> type() default UndefinedBinderImplementationType.class;

/**
* Class used as a marker for the default value of the {@link #type()} attribute.
*/
abstract class UndefinedBinderImplementationType implements IdentifierBinder {
private UndefinedBinderImplementationType() {
}
}
}
Expand Up @@ -12,7 +12,6 @@
import java.lang.annotation.Target;

import org.hibernate.search.mapper.pojo.bridge.IdentifierBridge;
import org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.IdentifierBinder;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;

/**
Expand All @@ -38,18 +37,6 @@
*/
Class<? extends IdentifierBridge> type() default UndefinedBridgeImplementationType.class;

/**
* Reference an identifier bridge by the bean name of its binder.
* @return The bean name of the identifier binder.
*/
String binderName() default "";

/**
* Reference an identifier bridge by the type of its binder.
* @return The type of the identifier binder.
*/
Class<? extends IdentifierBinder> binderType() default UndefinedBinderImplementationType.class;

/**
* Class used as a marker for the default value of the {@link #type()} attribute.
*/
Expand All @@ -58,11 +45,4 @@ private UndefinedBridgeImplementationType() {
}
}

/**
* Class used as a marker for the default value of the {@link #binderType()} attribute.
*/
abstract class UndefinedBinderImplementationType implements IdentifierBinder {
private UndefinedBinderImplementationType() {
}
}
}

0 comments on commit 3374cb9

Please sign in to comment.