@Test public void testFindPluginDefinitionsForCategorySortedByPopularity() { sut.refreshGadgetDefinitionUserCounts(); PagedSet<PluginDefinition> results = sut.findForCategorySortedByPopularity("All", 0, 9); assertEquals(3, results.getPagedSet().size()); int firstNumberOfUsers = results.getPagedSet().get(0).getNumberOfUsers(); int secondNumberOfUsers = results.getPagedSet().get(1).getNumberOfUsers(); assertTrue(firstNumberOfUsers > secondNumberOfUsers); }
@SuppressWarnings("unchecked") @Override public void refreshGadgetDefinitionUserCounts() { Query q = getEntityManager().createQuery("from PluginDefinition gd"); List<PluginDefinition> pluginDefinitions = (List<PluginDefinition>) q.getResultList(); logger.debug("Retrieved: " + pluginDefinitions.size() + " Plugin defs from db"); q = getEntityManager().createQuery( "select f.streamPlugin.id " + "from Feed f , IN(f.feedSubscribers) fp group by f.streamPlugin.id, fp.entityId, fp.type"); List<Long> pluginDefinitionCountPerson = (List<Long>) q.getResultList(); if (logger.isDebugEnabled()) { logger.debug("Retrieved: " + pluginDefinitionCountPerson.size() + " UserCounts from db"); } for (PluginDefinition pD : pluginDefinitions) { int userCount = 0; for (Long pluginCount : pluginDefinitionCountPerson) { if (pluginCount == pD.getId()) { userCount++; } } pD.setNumberOfUsers(userCount); } getEntityManager().flush(); }
PluginDefinitionMapper extends CommonGadgetDefinitionMapper<PluginDefinition> implements
        GalleryItemMapper<PluginDefinition> { @SuppressWarnings("unchecked") @Override public void refreshGadgetDefinitionUserCounts() { Query q = getEntityManager().createQuery("from PluginDefinition gd"); List<PluginDefinition> pluginDefinitions = (List<PluginDefinition>) q.getResultList(); logger.debug("Retrieved: " + pluginDefinitions.size() + " Plugin defs from db"); q = getEntityManager().createQuery( "select f.streamPlugin.id " + "from Feed f , IN(f.feedSubscribers) fp group by f.streamPlugin.id, fp.entityId, fp.type"); List<Long> pluginDefinitionCountPerson = (List<Long>) q.getResultList(); if (logger.isDebugEnabled()) { logger.debug("Retrieved: " + pluginDefinitionCountPerson.size() + " UserCounts from db"); } for (PluginDefinition pD : pluginDefinitions) { int userCount = 0; for (Long pluginCount : pluginDefinitionCountPerson) { if (pluginCount == pD.getId()) { userCount++; } } pD.setNumberOfUsers(userCount); } getEntityManager().flush(); } }
PluginDefinitionMapper extends CommonGadgetDefinitionMapper<PluginDefinition> implements
        GalleryItemMapper<PluginDefinition> { @SuppressWarnings("unchecked") @Override public void refreshGadgetDefinitionUserCounts() { Query q = getEntityManager().createQuery("from PluginDefinition gd"); List<PluginDefinition> pluginDefinitions = (List<PluginDefinition>) q.getResultList(); logger.debug("Retrieved: " + pluginDefinitions.size() + " Plugin defs from db"); q = getEntityManager().createQuery( "select f.streamPlugin.id " + "from Feed f , IN(f.feedSubscribers) fp group by f.streamPlugin.id, fp.entityId, fp.type"); List<Long> pluginDefinitionCountPerson = (List<Long>) q.getResultList(); if (logger.isDebugEnabled()) { logger.debug("Retrieved: " + pluginDefinitionCountPerson.size() + " UserCounts from db"); } for (PluginDefinition pD : pluginDefinitions) { int userCount = 0; for (Long pluginCount : pluginDefinitionCountPerson) { if (pluginCount == pD.getId()) { userCount++; } } pD.setNumberOfUsers(userCount); } getEntityManager().flush(); } PluginDefinitionMapper(final QueryOptimizer inQueryOptimizer); }
PluginDefinitionMapper extends CommonGadgetDefinitionMapper<PluginDefinition> implements
        GalleryItemMapper<PluginDefinition> { @SuppressWarnings("unchecked") @Override public void refreshGadgetDefinitionUserCounts() { Query q = getEntityManager().createQuery("from PluginDefinition gd"); List<PluginDefinition> pluginDefinitions = (List<PluginDefinition>) q.getResultList(); logger.debug("Retrieved: " + pluginDefinitions.size() + " Plugin defs from db"); q = getEntityManager().createQuery( "select f.streamPlugin.id " + "from Feed f , IN(f.feedSubscribers) fp group by f.streamPlugin.id, fp.entityId, fp.type"); List<Long> pluginDefinitionCountPerson = (List<Long>) q.getResultList(); if (logger.isDebugEnabled()) { logger.debug("Retrieved: " + pluginDefinitionCountPerson.size() + " UserCounts from db"); } for (PluginDefinition pD : pluginDefinitions) { int userCount = 0; for (Long pluginCount : pluginDefinitionCountPerson) { if (pluginCount == pD.getId()) { userCount++; } } pD.setNumberOfUsers(userCount); } getEntityManager().flush(); } PluginDefinitionMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") @Override void refreshGadgetDefinitionUserCounts(); @Override void delete(final PluginDefinition inPlugin); }
PluginDefinitionMapper extends CommonGadgetDefinitionMapper<PluginDefinition> implements
        GalleryItemMapper<PluginDefinition> { @SuppressWarnings("unchecked") @Override public void refreshGadgetDefinitionUserCounts() { Query q = getEntityManager().createQuery("from PluginDefinition gd"); List<PluginDefinition> pluginDefinitions = (List<PluginDefinition>) q.getResultList(); logger.debug("Retrieved: " + pluginDefinitions.size() + " Plugin defs from db"); q = getEntityManager().createQuery( "select f.streamPlugin.id " + "from Feed f , IN(f.feedSubscribers) fp group by f.streamPlugin.id, fp.entityId, fp.type"); List<Long> pluginDefinitionCountPerson = (List<Long>) q.getResultList(); if (logger.isDebugEnabled()) { logger.debug("Retrieved: " + pluginDefinitionCountPerson.size() + " UserCounts from db"); } for (PluginDefinition pD : pluginDefinitions) { int userCount = 0; for (Long pluginCount : pluginDefinitionCountPerson) { if (pluginCount == pD.getId()) { userCount++; } } pD.setNumberOfUsers(userCount); } getEntityManager().flush(); } PluginDefinitionMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") @Override void refreshGadgetDefinitionUserCounts(); @Override void delete(final PluginDefinition inPlugin);  }