本文整理匯總了Java中javax.persistence.criteria.Root.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Root.get方法的具體用法?Java Root.get怎麽用?Java Root.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.criteria.Root
的用法示例。
在下文中一共展示了Root.get方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toPredicate
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,
CriteriaBuilder builder) {
Path expression = null;
if(fieldName.contains(".")){
String[] names = StringUtils.split(fieldName, ".");
expression = root.get(names[0]);
for (int i = 1; i < names.length; i++) {
expression = expression.get(names[i]);
}
}else{
expression = root.get(fieldName);
}
switch (operator) {
case EQ:
return builder.equal(expression, value);
case NE:
return builder.notEqual(expression, value);
case LIKE:
return builder.like((Expression<String>) expression, "%" + value + "%");
case LT:
return builder.lessThan(expression, (Comparable) value);
case GT:
return builder.greaterThan(expression, (Comparable) value);
case LTE:
return builder.lessThanOrEqualTo(expression, (Comparable) value);
case GTE:
return builder.greaterThanOrEqualTo(expression, (Comparable) value);
default:
return null;
}
}
示例2: findByDateRange
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
public Collection<EndPointCheck> findByDateRange(final EndPoint endPoint, final Date startDate,
final Date endDate) {
final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
final CriteriaQuery<EndPointCheck> criteriaQuery = criteriaBuilder.createQuery(getEntityClass());
final Root<EndPointCheck> root = criteriaQuery
.from(getEntityManager().getMetamodel().entity(getEntityClass()));
final ParameterExpression<EndPoint> endPointParameter = criteriaBuilder.parameter(EndPoint.class);
final ParameterExpression<Date> startDateParameter = criteriaBuilder.parameter(Date.class);
final ParameterExpression<Date> endDateParameter = criteriaBuilder.parameter(Date.class);
final Predicate endPointIdPredicate = criteriaBuilder
.equal(root.get("endPoint"), endPointParameter);
final Path<Date> checkDatePath = root.<Date> get("checkDate");
final Predicate startDatePredicate = criteriaBuilder
.greaterThanOrEqualTo(checkDatePath, startDateParameter);
final Predicate endDatePredicate = criteriaBuilder.lessThanOrEqualTo(
checkDatePath,
endDateParameter);
criteriaQuery.where(criteriaBuilder.and(endPointIdPredicate, startDatePredicate, endDatePredicate));
criteriaQuery.orderBy(Arrays.asList(criteriaBuilder.asc(checkDatePath)));
return getEntityManager().createQuery(criteriaQuery)
.setParameter(endPointParameter, endPoint)
.setParameter(startDateParameter, startDate, TemporalType.DATE)
.setParameter(endDateParameter, endDate, TemporalType.DATE)
.getResultList();
}
示例3: accountExpiresBefore
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
/**
* All customers with an {@link Account} expiring before the given date.
*
* @param date
* @return
*/
public static Specification<Customer> accountExpiresBefore(final LocalDate date) {
return new Specification<Customer>() {
@Override
public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Root<Account> accounts = query.from(Account.class);
Path<Date> expiryDate = accounts.<Date> get("expiryDate");
Predicate customerIsAccountOwner = cb.equal(accounts.<Customer> get("customer"), root);
Predicate accountExpiryDateBefore = cb.lessThan(expiryDate, date.toDateTimeAtStartOfDay().toDate());
return cb.and(customerIsAccountOwner, accountExpiryDateBefore);
}
};
}
示例4: getSort
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
private <T> List<Order> getSort(Root<T> p_root, CriteriaBuilder p_builder, Sort[] p_sort) {
List<Order> order = new LinkedList<Order>();
if (p_sort != null && p_sort.length > 0) {
for (Sort sort : p_sort) {
Path<?> property_path = null;
for (String hop : sort.getPropertyPath()) {
if (property_path == null)
property_path = p_root.get(hop);
else
property_path = property_path.get(hop);
}
if (sort.getOrderAscending()) {
order.add(p_builder.asc(property_path));
} else {
order.add(p_builder.desc(property_path));
}
}
}
return order;
}
示例5: getPath
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
public static <X, T> Expression<X> getPath(Root<T> root, String name) {
String[] array = name.split("[.]");
Expression<X> expr = root.get(array[0]);
for (int i = 1; i < array.length; i++) {
expr = ((Path<X>) expr).get(array[i]);
}
return expr;
}
示例6: buscarTodos
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"})
public List<T> buscarTodos(String... atributos) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery();
Root<T> root = cq.from(entityClass);
Selection[] selections = new Selection[atributos.length];
for (int i = 0; i < atributos.length; i++) {
selections[i] = root.get(atributos[i]);
}
cq.select(cb.construct(entityClass, selections));
cq.orderBy(cb.desc(root.get("id")));
return entityManager.createQuery(cq).getResultList();
}
示例7: getIsMemberOfPredicate
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private <C,T> Predicate getIsMemberOfPredicate(Root<C> p_root, CriteriaBuilder p_builder, Filter p_filter) {
if (p_filter == null)
return null;
Path<? extends Collection> property_path = null;
for (String hop : p_filter.getPropertyPath()) {
if (property_path == null)
property_path = p_root.get(hop);
else
property_path = property_path.get(hop);
}
return p_builder.isMember(p_filter.getValue(), property_path);
}
示例8: getFilterPredicate
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private <T> Predicate getFilterPredicate(Function<Predicate[], Predicate> p_method, Root<T> p_root, CriteriaBuilder p_builder, Filter[] p_filter) {
Predicate predicate = null;
if (p_filter != null && p_filter.length > 0) {
Path<?> property_path = null;
LinkedList<Predicate> predicates = new LinkedList<Predicate>();
for (Filter filter: p_filter) {
for (String hop : filter.getPropertyPath()) {
if (property_path == null)
property_path = p_root.get(hop);
else
property_path = property_path.get(hop);
}
if (filter.getValue() != null) {
if (filter.isExact())
predicates.add(p_builder.equal(property_path, filter.getValue()));
else
predicates.add(p_builder.like((Expression<String>) property_path, filter.getValue()+"%"));
} else {
if (filter.isInverse())
predicates.add(p_builder.isNotNull(property_path));
else
predicates.add(p_builder.isNull(property_path));
}
property_path = null;
}
if (predicates.size() > 1)
predicate = p_method.apply(predicates.toArray(new Predicate[predicates.size()]));
else
predicate = predicates.get(0);
}
return predicate;
}
示例9: updateTask
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
public void updateTask(final ToDoList pToDoList) {
final CriteriaBuilder lCriteriaBuilder = entityManager.getCriteriaBuilder();
//Creation de la requête d'update
final CriteriaUpdate<ToDoList> lCriteriaUpdate = lCriteriaBuilder.createCriteriaUpdate(ToDoList.class);
final Root<ToDoList> lRoot = lCriteriaUpdate.from(ToDoList.class);
final Path<ToDoList> lPath = lRoot.get("id");
//On utilise la variable pToDoList transmise en parametre de la methode
final Expression<Boolean> lExpression = lCriteriaBuilder.equal(lPath, pToDoList.getId());
lCriteriaUpdate.where(lExpression);
lCriteriaUpdate.set("libelle", pToDoList.getLibelle());
final Query lQuery = entityManager.createQuery(lCriteriaUpdate);
final int lRowCount = lQuery.executeUpdate();
//Si la requête modifie un nombre d'occurrences différent de 1 > erreur
//Sinon update fait.
if (lRowCount != 1) {
final org.hibernate.Query lHQuery = lQuery.unwrap(org.hibernate.Query.class);
final String lSql = lHQuery.getQueryString();
throw new RuntimeException("Nombre d'occurences (" + lRowCount +
") modifiés différent de 1 pour " + lSql);
}
}
示例10: filtrarPorNome
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
public List<Pessoa> filtrarPorNome(String filtro){
final CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
final CriteriaQuery<Pessoa> cquery = cb.createQuery(Pessoa.class);
final Root<Pessoa> root = cquery.from(Pessoa.class);
final List<Predicate> condicoes = new ArrayList<Predicate>();
Expression<String> path = root.get("nome");
condicoes.add(cb.like(path, "%"+filtro+"%"));
cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
List<Pessoa> pessoas = getEntityManager().createQuery(cquery).getResultList();
return pessoas;
}
示例11: getExpression
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
/**
* Cree une expression Criteria API avec l'atribut de l'entité passé en parametre
*
* @param root
* entité JPA contenant le champ
* @param columnData
* nom du champ
* @param clazz
* class du champ
* @param <S>
* type du champ
* @return l'expression de l'atribut
*/
public static <S> Path<S> getExpression(final Root<?> root, final String columnData, final Class<S> clazz) {
if (!columnData.contains(DatatableSpecification.ATTRIBUTE_SEPARATOR)) {
// columnData is like "attribute" so nothing particular to do
return root.get(columnData);
}
// columnData is like "joinedEntity.attribute" so add a join clause
final String[] values = columnData.split(DatatableSpecification.ESCAPED_ATTRIBUTE_SEPARATOR);
final Attribute<?, ?> attribute = root.getModel().getAttribute(values[0]);
if (attribute == null) {
throw new IllegalArgumentException(
"Colonne '" + values[0] + "' (" + columnData + ") introuvable depuis l'entité '" + root.getJavaType()
+ "'");
}
if (attribute.getPersistentAttributeType() == PersistentAttributeType.EMBEDDED) {
// with @Embedded attribute
return root.get(values[0]).get(values[1]);
}
From<?, ?> from = root;
for (int i = 0; i < values.length - 1; i++) {
Join<?, ?> join = null;
for (final Join<?, ?> joinCandidate : from.getJoins()) {
if (joinCandidate.getAttribute().getName().equals(values[i])) {
// LOGGER.debug("Trouve joint d'entite: '{}'", values[i]);
join = joinCandidate;
}
}
if (join == null) {
// LOGGER.debug("Joigant entite '{}'...", values[i]);
join = from.join(values[i], JoinType.INNER);
}
from = join;
}
return from.get(values[values.length - 1]);
}
示例12: hibernatePluralPathTest
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
@Test
public void hibernatePluralPathTest() {
CriteriaBuilder build = em.getCriteriaBuilder();
CriteriaQuery<OneToManyInstance> critQ = build.createQuery(OneToManyInstance.class);
Root<OneToManyInstance> resultRoot = critQ.from(OneToManyInstance.class);
Path pluralPath = resultRoot.get("many");
Bindable shouldBePluralAttribute = pluralPath.getModel();
assertNotNull(shouldBePluralAttribute);
assertTrue(shouldBePluralAttribute instanceof PluralAttribute);
}
示例13: toPredicate
import javax.persistence.criteria.Root; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
Path expression = null;
if (fieldName.contains(".")) {
System.out.println(root);
String[] names = StringUtils.split(fieldName, ".");
expression = root.get(names[0]);
for (int i = 1; i < names.length; i++) {
expression = expression.get(names[i]);
}
} else {
expression = root.get(fieldName);
}
switch (operator) {
case EQ:
return builder.equal(expression, value);
case NE:
return builder.notEqual(expression, value);
case LIKE:
return builder.like((Expression<String>) expression, "%" + value + "%");
case RLIKE:
return builder.like((Expression<String>) expression, value + "%");
case LLIKE:
return builder.like((Expression<String>) expression, value + "%");
case LT:
return builder.lessThan(expression, (Comparable) value);
case GT:
return builder.greaterThan(expression, (Comparable) value);
case LTE:
return builder.lessThanOrEqualTo(expression, (Comparable) value);
case GTE:
return builder.greaterThanOrEqualTo(expression, (Comparable) value);
case ISNULL:
return builder.isNull(expression);
case NOTNULL:
return builder.isNotNull(expression);
default:
return null;
}
}