當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。