Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock;
import org.hibernate.search.util.impl.test.SubTest;

import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -51,13 +52,17 @@ public IndexNullAsErrorIT(PropertyTypeDescriptor<V> typeDescriptor, Optional<Def

@Test
public void testParsingException() {
String unparsableNullAsValue = expectations.getUnparsableNullAsValue();
// Null means "there's no value I can't parse". Useful for the String type.
Assume.assumeNotNull( unparsableNullAsValue );

SubTest.expectException( () ->
setupHelper.start().withConfiguration( c -> c
.addEntityType( expectations.getTypeWithValueBridge1() )
.programmaticMapping()
.type( expectations.getTypeWithValueBridge1() ).indexed()
.property( FIELD_NAME ).genericField( FIELD_NAME )
.property( FIELD_NAME ).genericField( FIELD_INDEXNULLAS_NAME ).indexNullAs( expectations.getUnparsableNullAsValue() )
.property( FIELD_NAME ).genericField( FIELD_INDEXNULLAS_NAME ).indexNullAs( unparsableNullAsValue )
).setup()
)
.assertThrown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class PropertyTypeDescriptor<V> {
public static List<PropertyTypeDescriptor<?>> getAll() {
if ( all == null ) {
all = Collections.unmodifiableList( Arrays.asList(
new StringPropertyTypeDescriptor(),
new BoxedIntegerPropertyTypeDescriptor(),
new BoxedLongPropertyTypeDescriptor(),
new BoxedBooleanPropertyTypeDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* 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.integrationtest.mapper.pojo.testsupport.types;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.hibernate.search.integrationtest.mapper.pojo.testsupport.types.expectations.DefaultIdentifierBridgeExpectations;
import org.hibernate.search.integrationtest.mapper.pojo.testsupport.types.expectations.DefaultValueBridgeExpectations;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;

public class StringPropertyTypeDescriptor extends PropertyTypeDescriptor<String> {

StringPropertyTypeDescriptor() {
super( String.class );
}

@Override
public Optional<DefaultIdentifierBridgeExpectations<String>> getDefaultIdentifierBridgeExpectations() {
return Optional.of( new DefaultIdentifierBridgeExpectations<String>() {
@Override
public List<String> getEntityIdentifierValues() {
return Arrays.asList( "", "a", "AaaA", "Some words", "\000", "http://foo", "yop@yopmail.com" );
}

@Override
public List<String> getDocumentIdentifierValues() {
return getEntityIdentifierValues();
}

@Override
public Class<?> getTypeWithIdentifierBridge1() {
return TypeWithIdentifierBridge1.class;
}

@Override
public Object instantiateTypeWithIdentifierBridge1(String identifier) {
TypeWithIdentifierBridge1 instance = new TypeWithIdentifierBridge1();
instance.id = identifier;
return instance;
}

@Override
public Class<?> getTypeWithIdentifierBridge2() {
return TypeWithIdentifierBridge2.class;
}
} );
}

@Override
public Optional<DefaultValueBridgeExpectations<String, ?>> getDefaultValueBridgeExpectations() {
return Optional.of( new DefaultValueBridgeExpectations<String, String>() {
@Override
public Class<String> getProjectionType() {
return String.class;
}

@Override
public Class<String> getIndexFieldJavaType() {
return String.class;
}

@Override
public List<String> getEntityPropertyValues() {
return Arrays.asList( "", "a", "AaaA", "Some words", "\000", "http://foo", "yop@yopmail.com" );
}

@Override
public List<String> getDocumentFieldValues() {
return getEntityPropertyValues();
}

@Override
public Class<?> getTypeWithValueBridge1() {
return TypeWithValueBridge1.class;
}

@Override
public Object instantiateTypeWithValueBridge1(int identifier, String propertyValue) {
TypeWithValueBridge1 instance = new TypeWithValueBridge1();
instance.id = identifier;
instance.myProperty = propertyValue;
return instance;
}

@Override
public Class<?> getTypeWithValueBridge2() {
return TypeWithValueBridge2.class;
}

@Override
public String getNullAsValueBridge1() {
return "";
}

@Override
public String getNullAsValueBridge2() {
return "some value";
}

@Override
public String getUnparsableNullAsValue() {
// Every string is valid
return null;
}
} );
}

@Indexed(index = DefaultIdentifierBridgeExpectations.TYPE_WITH_IDENTIFIER_BRIDGE_1_INDEX_NAME)
public static class TypeWithIdentifierBridge1 {
String id;
@DocumentId
public String getId() {
return id;
}
}

@Indexed(index = DefaultIdentifierBridgeExpectations.TYPE_WITH_IDENTIFIER_BRIDGE_2_INDEX_NAME)
public static class TypeWithIdentifierBridge2 {
String id;
@DocumentId
public String getId() {
return id;
}
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_1_INDEX_NAME)
public static class TypeWithValueBridge1 {
Integer id;
String myProperty;
String indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public String getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "")
public String getIndexNullAsProperty() {
return indexNullAsProperty;
}
}

@Indexed(index = DefaultValueBridgeExpectations.TYPE_WITH_VALUE_BRIDGE_2_INDEX_NAME)
public static class TypeWithValueBridge2 {
Integer id;
String myProperty;
String indexNullAsProperty;

@DocumentId
public Integer getId() {
return id;
}

@GenericField
public String getMyProperty() {
return myProperty;
}

@GenericField(indexNullAs = "some value")
public String getIndexNullAsProperty() {
return indexNullAsProperty;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.builtin.impl;

import org.hibernate.search.mapper.pojo.bridge.IdentifierBridge;
import org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeFromDocumentIdentifierContext;
import org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeToDocumentIdentifierContext;

public final class DefaultStringIdentifierBridge implements IdentifierBridge<String> {

@Override
public String toDocumentIdentifier(String propertyValue, IdentifierBridgeToDocumentIdentifierContext context) {
return propertyValue;
}

@Override
public String fromDocumentIdentifier(String documentIdentifier, IdentifierBridgeFromDocumentIdentifierContext context) {
return documentIdentifier;
}

@Override
public boolean isCompatibleWith(IdentifierBridge<?> other) {
return getClass().equals( other.getClass() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.hibernate.search.mapper.pojo.bridge.builtin.impl.DefaultLongIdentifierBridge;
import org.hibernate.search.mapper.pojo.bridge.builtin.impl.DefaultPeriodValueBridge;
import org.hibernate.search.mapper.pojo.bridge.builtin.impl.DefaultShortIdentifierBridge;
import org.hibernate.search.mapper.pojo.bridge.builtin.impl.DefaultStringIdentifierBridge;
import org.hibernate.search.mapper.pojo.bridge.builtin.impl.DefaultUUIDIdentifierBridge;
import org.hibernate.search.mapper.pojo.bridge.builtin.impl.DefaultUUIDValueBridge;
import org.hibernate.search.mapper.pojo.bridge.builtin.impl.DefaultZoneIdValueBridge;
Expand Down Expand Up @@ -89,6 +90,7 @@ public BridgeResolver(TypePatternMatcherFactory typePatternMatcherFactory) {

TypePatternMatcher concreteGeoPointPattern = typePatternMatcherFactory.createRawSuperTypeMatcher( GeoPoint.class );

addIdentifierBridgeForExactRawType( String.class, new DefaultStringIdentifierBridge() );
addIdentifierBridgeForExactRawType( Integer.class, new DefaultIntegerIdentifierBridge() );
addIdentifierBridgeForExactRawType( Long.class, new DefaultLongIdentifierBridge() );
addIdentifierBinderForTypePattern( concreteEnumPattern, new DefaultEnumIdentifierBridge.Binder() );
Expand Down