本文整理汇总了Java中javax.persistence.NoResultException类的典型用法代码示例。如果您正苦于以下问题:Java NoResultException类的具体用法?Java NoResultException怎么用?Java NoResultException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NoResultException类属于javax.persistence包,在下文中一共展示了NoResultException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findDeploymentSpecByVirtualSystemProjectAndRegion
import javax.persistence.NoResultException; //导入依赖的package包/类
public static DeploymentSpec findDeploymentSpecByVirtualSystemProjectAndRegion(EntityManager em, VirtualSystem vs,
String projectId, String region) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<DeploymentSpec> query = cb.createQuery(DeploymentSpec.class);
Root<DeploymentSpec> root = query.from(DeploymentSpec.class);
query = query.select(root)
.where(cb.equal(root.get("projectId"), projectId),
cb.equal(root.get("region"), region),
cb.equal(root.get("virtualSystem"), vs));
try {
return em.createQuery(query).getSingleResult();
} catch (NoResultException nre) {
return null;
}
}
示例2: getReservListByThisDate
import javax.persistence.NoResultException; //导入依赖的package包/类
@Override
public List<Reservation> getReservListByThisDate(String today) {
List<Reservation> reservationsList = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Reservation> query = session.createQuery("from Reservation where checkinDate=:today", Reservation.class);
query.setParameter("today", today);
reservationsList = query.getResultList();
logging.setMessage("ReservationDaoImpl -> fetching all reservations by date...");
} catch (NoResultException e) {
final InformationFrame frame = new InformationFrame();
frame.setMessage("No reservation found!");
frame.setVisible(true);
} finally {
session.close();
}
return reservationsList;
}
示例3: getTotalCreditDollarPostingsForOneDay
import javax.persistence.NoResultException; //导入依赖的package包/类
@Override
public String getTotalCreditDollarPostingsForOneDay(String date) {
String totalCredit = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<String> query = session.createQuery("select sum(price) from Posting where "
+ "currency = 'CREDIT CARD' and currency = 'DOLLAR' and dateTime >= :date", String.class);
query.setParameter("date", date);
totalCredit = query.getSingleResult();
logging.setMessage("PostingDaoImpl -> fetching total credit card dollar posting for one day...");
} catch (NoResultException e) {
logging.setMessage("PostingDaoImpl Error -> " + e.getLocalizedMessage());
} finally {
session.close();
}
return totalCredit;
}
示例4: findByValue
import javax.persistence.NoResultException; //导入依赖的package包/类
public static Label findByValue(EntityManager em, String labelValue, Long vcId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Label> query = cb.createQuery(Label.class);
Root<Label> root = query.from(Label.class);
query = query.select(root)
.where(cb.equal(root.get("value"), labelValue),
cb.equal(root.join("securityGroupMembers").join("securityGroup").join("virtualizationConnector").get("id"), vcId));
try {
return em.createQuery(query).getSingleResult();
} catch (NoResultException nre) {
return null;
}
}
示例5: findByApplianceVersionVirtTypeAndVersion
import javax.persistence.NoResultException; //导入依赖的package包/类
public static ApplianceSoftwareVersion findByApplianceVersionVirtTypeAndVersion(EntityManager em, Long applianceId, String av,
VirtualizationType vt, String vv) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ApplianceSoftwareVersion> query = cb.createQuery(ApplianceSoftwareVersion.class);
Root<ApplianceSoftwareVersion> root = query.from(ApplianceSoftwareVersion.class);
query = query.select(root)
.where(cb.equal(root.join("appliance").get("id"), applianceId),
cb.equal(cb.upper(root.get("applianceSoftwareVersion")), av.toUpperCase()),
cb.equal(root.get("virtualizationType"), vt),
cb.equal(cb.upper(root.get("virtualizationSoftwareVersion")), vv.toUpperCase())
);
try {
return em.createQuery(query).getSingleResult();
} catch (NoResultException nre) {
return null;
}
}
示例6: findPoliciesById
import javax.persistence.NoResultException; //导入依赖的package包/类
/**
* Verifies if the request contains valid policies supported by security manager available on the OSC.
* If the request contains one or more invalid policies, throw an exception.
*/
// TODO Larkins: Improve the method not to do the validation
public static Set<Policy> findPoliciesById(EntityManager em, Set<Long> ids, ApplianceManagerConnector mc)
throws VmidcBrokerValidationException, Exception {
Set<Policy> policies = new HashSet<>();
Set<String> invalidPolicies = new HashSet<>();
for (Long id : ids) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Policy> query = cb.createQuery(Policy.class);
Root<Policy> root = query.from(Policy.class);
query = query.select(root).where(cb.equal(root.get("id"), id),
cb.equal(root.join("applianceManagerConnector").get("id"), mc.getId()));
try {
Policy policy = em.createQuery(query).getSingleResult();
policies.add(policy);
} catch (NoResultException nre) {
invalidPolicies.add(id.toString());
}
}
if (invalidPolicies.size() > 0) {
throw new VmidcBrokerValidationException(
"Invalid Request. Request contains invalid policies: " + String.join(", ", invalidPolicies));
}
return policies;
}
示例7: findByName
import javax.persistence.NoResultException; //导入依赖的package包/类
@Override
public Community findByName(String name) {
LOG.info("findByName(name = " + name + ")");
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Community> criteria = builder.createQuery(Community.class);
Root<Community> community = criteria.from(Community.class);
criteria.where(builder.equal(community.get("name"), name));
TypedQuery<Community> query = em.createQuery(criteria);
try {
Community c = query.getSingleResult();
return initializeCom(c);
} catch (NoResultException e) {
LOG.error(e.toString());
return null;
}
}
示例8: getTotalCreditPoundPostingsForOneDay
import javax.persistence.NoResultException; //导入依赖的package包/类
@Override
public String getTotalCreditPoundPostingsForOneDay(String date) {
String totalCredit = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<String> query = session.createQuery("select sum(price) from Posting where "
+ "currency = 'CREDIT CARD' and currency = 'POUND' and dateTime >= :date", String.class);
query.setParameter("date", date);
totalCredit = query.getSingleResult();
logging.setMessage("PostingDaoImpl -> fetching total credit card pound posting for one day...");
} catch (NoResultException e) {
logging.setMessage("PostingDaoImpl Error -> " + e.getLocalizedMessage());
} finally {
session.close();
}
return totalCredit;
}
示例9: getEntries
import javax.persistence.NoResultException; //导入依赖的package包/类
@Override
public List<Entry> getEntries(int page, int pagesize) {
List<Entry> entries = new ArrayList<>();
EntityManager em = EntityManagerHelper.getEntityManager();
try{
TypedQuery<Entry> typedQuery = em.createQuery("select e from Entry e order by e.creationTimestamp", Entry.class);
typedQuery.setFirstResult((page - 1)*pagesize);
typedQuery.setMaxResults(pagesize);
entries = typedQuery.getResultList();
} catch (NoResultException nre){
}
catch (Exception e) {
throw new RuntimeException("Error getting pagecount", e);
}
return entries;
}
示例10: findByGroupId
import javax.persistence.NoResultException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public List<CrfElmQuery> findByGroupId(Integer project_id, Integer event_id, String instrument) {
try {
if(event_id == null){//not required
return (List<CrfElmQuery>) em.createNamedQuery("CrfElmQuery.findByProjectInstrument")
.setParameter("project_id", project_id)
.setParameter("instrument", instrument)
.getResultList();
}else{
return (List<CrfElmQuery>) em.createNamedQuery("CrfElmQuery.findByProjectEventInstrument")
.setParameter("project_id", project_id)
.setParameter("event_id", event_id)
.setParameter("instrument", instrument)
.getResultList();
}
} catch (NoResultException e) {
return null;
}
}
开发者ID:Discovery-Research-Network-SCCM,项目名称:FHIR-CQL-ODM-service,代码行数:20,代码来源:CrfElmQueryService.java
示例11: findExternalId
import javax.persistence.NoResultException; //导入依赖的package包/类
public static Pod findExternalId(EntityManager em, String externalId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Pod> query = cb.createQuery(Pod.class);
Root<Pod> root = query.from(Pod.class);
query = query.select(root)
.where(cb.equal(root.get("externalId"), externalId));
try {
return em.createQuery(query).getSingleResult();
} catch (NoResultException nre) {
return null;
}
}
示例12: findSingleReservByThisDate
import javax.persistence.NoResultException; //导入依赖的package包/类
@Override
public Reservation findSingleReservByThisDate(String Date) {
Reservation theReservation = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Reservation> query = session.createQuery("from Reservation where checkinDate=:Date", Reservation.class);
query.setParameter("Date", Date);
theReservation = query.getSingleResult();
logging.setMessage("ReservationDaoImpl -> fetching reservation by date...");
} catch (NoResultException e) {
final InformationFrame frame = new InformationFrame();
frame.setMessage("There is no reservation at this date!");
frame.setVisible(true);
} finally {
session.close();
}
return theReservation;
}
示例13: findOneByProperty
import javax.persistence.NoResultException; //导入依赖的package包/类
/**
* 根据某些属性获取对象L
* @param name 属性名称
* @param value 属性值
* @param lockMode 对象锁类型
* @return
*/
public T findOneByProperty(String name, Object value, LockModeType lockMode) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> query = cb.createQuery(entityClass);
Root<T> root = query.from(entityClass);
query.where(cb.equal(QueryFormHelper.getPath(root, name), value));
TypedQuery<T> typedQuery = em.createQuery(query);
typedQuery.setLockMode(lockMode);
try {
List<T> list = typedQuery.getResultList();
if (list.isEmpty()) {
return null;
} else {
return list.get(0);
}
} catch (NoResultException e) {
return null;
}
}
示例14: getSecurityGroupById
import javax.persistence.NoResultException; //导入依赖的package包/类
@Override
public ManagerSecurityGroupElement getSecurityGroupById(String mgrSecurityGroupId) throws Exception {
if (mgrSecurityGroupId == null) {
return null;
}
DeviceEntity device = this.validationUtil.getDeviceOrThrow(this.vs.getMgrId());
return this.txControl.supports(() -> {
CriteriaBuilder cb = IsmSecurityGroupApi.this.em.getCriteriaBuilder();
CriteriaQuery<SecurityGroupEntity> query = cb.createQuery(SecurityGroupEntity.class);
Root<SecurityGroupEntity> root = query.from(SecurityGroupEntity.class);
query.select(root).where(cb.equal(root.get("id"), Long.valueOf(mgrSecurityGroupId)),
cb.equal(root.get("device"), device));
SecurityGroupEntity result = null;
try {
result = IsmSecurityGroupApi.this.em.createQuery(query).getSingleResult();
} catch (NoResultException e) {
LOG.error(String.format("Cannot find Security group with id %s under device %s", mgrSecurityGroupId,
device.getId()));
}
return result;
});
}
示例15: findSecurityGroupByName
import javax.persistence.NoResultException; //导入依赖的package包/类
private SecurityGroupEntity findSecurityGroupByName(final String name, DeviceEntity device) throws Exception {
return this.txControl.supports(() -> {
CriteriaBuilder cb = IsmSecurityGroupApi.this.em.getCriteriaBuilder();
CriteriaQuery<SecurityGroupEntity> query = cb.createQuery(SecurityGroupEntity.class);
Root<SecurityGroupEntity> root = query.from(SecurityGroupEntity.class);
query.select(root).where(cb.equal(root.get("name"), name), cb.equal(root.get("device"), device));
SecurityGroupEntity result = null;
try {
result = IsmSecurityGroupApi.this.em.createQuery(query).getSingleResult();
} catch (NoResultException e) {
LOG.error(
String.format("Cannot find Security group with name %s under device %s", name, device.getId()));
}
return result;
});
}