当前位置: 首页>>代码示例>>Java>>正文


Java Tuple类代码示例

本文整理汇总了Java中javax.persistence.Tuple的典型用法代码示例。如果您正苦于以下问题:Java Tuple类的具体用法?Java Tuple怎么用?Java Tuple使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Tuple类属于javax.persistence包,在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: countAllGroupByOwner

import javax.persistence.Tuple; //导入依赖的package包/类
@Override
public Map<Long, Long> countAllGroupByOwner() {
    CriteriaQuery<Tuple> query = criteriaBuilder.createTupleQuery();
    Root<DataFile> root = query.from(clazz);
    Join<DataFile, DataFileVersion> joinFileVersions = root.join(DataFile_.includedIn);
    Join<DataFileVersion, ContentVersion> joinVersion = joinFileVersions.join(DataFileVersion_.contentVersion);
    Join<ContentVersion, DigitalObject> joinObject = joinVersion.join(ContentVersion_.object);

    query.groupBy(joinObject.get(DigitalObject_.ownerId));
    query.multiselect(joinObject.get(DigitalObject_.ownerId), criteriaBuilder.countDistinct(root));

    Map<Long, Long> results = new HashMap<Long, Long>();
    for (Tuple tuple : entityManager.createQuery(query).getResultList()) {
        results.put((Long) tuple.get(0), (Long) tuple.get(1));
    }

    return results;
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:19,代码来源:DataFileDaoBean.java

示例2: findAll

import javax.persistence.Tuple; //导入依赖的package包/类
@Override
public FindOIDsResult<O> findAll(final UserContext userContext) {
	CriteriaBuilder builder = _entityManager.getCriteriaBuilder();
	
	// use projections to return ONLY the oid (see http://stackoverflow.com/questions/12618489/jpa-criteria-api-select-only-specific-columns)
	CriteriaQuery<Tuple> query = builder.createTupleQuery();
	Root<DB> root = query.from(_DBEntityType);
	if (Facetables.hasFacet(_modelObjectType,HasVersionableFacet.class)) {
		query.multiselect(root.get("_oid"),
						  root.get("_version"));
	} else {
		query.multiselect(root.get("_oid"));
	}
	List<Tuple> tupleResult = _entityManager.createQuery(query)
													.setHint(QueryHints.READ_ONLY,HintValues.TRUE)
										    .getResultList();
	FindOIDsResult<O> outOids = _buildResultsFromOids(userContext,
													  tupleResult);
	return outOids;
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:21,代码来源:DBFindForModelObjectBase.java

示例3: getValue

import javax.persistence.Tuple; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static Object getValue(String propertyName, Object obj) {
	if (obj instanceof Map) {
          return ((Map) obj).get(propertyName);
       } else if (obj instanceof Tuple) {
           return ((Tuple) obj).get(propertyName);
       } else if (obj != null) {
           PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(obj.getClass(), propertyName);
           try {
              return pd.getReadMethod().invoke(obj, new Object[]{});
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
	return null;
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:17,代码来源:JpaUtil.java

示例4: LinqImpl

import javax.persistence.Tuple; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public LinqImpl(Class<?> domainClass, Class<?> resultClass, EntityManager entityManager) {
	super(domainClass, entityManager);
	if (Tuple.class.isAssignableFrom(resultClass)) {
		criteria = cb.createTupleQuery();
		root = criteria.from(domainClass);
	} else if (Map.class.isAssignableFrom(resultClass)) {
		criteria = cb.createQuery(Object[].class);
		root = criteria.from(domainClass);
		resultTransformer = Transformers.ALIAS_TO_MAP;
		Set<?> attrs = em.getMetamodel().entity(domainClass).getDeclaredSingularAttributes();
		String[] selections = new String[attrs.size()];
		int i = 0;
		for (Object attr : attrs) {
			selections[i] = ((SingularAttribute)attr).getName();
			i++;
		}
		select(selections);
	} else {
		criteria = cb.createQuery(resultClass);
		root = criteria.from(domainClass);
	}
	this.resultClass = resultClass;
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:25,代码来源:LinqImpl.java

示例5: search

import javax.persistence.Tuple; //导入依赖的package包/类
@Override
public Optional<SearchResponse> search(final ServiceUser user,
                                       final SearchRequest request){
    final String dataSourceUuid = request.getQuery().getDataSource().getUuid();

    try (final Session session = database.openSession()) {
        final CriteriaBuilder cb = session.getCriteriaBuilder();

        final CriteriaQuery<Tuple> cq = cb.createTupleQuery();
        final Root<T> root = cq.from(this.dtoClass);

        cq.multiselect(this.fields.stream()
                .map(f -> root.get(f.getName()))
                .collect(Collectors.toList()));

        final Predicate requestPredicate = getPredicate(cb, root, request.getQuery().getExpression());
        final Predicate dataSourcePredicate = cb.equal(root.get(QueryableEntity.DATA_SOURCE_UUID), dataSourceUuid);

        cq.where(cb.and(requestPredicate, dataSourcePredicate));
        final List<Tuple> tuples = session.createQuery(cq).getResultList();
        final SearchResponse searchResponse = projectResults(request, tuples);

        return Optional.of(searchResponse);
    }
}
 
开发者ID:gchq,项目名称:stroom-query,代码行数:26,代码来源:QueryServiceCriteriaImpl.java

示例6: testGroupBy

import javax.persistence.Tuple; //导入依赖的package包/类
@Test
public void testGroupBy() throws Exception {

	Instance e1 = new Instance();
	e1.setName("testName1");
	e1.setNumber(1);
	e1.setField("A");
	em.persist(e1);

	Instance e2 = new Instance();
	e2.setName("testName2");
	e2.setNumber(2);
	e2.setField("A");
	em.persist(e2);

	JpaELFilterImpl el = new JpaELFilterImpl(em, Instance.class, Tuple.class);
	el.groupBy(new String[]{"field"}, "sum(number)", new String[]{"field"});
	List r = el.getResultList(Integer.MAX_VALUE, 0);

	assertNotNull(r);
	assertEquals(1, r.size());
	assertEquals("A", ((Tuple) r.get(0)).get(0));
	assertEquals(3, ((Tuple) r.get(0)).get(1));
}
 
开发者ID:gdjennings,项目名称:elrest-java,代码行数:25,代码来源:JPAFilterImplTest.java

示例7: fetchUsedQuotas

import javax.persistence.Tuple; //导入依赖的package包/类
private Map<Long, Integer> fetchUsedQuotas() {
    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<Tuple> query = builder.createTupleQuery();
    final Root<HarvestReport> root = query.from(HarvestReport.class);

    Join<Harvest, HarvestQuota> joinedQuotas = root.join(HarvestReport_.harvests).join(Harvest_.harvestQuota, JoinType.LEFT);
    Path<Long> quotaId = joinedQuotas.get(HarvestQuota_.id);

    Expression<Long> count = builder.count(root.get(HarvestReport_.id));

    Predicate onlyApproved = builder.equal(root.get(HarvestReport_.state), HarvestReport.State.APPROVED);
    Predicate quotaNotNull = builder.isNotNull(quotaId);

    CriteriaQuery<Tuple> q = query
            .multiselect(quotaId, count)
            .where(onlyApproved, quotaNotNull)
            .groupBy(quotaId);
    return map(entityManager.createQuery(q).getResultList());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:20,代码来源:PublicHarvestSeasonFeature.java

示例8: findByTupleQuery

import javax.persistence.Tuple; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public <T extends BaseEntity> List<Tuple> findByTupleQuery(TupleQueryCriteria<T> criteria) {
    EntityManager em = this.emf.createEntityManager();
    try {
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Tuple> cq = cb.createTupleQuery();
        Root<T> root = cq.from(criteria.getEntity());
        return em.createQuery(cq.multiselect(criteria.getSelections()
                .stream()
                .map(root::get)
                .collect(Collectors.toList())
                .toArray(new Selection[LEN_ZERO]))
                .where(cb.and(JpaUtil.getPredicates(criteria.getCriteriaAttributes(), cb, root))))
                .getResultList();
    } catch (RuntimeException ex) {
        LOGGER.error(ex.getMessage(), ex);
        throw new PersistenceException(ex.getMessage(), ex);
    } finally {
        JpaUtil.closeEntityManager(em);
    }
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:25,代码来源:EclipseLinkCrudRepository.java

示例9: selectTuples

import javax.persistence.Tuple; //导入依赖的package包/类
@Test
public void selectTuples() {
	log.info("... selectTuples ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> q = cb.createTupleQuery();
	Root<Author> author = q.from(Author.class);
	q.multiselect(author.get(Author_.firstName).alias("firstName"), 
					author.get(Author_.lastName).alias("lastName"));

	TypedQuery<Tuple> query = em.createQuery(q);
	List<Tuple> authorNames = query.getResultList();

	for (Tuple authorName : authorNames) {
		log.info(authorName.get("firstName") + " "
				+ authorName.get("lastName"));
	}

	em.getTransaction().commit();
	em.close();
}
 
开发者ID:thjanssen,项目名称:HibernateTips,代码行数:25,代码来源:TestCriteriaTuples.java

示例10: callSizeFunction

import javax.persistence.Tuple; //导入依赖的package包/类
@Test
public void callSizeFunction() {
	log.info("... callSizeFunction ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createTupleQuery();
	Root<Author> root = cq.from(Author.class);
	cq.multiselect(root, cb.size(root.get(Author_.books)));
	cq.groupBy(root.get(Author_.id));
	
	TypedQuery<Tuple> q = em.createQuery(cq);
	List<Tuple> results = q.getResultList();
	
	for (Tuple r :  results) {
		log.info(r.get(0) + " wrote " +  r.get(1) + " books.");
	}

	em.getTransaction().commit();
	em.close();
}
 
开发者ID:thjanssen,项目名称:HibernateTips,代码行数:24,代码来源:TestCriteriaFunction.java

示例11: getBooks

import javax.persistence.Tuple; //导入依赖的package包/类
@Test
public void getBooks() {
	log.info("... getBooks ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Tuple> cq = cb.createTupleQuery();
	Root<Book> root = cq.from(Book.class);
	cq.multiselect(root.get(Book_.title), root.get(Book_.publishingDate));
			
	List<Tuple> results = em.createQuery(cq).getResultList();
	
	for (Tuple r : results) {
		log.info(r.get(0) + " was published on " + r.get(1));
	}
	
	em.getTransaction().commit();
	em.close();
}
 
开发者ID:thjanssen,项目名称:HibernateTips,代码行数:22,代码来源:TestMetamodel.java

示例12: getSecureResult

import javax.persistence.Tuple; //导入依赖的package包/类
private <R> R getSecureResult(R result) {
    if (result == null) {
        return null;
    }
    if (isSimplePropertyType(result.getClass())) {
        return result;
    }
    if (result instanceof Tuple) {
        return (R)new SecureTuple((Tuple)result);
    }
    if (!(result instanceof Object[])) {
        return result;
    }
    Object[] scalarResult = (Object[])result;
    List<Object> entitiesToIgnore = new ArrayList<Object>();
    for (int i = 0; i < scalarResult.length; i++) {
        if (scalarResult[i] != null && !isSimplePropertyType(scalarResult[i].getClass())) {
            entitiesToIgnore.add(scalarResult[i]);
        }
    }
    DefaultAccessManager.Instance.get().ignoreChecks(AccessType.READ, entitiesToIgnore);
    return (R)scalarResult;
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:24,代码来源:SecureQuery.java

示例13: shouldUseTuple

import javax.persistence.Tuple; //导入依赖的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);
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:18,代码来源:JpaCriteriaTest.java

示例14: populate

import javax.persistence.Tuple; //导入依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @param input JAVADOC.
 *
 * @return JAVADOC.
 */
protected Collection<ProcessToken> populate(Collection<Tuple> input) {
    Collection<ProcessToken> result = new ArrayList<ProcessToken>();

    for (Tuple tuple : input) {
        ProcessToken wt = (ProcessToken) tuple.get(0);
        PersistableEntity pe = (PersistableEntity) tuple.get(1);

        Assert.notNull(wt, "token should not be null");
        Assert.notNull(pe, "domain should not be null");
        wt.setDomainObject(pe);
        result.add(wt);
    }

    return result;
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:23,代码来源:WorkflowRepositorySupport.java

示例15: findByProcessDefinitionId

import javax.persistence.Tuple; //导入依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @param wfid JAVADOC.
 *
 * @return JAVADOC.
 */
@Override
public Collection<ProcessToken> findByProcessDefinitionId(String wfid) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> tcq = cb.createTupleQuery();
    Root<ProcessToken> rt = tcq.from(ProcessToken.class);
    Predicate tokp = cb.equal(rt.get("processDefinitionId"), wfid);
    Path<Object> pid = rt.get("domainObjectId");

    Root<EntityDescriptor> rc = tcq.from(EntityDescriptor.class);
    Predicate clap = cb.equal(pid, rc.get("localId"));

    tcq.multiselect(rt, rc).where(cb.and(clap, tokp));

    Collection<Tuple> results = entityManager.createQuery(tcq).getResultList();

    if ((results == null) || (results.size() == 0)) {
        LOG.warn("Failed to find workflow instances for the workflowId:" + wfid);

        return Collections.emptyList();
    }

    return populate(results);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:31,代码来源:ProcessTokenRepositoryImpl.java


注:本文中的javax.persistence.Tuple类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。