本文整理匯總了Java中javax.persistence.TypedQuery.setParameter方法的典型用法代碼示例。如果您正苦於以下問題:Java TypedQuery.setParameter方法的具體用法?Java TypedQuery.setParameter怎麽用?Java TypedQuery.setParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.TypedQuery
的用法示例。
在下文中一共展示了TypedQuery.setParameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testQuery
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Test
public void testQuery() {
TypedQuery<Forum> query = entityManager
.createQuery("select f from Forum f left outer join fetch f.topics where f.id = :forumId", Forum.class);
query.setParameter("forumId", 1);
List<Forum> forumList = query.getResultList();
assertEquals("simple query ok", 1, forumList.size());
query = entityManager.createNamedQuery("findForumByIdFetchTopics", Forum.class);
query.setParameter("forumId", 1);
forumList = query.getResultList();
assertEquals("named query ok", 1, forumList.size());
String namedQuery = "my_runtime_named_query";
entityManager.getEntityManagerFactory().addNamedQuery(namedQuery, query);
query = entityManager.createNamedQuery(namedQuery, Forum.class);
query.setParameter("forumId", 1);
forumList = query.getResultList();
assertEquals("named query ok", 1, forumList.size());
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:19,代碼來源:CommonTestCase.java
示例2: getAllEntitiesWithProduct
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
/**
* Gets all order items for the given productId.
* @param productId The id of the product ordered.
* @param start The index of the first orderItem to return. Negative value to start at the beginning.
* @param limit The maximum number of orderItem to return. Negative value to return all.
* @return List of order items with the specified product.
*/
public List<PersistenceOrderItem> getAllEntitiesWithProduct(long productId, int start, int limit) {
List<PersistenceOrderItem> entities = null;
EntityManager em = getEM();
try {
em.getTransaction().begin();
PersistenceProduct prod = em.find(PersistenceProduct.class, productId);
if (prod != null) {
TypedQuery<PersistenceOrderItem> allMatchesQuery =
em.createQuery("SELECT u FROM " + getEntityClass().getName()
+ " u WHERE u.product = :prod", getEntityClass());
allMatchesQuery.setParameter("prod", prod);
entities = resultsWithStartAndLimit(em, allMatchesQuery, start, limit);
}
em.getTransaction().commit();
} finally {
em.close();
}
if (entities == null) {
return new ArrayList<PersistenceOrderItem>();
}
return entities;
}
示例3: searchForUser
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public List<UserModel> searchForUser(String search, RealmModel realm, int firstResult, int maxResults) {
TypedQuery<UserEntity> query = em.createNamedQuery("searchForUser", UserEntity.class);
query.setParameter("search", "%" + search.toLowerCase() + "%");
if (firstResult != -1) {
query.setFirstResult(firstResult);
}
if (maxResults != -1) {
query.setMaxResults(maxResults);
}
List<UserEntity> results = query.getResultList();
List<UserModel> users = new LinkedList<>();
for (UserEntity entity : results)
users.add(new UserAdapter(session, realm, model, entity));
return users;
}
示例4: findById
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public List<BookEntity> findById(int id) {
EntityManager em = connection.createEntityManager();
List<BookEntity> result;
try {
em.getTransaction().begin();
TypedQuery<BookEntity> query = em.createQuery("Select b from BookEntity b where b.id = :id", BookEntity.class);
query.setParameter("id", id);
result = query.getResultList();
em.getTransaction().commit();
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return result;
}
示例5: loadAuditLogs
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
/**
* load auditLogs by operationIds and date range, if operationIds is null or
* empty, load auditLogs only by date range
*
* @param operationIds
* @param startTime
* @param endTime
* @return
*/
public List<AuditLog> loadAuditLogs(List<String> operationIds,
long startTime, long endTime) {
TypedQuery<AuditLog> query;
if (operationIds == null || operationIds.isEmpty()) {
query = em.createNamedQuery("AuditLog.findByDateRange",
AuditLog.class);
} else {
query = em.createNamedQuery("AuditLog.findByOperationAndDateRange",
AuditLog.class);
query.setParameter("operationIds", operationIds);
}
query.setParameter("startTime", Long.valueOf(startTime));
query.setParameter("endTime", Long.valueOf(endTime));
return query.getResultList();
}
示例6: createRole
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
private Role createRole() {
Role role = new Role();
role.setRole(ADMINISTRATOR);
TypedQuery<Role> query =_em.createQuery("select r from Role r where r.role=:roleName", Role.class);
query.setParameter("roleName", ADMINISTRATOR);
Role tmpRole = null;
try {
tmpRole = query.getSingleResult();
}
catch (javax.persistence.NoResultException exc) {
exc.printStackTrace();
}
if (tmpRole != null)
role = tmpRole;
return role;
}
示例7: cleanUp
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@AfterClass
public void cleanUp() {
// Delete S3 bucket
DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest(ContentHelper.getInstance().getConfiguredBucketName());
s3Client.deleteBucket(deleteBucketRequest);
EntityManager _em = Persistence.createEntityManager();
TypedQuery<User> query =_em.createQuery("select u from User u where u.userName=:userName", User.class);
query.setParameter("userName", _user.getUserName());
_user = query.getSingleResult();
query.setParameter("userName", sharedUser.getUserName());
sharedUser = query.getSingleResult();
_em.getTransaction().begin();
_em.remove(_user);
_em.remove(sharedUser);
_em.getTransaction().commit();
}
示例8: findCardActionMessagesByEtatFinal
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public static TypedQuery<CardActionMessage> findCardActionMessagesByEtatFinal(Etat etatFinal) {
if (etatFinal == null) throw new IllegalArgumentException("The etatFinal argument is required");
EntityManager em = CardActionMessage.entityManager();
TypedQuery<CardActionMessage> q = em.createQuery("SELECT o FROM CardActionMessage AS o WHERE o.etatFinal = :etatFinal", CardActionMessage.class);
q.setParameter("etatFinal", etatFinal);
return q;
}
示例9: getAccountByAccountNumber
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
/**
* Find account by names. Note this will throw {@link NoResultException} which will roll back the
* transaction if the account is not found.
*/
@LogDuration(limit = 50)
public VirtualAccount getAccountByAccountNumber(Long vaNumber) {
TypedQuery<VirtualAccount> q = em.createQuery("select va from VirtualAccount va where va.vaNumber=:number",
VirtualAccount.class);
q.setParameter("number", vaNumber);
return q.getSingleResult();
}
示例10: haalAfnemerindicatiesOp
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public List<PersoonAfnemerindicatie> haalAfnemerindicatiesOp(final long persoonId) {
final String query = "SELECT pc FROM PersoonAfnemerindicatie pc WHERE pc.persoon.id = :persoonIdIndicatie";
final TypedQuery<PersoonAfnemerindicatie> typedQuery =
entityManager.createQuery(query, PersoonAfnemerindicatie.class);
typedQuery.setParameter("persoonIdIndicatie", persoonId);
return typedQuery.getResultList();
}
示例11: findByPersonaAndEventSessionId
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public EventDataEntity findByPersonaAndEventSessionId(Long personaId, Long eventSessionId) {
TypedQuery<EventDataEntity> query = entityManager.createNamedQuery("EventDataEntity.findByPersonaAndEventSessionId", EventDataEntity.class);
query.setParameter("personaId", personaId);
query.setParameter("eventSessionId", eventSessionId);
List<EventDataEntity> resultList = query.getResultList();
return !resultList.isEmpty() ? resultList.get(0) : null;
}
示例12: findByUser
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
public PromoCodeEntity findByUser(UserEntity userEntity) {
TypedQuery<PromoCodeEntity> query = entityManager.createNamedQuery("PromoCodeEntity.findByUser", PromoCodeEntity.class);
query.setParameter("user", userEntity);
List<PromoCodeEntity> resultList = query.getResultList();
return !resultList.isEmpty() ? resultList.get(0) : null;
}
示例13: getTemplate
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public ShiftTemplate getTemplate(Integer tenantId) {
TypedQuery<ShiftTemplate> q = entityManager.createNamedQuery("ShiftTemplate.get", ShiftTemplate.class);
q.setParameter("tenantId", tenantId);
List<ShiftTemplate> result = q.getResultList();
if (result.isEmpty()) {
return null;
} else if (1 != result.size()) {
throw new IllegalStateException("Each tenant can only have 1 template! Found " + result.size()
+ "templates!");
} else {
return result.get(0);
}
}
示例14: haalLo3FilterRubriekenVoorDienstbundel
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public final List<String> haalLo3FilterRubriekenVoorDienstbundel(final Integer dienstbundelId) {
final TypedQuery<String> query = entityManager.createQuery(
"select rubrieken.lo3Rubriek.naam from DienstbundelLo3Rubriek rubrieken where rubrieken.dienstbundel.id = :dienstbundelId", String.class);
query.setParameter("dienstbundelId", dienstbundelId);
return query.getResultList();
}
示例15: findByCustomer
import javax.persistence.TypedQuery; //導入方法依賴的package包/類
@Override
public List<Account> findByCustomer(Customer customer) {
TypedQuery<Account> query = em.createQuery("select a from Account a where a.customer = ?1", Account.class);
query.setParameter(1, customer);
return query.getResultList();
}