Revision 47a88d09
Added by Ben Clark over 15 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java | ||
---|---|---|
29 | 29 |
import org.hibernate.criterion.Restrictions; |
30 | 30 |
import org.hibernate.envers.query.AuditQuery; |
31 | 31 |
import org.hibernate.search.FullTextQuery; |
32 |
import org.joda.time.DateTime; |
|
32 | 33 |
import org.springframework.beans.factory.annotation.Autowired; |
33 | 34 |
import org.springframework.beans.factory.annotation.Qualifier; |
34 | 35 |
import org.springframework.dao.DataAccessException; |
36 |
import org.springframework.security.Authentication; |
|
37 |
import org.springframework.security.context.SecurityContextHolder; |
|
35 | 38 |
import org.springframework.stereotype.Repository; |
36 | 39 |
|
37 | 40 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
41 |
import eu.etaxonomy.cdm.model.common.User; |
|
42 |
import eu.etaxonomy.cdm.model.common.VersionableEntity; |
|
38 | 43 |
import eu.etaxonomy.cdm.persistence.dao.BeanInitializer; |
39 | 44 |
import eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao; |
40 | 45 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
... | ... | |
117 | 122 |
if (logger.isDebugEnabled()){logger.debug("dao saveOrUpdate start...");} |
118 | 123 |
if (logger.isDebugEnabled()){logger.debug("transientObject(" + transientObject.getClass().getSimpleName() + ") ID:" + transientObject.getId() + ", UUID: " + transientObject.getUuid()) ;} |
119 | 124 |
Session session = getSession(); |
125 |
if(transientObject.getId() != 0 && VersionableEntity.class.isAssignableFrom(transientObject.getClass())) { |
|
126 |
VersionableEntity versionableEntity = (VersionableEntity)transientObject; |
|
127 |
versionableEntity.setUpdated(new DateTime()); |
|
128 |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
129 |
if(authentication != null && authentication.getPrincipal() != null && authentication.getPrincipal() instanceof User) { |
|
130 |
User user = (User)authentication.getPrincipal(); |
|
131 |
versionableEntity.setUpdatedBy(user); |
|
132 |
} |
|
133 |
} |
|
120 | 134 |
session.saveOrUpdate(transientObject); |
121 | 135 |
if (logger.isDebugEnabled()){logger.debug("dao saveOrUpdate end");} |
122 | 136 |
return transientObject.getUuid(); |
Also available in: Unified diff
Removed code which introduced horrible performance problems and phantom commits.