public HostConfigMappingEntity buildHostConfigMappingEntity(HostConfigMapping hostConfigMapping) { HostConfigMappingEntity hostConfigMappingEntity = new HostConfigMappingEntity(); hostConfigMappingEntity.setClusterId(hostConfigMapping.getClusterId()); hostConfigMappingEntity.setCreateTimestamp(hostConfigMapping.getCreateTimestamp()); hostConfigMappingEntity.setHostName(hostConfigMapping.getHostName()); hostConfigMappingEntity.setSelected(hostConfigMapping.getSelected()); hostConfigMappingEntity.setServiceName(hostConfigMapping.getServiceName()); hostConfigMappingEntity.setType(hostConfigMapping.getType()); hostConfigMappingEntity.setUser(hostConfigMapping.getUser()); hostConfigMappingEntity.setVersion(hostConfigMapping.getVersion()); return hostConfigMappingEntity; }
private void populateCache() { if (!cacheLoaded) { gl.writeLock().lock(); try { gl.writeLock().lock(); try { if (hostConfigMappingByHost == null) { hostConfigMappingByHost = new WeakHashMap<String, Set<HostConfigMapping>>(); TypedQuery<HostConfigMappingEntity> query = entityManagerProvider .get() .createQuery( "SELECT entity FROM HostConfigMappingEntity entity", HostConfigMappingEntity.class); List<HostConfigMappingEntity> hostConfigMappingEntities = daoUtils.selectList(query); for (HostConfigMappingEntity hostConfigMappingEntity : hostConfigMappingEntities) { Set<HostConfigMapping> setByHost = hostConfigMappingByHost.get((hostConfigMappingEntity.getHostName())); if (setByHost == null) { setByHost = new HashSet<HostConfigMapping>(); hostConfigMappingByHost.put(hostConfigMappingEntity.getHostName(), setByHost); } HostConfigMapping hostConfigMapping = buildHostConfigMapping(hostConfigMappingEntity); setByHost.add(hostConfigMapping); } } } finally { gl.writeLock().unlock(); } } finally { gl.writeLock().unlock(); } cacheLoaded = true; } }