Example usage for com.liferay.portal.kernel.cache.thread.local ThreadLocalCache removeAll

List of usage examples for com.liferay.portal.kernel.cache.thread.local ThreadLocalCache removeAll

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.cache.thread.local ThreadLocalCache removeAll.

Prototype

public void removeAll() 

Source Link

Usage

From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java

License:Open Source License

protected void testAdvancedSearch(String searchUserName, String searchTitle, String searchDescription,
        boolean andOperator, String title, String description, int expectedAssetEntriesCount) throws Exception {

    ThreadLocalCache<Object[]> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST,
            AssetEntryServiceImpl.class.getName());

    threadLocalCache.removeAll();

    AssetEntryQuery assetEntryQuery = buildAssetEntryQueryWithAdvancedSearch(_group.getGroupId(), andOperator,
            searchTitle, searchDescription, searchUserName);

    int initialAssetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    BlogsEntry blogsEntry1 = BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(),
            StringUtil.randomString(), StringPool.BLANK, StringUtil.randomString(),
            RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true, null, StringPool.BLANK, null, null,
            serviceContext);/*from  ww  w . j  a v a 2s . c  om*/

    BlogsEntry blogsEntry2 = BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), title,
            StringPool.BLANK, description, RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true, null,
            StringPool.BLANK, null, null, serviceContext);

    threadLocalCache.removeAll();

    int assetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    Assert.assertEquals(initialAssetEntriesCount + expectedAssetEntriesCount, assetEntriesCount);

    BlogsEntryLocalServiceUtil.deleteEntry(blogsEntry1);
    BlogsEntryLocalServiceUtil.deleteEntry(blogsEntry2);
}

From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java

License:Open Source License

protected void testAssetCategorization(long[] assetCategoryIds, String[] assetTagNames, String title1,
        long[] assetCategoryIds1, String[] assetTagNames1, String title2, long[] assetCategoryIds2,
        String[] assetTagNames2, boolean any, boolean not, int expectedAssetEntriesCount) throws Exception {

    ThreadLocalCache<Object[]> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST,
            AssetEntryServiceImpl.class.getName());

    threadLocalCache.removeAll();

    AssetEntryQuery assetEntryQuery = buildAssetEntryQuery(_group.getGroupId(), assetCategoryIds, assetTagNames,
            any, not);//from  www  .j a  v a  2s. c o  m

    int initialAssetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    if (assetCategoryIds1 != null) {
        serviceContext.setAssetCategoryIds(assetCategoryIds1);
    }

    if (assetTagNames1 != null) {
        serviceContext.setAssetTagNames(assetTagNames1);
    }

    BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), title1, StringPool.BLANK, StringPool.BLANK,
            RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true, null, StringPool.BLANK, null, null,
            serviceContext);

    if (assetCategoryIds2 != null) {
        serviceContext.setAssetCategoryIds(assetCategoryIds2);
    }

    if (assetTagNames2 != null) {
        serviceContext.setAssetTagNames(assetTagNames2);
    }

    BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), title2, StringPool.BLANK, StringPool.BLANK,
            RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true, null, StringPool.BLANK, null, null,
            serviceContext);

    threadLocalCache.removeAll();

    assetEntryQuery = buildAssetEntryQuery(_group.getGroupId(), assetCategoryIds, assetTagNames, any, not);

    int assetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    Assert.assertEquals(initialAssetEntriesCount + expectedAssetEntriesCount, assetEntriesCount);
}

From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java

License:Open Source License

protected void testAssetKeywords(String keywords, String title, String description,
        int expectedAssetEntriesCount) throws Exception {

    ThreadLocalCache<Object[]> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST,
            AssetEntryServiceImpl.class.getName());

    threadLocalCache.removeAll();

    AssetEntryQuery assetEntryQuery = buildAssetEntryQueryWithKeywords(_group.getGroupId(), keywords);

    int initialAssetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), StringUtil.randomString(),
            StringPool.BLANK, StringUtil.randomString(), RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true,
            true, null, StringPool.BLANK, null, null, serviceContext);

    BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), title, StringPool.BLANK, description,
            RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true, null, StringPool.BLANK, null, null,
            serviceContext);//  w w w  . j av  a  2  s.  c  om

    threadLocalCache.removeAll();

    int assetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    Assert.assertEquals(initialAssetEntriesCount + expectedAssetEntriesCount, assetEntriesCount);
}

From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java

License:Open Source License

protected void testOrderByRatings(double[] scores, double[] orderedScores, String orderByType)
        throws Exception {

    ThreadLocalCache<Object[]> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST,
            AssetEntryServiceImpl.class.getName());

    threadLocalCache.removeAll();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    Calendar displayDateCalendar = CalendarFactoryUtil.getCalendar(2012, 1, 1);

    for (int i = 0; i < scores.length; i++) {
        BlogsEntry blogsEntry = BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(),
                RandomTestUtil.randomString(), RandomTestUtil.randomString(), displayDateCalendar.getTime(),
                serviceContext);//w  w  w  . ja  v  a2s .c  om

        RatingsEntryServiceUtil.updateEntry(BlogsEntry.class.getName(), blogsEntry.getEntryId(), scores[i]);
    }

    threadLocalCache.removeAll();

    AssetEntryQuery assetEntryQuery = buildAssetEntryQuery(_group.getGroupId(), null, null, false, false);

    assetEntryQuery.setOrderByCol1("ratings");
    assetEntryQuery.setOrderByType1(orderByType);

    List<AssetEntry> assetEntries = AssetEntryServiceUtil.getEntries(assetEntryQuery);

    for (int i = 0; i < assetEntries.size(); i++) {
        AssetEntry assetEntry = assetEntries.get(i);

        RatingsStats ratingsStats = RatingsStatsLocalServiceUtil.getStats(assetEntry.getClassName(),
                assetEntry.getClassPK());

        Assert.assertEquals(ratingsStats.getAverageScore(), orderedScores[i], 0);
    }
}

From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java

License:Open Source License

protected void testOrderByViewCount(int[] viewCounts, int[] orderedViewCounts, String orderByType)
        throws Exception {

    ThreadLocalCache<Object[]> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST,
            AssetEntryServiceImpl.class.getName());

    threadLocalCache.removeAll();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    Calendar displayDateCalendar = CalendarFactoryUtil.getCalendar(2012, 1, 1);

    for (int i = 0; i < viewCounts.length; i++) {
        BlogsEntry entry = BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(),
                RandomTestUtil.randomString(), RandomTestUtil.randomString(), displayDateCalendar.getTime(),
                serviceContext);/*from  w w  w. j  a  va  2s  .  c o m*/

        AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(BlogsEntry.class.getName(),
                entry.getEntryId());

        assetEntry.setViewCount(viewCounts[i]);

        AssetEntryLocalServiceUtil.updateAssetEntry(assetEntry);
    }

    threadLocalCache.removeAll();

    AssetEntryQuery assetEntryQuery = buildAssetEntryQuery(_group.getGroupId(), null, null, false, false);

    assetEntryQuery.setOrderByCol1("viewCount");
    assetEntryQuery.setOrderByType1(orderByType);

    List<AssetEntry> assetEntries = AssetEntryServiceUtil.getEntries(assetEntryQuery);

    for (int i = 0; i < assetEntries.size(); i++) {
        AssetEntry assetEntry = assetEntries.get(i);

        Assert.assertEquals(assetEntry.getViewCount(), orderedViewCounts[i]);
    }
}