HHH-10774 - SortedMap defined in .hbm.xml are not sortable
This commit is contained in:
parent
b112e5af3f
commit
60aac117e6
|
@ -11,9 +11,15 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmMapType;
|
||||||
import org.hibernate.boot.model.source.spi.AttributeSourceContainer;
|
import org.hibernate.boot.model.source.spi.AttributeSourceContainer;
|
||||||
import org.hibernate.boot.model.source.spi.PluralAttributeIndexSource;
|
import org.hibernate.boot.model.source.spi.PluralAttributeIndexSource;
|
||||||
import org.hibernate.boot.model.source.spi.PluralAttributeNature;
|
import org.hibernate.boot.model.source.spi.PluralAttributeNature;
|
||||||
|
import org.hibernate.boot.model.source.spi.Sortable;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
public class PluralAttributeSourceMapImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource {
|
public class PluralAttributeSourceMapImpl
|
||||||
|
extends AbstractPluralAttributeSourceImpl
|
||||||
|
implements IndexedPluralAttributeSource, Sortable {
|
||||||
|
private final String sorting;
|
||||||
private final PluralAttributeIndexSource indexSource;
|
private final PluralAttributeIndexSource indexSource;
|
||||||
|
|
||||||
private final String xmlNodeName;
|
private final String xmlNodeName;
|
||||||
|
|
||||||
public PluralAttributeSourceMapImpl(
|
public PluralAttributeSourceMapImpl(
|
||||||
|
@ -23,6 +29,8 @@ public class PluralAttributeSourceMapImpl extends AbstractPluralAttributeSourceI
|
||||||
super( sourceMappingDocument, jaxbMap, container );
|
super( sourceMappingDocument, jaxbMap, container );
|
||||||
this.xmlNodeName = jaxbMap.getNode();
|
this.xmlNodeName = jaxbMap.getNode();
|
||||||
|
|
||||||
|
this.sorting = interpretSorting( jaxbMap.getSort() );
|
||||||
|
|
||||||
if ( jaxbMap.getMapKey() != null ) {
|
if ( jaxbMap.getMapKey() != null ) {
|
||||||
this.indexSource = new PluralAttributeMapKeySourceBasicImpl( sourceMappingDocument, jaxbMap.getMapKey() );
|
this.indexSource = new PluralAttributeMapKeySourceBasicImpl( sourceMappingDocument, jaxbMap.getMapKey() );
|
||||||
}
|
}
|
||||||
|
@ -69,6 +77,18 @@ public class PluralAttributeSourceMapImpl extends AbstractPluralAttributeSourceI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String interpretSorting(String sort) {
|
||||||
|
if ( StringHelper.isEmpty( sort ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( "unsorted".equals( sort ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sort;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluralAttributeIndexSource getIndexSource() {
|
public PluralAttributeIndexSource getIndexSource() {
|
||||||
return indexSource;
|
return indexSource;
|
||||||
|
@ -88,4 +108,14 @@ public class PluralAttributeSourceMapImpl extends AbstractPluralAttributeSourceI
|
||||||
public String getXmlNodeName() {
|
public String getXmlNodeName() {
|
||||||
return xmlNodeName;
|
return xmlNodeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSorted() {
|
||||||
|
return sorting != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getComparatorName() {
|
||||||
|
return sorting;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
<key column="searchString"/>
|
<key column="searchString"/>
|
||||||
<element column="text" type="string"/>
|
<element column="text" type="string"/>
|
||||||
</set>
|
</set>
|
||||||
|
<map name="tokens" sort="natural" table="search_tokens">
|
||||||
|
<key column="searchString"/>
|
||||||
|
<map-key column="key" type="string"/>
|
||||||
|
<element column="value" type="string"/>
|
||||||
|
</map>
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
||||||
|
|
|
@ -7,12 +7,15 @@
|
||||||
|
|
||||||
//$Id: Search.java 7772 2005-08-05 23:03:46Z oneovthafew $
|
//$Id: Search.java 7772 2005-08-05 23:03:46Z oneovthafew $
|
||||||
package org.hibernate.test.sorted;
|
package org.hibernate.test.sorted;
|
||||||
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public class Search {
|
public class Search {
|
||||||
private String searchString;
|
private String searchString;
|
||||||
private SortedSet searchResults = new TreeSet();
|
private SortedSet searchResults = new TreeSet();
|
||||||
|
private SortedMap<String,String> tokens = new TreeMap<>();
|
||||||
|
|
||||||
Search() {}
|
Search() {}
|
||||||
|
|
||||||
|
@ -20,16 +23,27 @@ public class Search {
|
||||||
searchString = string;
|
searchString = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet getSearchResults() {
|
|
||||||
return searchResults;
|
|
||||||
}
|
|
||||||
public void setSearchResults(SortedSet searchResults) {
|
|
||||||
this.searchResults = searchResults;
|
|
||||||
}
|
|
||||||
public String getSearchString() {
|
public String getSearchString() {
|
||||||
return searchString;
|
return searchString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchString(String searchString) {
|
public void setSearchString(String searchString) {
|
||||||
this.searchString = searchString;
|
this.searchString = searchString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SortedSet getSearchResults() {
|
||||||
|
return searchResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchResults(SortedSet searchResults) {
|
||||||
|
this.searchResults = searchResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedMap<String, String> getTokens() {
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokens(SortedMap<String, String> tokens) {
|
||||||
|
this.tokens = tokens;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,16 @@ import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.annotations.SortNatural;
|
import org.hibernate.annotations.SortNatural;
|
||||||
|
import org.hibernate.mapping.Collection;
|
||||||
|
import org.hibernate.mapping.PersistentClass;
|
||||||
|
import org.hibernate.mapping.Property;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -36,7 +41,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
public class SortTest extends BaseCoreFunctionalTestCase {
|
public class SortTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] getMappings() {
|
protected String[] getMappings() {
|
||||||
|
@ -48,6 +53,19 @@ public class SortTest extends BaseCoreFunctionalTestCase {
|
||||||
return new Class<?>[] { Owner.class, Cat.class };
|
return new Class<?>[] { Owner.class, Cat.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSortedSetDefinitionInHbmXml() {
|
||||||
|
final PersistentClass entityMapping = metadata().getEntityBinding( Search.class.getName() );
|
||||||
|
|
||||||
|
final Property sortedSetProperty = entityMapping.getProperty( "searchResults" );
|
||||||
|
final Collection sortedSetMapping = assertTyping( Collection.class, sortedSetProperty.getValue() );
|
||||||
|
assertTrue( "SortedSet mapping not interpreted as sortable", sortedSetMapping.isSorted() );
|
||||||
|
|
||||||
|
final Property sortedMapProperty = entityMapping.getProperty( "tokens" );
|
||||||
|
final Collection sortedMapMapping = assertTyping( Collection.class, sortedMapProperty.getValue() );
|
||||||
|
assertTrue( "SortedMap mapping not interpreted as sortable", sortedMapMapping.isSorted() );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void testOrderBy() {
|
public void testOrderBy() {
|
||||||
|
|
Loading…
Reference in New Issue