本文整理汇总了Java中javax.persistence.criteria.ParameterExpression类的典型用法代码示例。如果您正苦于以下问题:Java ParameterExpression类的具体用法?Java ParameterExpression怎么用?Java ParameterExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParameterExpression类属于javax.persistence.criteria包,在下文中一共展示了ParameterExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findByDateRange
import javax.persistence.criteria.ParameterExpression; //导入依赖的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();
}
示例2: createQuery
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
public Object createQuery(CriteriaQueryWrapper criteriaQueryWrapper) {
TypedQuery typedQuery = this.original.createQuery(criteriaQueryWrapper.getOriginal());
QLStatement qlStmt = hqlAnalyzer.getQLSelectStatement(typedQuery);
int i=0;
for(Objectref parameter : criteriaQueryWrapper.getSymbolicParameter()) {
qlStmt.setParameter("param"+i++, parameter);
}
for(Object o : criteriaQueryWrapper.getOriginal().getParameters()) {
if(o instanceof ParameterExpression) {
ParameterExpression<?> paraExpr = (ParameterExpression<?>)o;
paraExpr.getAlias();
paraExpr.getName();
}
}
return qlStmt;
}
示例3: getAllByQueryTest
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
/**
* 对getAllByQuery的单元测试
*/
@Test
public void getAllByQueryTest() {
Query query = new Query(User.class, entityManager);
ParameterExpression<Enum> parameter1 = query.createParameter(Enum.class);
ParameterExpression<String> parameter2 = query.createParameter(String.class);
List resultList = query.whereEqual("authorityType", parameter1)
.whereLike("passWord", parameter2)
.createTypedQuery()
.setParameter(parameter1, AuthorityType.College_Level_Admin)
.setParameter(parameter2, "BaseRepository")
.getResultList();
if (resultList != null) {
resultList.forEach(System.out::println);
}
}
示例4: selectAuthorsCriteria
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
@Test
public void selectAuthorsCriteria() {
log.info("... selectAuthorsCriteria ...");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Author> cq = cb.createQuery(Author.class);
Root<Author> root = cq.from(Author.class);
cq.select(root);
ParameterExpression<Long> idParam = cb.parameter(Long.class, "id");
cq.where(cb.equal(root.get("id"), idParam));
TypedQuery<Author> q = em.createQuery(cq);
q.setParameter("id", 1L);
q.setHint("org.hibernate.comment", "This is my comment");
q.getSingleResult();
em.getTransaction().commit();
em.close();
}
示例5: shouldUseTuple
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
@Test
public void shouldUseTuple(){
String searchName = "borowiec2";
CriteriaBuilder cb = em.getCriteriaBuilder();
//CriteriaQuery<Object[]> c = cb.createQuery(Object[].class); //<4>
CriteriaQuery<Tuple> criteria = cb.createQuery(Tuple.class); //<1>
Root<Person> root = criteria.from(Person.class);//<2>
ParameterExpression<String> lastNameParameter = cb.parameter(String.class,"lastName");
criteria.multiselect(root.get("firstName"), root.get("version")).where(cb.equal(root.get("lastName"),lastNameParameter));
List<Tuple> tupleResult = em.createQuery(criteria).setParameter("lastName", searchName).getResultList();//<3>
for (Tuple t : tupleResult) {
log.info("fistName : {} , version : {} ",t.get(0),t.get(1));
}
Assertions.assertThat(tupleResult.size()).isEqualTo(1);
}
示例6: findAlternativeEntitiesByPollId
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
private List<Alternative> findAlternativeEntitiesByPollId(Long pollId, boolean all, int maxResults, int firstResult) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Alternative> q = cb.createQuery(Alternative.class);
Root<Alternative> alt = q.from(Alternative.class);
ParameterExpression<Long> pid = cb.parameter(Long.class);
q.select(alt).where(cb.equal(alt.get(Alternative_.poll).get(Poll_.id), pid));
TypedQuery<Alternative> query = em.createQuery(q);
query.setParameter(pid, pollId);
if (!all) {
query.setMaxResults(maxResults);
query.setFirstResult(firstResult);
}
List<Alternative> results = query.getResultList();
System.out.println(">>>>>>>>>>>>>>>>>>>> Alternatives: " + results);
return results;
}
示例7: findVoteEntitiesByPollAltIds
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
private List<Vote> findVoteEntitiesByPollAltIds(Long pollId, Long altId, boolean all, int maxResults, int firstResult) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Vote> q = cb.createQuery(Vote.class);
Root<Vote> vote = q.from(Vote.class);
ParameterExpression<Long> pid = cb.parameter(Long.class);
ParameterExpression<Long> aid = cb.parameter(Long.class);
q.select(vote).where(cb.and(
cb.equal(vote.get(Vote_.alternative).get(Alternative_.poll).get(Poll_.id), pid),
cb.equal(vote.get(Vote_.alternative).get(Alternative_.id), aid)
));
TypedQuery<Vote> query = em.createQuery(q);
query.setParameter(pid, pollId).setParameter(aid, altId);
if (!all) {
query.setMaxResults(maxResults);
query.setFirstResult(firstResult);
}
List<Vote> results = query.getResultList();
System.out.println(">>>>>>>>>>>>>>>>>>>> Votes: " + results);
return results;
}
示例8: findByName
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
public Optional<Configuration> findByName(ReadContext ctx, String name) {
EntityManager em = emf.createEntityManager();
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, ctx.getTenant());
em.setProperty("private-key", ctx.getPrivateKey());
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Configuration> q = cb.createQuery(Configuration.class);
Root<Configuration> c = q.from(Configuration.class);
ParameterExpression<String> p = cb.parameter(String.class);
q.select(c).where(cb.equal(c.get("name"), p));
TypedQuery<Configuration> query = em.createQuery(q);
query.setParameter(p, name);
Configuration configuration = query.getSingleResult();
return Optional.ofNullable(configuration);
}
示例9: findByName
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
public Optional<Status> findByName(Status.Name statusName) {
EntityManager em = emf.createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Status> q = cb.createQuery(Status.class);
Root<Status> c = q.from(Status.class);
ParameterExpression<String> p = cb.parameter(String.class);
q.select(c).where(cb.equal(c.get("name"), p));
TypedQuery<Status> query = em.createQuery(q);
query.setParameter(p, statusName.name());
try {
Status status = query.getSingleResult();
return Optional.of(status);
} catch (NoResultException e) {
return Optional.empty();
}
}
示例10: findPersonByEmail
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
/**
* @param aEmail
* @return
*/
public OxUser findPersonByEmail( String aEmail )
{
CriteriaBuilder cb = myEntityManager.getCriteriaBuilder();
CriteriaQuery<OxUser> criteria = cb.createQuery(OxUser.class);
Root<OxUser> root = criteria.from(OxUser.class);
ParameterExpression<String> mailParam = cb.parameter(String.class);
criteria.select(root).where(cb.equal( root.get("email"), mailParam ));
TypedQuery<OxUser> queryEMail = myEntityManager.createQuery(criteria);
queryEMail.setParameter( mailParam, aEmail );
List<OxUser> results = queryEMail.getResultList();
OxUser oxUser = null;
if ( results.size() > 0 )
{
oxUser = results.get( 0 );
} // if results.size() > 0
return oxUser;
}
示例11: findUnapprovedUser
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
/**
* @param aUserId
* @return
*/
public OxUserUnapproved findUnapprovedUser( Long aUserId )
{
CriteriaBuilder cb = myEntityManager.getCriteriaBuilder();
CriteriaQuery<OxUserUnapproved> criteria = cb.createQuery(OxUserUnapproved.class);
Root<OxUserUnapproved> root = criteria.from(OxUserUnapproved.class);
ParameterExpression<Long> param = cb.parameter(Long.class);
criteria.select(root).where(cb.equal( root.get("userId"), param ));
TypedQuery<OxUserUnapproved> queryEMail = myEntityManager.createQuery(criteria);
queryEMail.setParameter( param, aUserId );
List<OxUserUnapproved> results = queryEMail.getResultList();
OxUserUnapproved userUnapproved = null;
if ( results.size() > 0 )
{
userUnapproved = results.get( 0 );
} // if results.size() > 0
return userUnapproved;
}
示例12: doParameterQuery
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
/**
* SELECT e FROM jpa_query_employee e WHERE e.name= :name
*/
@Transactional
public void doParameterQuery(){
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Employee> c = cb.createQuery(Employee.class);
Root<Employee> e = c.from(Employee.class);
// parameter, equal to ":name"
ParameterExpression<String> paraName = cb.parameter(String.class, "name");
// e.name = ":name"
c.select(e)
.where(cb.equal(e.get("name"), paraName));
// set param value
TypedQuery<Employee> query = em.createQuery(c);
query.setParameter("name", "employee_1");
List<Employee> result = query.getResultList();
ResultViewer.showResult(result, "criteria query : parameter query");
}
示例13: buildGetByValue
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
/**
* Builds a criteria query equal to the JPQL
*
* <code>SELECT _testEntity FROM TestEntity _testEntity WHERE _testEntity.value :value</code>
*
*
*/
private TypedQuery<TestEntity> buildGetByValue() {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<TestEntity> criteriaQuery = criteriaBuilder.createQuery(TestEntity.class);
Root<TestEntity> root = criteriaQuery.from(TestEntity.class);
ParameterExpression<String> valueParameter = criteriaBuilder.parameter(String.class, TestEntity_.value.getName());
criteriaQuery.select(root)
.where(
criteriaBuilder.equal(
root.get(TestEntity_.value), valueParameter)
);
return entityManager.createQuery(criteriaQuery);
}
示例14: createSelectCustom
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
public <C> Query<C> createSelectCustom(JPAQueryCustomiser customiser)
{
customiser.apply(criteriaBuilder, generated, root, this);
final Query query = session.createQuery(generated);
if (offset != null)
query.getQueryOptions().setFirstRow(offset);
if (limit != null)
query.getQueryOptions().setMaxRows(limit);
// Set all the parameters
for (Map.Entry<ParameterExpression, Object> entry : this.params.entrySet())
{
query.setParameter(entry.getKey(), entry.getValue());
}
return query;
}
示例15: createSelectEntity
import javax.persistence.criteria.ParameterExpression; //导入依赖的package包/类
public Query<T> createSelectEntity()
{
generated.select(root);
applyFetches();
generated.orderBy(orders); // Make sure we return the results in the correct order
final Query<T> query = session.createQuery(generated);
if (offset != null)
query.getQueryOptions().setFirstRow(offset);
if (limit != null)
query.getQueryOptions().setMaxRows(limit);
query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
// Set all the parameters
for (Map.Entry<ParameterExpression, Object> entry : this.params.entrySet())
{
query.setParameter(entry.getKey(), entry.getValue());
}
return query;
}