1 /* 2 * Copyright 2005 Arnaud Prost 3 * 4 * Arnaud.prost@gmail.com 5 * 6 * This software is a computer program whose purpose is to ease the 7 * management of software project. 8 * 9 * This software is governed by the CeCILL license under French law and 10 * abiding by the rules of distribution of free software. You can use, 11 * modify and/ or redistribute the software under the terms of the CeCILL 12 * license as circulated by CEA, CNRS and INRIA at the following URL 13 * "http://www.cecill.info". 14 * 15 * As a counterpart to the access to the source code and rights to copy, 16 * modify and redistribute granted by the license, users are provided only 17 * with a limited warranty and the software's author, the holder of the 18 * economic rights, and the successive licensors have only limited 19 * liability. 20 * 21 * In this respect, the user's attention is drawn to the risks associated 22 * with loading, using, modifying and/or developing or reproducing the 23 * software by the user in light of its specific status of free software, 24 * that may mean that it is complicated to manipulate, and that also 25 * therefore means that it is reserved for developers and experienced 26 * professionals having in-depth computer knowledge. Users are therefore 27 * encouraged to load and test the software's suitability as regards their 28 * requirements in conditions enabling the security of their systems and/or 29 * data to be ensured and, more generally, to use and operate it in the 30 * same conditions as regards security. 31 * 32 * The fact that you are presently reading this means that you have had 33 * knowledge of the CeCILL license and that you accept its terms. 34 */ 35 36 package net.sf.pmr.core.domain.basicProject; 37 38 import java.util.HashSet; 39 import java.util.Set; 40 41 import net.sf.pmr.keopsframework.data.DomainListMapper; 42 43 import org.aopalliance.intercept.MethodInvocation; 44 import org.springframework.aop.TargetSource; 45 import org.springframework.aop.framework.Advised; 46 import org.springframework.aop.target.SingletonTargetSource; 47 48 49 /*** 50 * @author Arnaud Prost (arnaud.prost@gmail.com) 51 * 52 * réalise un lasy loading sur la liste des membres d'un projet. 53 */ 54 public class GetMembersLasyLoadingInterceptor implements 55 DomainCollectionLasyLoadingInterceptor { 56 57 private DomainListMapper domainListMapper; 58 59 /*** 60 * set the DomainListMapper 61 * 62 * @param domainListMapper 63 * domainListMapper 64 */ 65 public void setDomainListMapper(final DomainListMapper domainListMapper) { 66 this.domainListMapper = domainListMapper; 67 } 68 69 /*** 70 * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) 71 */ 72 public Object invoke(final MethodInvocation invocation) throws Throwable { 73 74 // invocation 75 Object returnValue = invocation.proceed(); 76 77 // BasicProject est un proxy, il faut récupérer la target 78 BasicProject basicProject = (BasicProject) invocation.getThis(); 79 80 // après invocation si l'oject est null (la collection), interrogation 81 // de la base 82 // ATTENTION : l'object doit exister en base !!!! Sinon exception hibernate. Donc l'Id doit être > à 0 83 if (returnValue == null && basicProject.getPersistanceId() > 0 ) { 84 85 returnValue = domainListMapper.findCollectionForObject(basicProject); 86 87 // la valeur de retour est donnée à l'object 88 basicProject.setMembers((Set) returnValue); 89 90 } else if (returnValue == null ){ 91 // si non ne va pas chercher en base et si la collection est null, création d'une collection 92 // histoire d'éviter plus tard une NullPointerException.... 93 returnValue = new HashSet(); 94 basicProject.setMembers((Set) returnValue); 95 } 96 97 // sinon on ne fait rien... 98 99 return returnValue; 100 101 } 102 103 }