
com.github.fluent.hibernate.builder.InBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluent-hibernate-core Show documentation
Show all versions of fluent-hibernate-core Show documentation
A library to work with Hibernate by fluent API. This library hasn't dependencies except Hibernate dependencies. It requires Java 1.6 and above.
package com.github.fluent.hibernate.builder;
import java.util.Collection;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import com.github.fluent.hibernate.internal.util.InternalUtils.CollectionUtils;
import com.github.fluent.hibernate.request.HibernateRequest;
/**
*
* @author alexey.pchelnikov.
*/
public class InBuilder implements IBuilder {
private final String propertyName;
private final Collection> values;
private boolean nothingForEmptyCollection;
/*package*/InBuilder(String propertyName, Collection> values) {
this.propertyName = propertyName;
this.values = values;
}
public IBuilder nothingForEmptyCollection() {
nothingForEmptyCollection = true;
return this;
}
@Override
public void build(HibernateRequest hibernateRequest) {
if (nothingForEmptyCollection && CollectionUtils.isEmpty(values)) {
hibernateRequest.add(getFalseRestriction());
} else {
hibernateRequest.in(propertyName, values);
}
}
private Criterion getFalseRestriction() {
return Restrictions.sqlRestriction("1<>1");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy