remove deprecated Sort annotation

This commit is contained in:
Gavin King 2021-02-25 12:02:55 +01:00
parent d0afd6359e
commit bbf4619fcd
12 changed files with 14 additions and 126 deletions

View File

@ -1173,11 +1173,6 @@ The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibern
See the <<chapters/domain/entity.adoc#locking-optimistic-lock-type-dirty-example, `OptimisticLockType.DIRTY` mapping>> section for more info on how `@SelectBeforeUpdate` works. See the <<chapters/domain/entity.adoc#locking-optimistic-lock-type-dirty-example, `OptimisticLockType.DIRTY` mapping>> section for more info on how `@SelectBeforeUpdate` works.
[[annotations-hibernate-sort]]
==== [line-through]#`@Sort`#
The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/annotations/Sort.html[[line-through]#`@Sort`#] annotation is deprecated. Use the Hibernate specific <<annotations-hibernate-sortcomparator>> or <<annotations-hibernate-sortnatural>> annotations instead.
[[annotations-hibernate-sortcomparator]] [[annotations-hibernate-sortcomparator]]
==== `@SortComparator` ==== `@SortComparator`

View File

@ -1,40 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Collection sort (in-memory sorting). Different than ordering, which is applied during the SQL select.
*
* @author Emmanuel Bernard
*
* @see OrderBy
*
* @deprecated Use {@link SortComparator} or {@link SortNatural} instead depending on need.
*/
@Target({METHOD, FIELD})
@Retention(RUNTIME)
@Deprecated
public @interface Sort {
/**
* The type of sorting to use. The default is to not use sorting.
*/
SortType type() default SortType.UNSORTED;
/**
* Specifies the comparator to use. Only valid when {@link #type} specifies {@link SortType#COMPARATOR}.
*
* TODO find a way to use {@code Class<Comparator>} -> see HHH-8164
*/
Class comparator() default void.class;
}

View File

@ -1,30 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* 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.annotations;
/**
* Possible collection sorting strategies.
*
* @author Emmanuel Bernard
*
* @deprecated Since {@link Sort} is deprecated.
*/
@Deprecated
public enum SortType {
/**
* The collection is unsorted.
*/
UNSORTED,
/**
* The collection is sorted using its natural sorting.
*/
NATURAL,
/**
* The collection is sorted using a supplied comparator.
*/
COMPARATOR
}

View File

@ -116,7 +116,6 @@ import org.hibernate.annotations.ParamDef;
import org.hibernate.annotations.Parameter; import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Parent; import org.hibernate.annotations.Parent;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortComparator; import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortNatural; import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.Source; import org.hibernate.annotations.Source;
@ -2043,7 +2042,6 @@ public final class AnnotationBinder {
collectionBinder.setJpaOrderBy( property.getAnnotation( javax.persistence.OrderBy.class ) ); collectionBinder.setJpaOrderBy( property.getAnnotation( javax.persistence.OrderBy.class ) );
collectionBinder.setSqlOrderBy( property.getAnnotation( OrderBy.class ) ); collectionBinder.setSqlOrderBy( property.getAnnotation( OrderBy.class ) );
collectionBinder.setSort( property.getAnnotation( Sort.class ) );
collectionBinder.setNaturalSort( property.getAnnotation( SortNatural.class ) ); collectionBinder.setNaturalSort( property.getAnnotation( SortNatural.class ) );
collectionBinder.setComparatorSort( property.getAnnotation( SortComparator.class ) ); collectionBinder.setComparatorSort( property.getAnnotation( SortComparator.class ) );

View File

@ -60,10 +60,8 @@ import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.SQLInsert; import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate; import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortComparator; import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortNatural; import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
import org.hibernate.annotations.WhereJoinTable; import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XClass;
@ -170,7 +168,6 @@ public abstract class CollectionBinder {
private boolean isSortedCollection; private boolean isSortedCollection;
private javax.persistence.OrderBy jpaOrderBy; private javax.persistence.OrderBy jpaOrderBy;
private OrderBy sqlOrderBy; private OrderBy sqlOrderBy;
private Sort deprecatedSort;
private SortNatural naturalSort; private SortNatural naturalSort;
private SortComparator comparatorSort; private SortComparator comparatorSort;
@ -247,10 +244,6 @@ public abstract class CollectionBinder {
this.sqlOrderBy = sqlOrderBy; this.sqlOrderBy = sqlOrderBy;
} }
public void setSort(Sort deprecatedSort) {
this.deprecatedSort = deprecatedSort;
}
public void setNaturalSort(SortNatural naturalSort) { public void setNaturalSort(SortNatural naturalSort) {
this.naturalSort = naturalSort; this.naturalSort = naturalSort;
} }
@ -623,21 +616,7 @@ public abstract class CollectionBinder {
Class<? extends Comparator<?>> comparatorClass = null; Class<? extends Comparator<?>> comparatorClass = null;
if ( jpaOrderBy == null && sqlOrderBy == null ) { if ( jpaOrderBy == null && sqlOrderBy == null ) {
if ( deprecatedSort != null ) { if ( naturalSort != null ) {
LOG.debug( "Encountered deprecated @Sort annotation; use @SortNatural or @SortComparator instead." );
if ( naturalSort != null || comparatorSort != null ) {
throw buildIllegalSortCombination();
}
hadExplicitSort = deprecatedSort.type() != SortType.UNSORTED;
if ( deprecatedSort.type() == SortType.NATURAL ) {
isSortedCollection = true;
}
else if ( deprecatedSort.type() == SortType.COMPARATOR ) {
isSortedCollection = true;
comparatorClass = deprecatedSort.comparator();
}
}
else if ( naturalSort != null ) {
if ( comparatorSort != null ) { if ( comparatorSort != null ) {
throw buildIllegalSortCombination(); throw buildIllegalSortCombination();
} }
@ -692,7 +671,6 @@ public abstract class CollectionBinder {
String.format( String.format(
"Illegal combination of annotations on %s. Only one of @%s, @%s and @%s can be used", "Illegal combination of annotations on %s. Only one of @%s, @%s and @%s can be used",
safeCollectionRole(), safeCollectionRole(),
Sort.class.getName(),
SortNatural.class.getName(), SortNatural.class.getName(),
SortComparator.class.getName() SortComparator.class.getName()
) )

View File

@ -11,7 +11,6 @@ import java.util.Map;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.annotations.OrderBy; import org.hibernate.annotations.OrderBy;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
@ -38,7 +37,7 @@ import org.jboss.logging.Logger;
* @author Matthew Inger * @author Matthew Inger
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@SuppressWarnings({"unchecked", "serial"}) @SuppressWarnings("unchecked")
public class ListBinder extends CollectionBinder { public class ListBinder extends CollectionBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, ListBinder.class.getName() ); private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, ListBinder.class.getName() );
@ -58,13 +57,6 @@ public class ListBinder extends CollectionBinder {
} }
} }
@Override
public void setSort(Sort sortAnn) {
if ( sortAnn != null ) {
LOG.sortAnnotationIndexedCollection();
}
}
@Override @Override
public SecondPass getSecondPass( public SecondPass getSecondPass(
final Ejb3JoinColumn[] fkJoinColumns, final Ejb3JoinColumn[] fkJoinColumns,

View File

@ -18,8 +18,7 @@ import javax.persistence.Id;
import javax.persistence.MapKeyColumn; import javax.persistence.MapKeyColumn;
import org.hibernate.annotations.MapKeyType; import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
/** /**
@ -34,7 +33,7 @@ public class Matrix {
@MapKeyType( @Type(type="integer") ) @MapKeyType( @Type(type="integer") )
@ElementCollection @ElementCollection
@Sort(type = SortType.NATURAL) @SortNatural
@Type(type = "float") @Type(type = "float")
@MapKeyColumn(nullable = false) @MapKeyColumn(nullable = false)
private SortedMap<Integer, Float> mvalues = new TreeMap<Integer, Float>(); private SortedMap<Integer, Float> mvalues = new TreeMap<Integer, Float>();

View File

@ -30,7 +30,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
* <ul> * <ul>
* <li>{@link org.hibernate.annotations.SortNatural @SortNatural}</li> * <li>{@link org.hibernate.annotations.SortNatural @SortNatural}</li>
* <li>{@link org.hibernate.annotations.SortComparator @SortComparator}</li> * <li>{@link org.hibernate.annotations.SortComparator @SortComparator}</li>
* <li>{@link org.hibernate.annotations.Sort @Sort}</li>
* <li>{@link org.hibernate.annotations.OrderBy @OrderBy(from hibernate)}</li> * <li>{@link org.hibernate.annotations.OrderBy @OrderBy(from hibernate)}</li>
* <li>{@link javax.persistence.OrderBy @OrderBy(from JPA)}</li> * <li>{@link javax.persistence.OrderBy @OrderBy(from JPA)}</li>
* </ul> * </ul>

View File

@ -20,8 +20,7 @@ import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import org.hibernate.annotations.Cascade; import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortType;
import static org.hibernate.annotations.CascadeType.ALL; import static org.hibernate.annotations.CascadeType.ALL;
@ -62,7 +61,7 @@ public class Customer implements Serializable {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "CUST_ID") @JoinColumn(name = "CUST_ID")
@Sort(type = SortType.COMPARATOR, comparator = TicketComparator.class) @SortComparator(TicketComparator.class)
public SortedSet<Ticket> getTickets() { public SortedSet<Ticket> getTickets() {
return tickets; return tickets;
} }

View File

@ -15,8 +15,7 @@ import javax.persistence.Id;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.MapKey; import javax.persistence.MapKey;
import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.SortType;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
@ -24,7 +23,7 @@ import org.hibernate.annotations.SortType;
@Entity @Entity
public class Training { public class Training {
@Id @GeneratedValue private Long id; @Id @GeneratedValue private Long id;
@Sort(type= SortType.NATURAL) @SortNatural
@MapKey(name="name") @ManyToMany SortedMap<String, Trainee> trainees = new TreeMap<String, Trainee>(); @MapKey(name="name") @ManyToMany SortedMap<String, Trainee> trainees = new TreeMap<String, Trainee>();
public Long getId() { public Long getId() {

View File

@ -16,8 +16,7 @@ import javax.persistence.Id;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.MapKeyJoinColumn; import javax.persistence.MapKeyJoinColumn;
import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortType;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.StrTestEntity;
import org.hibernate.envers.test.entities.StrTestEntityComparator; import org.hibernate.envers.test.entities.StrTestEntityComparator;
@ -37,12 +36,12 @@ public class SortedSetEntity {
@Audited @Audited
@ManyToMany @ManyToMany
@Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) @SortComparator(StrTestEntityComparator.class)
private SortedSet<StrTestEntity> sortedSet = new TreeSet<StrTestEntity>( StrTestEntityComparator.INSTANCE ); private SortedSet<StrTestEntity> sortedSet = new TreeSet<StrTestEntity>( StrTestEntityComparator.INSTANCE );
@Audited @Audited
@ElementCollection @ElementCollection
@MapKeyJoinColumn @MapKeyJoinColumn
@Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) @SortComparator(StrTestEntityComparator.class)
private SortedMap<StrTestEntity, String> sortedMap = new TreeMap<StrTestEntity, String>( StrTestEntityComparator.INSTANCE ); private SortedMap<StrTestEntity, String> sortedMap = new TreeMap<StrTestEntity, String>( StrTestEntityComparator.INSTANCE );
public SortedSetEntity() { public SortedSetEntity() {

View File

@ -13,7 +13,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortNatural;
/** /**
* @author Hardy Ferentschik * @author Hardy Ferentschik
@ -25,11 +25,11 @@ public class Printer {
private long id; private long id;
@OneToMany @OneToMany
@Sort @SortNatural
private SortedSet<PrintJob> printQueue; private SortedSet<PrintJob> printQueue;
@OneToMany @OneToMany
@Sort @SortNatural
private SortedMap<String, PrintJob> printedJobs; private SortedMap<String, PrintJob> printedJobs;
} }