项目:osc-core
文件:DeploymentSpecEntityMgr.java
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;
}
}
@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 @R_863_4045@ionFrame frame = new @R_863_4045@ionFrame();
frame.setMessage("No reservation found!");
frame.setVisible(true);
} finally {
session.close();
}
return reservationsList;
}
@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;
}
项目:osc-core
文件:LabelEntityMgr.java
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;
}
}
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;
}
}
项目:osc-core
文件:PolicyEntityMgr.java
/**
* 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;
}
@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;
}
}
@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",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;
}
项目:Guestbook9001
文件:DefaultEntryDao.java
@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;
}
项目:FHIR-CQL-ODM-service
文件:CrfElmQueryService.java
@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;
}
}
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;
}
}
@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 @R_863_4045@ionFrame frame = new @R_863_4045@ionFrame();
frame.setMessage("There is no reservation at this date!");
frame.setVisible(true);
} finally {
session.close();
}
return theReservation;
}
项目:sucok-framework
文件:BaseDao.java
/**
* 根据某些属性获取对象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;
}
}
@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;
});
}
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"),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;
});
}
private SecurityGroupInterfaceEntity getSecurityGroupInterfaceById(String id,DeviceEntity device)
throws Exception {
return this.txControl.supports(() -> {
CriteriaBuilder cb = IsmSecurityGroupInterfaceApi.this.em.getCriteriaBuilder();
CriteriaQuery<SecurityGroupInterfaceEntity> query = cb.createquery(SecurityGroupInterfaceEntity.class);
Root<SecurityGroupInterfaceEntity> root = query.from(SecurityGroupInterfaceEntity.class);
query.select(root).where(cb.equal(root.get("id"),Long.valueOf(id)),device));
SecurityGroupInterfaceEntity result = null;
try {
result = IsmSecurityGroupInterfaceApi.this.em.createquery(query).getSingleResult();
} catch (noresultException e) {
LOG.error(String.format("Cannot find Security group interface with id %s under device %s",id,device.getId()));
}
return result;
});
}
项目:osc-core
文件:ApplianceEntityMgr.java
public static Appliance findByModel(EntityManager em,String model) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Appliance> query = cb.createquery(Appliance.class);
Root<Appliance> root = query.from(Appliance.class);
query = query.select(root)
.where(cb.equal(root.get("model"),model));
try {
return em.createquery(query).getSingleResult();
} catch (noresultException nre) {
return null;
}
}
项目:oscm-app
文件:TemplateFileDAO.java
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();
}
}
public static subnet findByOpenstackId(EntityManager em,String id) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<subnet> query = cb.createquery(subnet.class);
Root<subnet> root = query.from(subnet.class);
query = query.select(root)
.where(cb.equal(root.get("openstackId"),id));
try {
return em.createquery(query).getSingleResult();
} catch (noresultException nre) {
return null;
}
}
@Override
public Payment getLastPayment() {
Payment thePayment = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Payment> query = session.createquery("from Payment order by Id DESC",Payment.class);
query.setMaxResults(1);
thePayment = query.getSingleResult();
logging.setMessage("PaymentDaoImpl -> fetching last payment for today...");
} catch (noresultException e) {
logging.setMessage("PaymentDaoImpl Error ->" + e.getLocalizedMessage());
} finally {
session.close();
}
return thePayment;
}
@Override
public Payment getEarlyPaymentByRoomNumber(String number) {
Payment thePayment = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Payment> query = session.createquery(
"from Payment where roomNumber = :theRoomNumber and title = 'EARLY PAYMENT'",Payment.class);
query.setParameter("theRoomNumber",number);
query.setMaxResults(1);
thePayment = query.getSingleResult();
logging.setMessage("PaymentDaoImpl -> fetching early payment by room number...");
} catch (noresultException e) {
logging.setMessage("PaymentDaoImpl Error ->" + e.getLocalizedMessage());
} finally {
session.close();
}
return thePayment;
}
项目:Homework
文件:MasterDaoImp.java
@Override
public boolean findMaster(Master master)
{
if (master == null)
{
return false;
}
String hql = "select m from Master m where m.username = :username and m.password = :password";
try
{
Master m = hib.getSession().createquery(hql,Master.class)
.setParameter("username",master.getName())
.setParameter("password",master.getpassword())
.getSingleResult();
}
catch (noresultException e)
{
return false;
}
return true;
}
@Override
public User getUserByName(String theName) {
User user = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<User> query = session.createquery("from User where NickName=:theName",User.class);
query.setParameter("theName",theName);
user = query.getSingleResult();
logging.setMessage("UserDaoImpl -> user "+user.getNickName()+" saved successfully.");
} catch (noresultException e) {
session.getTransaction().rollback();
logging.setMessage("UserDaoImpl : " + e.getLocalizedMessage());
} finally {
session.close();
}
return user;
}
@Override
public List<Reservation> getReservsAsWaitlist(String reservDate) {
List<Reservation> reservationsList = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Reservation> query = session.createquery("from Reservation "
+ "where bookStatus = 'WAITLIST' and checkinDate=:today",reservDate);
reservationsList = query.getResultList();
logging.setMessage("ReservationDaoImpl -> fetching all waiting reservations...");
} catch (noresultException e) {
logging.setMessage("ReservationDaoImpl Error -> " + e.getLocalizedMessage());
} finally {
session.close();
}
return reservationsList;
}
项目:Your-Microservice
文件:IdentityProviderEntityManagerImpl.java
@Override
@Transactional(readOnly = true)
public YourEntity findYourEntityByEmail(String email) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<YourEntity> criteriaQuery = criteriaBuilder.createquery(YourEntity.class);
final Root<YourEntity> yourEntityRoot = criteriaQuery.from(YourEntity.class);
criteriaQuery.select(yourEntityRoot);
criteriaQuery.where(criteriaBuilder.equal(yourEntityRoot.get("entityEmailAddress"),email));
try {
return entityManager.createquery(criteriaQuery).getSingleResult();
} catch(noresultException nre) {
return null;
}
}
项目:oscm
文件:TenantDao.java
public TenantSetting getTenantSetting(String settingKey,String tenantId)
throws ObjectNotFoundException {
Tenant tenant = this.getTenantByTenantId(tenantId);
Query query = dataManager
.createNamedQuery("TenantSetting.findByBusinessKey");
query.setParameter("tenant",tenant);
query.setParameter("name",IdpSettingType.valueOf(settingKey));
TenantSetting tenantSetting;
try {
tenantSetting = (TenantSetting) query.getSingleResult();
} catch (noresultException e) {
throw new ObjectNotFoundException(ClassEnum.TENANT_SETTING,settingKey + " for tenant: " + tenantId);
}
return tenantSetting;
}
@Override
public String getTotalCashLiraPostingsForOneDay(String today) {
String totalCash = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<String> query = session.createquery("select sum(price) from Posting where currency = 'TURKISH LIRA' and dateTime >= :today",String.class);
query.setParameter("today",today);
totalCash = query.getSingleResult();
logging.setMessage("PostingDaoImpl -> fetching total cash lira posting for one day...");
} catch (noresultException e) {
logging.setMessage("PostingDaoImpl Error -> " + e.getLocalizedMessage());
} finally {
session.close();
}
return totalCash;
}
@Override
public String getTotalCreditDollarPaymentsForOneDay(String date) {
String totalCredit = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<String> query = session.createquery(
"select sum(price) from Payment where "
+ "paymentType = 'CREDIT CARD' and currency = 'DOLLAR' and dateTime >= :date",date);
totalCredit = query.getSingleResult();
logging.setMessage("PaymentDaoImpl -> fetching total credit dollar for one day...");
} catch (noresultException e) {
logging.setMessage("PaymentDaoImpl Error ->" + e.getLocalizedMessage());
} finally {
session.close();
}
return totalCredit;
}
项目:cr-private-server
文件:AssetService.java
public AssetEntity get(String name) {
AssetEntity entity;
try (Session session = session()) {
try {
entity = session.createNamedQuery("AssetEntity.byName",AssetEntity.class)
.setParameter("name",name)
.getSingleResult();
} catch (noresultException ignored) {
entity = new AssetEntity();
entity.setName(name);
entity.setLastUpdated(new Date(System.currentTimeMillis()));
}
}
return entity;
}
项目:Guestbook9001
文件:DefaultEntryDao.java
@Override
public int getPageCount(int pagesize) {
EntityManager em = EntityManagerHelper.getEntityManager();
int numberofentries = 0;
try {
// sql count is always returned as long from JPA
TypedQuery q = em.createquery("select count(*) from Entry",Long.class);
numberofentries = Math.toIntExact((long)q.getSingleResult());
} catch(noresultException nre){
}
catch (Exception e){
throw new RuntimeException("Error getting pagecount",e);
}
EntityManagerHelper.closeEntityManager();
return (int) Math.ceil(numberofentries / pagesize);
}
@Override
public String getTotalCreditLiraPostingsForOneDay(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 = 'TURKISH LIRA' and dateTime >= :date",date);
totalCredit = query.getSingleResult();
logging.setMessage("PostingDaoImpl -> fetching total credit card lira posting for one day...");
} catch (noresultException e) {
logging.setMessage("PostingDaoImpl Error -> " + e.getLocalizedMessage());
} finally {
session.close();
}
return totalCredit;
}
项目:full-javaee-app
文件:ConversationDataAccessObject.java
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;
}
public List<Reservation> getGaranteedReservs(String reservDate) {
List<Reservation> reservationsList = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Reservation> query = session.createquery("from Reservation "
+ "where bookStatus = 'GUaraNTEE' and checkinDate=:today",reservDate);
reservationsList = query.getResultList();
logging.setMessage("ReservationDaoImpl -> fetching all garanteed reservations...");
} catch (noresultException e) {
logging.setMessage("ReservationDaoImpl Error -> " + e.getLocalizedMessage());
} finally {
session.close();
}
return reservationsList;
}
项目:oscm
文件:SharesDataRetrievalServiceBean.java
@Override
public BigDecimal loadOperatorRevenueSharePercentage(long serviceKey,long endPeriod) {
Query query = dm
.createNamedQuery("RevenueShareModelHistory.findOperatorRevenueSharePercentage");
query.setParameter("productObjKey",Long.valueOf(serviceKey));
query.setParameter("modDate",new Date(endPeriod));
query.setMaxResults(1);
BigDecimal percentage;
try {
RevenueShareModelHistory revenueShareModelHistory = (RevenueShareModelHistory) query
.getSingleResult();
percentage = revenueShareModelHistory.getDataContainer()
.getRevenueShare();
} catch (noresultException e) {
logger.logError(
Log4jLogger.SYstem_LOG,e,LogMessageIdentifier.ERROR_OPERATOR_REVENUE_SHARE_OF_SERVICE_NOT_FOUND,Long.toString(serviceKey));
throw e;
}
return percentage;
}
public List<Payment> getAllPaymentsForToday(String today) {
List<Payment> paymentsList = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Payment> query = session.createquery("from Payment where dateTime >= :today",Payment.class);
query.setParameter("today",today);
paymentsList = query.getResultList();
logging.setMessage("PaymentDaoImpl -> fetching all payments for today...");
} catch (noresultException e) {
logging.setMessage("PaymentDaoImpl Error ->" + e.getLocalizedMessage());
} finally {
session.close();
}
return paymentsList;
}
@Test (expected = FileUtilityException.class)
public void testCreateWithExistingBinaryFailsForNonExistentFile() throws IOException {
final Map<String,String> dataMap = new HashMap<>();
dataMap.put("name","tomcat");
dataMap.put("type","TOMCAT");
dataMap.put("remoteDir","c:/tomcat");
final Map<String,Object> mediaFileDataMap = new HashMap<>();
mediaFileDataMap.put("filename","apache-tomcat-test.zip");
mediaFileDataMap.put("content",new BufferedInputStream(new FileInputStream(new File("./src/test/resources/binaries/apache-tomcat-test.zip"))));
when(Config.mockMediaRepositoryService.upload(anyString(),any(InputStream.class)))
.thenReturn("/does/not.exist");
when(Config.mockMediaRepositoryService.getBinariesByBasename(anyString())).thenReturn(Collections.singletonList("./src/test/resources/binaries/apache-tomcat-test.zip"));
when(Config.mockMediaDao.findByNameAndType(anyString(),any(MediaType.class))).thenThrow(noresultException.class);
mediaService.create(dataMap,mediaFileDataMap);
}
public static SecurityGroup listSecurityGroupsByVcIdAndMgrId(EntityManager em,Long vcId,String mgrId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroup> query = cb.createquery(SecurityGroup.class);
Root<SecurityGroup> root = query.from(SecurityGroup.class);
query = query.select(root)
.where(cb.equal(root.join("virtualizationConnector").get("id"),vcId),cb.equal(root.join("securityGroupInterfaces").get("mgrSecurityGroupId"),mgrId))
.orderBy(cb.asc(root.get("name")));
try {
return em.createquery(query).getSingleResult();
} catch (noresultException nre) {
return null;
}
}
public List<Posting> getAllPostingsForToday(String today) {
List<Posting> postingsList = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Posting> query = session.createquery("from Posting where dateTime >= :today",Posting.class);
query.setParameter("today",today);
postingsList = query.getResultList();
logging.setMessage("PostingDaoImpl -> fetching all postings for today...");
} catch (noresultException e) {
logging.setMessage("PostingDaoImpl Error -> " + e.getLocalizedMessage());
} finally {
session.close();
}
return postingsList;
}
public List<Reservation> getReservationBetweenTwoDates(String checkinDate,String checkoutDate) {
List<Reservation> reservationsList = null;
try {
session = dataSourceFactory.getSessionFactory().openSession();
beginTransactionIfAllowed(session);
Query<Reservation> query = session.createquery("from Reservation AS r WHERE r.checkinDate BETWEEN :checkinDate AND :checkoutDate",Reservation.class);
query.setParameter("checkinDate",checkinDate);
query.setParameter("checkoutDate",checkoutDate);
reservationsList = query.getResultList();
if(reservationsList == null)
reservationsList = session.createquery("from Reservation",Reservation.class).getResultList();
logging.setMessage("ReservationDaoImpl -> fetching reservation that between two dates...");
} catch (noresultException e) {
logging.setMessage("ReservationDaoImpl Error -> " + e.getLocalizedMessage());
}
return reservationsList;
}
项目:osc-core
文件:NetworkEntityManager.java
public static Network findByOpenstackId(EntityManager em,String id) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Network> query = cb.createquery(Network.class);
Root<Network> root = query.from(Network.class);
query = query.select(root)
.where(cb.equal(root.get("openstackId"),id));
try {
return em.createquery(query).getSingleResult();
} catch (noresultException nre) {
return null;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。