@Test public void loadCategoryMapping() throws Exception { final GenericDAO<Shop, Long> shopDao = this.context.mock(GenericDAO.class, "shopDao"); final GenericDAO<Category, Long> categoryDao = this.context.mock(GenericDAO.class, "categoryDao"); this.context.checking(new Expectations() {{ allowing(categoryDao).findQueryObjectByNamedQuery("CATEGORY.PARENT.LINK.ALL"); will(returnValue(dbCategories)); }}); final ShopCategoryRelationshipSupportImpl support = new ShopCategoryRelationshipSupportImpl(shopDao, categoryDao) { @Override public ShopCategoryRelationshipSupport getSelf() { return this; } }; final Map<Long, Set<Long>> mapping = support.loadCategoryMapping(); assertEquals(6, mapping.size()); final Set<Long> _100 = mapping.get(100L); assertEquals(4, _100.size()); assertTrue(_100.containsAll(Arrays.asList(101L, 102L, 103L, 104L))); final Set<Long> _101 = mapping.get(101L); assertEquals(3, _101.size()); assertTrue(_101.containsAll(Arrays.asList(1010L, 1011L, 1012L))); final Set<Long> _102 = mapping.get(102L); assertEquals(2, _102.size()); assertTrue(_102.containsAll(Arrays.asList(1020L, 1021L))); final Set<Long> _104 = mapping.get(104L); assertEquals(1, _104.size()); assertTrue(_104.containsAll(Arrays.asList(1040L))); final Set<Long> _1040 = mapping.get(1040L); assertEquals(5, _1040.size()); assertTrue(_1040.containsAll(Arrays.asList(10400L, 10401L, 101L, 10402L, 1021L))); final Set<Long> _10401 = mapping.get(10401L); assertEquals(3, _10401.size()); assertTrue(_10401.containsAll(Arrays.asList(1010L, 1011L, 1012L))); this.context.assertIsSatisfied(); }
Map<Long, Set<Long>> loadCategoryMapping() { final List<Object[]> idParentLinkList = (List) this.categoryDao.findQueryObjectByNamedQuery("CATEGORY.PARENT.LINK.ALL"); final Map<Long, Set<Long>> all = new HashMap<>(idParentLinkList.size() + 100); final List<Object[]> idParentLinkList2 = new ArrayList<>(idParentLinkList.size() > 100 ? 10 : idParentLinkList.size() / 10); for (final Object[] idParentLink : idParentLinkList) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; if (parent > 0L && !id.equals(parent)) { final Set<Long> children = all.computeIfAbsent(parent, k -> new HashSet<>()); children.add(id); if (link != null) { children.add(link); } } if (link != null) { idParentLinkList2.add(idParentLink); } } for (final Object[] idParentLink : idParentLinkList2) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; Set<Long> linkedChildren = all.get(link); if (linkedChildren != null) { all.put(id, linkedChildren); } } for (final Map.Entry<Long, Set<Long>> entry : all.entrySet()) { all.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue())); } return Collections.unmodifiableMap(all); }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { Map<Long, Set<Long>> loadCategoryMapping() { final List<Object[]> idParentLinkList = (List) this.categoryDao.findQueryObjectByNamedQuery("CATEGORY.PARENT.LINK.ALL"); final Map<Long, Set<Long>> all = new HashMap<>(idParentLinkList.size() + 100); final List<Object[]> idParentLinkList2 = new ArrayList<>(idParentLinkList.size() > 100 ? 10 : idParentLinkList.size() / 10); for (final Object[] idParentLink : idParentLinkList) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; if (parent > 0L && !id.equals(parent)) { final Set<Long> children = all.computeIfAbsent(parent, k -> new HashSet<>()); children.add(id); if (link != null) { children.add(link); } } if (link != null) { idParentLinkList2.add(idParentLink); } } for (final Object[] idParentLink : idParentLinkList2) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; Set<Long> linkedChildren = all.get(link); if (linkedChildren != null) { all.put(id, linkedChildren); } } for (final Map.Entry<Long, Set<Long>> entry : all.entrySet()) { all.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue())); } return Collections.unmodifiableMap(all); } }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { Map<Long, Set<Long>> loadCategoryMapping() { final List<Object[]> idParentLinkList = (List) this.categoryDao.findQueryObjectByNamedQuery("CATEGORY.PARENT.LINK.ALL"); final Map<Long, Set<Long>> all = new HashMap<>(idParentLinkList.size() + 100); final List<Object[]> idParentLinkList2 = new ArrayList<>(idParentLinkList.size() > 100 ? 10 : idParentLinkList.size() / 10); for (final Object[] idParentLink : idParentLinkList) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; if (parent > 0L && !id.equals(parent)) { final Set<Long> children = all.computeIfAbsent(parent, k -> new HashSet<>()); children.add(id); if (link != null) { children.add(link); } } if (link != null) { idParentLinkList2.add(idParentLink); } } for (final Object[] idParentLink : idParentLinkList2) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; Set<Long> linkedChildren = all.get(link); if (linkedChildren != null) { all.put(id, linkedChildren); } } for (final Map.Entry<Long, Set<Long>> entry : all.entrySet()) { all.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue())); } return Collections.unmodifiableMap(all); } ShopCategoryRelationshipSupportImpl(final GenericDAO<Shop, Long> shopDao,
                                               final GenericDAO<Category, Long> categoryDao); }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { Map<Long, Set<Long>> loadCategoryMapping() { final List<Object[]> idParentLinkList = (List) this.categoryDao.findQueryObjectByNamedQuery("CATEGORY.PARENT.LINK.ALL"); final Map<Long, Set<Long>> all = new HashMap<>(idParentLinkList.size() + 100); final List<Object[]> idParentLinkList2 = new ArrayList<>(idParentLinkList.size() > 100 ? 10 : idParentLinkList.size() / 10); for (final Object[] idParentLink : idParentLinkList) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; if (parent > 0L && !id.equals(parent)) { final Set<Long> children = all.computeIfAbsent(parent, k -> new HashSet<>()); children.add(id); if (link != null) { children.add(link); } } if (link != null) { idParentLinkList2.add(idParentLink); } } for (final Object[] idParentLink : idParentLinkList2) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; Set<Long> linkedChildren = all.get(link); if (linkedChildren != null) { all.put(id, linkedChildren); } } for (final Map.Entry<Long, Set<Long>> entry : all.entrySet()) { all.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue())); } return Collections.unmodifiableMap(all); } ShopCategoryRelationshipSupportImpl(final GenericDAO<Shop, Long> shopDao,
                                               final GenericDAO<Category, Long> categoryDao); @Override List<Shop> getAll(); @Override Category getCategoryById(final long pk); @Override CategoryRelationDTO getCategoryRelationById(final long categoryId); @Override Set<Long> getCategoryParentsIds(final long categoryId); @Override Set<Long> getCategoryLinkedIds(long categoryId); @Override Map<Long, Set<Long>> getAllCategoriesIdsMap(); @Override Set<Long> getShopCategoriesIds(final long shopId); @Override Set<Long> getCatalogCategoriesIds(final long branchId); ShopCategoryRelationshipSupport getSelf(); }
ShopCategoryRelationshipSupportImpl implements ShopCategoryRelationshipSupport { Map<Long, Set<Long>> loadCategoryMapping() { final List<Object[]> idParentLinkList = (List) this.categoryDao.findQueryObjectByNamedQuery("CATEGORY.PARENT.LINK.ALL"); final Map<Long, Set<Long>> all = new HashMap<>(idParentLinkList.size() + 100); final List<Object[]> idParentLinkList2 = new ArrayList<>(idParentLinkList.size() > 100 ? 10 : idParentLinkList.size() / 10); for (final Object[] idParentLink : idParentLinkList) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; if (parent > 0L && !id.equals(parent)) { final Set<Long> children = all.computeIfAbsent(parent, k -> new HashSet<>()); children.add(id); if (link != null) { children.add(link); } } if (link != null) { idParentLinkList2.add(idParentLink); } } for (final Object[] idParentLink : idParentLinkList2) { final Long id = (Long) idParentLink[0]; final Long parent = (Long) idParentLink[1]; final Long link = (Long) idParentLink[2]; Set<Long> linkedChildren = all.get(link); if (linkedChildren != null) { all.put(id, linkedChildren); } } for (final Map.Entry<Long, Set<Long>> entry : all.entrySet()) { all.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue())); } return Collections.unmodifiableMap(all); } ShopCategoryRelationshipSupportImpl(final GenericDAO<Shop, Long> shopDao,
                                               final GenericDAO<Category, Long> categoryDao); @Override List<Shop> getAll(); @Override Category getCategoryById(final long pk); @Override CategoryRelationDTO getCategoryRelationById(final long categoryId); @Override Set<Long> getCategoryParentsIds(final long categoryId); @Override Set<Long> getCategoryLinkedIds(long categoryId); @Override Map<Long, Set<Long>> getAllCategoriesIdsMap(); @Override Set<Long> getShopCategoriesIds(final long shopId); @Override Set<Long> getCatalogCategoriesIds(final long branchId); ShopCategoryRelationshipSupport getSelf();  }