use of com.liferay.blade.samples.servicebuilder.model.impl.FooModelImpl 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;
}
Aggregations