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


Java TypedQuery类代码示例

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


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

示例1: getByName

import javax.persistence.TypedQuery; //导入依赖的package包/类
public static Certifications getByName(String name) {
    if (name != null && !name.isEmpty()) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        String query = "SELECT cert from Certifications cert where cert.certification = :name";

        try {
            TypedQuery<Certifications> q = em.createQuery(query, Certifications.class);
            q.setParameter("name", name);
            return q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            em.close();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:18,代码来源:CertificationPersistence.java

示例2: getPlayersByPositionAndName

import javax.persistence.TypedQuery; //导入依赖的package包/类
public List<PlayerDetails> getPlayersByPositionAndName(String position, String name) {
    logger.info("getPlayersByPositionAndName");
    List<Player> players = null;

    try {
        CriteriaQuery<Player> cq = cb.createQuery(Player.class);
        if (cq != null) {
            Root<Player> player = cq.from(Player.class);

            // Get MetaModel from Root
            //EntityType<Player> Player_ = player.getModel();

            // set the where clause
            cq.where(cb.equal(player.get(Player_.position), position),
                    cb.equal(player.get(Player_.name), name));
            cq.select(player).distinct(true);
            TypedQuery<Player> q = em.createQuery(cq);
            players = q.getResultList();
        }
        return copyPlayersToDetails(players);
    } catch (Exception ex) {
        throw new EJBException(ex);
    }
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:25,代码来源:RequestBeanQueries.java

示例3: getTaskCount

import javax.persistence.TypedQuery; //导入依赖的package包/类
public Long getTaskCount(Long jobId) throws InterruptedException, VmidcException {

        try {
            EntityManager em = this.dbMgr.getTransactionalEntityManager();
            return this.dbMgr.getTransactionControl().required(() -> {

                String hql = "SELECT count(*) FROM TaskRecord WHERE job_fk = :jobId";

                TypedQuery<Long> query = em.createQuery(hql, Long.class);
                query.setParameter("jobId", jobId);
                return query.getSingleResult();
            });
        } catch (ScopedWorkException swe) {
            throw swe.as(RuntimeException.class);
        }
    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:JobEntityManager.java

示例4: loadPriceModelStartDate

import javax.persistence.TypedQuery; //导入依赖的package包/类
@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public Date loadPriceModelStartDate(long priceModelKeyForSubscription) {
    TypedQuery<PriceModelHistory> query = dm.createNamedQuery(
            "PriceModelHistory.findByObjectAndProvisioningCompleted",
            PriceModelHistory.class);
    query.setParameter("objKey", Long.valueOf(priceModelKeyForSubscription));
    query.setParameter("provisioningCompleted", Boolean.TRUE);

    List<PriceModelHistory> resultList = query.getResultList();
    if (resultList.isEmpty()) {
        throw new BillingRunFailed(
                "History data is missing for price model with key "
                        + priceModelKeyForSubscription);
    }

    return resultList.get(0).getModdate();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:BillingDataRetrievalServiceBean.java

示例5: getAllPlayers

import javax.persistence.TypedQuery; //导入依赖的package包/类
public List<PlayerDetails> getAllPlayers() {
    logger.info("getAllPlayers");
    List<Player> players = null;

    try {
        CriteriaQuery<Player> cq = cb.createQuery(Player.class);
        if (cq != null) {
            Root<Player> player = cq.from(Player.class);

            cq.select(player);
            TypedQuery<Player> q = em.createQuery(cq);
            players = q.getResultList();
        }
        return copyPlayersToDetails(players);
    } catch (Exception ex) {
        throw new EJBException(ex);
    }
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:19,代码来源:RequestBeanQueries.java

示例6: queryButtonActionPerformed

import javax.persistence.TypedQuery; //导入依赖的package包/类
private void queryButtonActionPerformed(ActionEvent e)
{
   // query that returns all contacts
   TypedQuery<Addresses> findByLastname = 
      entityManager.createNamedQuery(
         "Addresses.findByLastname", Addresses.class);

   // configure parameter for query
   findByLastname.setParameter("lastname", queryTextField.getText());
   results = findByLastname.getResultList(); // get all addresses
   numberOfEntries = results.size();
   
   if (numberOfEntries != 0)
   {
      currentEntryIndex = 0;
      displayRecord();
      nextButton.setEnabled(true);
      previousButton.setEnabled(true);
   } 
   else
      browseButtonActionPerformed(e);
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:23,代码来源:AddressBook.java

示例7: findAll

import javax.persistence.TypedQuery; //导入依赖的package包/类
public List<PublisherEntity> findAll() {
	EntityManager em = connection.createEntityManager();
	List<PublisherEntity> result;
	
	try {
		em.getTransaction().begin();
		TypedQuery<PublisherEntity> query = em.createQuery("Select p from PublisherEntity p", PublisherEntity.class);
		result = query.getResultList();
		em.getTransaction().commit();
	} finally {
		if (em.getTransaction().isActive()) {
			em.getTransaction().rollback();
		}
		em.close();
	}
	
	return result;
}
 
开发者ID:PawelBogdan,项目名称:BecomeJavaHero,代码行数:19,代码来源:PublisherDAOImpl.java

示例8: getTemplateFilesByControllerId

import javax.persistence.TypedQuery; //导入依赖的package包/类
public List<TemplateFile> getTemplateFilesByControllerId(
        String controllerId) {

    TypedQuery<TemplateFile> query = em.createNamedQuery(
            "TemplateFile.getForControllerId", TemplateFile.class);
    query.setParameter("controllerId", controllerId);

    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return Collections.emptyList();
    }
}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:14,代码来源:TemplateFileDAO.java

示例9: countAuditLogs

import javax.persistence.TypedQuery; //导入依赖的package包/类
/**
 * count the number of auditLogs by operationIds and date range, if
 * operationIds is null or empty, count the number of AuditLogs only by date
 * range
 * 
 * @param operationIds
 * @param startTime
 * @param endTime
 * @return
 */
public long countAuditLogs(List<String> operationIds, long startTime,
        long endTime) {
    TypedQuery<Number> query;
    if (operationIds == null || operationIds.isEmpty()) {
        query = em.createNamedQuery("AuditLog.countByDateRange",
                Number.class);
    } else {
        query = em.createNamedQuery(
                "AuditLog.countByOperationAndDateRange", Number.class);
        query.setParameter("operationIds", operationIds);
    }
    query.setParameter("startTime", Long.valueOf(startTime));
    query.setParameter("endTime", Long.valueOf(endTime));
    return query.getSingleResult().longValue();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:AuditLogDao.java

示例10: findAll

import javax.persistence.TypedQuery; //导入依赖的package包/类
public List<BookEntity> findAll() {
	EntityManager em = connection.createEntityManager();
	List<BookEntity> result;
	
	try {
		em.getTransaction().begin();
		TypedQuery<BookEntity> query = em.createQuery("Select b from BookEntity b", BookEntity.class);
		result = query.getResultList();
		em.getTransaction().commit();
	} finally {
		if (em.getTransaction().isActive()) {
			em.getTransaction().rollback();
		}
		em.close();
	}
	
	return result;
}
 
开发者ID:PawelBogdan,项目名称:BecomeJavaHero,代码行数:19,代码来源:BookDAOImpl.java

示例11: loadAll

import javax.persistence.TypedQuery; //导入依赖的package包/类
public void loadAll() {

        List<DocumentDetail> ListDocumentDetail = new ArrayList<DocumentDetail>();

        Items it = new Items();
        EntityManager em = it.getEntityManager();
        TypedQuery<DocumentDetail> consultItems = em.createNamedQuery("DocumentDetail.findAll", DocumentDetail.class);
        ListDocumentDetail = consultItems.getResultList();

        ListProducts = new ArrayList<Products>();

        for (DocumentDetail selectedItem : ListDocumentDetail) {
            Products newProduct = new Products();
            newProduct.setArticulo(selectedItem.getItemId().getName());
            newProduct.setBodega(selectedItem.getWarehousesId().getName());
            if (selectedItem.getDocumentId().getTypedocId().getCode().equals("1")) {
                newProduct.setEntradas(selectedItem.getQuantity());
            } else {
                newProduct.setSallidas(selectedItem.getQuantity());

            }
            newProduct.setFecha(selectedItem.getDocumentId().getDocumentDate().toString());
            newProduct.setConsecutivo(selectedItem.getDocumentId().getConsecutive() + "");
            ListProducts.add(newProduct);
        }
    }
 
开发者ID:Whistler092,项目名称:programacion4-final,代码行数:27,代码来源:ControllerReports.java

示例12: test201_Insert

import javax.persistence.TypedQuery; //导入依赖的package包/类
@Test
public void test201_Insert() throws Exception {
    em.getTransaction().begin();

    Employee e = new Employee();
    e.setEmpNo(99999);
    e.setFirstName("John");
    e.setLastName("Doe");
    e.setBirthDate(DATE_FORMATTER.parse("2008-04-12"));
    e.setGender(Gender.MALE);
    e.setHireDate(DATE_FORMATTER.parse("2016-01-30"));
    e.setSalaries(null);
    em.persist(e);

    em.getTransaction().commit();

    TypedQuery<Employee> q = em.createQuery("select e from employee e where e.empNo = :empNo", Employee.class);
    q.setParameter("empNo", 99999);
    Employee inserted = q.getSingleResult();
    Assert.assertEquals(e, inserted);
}
 
开发者ID:jruesga,项目名称:phoenix-hibernate-dialect,代码行数:22,代码来源:PhoenixDialectTest.java

示例13: findRouteLegByFromToHQL

import javax.persistence.TypedQuery; //导入依赖的package包/类
/**
 * HQL version of the query
 */
private <T extends RouteLeg> RouteLeg findRouteLegByFromToHQL(GeoCoord from, GeoCoord to, Class clazz) throws DatabaseException {
    final String bikeQuery = "SELECT leg from BikeLeg leg WHERE leg.from = :fromGeo AND leg.to = :toGeo";
    final String carQuery = "SELECT leg from CarLeg leg WHERE leg.from = :fromGeo AND leg.to = :toGeo";

    try {
        TypedQuery<? extends RouteLeg> query;
        if (clazz == BikeLeg.class) {
            query = entityManager.createQuery(bikeQuery, BikeLeg.class);
        } else {
            query = entityManager.createQuery(carQuery, CarLeg.class);
        }

        List<? extends RouteLeg> resultList = query.setParameter("fromGeo", from)
                                                   .setParameter("toGeo", to)
                                                   .getResultList();

        return extractOne(resultList);

    } catch (IndexOutOfBoundsException e) {
        throw new DatabaseException("Could not find entity " + clazz + " for coordinates " + from + " -> " + to);
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:26,代码来源:RouteLegRepositoryImpl.java

示例14: getByClientAndCandidateID

import javax.persistence.TypedQuery; //导入依赖的package包/类
public static Conversations getByClientAndCandidateID(int clientID, int candidateID) throws NoResultException {
    if (clientID > 0 && candidateID > 0) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        String query = "SELECT c FROM Conversations c WHERE c.clientID = :clientID AND c.candidateID = :candidateID";
        try {
            TypedQuery<Conversations> q = em.createQuery(query, Conversations.class);
            q.setParameter("clientID", clientID);
            q.setParameter("candidateID", candidateID);
            Conversations conversation = q.getSingleResult();
            em.close();
            return conversation;
        } finally {
            if (em.isOpen()) {
                em.close();
            }
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:20,代码来源:ConversationDataAccessObject.java

示例15: subSelectTest

import javax.persistence.TypedQuery; //导入依赖的package包/类
@Test
   public void subSelectTest() {
StrQLBuilder jpa = StrQLBuilder.createJPQL()
	.select("p.id")
	.from("Person p")
	.where("not exists (:jpa)", StrQLBuilder.createNative()
		.select("1")
		.from("Job j")
		.where("j.id = p.id")
		.and("1 = :val", 1)
		.and("exists (:jpa2)", StrQLBuilder.createNative()
			.select("1")
			.from("Person p")
			.where("1 = :val2", 1)));
TypedQuery<Long> query = jpa.createQuery(entityManager, Long.class);
List<Long> persons = query.getResultList();
assertThat(persons, is(not(empty())));
   }
 
开发者ID:iaunzu,项目名称:strqlbuilder,代码行数:19,代码来源:StrQLBuilderJPQLTest.java


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