@Test public void testFindSelectedByType() throws Exception { HostConfigMapping entity1 = createEntity(1L, "h1", "global", "version1"); HostEntity hostEntity = hostDAO.findByName("h1"); HostConfigMapping target = hostConfigMappingDAO.findSelectedByType(1L, hostEntity.getHostId(), "core-site"); Assert.assertNull("Expected null entity for type 'core-site'", target); target = hostConfigMappingDAO.findSelectedByType(1L, hostEntity.getHostId(), "global"); Assert.assertNotNull("Expected non-null entity for type 'global'", target); Assert.assertEquals("Expected version to be '" + entity1.getVersion() + "'", entity1.getVersion(), target.getVersion()); target.setSelected(0); hostConfigMappingDAO.merge(target); HostConfigMapping entity2 = createEntity(1L, "h1", "global", "version2"); target = hostConfigMappingDAO.findSelectedByType(1L, hostEntity.getHostId(), "global"); Assert.assertNotNull("Expected non-null entity for type 'global'", target); Assert.assertEquals("Expected version to be '" + entity2.getVersion() + "'", entity2.getVersion(), target.getVersion()); Assert.assertEquals("Expected instance equality", entity2, target); }
@RequiresSession public HostConfigMapping findSelectedByType(final long clusterId, Long hostId, final String type) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return null; Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostId)); HostConfigMapping result = (HostConfigMapping) CollectionUtils.find(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getType().equals(type) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return result; }
HostConfigMappingDAO { @RequiresSession public HostConfigMapping findSelectedByType(final long clusterId, Long hostId, final String type) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return null; Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostId)); HostConfigMapping result = (HostConfigMapping) CollectionUtils.find(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getType().equals(type) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return result; } }
HostConfigMappingDAO { @RequiresSession public HostConfigMapping findSelectedByType(final long clusterId, Long hostId, final String type) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return null; Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostId)); HostConfigMapping result = (HostConfigMapping) CollectionUtils.find(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getType().equals(type) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return result; }  }
HostConfigMappingDAO { @RequiresSession public HostConfigMapping findSelectedByType(final long clusterId, Long hostId, final String type) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return null; Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostId)); HostConfigMapping result = (HostConfigMapping) CollectionUtils.find(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getType().equals(type) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return result; }  @Transactional void create(HostConfigMapping hostConfigMapping); @Transactional HostConfigMapping merge(HostConfigMapping hostConfigMapping); @RequiresSession Set<HostConfigMapping> findByType(final long clusterId, Long hostId, final String type); @RequiresSession HostConfigMapping findSelectedByType(final long clusterId,
      Long hostId, final String type); @RequiresSession Set<HostConfigMapping> findSelected(final long clusterId, Long hostId); @RequiresSession Set<HostConfigMapping> findSelectedByHosts(Collection<Long> hostIds); @RequiresSession Map<String, List<HostConfigMapping>> findSelectedHostsByTypes(final long clusterId,
                                                                             Collection<String> types); @RequiresSession List<HostConfigMappingEntity> findAll(); @Transactional void removeByHostId(Long hostId); @Transactional void removeByClusterAndHostName(final long clusterId, String hostName); HostConfigMappingEntity buildHostConfigMappingEntity(HostConfigMapping hostConfigMapping); HostConfigMapping buildHostConfigMapping(
      HostConfigMappingEntity hostConfigMappingEntity); }
HostConfigMappingDAO { @RequiresSession public HostConfigMapping findSelectedByType(final long clusterId, Long hostId, final String type) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return null; Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostId)); HostConfigMapping result = (HostConfigMapping) CollectionUtils.find(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getType().equals(type) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return result; }  @Transactional void create(HostConfigMapping hostConfigMapping); @Transactional HostConfigMapping merge(HostConfigMapping hostConfigMapping); @RequiresSession Set<HostConfigMapping> findByType(final long clusterId, Long hostId, final String type); @RequiresSession HostConfigMapping findSelectedByType(final long clusterId,
      Long hostId, final String type); @RequiresSession Set<HostConfigMapping> findSelected(final long clusterId, Long hostId); @RequiresSession Set<HostConfigMapping> findSelectedByHosts(Collection<Long> hostIds); @RequiresSession Map<String, List<HostConfigMapping>> findSelectedHostsByTypes(final long clusterId,
                                                                             Collection<String> types); @RequiresSession List<HostConfigMappingEntity> findAll(); @Transactional void removeByHostId(Long hostId); @Transactional void removeByClusterAndHostName(final long clusterId, String hostName); HostConfigMappingEntity buildHostConfigMappingEntity(HostConfigMapping hostConfigMapping); HostConfigMapping buildHostConfigMapping(
      HostConfigMappingEntity hostConfigMappingEntity);  }