public Filter getFilterFromExample(Object example, ExampleOptions options) { if (example == null) return null; if (options == null) options = defaultExampleOptions; List<Filter> filters = new ArrayList<Filter>(); LinkedList<String> path = new LinkedList<String>(); Metadata metadata = metadataUtil.get(example.getClass()); getFilterFromExampleRecursive(example, metadata, options, path, filters); if (filters.size() == 0) { return null; } else if (filters.size() == 1) { return filters.get(0); } else { return new Filter("AND", filters, Filter.OP_AND); } }
/** * Returns the number of instances of this entity in the datastore. */ protected int _count(Class<?> type) { return ((Number) em().createQuery("select count(_it_) from " + getMetadataUtil().get(type).getEntityName() + " _it_").getSingleResult()).intValue(); }
/** * Returns the number of instances of this entity in the datastore. */ protected int _count(Class<?> type) { return ((Number) em().createQuery("select count(_it_) from " + getMetadataUtil().get(type).getEntityName() + " _it_").getSingleResult()).intValue(); }
protected boolean _exists(Class<?> type, Serializable id) { if (type == null) throw new NullPointerException("Type is null."); if (!validId(id)) return false; Query query = em().createQuery("select _it_.id from " + getMetadataUtil().get(type).getEntityName() + " _it_ where _it_.id = :id"); query.setParameter("id", id); return query.getResultList().size() == 1; }
protected boolean _exists(Class<?> type, Serializable id) { if (type == null) throw new NullPointerException("Type is null."); if (!validId(id)) return false; Query query = em().createQuery("select _it_.id from " + getMetadataUtil().get(type).getEntityName() + " _it_ where _it_.id = :id"); query.setParameter("id", id); return query.getResultList().size() == 1; }
private List<?> pullByIds(String select, Class<?> type, Serializable[] ids) { List<Serializable> nonNulls = new LinkedList<Serializable>(); StringBuilder sb = new StringBuilder(select); sb.append(" from "); sb.append(getMetadataUtil().get(type).getEntityName()); sb.append(" _it_ where "); for (Serializable id : ids) { if (id != null) { if (nonNulls.size() == 0) sb.append("_it_.id = ?1"); else sb.append(" or _it_.id = ?").append(nonNulls.size() + 1); nonNulls.add(id); } } if (nonNulls.size() == 0) return new ArrayList<Object>(0); Query query = em().createQuery(sb.toString()); int idx = 1; for (Serializable id : nonNulls) { query.setParameter(idx++, id); } return query.getResultList(); }
/** * Get a list of all the entities of the specified class. */ protected <T> List<T> _all(Class<T> type) { return em().createQuery("select _it_ from " + getMetadataUtil().get(type).getEntityName() + " _it_").getResultList(); }
private List<?> pullByIds(String select, Class<?> type, Serializable[] ids) { List<Serializable> nonNulls = new LinkedList<Serializable>(); StringBuilder sb = new StringBuilder(select); sb.append(" from "); sb.append(getMetadataUtil().get(type).getEntityName()); sb.append(" _it_ where "); for (Serializable id : ids) { if (id != null) { if (nonNulls.size() == 0) sb.append("_it_.id = ?1"); else sb.append(" or _it_.id = ?").append(nonNulls.size() + 1); nonNulls.add(id); } } if (nonNulls.size() == 0) return new ArrayList<Object>(0); Query query = em().createQuery(sb.toString()); int idx = 1; for (Serializable id : nonNulls) { query.setParameter(idx++, id); } return query.getResultList(); }
/** * Get a list of all the entities of the specified class. */ protected <T> List<T> _all(Class<T> type) { return em().createQuery("select _it_ from " + getMetadataUtil().get(type).getEntityName() + " _it_").getResultList(); }
/** * Internal method for generating from clause. This method should be called * after generating other clauses because it relies on the aliases they * create. This method takes every path that is called for in the other * clauses and makes it available as an alias using left joins. It also adds * join fetching for properties specified by <code>fetches</code> if * <code>doEagerFetching</code> is <code>true</code>. <b>NOTE:</b> When * using eager fetching, <code>applyFetches()</code> must be executed first. */ protected String generateFromClause(SearchContext ctx, boolean doEagerFetching) { StringBuilder sb = new StringBuilder(" from "); sb.append(getMetadataUtil().get(ctx.rootClass).getEntityName()); sb.append(" "); sb.append(ctx.getRootAlias()); sb.append(generateJoins(ctx, doEagerFetching)); return sb.toString(); }
/** * Remove the entity of the specified class with the specified id from the * datastore. * * @return <code>true</code> if the object is found in the datastore and * deleted, <code>false</code> if the item is not found. */ protected boolean _removeById(Class<?> type, Serializable id) { if (id != null) { Query query = em().createQuery("select _it_.id from " + getMetadataUtil().get(type).getEntityName() + " _it_ where _it_.id = ?1").setParameter(1, id); if (query.getResultList().size() != 0) { em().remove(em().getReference(type, id)); return true; } } return false; }
/** * Remove the entity of the specified class with the specified id from the * datastore. * * @return <code>true</code> if the object is found in the datastore and * deleted, <code>false</code> if the item is not found. */ protected boolean _removeById(Class<?> type, Serializable id) { if (id != null) { Query query = em().createQuery("select _it_.id from " + getMetadataUtil().get(type).getEntityName() + " _it_ where _it_.id = ?1").setParameter(1, id); if (query.getResultList().size() != 0) { em().remove(em().getReference(type, id)); return true; } } return false; }
ctx2.rootClass = metadataUtil.get(ctx.rootClass, property).getJavaClass(); ctx2.setRootAlias(rootAlias + (ctx.nextSubqueryNum++)); ctx2.paramList = ctx.paramList;
expectedClass = Integer.class; } else { expectedClass = metadataUtil.get(rootClass, property).getJavaClass();
} else if (sort.isIgnoreCase() && metadataUtil.get(ctx.rootClass, sort.getProperty()).isString()) { sb.append("lower("); sb.append(getPathRef(ctx, sort.getProperty()));
Object value = InternalUtil.convertIfNeeded(filter.getValue(), metadataUtil.get(ctx.rootClass, property) .getJavaClass()); return param(ctx, value) + op + operation + " elements(" + getPathRef(ctx, property) + ")";