use of com.pratilipi.data.type.GenericOfyType in project pratilipi by Pratilipi.
the class DataAccessorGaeImpl method createOrUpdateEntity.
private <T extends GenericOfyType> T createOrUpdateEntity(T entity, Page page, AuditLog auditLog) {
if (entity.getKey() == null) {
if (page == null) {
Key<T> key = ObjectifyService.ofy().save().entity(entity).now();
entity.setKey(key);
} else {
Map<Key<GenericOfyType>, GenericOfyType> map = ObjectifyService.ofy().save().entities(entity, page).now();
for (Key<GenericOfyType> key : map.keySet()) map.get(key).setKey(key);
}
if (entity.getKey().getName() == null)
auditLog.setPrimaryContentId(entity.getKey().getId());
else
auditLog.setPrimaryContentId(entity.getKey().getName());
auditLog.setEventDataNew(entity);
auditLog.setCreationDate(new Date());
Key<AuditLog> key = ObjectifyService.ofy().save().entity(auditLog).now();
auditLog.setKey(key);
} else {
if (entity.getKey().getName() == null)
auditLog.setPrimaryContentId(entity.getKey().getId());
else
auditLog.setPrimaryContentId(entity.getKey().getName());
auditLog.setEventDataNew(entity);
auditLog.setCreationDate(new Date());
Map<Key<GenericOfyType>, GenericOfyType> map = page == null ? ObjectifyService.ofy().save().entities(entity, auditLog).now() : ObjectifyService.ofy().save().entities(entity, page, auditLog).now();
for (Key<GenericOfyType> key : map.keySet()) map.get(key).setKey(key);
}
if (page != null)
// Updating additional page memcache ids
_createOrUpdatePageMemcache(page);
return entity;
}
Aggregations