Example usage for javax.persistence PersistenceException getMessage

List of usage examples for javax.persistence PersistenceException getMessage

Introduction

In this page you can find the example usage for javax.persistence PersistenceException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public HotelRatePlan getHotelRatePlanInfo(int hotelInfoId, String ratePlanCode) {
    List<HotelRatePlan> ratePlans = null;

    try {/*  www .  j  a v a  2  s  .  c o  m*/
        //body
        ratePlans = getEm().createQuery(
                "select o from HotelRatePlan o where o.hotelInfo.id = :hotelId and o.ratePlanCode = :ratePlanCode")
                .setParameter("hotelId", hotelInfoId)
                .setParameter("ratePlanCode", Integer.parseInt(ratePlanCode)).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return ratePlans.size() > 0 ? ratePlans.get(0) : null;

}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<String> getAllHotelCodesByCityId(int cityId) {
    List<String> hotelCodes = new ArrayList<String>();
    Date baseTime = DateUtil.getCurDateTime();

    try {// ww w  .j  a  v  a  2  s.  c o m
        //body
        hotelCodes = getEm()
                .createQuery("select o.hotelCode from HotelInfo o where o.cityId = :cityId order by o.id")
                .setParameter("cityId", cityId).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    int span = DateUtil.getPastTime(baseTime);
    logger.info("get all hotel codes in city (" + cityId + ") elapsed: " + span + "ms.");

    return hotelCodes;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<String> getAllHotelCodes2(String cityCode) {
    List<String> hotelCodes = new ArrayList<String>();

    try {//from   w ww  .  ja  v a  2 s.  c  o  m
        //body
        Date date = DateUtil.getCurDate();
        date = DateUtil.add(date, -7);

        int cityId = getCityIdByCityCode(cityCode);

        if (cityId == 0) {
            hotelCodes = getEm().createQuery(
                    "select h.hotelCode from HotelInfo h where h.hotelCode not in (select o.hotelCode from CacheHotel o where o.cacheTime > :date)")
                    .setParameter("date", date).getResultList();
        } else {
            hotelCodes = getEm().createQuery(
                    "select h.hotelCode from HotelInfo h where h.cityId = :cityId and h.hotelCode not in (select o.hotelCode from CacheHotel o where o.cacheTime > :date)")
                    .setParameter("date", date).setParameter("cityId", cityId).getResultList();
        }

    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return hotelCodes;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<String> getHotelCodes4RatePlan(int periodId, String cityCode, int ratePlanStatus) {
    List<String> hotelCodes = new ArrayList<String>();

    try {//from  w  ww  .ja  v a  2s  .c  om
        //body
        Date date = DateUtil.getCurDate();
        date = DateUtil.add(date, -7);

        int cityId = getCityIdByCityCode(cityCode);

        //logger.info("[getHotelCodes4RatePlan] " + DateUtil.formatDate(date, "yyyy-MM-dd") + "," + periodId + "," + cityId + "," + cityCode);

        Date baseTime = DateUtil.getCurDateTime();
        if (cityId == 0) {
            hotelCodes = getEm().createQuery(
                    "select h.hotelCode from HotelInfo h where h.ratePlanStatus = :ratePlanStatus and h.hotelCode not in (select o.hotelCode from CacheRatePlan o where o.cacheTime > :date and o.periodId = :periodId) order by h.id")
                    .setParameter("ratePlanStatus", ratePlanStatus).setParameter("date", date)
                    .setParameter("periodId", periodId).setMaxResults(10000).getResultList();
        } else {
            hotelCodes = getEm().createQuery(
                    "select h.hotelCode from HotelInfo h where h.ratePlanStatus = :ratePlanStatus and h.cityId = :cityId and  h.hotelCode not in (select o.hotelCode from CacheRatePlan o where o.cacheTime > :date and o.periodId = :periodId) order by h.id")
                    .setParameter("ratePlanStatus", ratePlanStatus).setParameter("date", date)
                    .setParameter("periodId", periodId).setParameter("cityId", cityId).setMaxResults(10000)
                    .getResultList();
        }
        //int span = DateUtil.getPastTime(baseTime);
        //logger.info("[getHotelCodes4RatePlan] elapsed time: " + span + " ms, size: " + hotelCodes.size() + ", period id: " + periodId);
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return hotelCodes;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<String> getHotelCodes4RatePlan(int periodId, String cityCode) {
    List<String> hotelCodes = new ArrayList<String>();

    try {/* ww w .java  2 s  .co m*/
        //body
        Date date = DateUtil.getCurDate();
        date = DateUtil.add(date, -7);

        int cityId = getCityIdByCityCode(cityCode);

        logger.info("[getHotelCodes4RatePlan] " + DateUtil.formatDate(date, "yyyy-MM-dd") + "," + periodId + ","
                + cityId + "," + cityCode);

        Date baseTime = DateUtil.getCurDateTime();
        if (cityId == 0) {
            hotelCodes = getEm().createQuery(
                    "select h.hotelCode from HotelInfo h where h.ratePlanStatus != -1 and h.hotelCode not in (select o.hotelCode from CacheRatePlan o where o.cacheTime > :date and o.periodId = :periodId) order by h.id")
                    .setParameter("date", date).setParameter("periodId", periodId).setMaxResults(10000)
                    .getResultList();
        } else {
            hotelCodes = getEm().createQuery(
                    "select h.hotelCode from HotelInfo h where h.ratePlanStatus != -1 and h.cityId = :cityId and  h.hotelCode not in (select o.hotelCode from CacheRatePlan o where o.cacheTime > :date and o.periodId = :periodId) order by h.id")
                    .setParameter("date", date).setParameter("periodId", periodId)
                    .setParameter("cityId", cityId).setMaxResults(10000).getResultList();
        }
        int span = DateUtil.getPastTime(baseTime);
        logger.info("[getHotelCodes4RatePlan] elapsed time: " + span + " ms, size: " + hotelCodes.size()
                + ", period id: " + periodId);
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return hotelCodes;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<HotelRatePlan> searchAvailableHotelRatePlan(int hotelId, Date checkInDate, Date checkOutDate) {
    List<HotelRatePlan> ratePlans = null;

    try {/*from   w w w . j av a  2 s.co  m*/
        //body
        ratePlans = getEm().createQuery("select o from HotelRatePlan o "
                + " left join fetch o.hotelRatePlanBookingRules " + " where o.hotelInfo.id = :hotelId")
                .setParameter("hotelId", hotelId).getResultList();
        for (HotelRatePlan rp : ratePlans) {
            //get offer info
            List<HotelRatePlanOffer> offers = getEm()
                    .createQuery("select o from HotelRatePlanOffer o where o.hotelRatePlan = :ratePlan")
                    .setParameter("ratePlan", rp).getResultList();
            rp.setHotelRatePlanOffers(offers);

            List<HotelRatePlanRate> rates = getEm().createQuery(
                    "select o from HotelRatePlanRate o " + " left join fetch o.hotelRatePlanRatePromotions " +
                    //" left join fetch o.hotelRatePlanRateGuaranteePolicies " +
                            "where o.startDate >= :startDate " + " and o.startDate < :endDate "
                            + " and o.hotelRatePlan.id = :id")
                    .setParameter("id", rp.getId()).setParameter("startDate", checkInDate)
                    .setParameter("endDate", checkOutDate).getResultList();
            for (HotelRatePlanRate rate : rates) {
                List<HotelRatePlanRateGuaranteePolicy> guaranteePolicies = getEm()
                        .createQuery("select o from HotelRatePlanRateGuaranteePolicy o"
                                + " where o.hotelRatePlanRate = :rate")
                        .setParameter("rate", rate).getResultList();
                rate.setHotelRatePlanRateGuaranteePolicies(guaranteePolicies);

                List<HotelRatePlanRateCancelPolicy> cancelPolicies = getEm()
                        .createQuery("select o from HotelRatePlanRateCancelPolicy o"
                                + " where o.hotelRatePlanRate = :rate")
                        .setParameter("rate", rate).getResultList();
                rate.setHotelRatePlanRateCancelPolicies(cancelPolicies);
            }

            rp.setHotelRatePlanRates(rates);
        }
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return ratePlans;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
//@Transactional/*from   w  w  w  .  jav  a 2s .c  o m*/
public HotelInfo getHotelDetailInfoByHotelCode(String hotelCode) {
    HotelInfo hotelInfo = null;

    try {
        List<HotelInfo> hotelInfos = getEm()
                .createQuery("select o from HotelInfo o   where o.hotelCode = :hotelCode ")
                .setParameter("hotelCode", hotelCode).getResultList();
        if (hotelInfos.size() > 0) {
            hotelInfo = hotelInfos.get(0);

            hotelInfo.setHotelAddressZones(
                    getEm().createQuery("select o from HotelAddressZone o where o.hotelInfo = :hotelInfo")
                            .setParameter("hotelInfo", hotelInfo).getResultList());

            // hotelInfo.getHotelServices().size();
            hotelInfo.setHotelServices(
                    getEm().createQuery("select o from HotelServiceInfo o where o.hotelInfo = :hotelInfo")
                            .setParameter("hotelInfo", hotelInfo).getResultList());
            //hotelInfo.getHotelAwards().size();
            hotelInfo.setHotelAwards(
                    getEm().createQuery("select o from HotelAward o where o.hotelInfo = :hotelInfo")
                            .setParameter("hotelInfo", hotelInfo).getResultList());
            // hotelInfo.getRelativePositions().size();
            hotelInfo.setRelativePositions(
                    getEm().createQuery("select o from HotelRelativePosition o where o.hotelInfo = :hotelInfo")
                            .setParameter("hotelInfo", hotelInfo).getResultList());
            //hotelInfo.getGuestRooms().size();
            hotelInfo.setGuestRooms(
                    getEm().createQuery("select o from HotelGuestRoom o where o.hotelInfo = :hotelInfo")
                            .setParameter("hotelInfo", hotelInfo).getResultList());
            // hotelInfo.getRefPoints().size();
            hotelInfo.setRefPoints(
                    getEm().createQuery("select o from HotelRefPoint o where o.hotelInfo = :hotelInfo")
                            .setParameter("hotelInfo", hotelInfo).getResultList());
            //hotelInfo.getMedias().size();
            hotelInfo.setMedias(
                    getEm().createQuery("select o from HotelMultimediaInfo o where o.hotelInfo = :hotelInfo")
                            .setParameter("hotelInfo", hotelInfo).getResultList());
        }
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return hotelInfo;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public HotelRatePlan searchAvailableHotelRatePlan(int hotelId, Date checkInDate, Date checkOutDate,
        int ratePlanCode) {
    List<HotelRatePlan> ratePlans = null;

    try {/*from  w  w  w .j  a v a2 s  . c o  m*/
        //body
        ratePlans = getEm()
                .createQuery("select o from HotelRatePlan o " + " left join fetch o.hotelRatePlanBookingRules "
                        + " where o.hotelInfo.id = :hotelId and o.ratePlanCode = :ratePlanCode")
                .setParameter("hotelId", hotelId).setParameter("ratePlanCode", ratePlanCode).getResultList();
        for (HotelRatePlan rp : ratePlans) {
            //get offer info
            List<HotelRatePlanOffer> offers = getEm()
                    .createQuery("select o from HotelRatePlanOffer o where o.hotelRatePlan = :ratePlan")
                    .setParameter("ratePlan", rp).getResultList();
            rp.setHotelRatePlanOffers(offers);

            List<HotelRatePlanRate> rates = getEm().createQuery(
                    "select o from HotelRatePlanRate o " + " left join fetch o.hotelRatePlanRatePromotions " +
                    //" left join fetch o.hotelRatePlanRateGuaranteePolicies " +
                            "where o.startDate >= :startDate " + " and o.startDate < :endDate "
                            + " and o.hotelRatePlan.id = :id")
                    .setParameter("id", rp.getId()).setParameter("startDate", checkInDate)
                    .setParameter("endDate", checkOutDate).getResultList();
            for (HotelRatePlanRate rate : rates) {
                List<HotelRatePlanRateGuaranteePolicy> guaranteePolicies = getEm()
                        .createQuery("select o from HotelRatePlanRateGuaranteePolicy o"
                                + " where o.hotelRatePlanRate = :rate")
                        .setParameter("rate", rate).getResultList();
                rate.setHotelRatePlanRateGuaranteePolicies(guaranteePolicies);

                List<HotelRatePlanRateCancelPolicy> cancelPolicies = getEm()
                        .createQuery("select o from HotelRatePlanRateCancelPolicy o"
                                + " where o.hotelRatePlanRate = :rate")
                        .setParameter("rate", rate).getResultList();
                rate.setHotelRatePlanRateCancelPolicies(cancelPolicies);
            }

            rp.setHotelRatePlanRates(rates);
        }
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return ratePlans.size() > 0 ? ratePlans.get(0) : null;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
public List<HotelInfo> searchAvailableHotel(HotelSearchCriteria sc) {

    List<HotelInfo> hotelInfos = null;

    try {//from   ww  w . ja v  a2  s .  co m
        //body
        CriteriaBuilder cb = getEm().getCriteriaBuilder();

        CriteriaQuery<HotelInfo> cq = cb.createQuery(HotelInfo.class);
        Root<HotelInfo> root = cq.from(HotelInfo.class);
        root.alias("h");

        List<Predicate> predicates = new ArrayList<Predicate>();

        Predicate predicate = cb.equal(root.get(HotelInfo_.cityId), sc.getCityId());
        predicates.add(predicate);

        /**
         * ratePlanStatus-1???)  yfddai 2015-1-8
         */
        predicate = cb.notEqual(root.get(HotelInfo_.ratePlanStatus), -1);
        predicates.add(predicate);

        if (sc.getDistrictId() > 0) {
            predicate = cb.equal(root.get(HotelInfo_.areaId), sc.getDistrictId());
            predicates.add(predicate);
        }

        if (sc.getHotelName() != null && sc.getHotelName().trim().length() > 0) {
            predicate = cb.like(root.get(HotelInfo_.hotelName), "%" + sc.getHotelName() + "%");
            predicates.add(predicate);
        }

        if (sc.getStar() != null && sc.getStar().length() > 0) {
            Join<HotelInfo, HotelAward> hotelAward = root.join("hotelAwards", JoinType.LEFT);
            hotelAward.alias("ha");

            predicates.add(cb.equal(hotelAward.get("provider"), "HotelStarRate"));

            String[] stars = sc.getStar().split(",");
            Predicate p0 = cb.disjunction();
            for (String star : stars) {
                if (star.length() == 0)
                    continue;
                int starLevel = Integer.parseInt(star);
                if (starLevel == 2)
                    p0 = cb.or(p0, cb.le(hotelAward.get(HotelAward_.rating), starLevel));
                else
                    p0 = cb.or(p0, cb.equal(hotelAward.get("rating"), starLevel));
            }
            predicates.add(p0);
        }

        if (sc.getZoneId() > 0) {
            Join<HotelInfo, HotelAddressZone> hotelZone = root.join(HotelInfo_.hotelAddressZones,
                    JoinType.LEFT);
            hotelZone.alias("hz");

            predicate = cb.equal(hotelZone.get(HotelAddressZone_.zoneCode), sc.getZoneId());
            predicates.add(predicate);
        }

        // count items
        CriteriaQuery<Long> cq0 = cb.createQuery(Long.class);
        Root<HotelInfo> root0 = cq0.from(HotelInfo.class);
        root0.alias("h");
        if (sc.getStar() != null && sc.getStar().length() > 0) {
            Join<HotelInfo, HotelAward> hotelAward0 = root0.join("hotelAwards", JoinType.LEFT);
            hotelAward0.alias("ha");
        }
        if (sc.getZoneId() > 0) {
            Join<HotelInfo, HotelAddressZone> hotelZone0 = root0.join(HotelInfo_.hotelAddressZones,
                    JoinType.LEFT);
            hotelZone0.alias("hz");
        }
        cq0.select(cb.count(root0)).where(predicates.toArray(new Predicate[0]));
        Long count = getEm().createQuery(cq0).getSingleResult();

        sc.getPage().setRowCount(count.intValue());

        int firstPosition = (sc.getPage().getPageNo() - 1) * sc.getPage().getPageSize();
        cq.select(root).where(predicates.toArray(new Predicate[0]));

        hotelInfos = getEm().createQuery(cq).setFirstResult(firstPosition)
                .setMaxResults(sc.getPage().getPageSize()).getResultList();
    } catch (PersistenceException e) {
        logger.error(e.getMessage());
    }

    return hotelInfos == null ? new ArrayList<HotelInfo>() : hotelInfos;
}

From source file:net.navasoft.madcoin.backend.model.controller.impl.EndUsersDataAccess.java

/**
 * Creates the.//  w w w.j  a  va  2s  .  c o  m
 * 
 * @param entity
 *            the entity
 * @return the end users
 * @since 2/09/2014, 09:31:48 PM
 */
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RollbackException.class,
        ConstraintViolationException.class, JDBCException.class })
public EndUsers create(EndUsers entity) {
    try {
        AppUsers super_user = new AppUsers();
        super_user.setCreatedOn(Calendar.getInstance().getTime());
        super_user = appUsersDao.create(super_user);
        AppUserXStatus statusRef = new AppUserXStatus();
        statusRef.setIdUser(super_user);
        statusRef.setIdUserStatus(new UserStatus(7));
        statusRef = userStatusDao.create(statusRef);
        entity.getEndUsersPK().setIdEndUser(super_user.getIdApplicationUsers());
        entity.setAppUsers(super_user);
        preConstruct(entity);
        entityManager.persist(entity);
        entityManager.flush();
        entity = getByLogicalId(entity.getNormalizedId());
        postConstruct(entity);
    } catch (PersistenceException e) {
        throw new AlreadyOnSourceException(e.getCause().getCause().getMessage());
    } catch (PreexistingEntityException e) {
        throw new AlreadyOnSourceException(e.getMessage());
    }
    return entity;
}