Search in sources :

Example 1 with GenericOfyType

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;
}
Also used : Key(com.googlecode.objectify.Key) Date(java.util.Date) AuditLog(com.pratilipi.data.type.AuditLog) GenericOfyType(com.pratilipi.data.type.GenericOfyType)

Aggregations

Key (com.googlecode.objectify.Key)1 AuditLog (com.pratilipi.data.type.AuditLog)1 GenericOfyType (com.pratilipi.data.type.GenericOfyType)1 Date (java.util.Date)1