2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.validation
;
13 import javax
.validation
.ConstraintViolation
;
15 import org
.springframework
.transaction
.TransactionStatus
;
17 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
18 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.validation
.CRUDEventType
;
21 import eu
.etaxonomy
.cdm
.persistence
.dao
.validation
.IEntityValidationCrud
;
22 import eu
.etaxonomy
.cdm
.persistence
.validation
.Level3ValidationTask
;
25 * A {@link Runnable} performing Level-3 validation of a JPA entity
27 * @author ayco_holleman
30 class Level3TransactionalValidationTask
extends Level3ValidationTask
{
32 private ICdmRepository repository
;
34 public Level3TransactionalValidationTask(CdmBase entity
, IEntityValidationCrud dao
) {
38 public Level3TransactionalValidationTask(ICdmBase entity
, CRUDEventType crudEventType
, IEntityValidationCrud dao
, ICdmRepository repository
) {
39 super(entity
, crudEventType
, dao
);
40 this.repository
= repository
;
44 protected Set
<ConstraintViolation
<ICdmBase
>> validateWithErrorHandling() {
45 if (repository
!= null){
46 TransactionStatus tx
= repository
.startTransaction(true);
47 //TODO what if getEntity() is not CdmBase?
48 CdmBase cdmBase
= CdmBase
.deproxy(getEntity(), CdmBase
.class);
49 repository
.getCommonService().find(cdmBase
.getClass(), cdmBase
.getId());
50 //was "create Entity in 2 open sessions" error
51 //not sure if the above works, should set the entity, but allowing to do so is critical the id is part of hash function, so we have to make sure that only entities with the same id can be replaced
52 // repository.getCommonService().updateEntity(cdmBase);
53 Set
<ConstraintViolation
<ICdmBase
>> result
= super.validateWithErrorHandling();
54 repository
.commitTransaction(tx
);
57 return super.validateWithErrorHandling();