@Test public void testFindLastUpgradeForCluster() throws Exception { RequestEntity requestEntity = new RequestEntity(); requestEntity.setRequestId(1L); requestEntity.setClusterId(clusterId.longValue()); requestEntity.setStatus(HostRoleStatus.PENDING); requestEntity.setStages(new ArrayList<StageEntity>()); requestDAO.create(requestEntity); UpgradeEntity entity1 = new UpgradeEntity(); entity1.setId(11L); entity1.setClusterId(clusterId.longValue()); entity1.setDirection(Direction.UPGRADE); entity1.setRequestId(1L); entity1.setFromVersion("2.2.0.0-1234"); entity1.setToVersion("2.3.0.0-4567"); entity1.setUpgradeType(UpgradeType.ROLLING); entity1.setUpgradePackage("test-upgrade"); entity1.setDowngradeAllowed(true); dao.create(entity1); UpgradeEntity entity2 = new UpgradeEntity(); entity2.setId(22L); entity2.setClusterId(clusterId.longValue()); entity2.setDirection(Direction.DOWNGRADE); entity2.setRequestId(1L); entity2.setFromVersion("2.3.0.0-4567"); entity2.setToVersion("2.2.0.0-1234"); entity2.setUpgradeType(UpgradeType.ROLLING); entity2.setUpgradePackage("test-upgrade"); entity2.setDowngradeAllowed(true); dao.create(entity2); UpgradeEntity entity3 = new UpgradeEntity(); entity3.setId(33L); entity3.setClusterId(clusterId.longValue()); entity3.setDirection(Direction.UPGRADE); entity3.setRequestId(1L); entity3.setFromVersion("2.2.0.0-1234"); entity3.setToVersion("2.3.1.1-4567"); entity3.setUpgradeType(UpgradeType.ROLLING); entity3.setUpgradePackage("test-upgrade"); entity3.setDowngradeAllowed(true); dao.create(entity3); UpgradeEntity lastUpgradeForCluster = dao.findLastUpgradeForCluster(clusterId.longValue(), Direction.UPGRADE); assertNotNull(lastUpgradeForCluster); assertEquals(33L, (long)lastUpgradeForCluster.getId()); }
@RequiresSession public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class); query.setMaxResults(1); query.setParameter("clusterId", clusterId); query.setParameter("direction", direction); query.setHint(QueryHints.REFRESH, HintValues.TRUE); return daoUtils.selectSingle(query); }
UpgradeDAO { @RequiresSession public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class); query.setMaxResults(1); query.setParameter("clusterId", clusterId); query.setParameter("direction", direction); query.setHint(QueryHints.REFRESH, HintValues.TRUE); return daoUtils.selectSingle(query); } }
UpgradeDAO { @RequiresSession public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class); query.setMaxResults(1); query.setParameter("clusterId", clusterId); query.setParameter("direction", direction); query.setHint(QueryHints.REFRESH, HintValues.TRUE); return daoUtils.selectSingle(query); }  }
UpgradeDAO { @RequiresSession public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class); query.setMaxResults(1); query.setParameter("clusterId", clusterId); query.setParameter("direction", direction); query.setHint(QueryHints.REFRESH, HintValues.TRUE); return daoUtils.selectSingle(query); }  @RequiresSession List<UpgradeEntity> findAll(); @RequiresSession List<UpgradeEntity> findUpgrades(long clusterId); @RequiresSession UpgradeEntity findUpgrade(long upgradeId); @RequiresSession UpgradeEntity findUpgradeByRequestId(Long requestId); @Transactional void create(UpgradeEntity entity); @Transactional void removeAll(long clusterId); @RequiresSession UpgradeGroupEntity findUpgradeGroup(Long groupId); @RequiresSession UpgradeItemEntity findUpgradeItem(long itemId); @RequiresSession UpgradeItemEntity findUpgradeItemByRequestAndStage(Long requestId, Long stageId); @RequiresSession UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction); @RequiresSession UpgradeEntity findLastUpgradeOrDowngradeForCluster(long clusterId); @Transactional UpgradeEntity merge(UpgradeEntity upgradeEntity); }
UpgradeDAO { @RequiresSession public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class); query.setMaxResults(1); query.setParameter("clusterId", clusterId); query.setParameter("direction", direction); query.setHint(QueryHints.REFRESH, HintValues.TRUE); return daoUtils.selectSingle(query); }  @RequiresSession List<UpgradeEntity> findAll(); @RequiresSession List<UpgradeEntity> findUpgrades(long clusterId); @RequiresSession UpgradeEntity findUpgrade(long upgradeId); @RequiresSession UpgradeEntity findUpgradeByRequestId(Long requestId); @Transactional void create(UpgradeEntity entity); @Transactional void removeAll(long clusterId); @RequiresSession UpgradeGroupEntity findUpgradeGroup(Long groupId); @RequiresSession UpgradeItemEntity findUpgradeItem(long itemId); @RequiresSession UpgradeItemEntity findUpgradeItemByRequestAndStage(Long requestId, Long stageId); @RequiresSession UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction); @RequiresSession UpgradeEntity findLastUpgradeOrDowngradeForCluster(long clusterId); @Transactional UpgradeEntity merge(UpgradeEntity upgradeEntity);  }