@Test public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception { LayoutSet newLayoutSet = addLayoutSet(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newLayoutSet.getPrimaryKey()); Map<Serializable, LayoutSet> layoutSets = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, layoutSets.size()); Assert.assertEquals(newLayoutSet, layoutSets.get(newLayoutSet.getPrimaryKey())); }
@Override protected LayoutSet removeImpl(LayoutSet layoutSet) throws SystemException { layoutSet = toUnwrappedModel(layoutSet); Session session = null; try { session = openSession(); BatchSessionUtil.delete(session, layoutSet); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST); LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl) layoutSet; FinderCacheUtil.removeResult( FINDER_PATH_FETCH_BY_G_P, new Object[] { Long.valueOf(layoutSetModelImpl.getGroupId()), Boolean.valueOf(layoutSetModelImpl.getPrivateLayout()) }); EntityCacheUtil.removeResult( LayoutSetModelImpl.ENTITY_CACHE_ENABLED, LayoutSetImpl.class, layoutSet.getPrimaryKey()); return layoutSet; }
protected LayoutSet toUnwrappedModel(LayoutSet layoutSet) { if (layoutSet instanceof LayoutSetImpl) { return layoutSet; } LayoutSetImpl layoutSetImpl = new LayoutSetImpl(); layoutSetImpl.setNew(layoutSet.isNew()); layoutSetImpl.setPrimaryKey(layoutSet.getPrimaryKey()); layoutSetImpl.setLayoutSetId(layoutSet.getLayoutSetId()); layoutSetImpl.setGroupId(layoutSet.getGroupId()); layoutSetImpl.setCompanyId(layoutSet.getCompanyId()); layoutSetImpl.setPrivateLayout(layoutSet.isPrivateLayout()); layoutSetImpl.setLogo(layoutSet.isLogo()); layoutSetImpl.setLogoId(layoutSet.getLogoId()); layoutSetImpl.setThemeId(layoutSet.getThemeId()); layoutSetImpl.setColorSchemeId(layoutSet.getColorSchemeId()); layoutSetImpl.setWapThemeId(layoutSet.getWapThemeId()); layoutSetImpl.setWapColorSchemeId(layoutSet.getWapColorSchemeId()); layoutSetImpl.setCss(layoutSet.getCss()); layoutSetImpl.setPageCount(layoutSet.getPageCount()); layoutSetImpl.setSettings(layoutSet.getSettings()); layoutSetImpl.setLayoutSetPrototypeId(layoutSet.getLayoutSetPrototypeId()); return layoutSetImpl; }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist() throws Exception { LayoutSet newLayoutSet = addLayoutSet(); long pk = RandomTestUtil.nextLong(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newLayoutSet.getPrimaryKey()); primaryKeys.add(pk); Map<Serializable, LayoutSet> layoutSets = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, layoutSets.size()); Assert.assertEquals(newLayoutSet, layoutSets.get(newLayoutSet.getPrimaryKey())); }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist() throws Exception { LayoutSet newLayoutSet1 = addLayoutSet(); LayoutSet newLayoutSet2 = addLayoutSet(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newLayoutSet1.getPrimaryKey()); primaryKeys.add(newLayoutSet2.getPrimaryKey()); Map<Serializable, LayoutSet> layoutSets = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(2, layoutSets.size()); Assert.assertEquals(newLayoutSet1, layoutSets.get(newLayoutSet1.getPrimaryKey())); Assert.assertEquals(newLayoutSet2, layoutSets.get(newLayoutSet2.getPrimaryKey())); }
@Test public void testFetchByPrimaryKeyExisting() throws Exception { LayoutSet newLayoutSet = addLayoutSet(); LayoutSet existingLayoutSet = _persistence.fetchByPrimaryKey(newLayoutSet.getPrimaryKey()); Assert.assertEquals(existingLayoutSet, newLayoutSet); }
@Test public void testCreate() throws Exception { long pk = RandomTestUtil.nextLong(); LayoutSet layoutSet = _persistence.create(pk); Assert.assertNotNull(layoutSet); Assert.assertEquals(layoutSet.getPrimaryKey(), pk); }
@Test public void testRemove() throws Exception { LayoutSet newLayoutSet = addLayoutSet(); _persistence.remove(newLayoutSet); LayoutSet existingLayoutSet = _persistence.fetchByPrimaryKey(newLayoutSet.getPrimaryKey()); Assert.assertNull(existingLayoutSet); }
@Override public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet, boolean merge) throws SystemException { layoutSet = toUnwrappedModel(layoutSet); boolean isNew = layoutSet.isNew(); LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl) layoutSet; Session session = null; try { session = openSession(); BatchSessionUtil.update(session, layoutSet, merge); layoutSet.setNew(false); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST); EntityCacheUtil.putResult( LayoutSetModelImpl.ENTITY_CACHE_ENABLED, LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet); if (!isNew && ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId()) || (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) { FinderCacheUtil.removeResult( FINDER_PATH_FETCH_BY_G_P, new Object[] { Long.valueOf(layoutSetModelImpl.getOriginalGroupId()), Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout()) }); } if (isNew || ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId()) || (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) { FinderCacheUtil.putResult( FINDER_PATH_FETCH_BY_G_P, new Object[] { Long.valueOf(layoutSet.getGroupId()), Boolean.valueOf(layoutSet.getPrivateLayout()) }, layoutSet); } return layoutSet; }
public int compareTo(LayoutSet layoutSet) { long primaryKey = layoutSet.getPrimaryKey(); if (getPrimaryKey() < primaryKey) { return -1; } else if (getPrimaryKey() > primaryKey) { return 1; } else { return 0; } }
/** * Clears the cache for the layout set. * * <p>The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link * com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method. */ @Override public void clearCache(LayoutSet layoutSet) { EntityCacheUtil.removeResult( LayoutSetModelImpl.ENTITY_CACHE_ENABLED, LayoutSetImpl.class, layoutSet.getPrimaryKey()); FinderCacheUtil.removeResult( FINDER_PATH_FETCH_BY_G_P, new Object[] { Long.valueOf(layoutSet.getGroupId()), Boolean.valueOf(layoutSet.getPrivateLayout()) }); }
/** * Caches the layout sets in the entity cache if it is enabled. * * @param layoutSets the layout sets */ public void cacheResult(List<LayoutSet> layoutSets) { for (LayoutSet layoutSet : layoutSets) { if (EntityCacheUtil.getResult( LayoutSetModelImpl.ENTITY_CACHE_ENABLED, LayoutSetImpl.class, layoutSet.getPrimaryKey(), this) == null) { cacheResult(layoutSet); } } }
@Test public void testResetOriginalValues() throws Exception { LayoutSet newLayoutSet = addLayoutSet(); _persistence.clearCache(); LayoutSet existingLayoutSet = _persistence.findByPrimaryKey(newLayoutSet.getPrimaryKey()); Assert.assertEquals( existingLayoutSet.getGroupId(), ReflectionTestUtil.invoke(existingLayoutSet, "getOriginalGroupId", new Class<?>[0])); Assert.assertEquals( existingLayoutSet.getPrivateLayout(), ReflectionTestUtil.invoke(existingLayoutSet, "getOriginalPrivateLayout", new Class<?>[0])); }
/** * Caches the layout set in the entity cache if it is enabled. * * @param layoutSet the layout set */ public void cacheResult(LayoutSet layoutSet) { EntityCacheUtil.putResult( LayoutSetModelImpl.ENTITY_CACHE_ENABLED, LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet); FinderCacheUtil.putResult( FINDER_PATH_FETCH_BY_G_P, new Object[] { Long.valueOf(layoutSet.getGroupId()), Boolean.valueOf(layoutSet.getPrivateLayout()) }, layoutSet); layoutSet.resetOriginalValues(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof LayoutSet)) { return false; } LayoutSet layoutSet = (LayoutSet) obj; long primaryKey = layoutSet.getPrimaryKey(); if (getPrimaryKey() == primaryKey) { return true; } else { return false; } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } LayoutSet layoutSet = null; try { layoutSet = (LayoutSet) obj; } catch (ClassCastException cce) { return false; } long primaryKey = layoutSet.getPrimaryKey(); if (getPrimaryKey() == primaryKey) { return true; } else { return false; } }
@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); LayoutSet newLayoutSet = _persistence.create(pk); newLayoutSet.setMvccVersion(RandomTestUtil.nextLong()); newLayoutSet.setGroupId(RandomTestUtil.nextLong()); newLayoutSet.setCompanyId(RandomTestUtil.nextLong()); newLayoutSet.setCreateDate(RandomTestUtil.nextDate()); newLayoutSet.setModifiedDate(RandomTestUtil.nextDate()); newLayoutSet.setPrivateLayout(RandomTestUtil.randomBoolean()); newLayoutSet.setLogoId(RandomTestUtil.nextLong()); newLayoutSet.setThemeId(RandomTestUtil.randomString()); newLayoutSet.setColorSchemeId(RandomTestUtil.randomString()); newLayoutSet.setWapThemeId(RandomTestUtil.randomString()); newLayoutSet.setWapColorSchemeId(RandomTestUtil.randomString()); newLayoutSet.setCss(RandomTestUtil.randomString()); newLayoutSet.setPageCount(RandomTestUtil.nextInt()); newLayoutSet.setSettings(RandomTestUtil.randomString()); newLayoutSet.setLayoutSetPrototypeUuid(RandomTestUtil.randomString()); newLayoutSet.setLayoutSetPrototypeLinkEnabled(RandomTestUtil.randomBoolean()); _layoutSets.add(_persistence.update(newLayoutSet)); LayoutSet existingLayoutSet = _persistence.findByPrimaryKey(newLayoutSet.getPrimaryKey()); Assert.assertEquals(existingLayoutSet.getMvccVersion(), newLayoutSet.getMvccVersion()); Assert.assertEquals(existingLayoutSet.getLayoutSetId(), newLayoutSet.getLayoutSetId()); Assert.assertEquals(existingLayoutSet.getGroupId(), newLayoutSet.getGroupId()); Assert.assertEquals(existingLayoutSet.getCompanyId(), newLayoutSet.getCompanyId()); Assert.assertEquals( Time.getShortTimestamp(existingLayoutSet.getCreateDate()), Time.getShortTimestamp(newLayoutSet.getCreateDate())); Assert.assertEquals( Time.getShortTimestamp(existingLayoutSet.getModifiedDate()), Time.getShortTimestamp(newLayoutSet.getModifiedDate())); Assert.assertEquals(existingLayoutSet.getPrivateLayout(), newLayoutSet.getPrivateLayout()); Assert.assertEquals(existingLayoutSet.getLogoId(), newLayoutSet.getLogoId()); Assert.assertEquals(existingLayoutSet.getThemeId(), newLayoutSet.getThemeId()); Assert.assertEquals(existingLayoutSet.getColorSchemeId(), newLayoutSet.getColorSchemeId()); Assert.assertEquals(existingLayoutSet.getWapThemeId(), newLayoutSet.getWapThemeId()); Assert.assertEquals( existingLayoutSet.getWapColorSchemeId(), newLayoutSet.getWapColorSchemeId()); Assert.assertEquals(existingLayoutSet.getCss(), newLayoutSet.getCss()); Assert.assertEquals(existingLayoutSet.getPageCount(), newLayoutSet.getPageCount()); Assert.assertEquals(existingLayoutSet.getSettings(), newLayoutSet.getSettings()); Assert.assertEquals( existingLayoutSet.getLayoutSetPrototypeUuid(), newLayoutSet.getLayoutSetPrototypeUuid()); Assert.assertEquals( existingLayoutSet.getLayoutSetPrototypeLinkEnabled(), newLayoutSet.getLayoutSetPrototypeLinkEnabled()); }