use of com.liferay.portal.kernel.service.ServiceContext in project liferay-ide by liferay.
the class RosterPersistenceImpl method updateImpl.
@Override
public Roster updateImpl(Roster roster) {
roster = toUnwrappedModel(roster);
boolean isNew = roster.isNew();
RosterModelImpl rosterModelImpl = (RosterModelImpl) roster;
if (Validator.isNull(roster.getUuid())) {
String uuid = PortalUUIDUtil.generate();
roster.setUuid(uuid);
}
ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
Date now = new Date();
if (isNew && (roster.getCreateDate() == null)) {
if (serviceContext == null) {
roster.setCreateDate(now);
} else {
roster.setCreateDate(serviceContext.getCreateDate(now));
}
}
if (!rosterModelImpl.hasSetModifiedDate()) {
if (serviceContext == null) {
roster.setModifiedDate(now);
} else {
roster.setModifiedDate(serviceContext.getModifiedDate(now));
}
}
Session session = null;
try {
session = openSession();
if (roster.isNew()) {
session.save(roster);
roster.setNew(false);
} else {
roster = (Roster) session.merge(roster);
}
} catch (Exception e) {
throw processException(e);
} finally {
closeSession(session);
}
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
if (isNew || !RosterModelImpl.COLUMN_BITMASK_ENABLED) {
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
} else {
if ((rosterModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
Object[] args = new Object[] { rosterModelImpl.getOriginalUuid() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
args = new Object[] { rosterModelImpl.getUuid() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
}
if ((rosterModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLUBID.getColumnBitmask()) != 0) {
Object[] args = new Object[] { rosterModelImpl.getOriginalClubId() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_CLUBID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLUBID, args);
args = new Object[] { rosterModelImpl.getClubId() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_CLUBID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLUBID, args);
}
}
entityCache.putResult(RosterModelImpl.ENTITY_CACHE_ENABLED, RosterImpl.class, roster.getPrimaryKey(), roster, false);
roster.resetOriginalValues();
return roster;
}
use of com.liferay.portal.kernel.service.ServiceContext in project liferay-blade-samples by liferay.
the class FooPersistenceImpl method updateImpl.
@Override
public Foo updateImpl(Foo foo) {
foo = toUnwrappedModel(foo);
boolean isNew = foo.isNew();
FooModelImpl fooModelImpl = (FooModelImpl) foo;
if (Validator.isNull(foo.getUuid())) {
String uuid = PortalUUIDUtil.generate();
foo.setUuid(uuid);
}
ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
Date now = new Date();
if (isNew && (foo.getCreateDate() == null)) {
if (serviceContext == null) {
foo.setCreateDate(now);
} else {
foo.setCreateDate(serviceContext.getCreateDate(now));
}
}
if (!fooModelImpl.hasSetModifiedDate()) {
if (serviceContext == null) {
foo.setModifiedDate(now);
} else {
foo.setModifiedDate(serviceContext.getModifiedDate(now));
}
}
Session session = null;
try {
session = openSession();
if (foo.isNew()) {
session.save(foo);
foo.setNew(false);
} else {
foo = (Foo) session.merge(foo);
}
} catch (Exception e) {
throw processException(e);
} finally {
closeSession(session);
}
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
if (isNew || !FooModelImpl.COLUMN_BITMASK_ENABLED) {
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
} else {
if ((fooModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
Object[] args = new Object[] { fooModelImpl.getOriginalUuid() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
args = new Object[] { fooModelImpl.getUuid() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
}
if ((fooModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
Object[] args = new Object[] { fooModelImpl.getOriginalUuid(), fooModelImpl.getOriginalCompanyId() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);
args = new Object[] { fooModelImpl.getUuid(), fooModelImpl.getCompanyId() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);
}
if ((fooModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FIELD2.getColumnBitmask()) != 0) {
Object[] args = new Object[] { fooModelImpl.getOriginalField2() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_FIELD2, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FIELD2, args);
args = new Object[] { fooModelImpl.getField2() };
finderCache.removeResult(FINDER_PATH_COUNT_BY_FIELD2, args);
finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FIELD2, args);
}
}
entityCache.putResult(FooModelImpl.ENTITY_CACHE_ENABLED, FooImpl.class, foo.getPrimaryKey(), foo, false);
clearUniqueFindersCache(fooModelImpl);
cacheUniqueFindersCache(fooModelImpl, isNew);
foo.resetOriginalValues();
return foo;
}
use of com.liferay.portal.kernel.service.ServiceContext in project com-liferay-apio-architect by liferay.
the class BlogPostingNestedCollectionResource method _updateBlogsEntry.
private BlogsEntry _updateBlogsEntry(Long entryId, BlogPostingForm blogPostingForm) throws PortalException {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
BlogsEntry blogsEntry = _blogsService.getEntry(entryId);
serviceContext.setScopeGroupId(blogsEntry.getGroupId());
return _blogsService.updateEntry(entryId, blogPostingForm.getHeadline(), blogPostingForm.getAlternativeHeadline(), blogPostingForm.getDescription(), blogPostingForm.getArticleBody(), blogPostingForm.getDisplayDateMonth(), blogPostingForm.getDisplayDateDay(), blogPostingForm.getDisplayDateYear(), blogPostingForm.getDisplayDateHour(), blogPostingForm.getDisplayDateMinute(), false, false, null, null, null, null, serviceContext);
}
use of com.liferay.portal.kernel.service.ServiceContext in project com-liferay-apio-architect by liferay.
the class MediaObjectNestedCollectionResource method _addFileEntry.
private FileEntry _addFileEntry(Long folderId, MediaObjectCreatorForm mediaObjectCreatorForm) throws PortalException {
Folder folder = _dlAppService.getFolder(folderId);
BinaryFile binaryFile = mediaObjectCreatorForm.getBinaryFile();
return _dlAppService.addFileEntry(folder.getGroupId(), folderId, mediaObjectCreatorForm.getName(), binaryFile.getMimeType(), mediaObjectCreatorForm.getTitle(), mediaObjectCreatorForm.getDescription(), null, binaryFile.getInputStream(), binaryFile.getSize(), new ServiceContext());
}
use of com.liferay.portal.kernel.service.ServiceContext in project com-liferay-apio-architect by liferay.
the class BlogPostingNestedCollectionResource method _addBlogsEntry.
private BlogsEntry _addBlogsEntry(Long groupId, BlogPostingForm blogPostingForm) throws PortalException {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setScopeGroupId(groupId);
return _blogsService.addEntry(blogPostingForm.getHeadline(), blogPostingForm.getAlternativeHeadline(), blogPostingForm.getDescription(), blogPostingForm.getArticleBody(), blogPostingForm.getDisplayDateMonth(), blogPostingForm.getDisplayDateDay(), blogPostingForm.getDisplayDateYear(), blogPostingForm.getDisplayDateHour(), blogPostingForm.getDisplayDateMinute(), false, false, null, null, null, null, serviceContext);
}
Aggregations