Java 类javax.persistence.NoResultException 实例源码

项目: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;
    }
}
项目:Hotel-Properties-Management-System    文件:ReservationDaoImpl.java   
@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;
}
项目:Hotel-Properties-Management-System    文件:PostingDaoImpl.java   
@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;
        }
    }
项目:osc-core    文件:ApplianceSoftwareVersionEntityMgr.java   
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;
}
项目:chr-krenn-fhj-ws2017-sd17-pse    文件:CommunityDAOImpl.java   
@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;
    }
}
项目:Hotel-Properties-Management-System    文件:PostingDaoImpl.java   
@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;
}
项目: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;
    }
}
项目:osc-core    文件:PodEntityMgr.java   
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;
        }
    }
项目:Hotel-Properties-Management-System    文件:ReservationDaoImpl.java   
@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;
}
项目: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;
    }
}
项目:security-mgr-sample-plugin    文件:IsmSecurityGroupApi.java   
@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;
    });
}
项目:security-mgr-sample-plugin    文件:IsmSecurityGroupApi.java   
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;
        });
    }
项目:security-mgr-sample-plugin    文件:IsmSecurityGroupInterfaceApi.java   
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)), cb.equal(root.get("device"), 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();
    }
}
项目:osc-core    文件:SubnetEntityManager.java   
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;
        }
    }
项目:Hotel-Properties-Management-System    文件:PaymentDaoImpl.java   
@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;
}
项目:Hotel-Properties-Management-System    文件:PaymentDaoImpl.java   
@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;
}
项目:Hotel-Properties-Management-System    文件:UserDaoImpl.java   
@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;
}
项目:Hotel-Properties-Management-System    文件:ReservationDaoImpl.java   
@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", Reservation.class);
        query.setParameter("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;
}
项目:Hotel-Properties-Management-System    文件:PostingDaoImpl.java   
@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;
}
项目:Hotel-Properties-Management-System    文件:PaymentDaoImpl.java   
@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",
                String.class);
        query.setParameter("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);
}
项目:Hotel-Properties-Management-System    文件:PostingDaoImpl.java   
@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", String.class);
        query.setParameter("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;
}
项目:Hotel-Properties-Management-System    文件:ReservationDaoImpl.java   
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", Reservation.class);
        query.setParameter("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;
}
项目:Hotel-Properties-Management-System    文件:PaymentDaoImpl.java   
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;
}
项目:jwala    文件:MediaServiceImplTest.java   
@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);
}
项目:osc-core    文件:SecurityGroupEntityMgr.java   
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;
    }
}
项目:Hotel-Properties-Management-System    文件:PostingDaoImpl.java   
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;
}
项目:Hotel-Properties-Management-System    文件:ReservationDaoImpl.java   
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;
        }
    }