本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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())));
}