org.hibernate.annotations.OrderBy Java Examples

The following examples show how to use org.hibernate.annotations.OrderBy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CollectionBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setJpaOrderBy(javax.persistence.OrderBy jpaOrderBy) {
	this.jpaOrderBy = jpaOrderBy;
}
 
Example #2
Source File: CollectionBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setSqlOrderBy(OrderBy sqlOrderBy) {
	this.sqlOrderBy = sqlOrderBy;
}
 
Example #3
Source File: CollectionBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void applySortingAndOrdering(Collection collection) {
	boolean hadOrderBy = false;
	boolean hadExplicitSort = false;

	Class<? extends Comparator> comparatorClass = null;

	if ( jpaOrderBy == null && sqlOrderBy == null ) {
		if ( deprecatedSort != 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 ) {
				throw buildIllegalSortCombination();
			}
			hadExplicitSort = true;
		}
		else if ( comparatorSort != null ) {
			hadExplicitSort = true;
			comparatorClass = comparatorSort.value();
		}
	}
	else {
		if ( jpaOrderBy != null && sqlOrderBy != null ) {
			throw new AnnotationException(
					String.format(
							"Illegal combination of @%s and @%s on %s",
							javax.persistence.OrderBy.class.getName(),
							OrderBy.class.getName(),
							safeCollectionRole()
					)
			);
		}

		hadOrderBy = true;
		hadExplicitSort = false;

		// we can only apply the sql-based order by up front.  The jpa order by has to wait for second pass
		if ( sqlOrderBy != null ) {
			collection.setOrderBy( sqlOrderBy.clause() );
		}
	}

	if ( isSortedCollection ) {
		if ( ! hadExplicitSort && !hadOrderBy ) {
			throw new AnnotationException(
					"A sorted collection must define and ordering or sorting : " + safeCollectionRole()
			);
		}
	}

	collection.setSorted( isSortedCollection || hadExplicitSort );

	if ( comparatorClass != null ) {
		try {
			collection.setComparator( comparatorClass.newInstance() );
		}
		catch (Exception e) {
			throw new AnnotationException(
					String.format(
							"Could not instantiate comparator class [%s] for %s",
							comparatorClass.getName(),
							safeCollectionRole()
					)
			);
		}
	}
}
 
Example #4
Source File: CollectionBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String extractHqlOrderBy(javax.persistence.OrderBy jpaOrderBy) {
	if ( jpaOrderBy != null ) {
		return jpaOrderBy.value(); // Null not possible. In case of empty expression, apply default ordering.
	}
	return null; // @OrderBy not found.
}
 
Example #5
Source File: ListBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setSqlOrderBy(OrderBy orderByAnn) {
	if ( orderByAnn != null ) {
		LOG.orderByAnnotationIndexedCollection();
	}
}
 
Example #6
Source File: SetBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setSqlOrderBy(OrderBy orderByAnn) {
	if ( orderByAnn != null ) {
		super.setSqlOrderBy( orderByAnn );
	}
}
 
Example #7
Source File: CgFormHeadEntity.java    From jeewx with Apache License 2.0 4 votes vote down vote up
@OneToMany(cascade=CascadeType.REMOVE,mappedBy="table")
@OrderBy(clause="orderNum asc")
public List<CgFormFieldEntity> getColumns() {
	return columns;
}
 
Example #8
Source File: CgFormHeadEntity.java    From jeecg with Apache License 2.0 4 votes vote down vote up
@OneToMany(cascade=CascadeType.REMOVE,mappedBy="table")
@OrderBy(clause="orderNum asc")
public List<CgFormFieldEntity> getColumns() {
	return columns;
}