Skip to content

Commit

Permalink
HSEARCH-2457 Fixed confusions between property name and absolute/rela…
Browse files Browse the repository at this point in the history
…tive field name
  • Loading branch information
yrodiere authored and gsmet committed Nov 23, 2016
1 parent 2770721 commit 242712f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
Expand Up @@ -69,10 +69,10 @@ public interface ConversionContext {
* All invocations to a push need to cleanup with a {@link #popProperty()},
* especially after exceptions.
*
* @param property the property which is being followed for embedded indexing
* @param propertyName the name of the property which is being followed for embedded indexing
* @return this for method chaining.
*/
ConversionContext pushProperty(String property);
ConversionContext pushProperty(String propertyName);

/**
* Pops the last pushed property from the stack. See {@link #pushIdentifierProperty()}
Expand Down
Expand Up @@ -49,8 +49,8 @@ public ConversionContext setClass(Class<?> clazz) {
}

@Override
public ConversionContext pushProperty(String property) {
path.add( property );
public ConversionContext pushProperty(String propertyName) {
path.add( propertyName );
return this;
}

Expand Down
Expand Up @@ -165,7 +165,7 @@ private static void processMetadataRecursivelyForProjections(TypeMetadata typeMe
final String fieldName = fieldMetadata.getAbsoluteName();
int matchingPosition = getFieldPosition( fields, fieldName );
if ( matchingPosition != -1 && result[matchingPosition] == NOT_SET ) {
contextualBridge.pushProperty( fieldName );
contextualBridge.pushProperty( propertyMetadata.getPropertyAccessorName() );
try {
populateResult(
fieldName,
Expand Down
Expand Up @@ -367,14 +367,19 @@ public Document getDocument(
LuceneOptions luceneOptions = new LuceneOptionsImpl( idFieldMetaData, idFieldMetaData.getBoost(), documentLevelBoost );
final FieldBridge contextualizedBridge = conversionContext.oneWayConversionContext( getIdBridge() );
conversionContext.setClass( entityType );
conversionContext.pushProperty( idFieldMetaData.getAbsoluteName() );

if ( idPropertyName != null ) {
conversionContext.pushProperty( idPropertyName );
}

try {
contextualizedBridge.set( idFieldMetaData.getAbsoluteName(), id, doc, luceneOptions );
addSortFieldDocValues( doc, idPropertyMetadata, documentLevelBoost, id );
}
finally {
conversionContext.popProperty();
if ( idPropertyName != null ) {
conversionContext.popProperty();
}
}
}

Expand Down Expand Up @@ -853,18 +858,12 @@ private void buildDocumentFieldForClassBridges(Document doc,
FieldBridge fieldBridge = fieldMetadata.getFieldBridge();
final String fieldName = fieldMetadata.getAbsoluteName();
final FieldBridge oneWayConversionContext = conversionContext.oneWayConversionContext( fieldBridge );
conversionContext.pushProperty( fieldName );
try {
oneWayConversionContext.set(
fieldName,
unproxiedInstance,
doc,
typeMetadata.getClassLuceneOptions( fieldMetadata, documentBoost )
);
}
finally {
conversionContext.popProperty();
}
oneWayConversionContext.set(
fieldName,
unproxiedInstance,
doc,
typeMetadata.getClassLuceneOptions( fieldMetadata, documentBoost )
);
}
}

Expand Down
Expand Up @@ -267,7 +267,10 @@ private void index(Object entity, Session session, InstanceInitializer sessionIn

DocumentBuilderIndexedEntity docBuilder = entityIndexBinding.getDocumentBuilder();
TwoWayFieldBridge idBridge = docBuilder.getIdBridge();
conversionContext.pushProperty( docBuilder.getIdFieldName() );
String idPropertyName = docBuilder.getIdPropertyName();
if ( idPropertyName != null ) {
conversionContext.pushProperty( idPropertyName );
}
String idInString = null;
try {
idInString = conversionContext
Expand All @@ -276,7 +279,9 @@ private void index(Object entity, Session session, InstanceInitializer sessionIn
.objectToString( id );
}
finally {
conversionContext.popProperty();
if ( idPropertyName != null ) {
conversionContext.popProperty();
}
}
//depending on the complexity of the object graph going to be indexed it's possible
//that we hit the database several times during work construction.
Expand Down
Expand Up @@ -52,8 +52,7 @@ public void testClassBridgeError() throws Exception {
Throwable cause = e.getCause();
assertTrue( cause instanceof BridgeException );
String expectedErrorMessage = "Exception while calling bridge#set\n" +
"\tclass: org.hibernate.search.test.bridge.BridgeConversionErrorTest$ClassBridged\n" +
"\tpath: test";
"\tclass: org.hibernate.search.test.bridge.BridgeConversionErrorTest$ClassBridged";
assertEquals( "Wrong error message", expectedErrorMessage, cause.getMessage() );
}
}
Expand Down

0 comments on commit 242712f

Please sign in to comment.