Project

General

Profile

« Previous | Next » 

Revision 933e5ac3

Added by Cherian Mathew about 9 years ago

ICdmCacher, ICdmUuidCacher, CdmCacher, CdmTermCacher : refactored and added load method
Language, NameRelationshipType, Rank : now uses cacher only if termap is null or empty and only when class matches the specific term type
MockCdmCacher: not required anymore
DefaultTermInitializer : removed acall to mock cacher
MatchStrategyConfigurator : moved from editor to cdmlib
CdmDataChangeEvent : added constructor
CommonServiceImpl, ICommonService : added call to findMatchingStrategy with enum instead of object
DescriptionServiceImpl, IDescriptionService, PolytomousKeyNodeServiceImpl, IPolytomousKeyNodeService, TaxonNodeServiceImpl, ITaxonNodeService, TaxonServiceImpl: added uuid methods

View differences:

.gitattributes
712 712
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/CdmBaseType.java -text
713 713
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/CdmTypeScanner.java -text
714 714
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/ICdmCacher.java -text
715
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/ICdmUuidCacher.java -text
715 716
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/Address.java -text
716 717
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/AgentBase.java -text
717 718
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/Contact.java -text
......
794 795
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/WrongTermTypeException.java -text
795 796
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/ITermInitializer.java -text
796 797
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/ITermLoader.java -text
797
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/MockCdmCacher.java -text
798 798
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/TermLoader.java -text
799 799
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/TermNotFoundException.java -text
800 800
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/package-info.java -text
......
1030 1030
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/Match.java -text
1031 1031
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/MatchException.java -text
1032 1032
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/MatchMode.java -text
1033
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/MatchStrategyConfigurator.java -text
1033 1034
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/Matching.java -text
1034 1035
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/merge/DefaultMergeStrategy.java -text
1035 1036
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/merge/IMergable.java -text
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/ICdmCacher.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
1 10
package eu.etaxonomy.cdm.model;
2 11

  
3
import java.util.UUID;
4

  
5 12
import eu.etaxonomy.cdm.model.common.CdmBase;
6 13

  
7 14
/**
8 15
 * @author cmathew
16
 * @date 19 Feb 2015
9 17
 *
10
 * Cache class for CDM Entities based on Ehcache.
11
 * The class manages a singleton {@link net.sf.ehcache.CacheManager} having a
12
 * {@link net.sf.ehcache.Cache} initialised with a default configuration.
13
 *
14
 * FIXME: This interface should actually be in an external project which also
15
 * includes the implemented cachers.
16
 *
17
 * @param <T>
18 18
 */
19
public interface ICdmCacher<T extends CdmBase> {
20

  
21
    /**
22
     * Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
23
     * in the cache
24
     *
25
     * @param uuid
26
     * @param cdmEntity
27
     */
28
    public  T put(UUID uuid, T cdmEntity);
19
public interface ICdmCacher {
29 20

  
30
	/**
31
	 * Load a CDM Entity object with given UUID.
32
	 * This method checks the (default) cache for the entity,
33
	 * else retrieves the entity from the service layer.
34
	 *
35
	 * NOTE : Currently this method can only be used for CDM Term
36
	 * (DefinedTermBase) entities.
37
	 *
38
	 * @param uuid of CDM Entity to return
39
	 * @return
40
	 */
41
	public T load(UUID uuid);
21
    public CdmBase getFromCache(CdmBase cdmBase);
42 22

  
43
	/**
44
	 * Get a CDM Entity object with given UUID from the (default) cache.
45
	 *
46
	 * @param uuid
47
	 * @return
48
	 */
49
	public T getFromCache(UUID uuid);
23
    public void put(CdmBase cdmEntity);
50 24

  
51
	/**
52
	 * Check if a CDM Entity with given UUID exists in the cache.
53
	 *
54
	 * @param uuid of CDM Entity to check
55
	 * @return true if CDM Entity with given UUID exists in the cache, o/w false
56
	 */
57
	public boolean exists(UUID uuid);
25
    public CdmBase load(CdmBase cdmEntity);
58 26

  
59
	/**
60
	 * Check if a CDM Entity with given UUID exists in the cache
61
	 * and that it is not null.
62
	 *
63
	 * @param uuid of CDM Entity to check
64
	 * @return true if CDM Entity with given UUID exists in the cache and that it is not null, o/w false
65
	 */
66
	public boolean existsAndIsNotNull(UUID uuid);
27
    public boolean isCachable(CdmBase cdmEntity);
67 28

  
68
}
29
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/ICdmUuidCacher.java
1
package eu.etaxonomy.cdm.model;
2

  
3
import java.util.UUID;
4

  
5
import eu.etaxonomy.cdm.model.common.CdmBase;
6

  
7
/**
8
 * @author cmathew
9
 *
10
 * Cache class for CDM Entities based on Ehcache.
11
 * The class manages a singleton {@link net.sf.ehcache.CacheManager} having a
12
 * {@link net.sf.ehcache.Cache} initialised with a default configuration.
13
 *
14
 * FIXME: This interface should actually be in an external project which also
15
 * includes the implemented cachers.
16
 *
17
 * @param <T>
18
 */
19
public interface ICdmUuidCacher extends ICdmCacher {
20

  
21
    /**
22
     * Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
23
     * in the cache
24
     *
25
     * @param uuid
26
     * @param cdmEntity
27
     */
28
    public  CdmBase put(UUID uuid, CdmBase cdmEntity);
29

  
30
	/**
31
	 * Load a CDM Entity object with given UUID.
32
	 * This method checks the (default) cache for the entity,
33
	 * else retrieves the entity from the service layer.
34
	 *
35
	 * NOTE : Currently this method can only be used for CDM Term
36
	 * (DefinedTermBase) entities.
37
	 *
38
	 * @param uuid of CDM Entity to return
39
	 * @return
40
	 */
41
	public CdmBase load(UUID uuid);
42

  
43
	/**
44
	 * Get a CDM Entity object with given UUID from the (default) cache.
45
	 *
46
	 * @param uuid
47
	 * @return
48
	 */
49
	public CdmBase getFromCache(UUID uuid);
50

  
51

  
52

  
53
	/**
54
	 * Check if a CDM Entity with given UUID exists in the cache.
55
	 *
56
	 * @param uuid of CDM Entity to check
57
	 * @return true if CDM Entity with given UUID exists in the cache, o/w false
58
	 */
59
	public boolean exists(UUID uuid);
60

  
61
	/**
62
	 * Check if a CDM Entity with given UUID exists in the cache
63
	 * and that it is not null.
64
	 *
65
	 * @param uuid of CDM Entity to check
66
	 * @return true if CDM Entity with given UUID exists in the cache and that it is not null, o/w false
67
	 */
68
	public boolean existsAndIsNotNull(UUID uuid);
69

  
70
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/DefaultTermInitializer.java
17 17

  
18 18
import eu.etaxonomy.cdm.model.common.init.ITermInitializer;
19 19
import eu.etaxonomy.cdm.model.common.init.ITermLoader;
20
import eu.etaxonomy.cdm.model.common.init.MockCdmCacher;
21 20
import eu.etaxonomy.cdm.model.common.init.TermLoader;
22 21

  
23 22
/**
......
44 43
			TermVocabulary<?> voc  = termLoader.loadTerms(vocabularyEnum, terms);
45 44
			setDefinedTerms(vocabularyEnum.getClazz(),voc);
46 45
		}
47
		//FIXME: temporary fix to make cdmlib-model test running until we completely moved to CdmCacher
48
		new MockCdmCacher();
49 46

  
50 47
	}
51 48

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/DefinedTermBase.java
48 48

  
49 49
import au.com.bytecode.opencsv.CSVWriter;
50 50
import eu.etaxonomy.cdm.hibernate.search.DefinedTermBaseClassBridge;
51
import eu.etaxonomy.cdm.model.ICdmCacher;
51
import eu.etaxonomy.cdm.model.ICdmUuidCacher;
52 52
import eu.etaxonomy.cdm.model.description.Feature;
53 53
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
54 54
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
......
476 476
    }
477 477

  
478 478
    // Currently the CDM Caching mechanism is only used for caching terms
479
    private static ICdmCacher cacher;
479
    private static ICdmUuidCacher cacher;
480 480

  
481 481
    /**
482 482
     * Gets the CDM cacher object
483 483
     *
484 484
     * @return the CDM cacher object
485 485
     */
486
    public static ICdmCacher getCacher() {
486
    public static ICdmUuidCacher getCacher() {
487 487
		return cacher;
488 488
	}
489 489

  
......
492 492
	 *
493 493
	 * @param cacher the CDM cacher object
494 494
	 */
495
	public static void setCacher(ICdmCacher cacher) {
495
	public static void setCacher(ICdmUuidCacher cacher) {
496 496
		DefinedTermBase.cacher = cacher;
497 497
	}
498

  
499
	public static <T extends DefinedTermBase> T getTermByClassAndUUID(Class<T> clazz, UUID uuid) {
500
	    if(cacher != null) {
501
	        Object obj = getCacher().load(uuid);
502
	        if(obj != null && obj.getClass().equals(clazz)) {
503
	            return (T)obj;
504
	        }
505
	    }
506
	    return null;
507
	}
498 508
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Language.java
50 50
    private static final Logger logger = Logger.getLogger(Language.class);
51 51

  
52 52
    public static final UUID uuidLanguageVocabulary = UUID.fromString("45ac7043-7f5e-4f37-92f2-3874aaaef2de");
53
    
53

  
54 54
    public static final UUID uuidEnglish = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
55 55

  
56 56
    private static final UUID uuidAfar = UUID.fromString("b3ad88e2-0080-466f-9bf4-b01ba4122563");
......
544 544

  
545 545
    protected static Map<UUID, Language> termMap = null;
546 546

  
547
// *************************** Factory MEthods ********************************/    
548
    
547
// *************************** Factory MEthods ********************************/
548

  
549 549
    public static Language NewInstance(){
550 550
        return new Language();
551 551
    }
......
577 577
        return result;
578 578
    }
579 579

  
580
//**************** Attributes *************************************/    
581
    
580
//**************** Attributes *************************************/
581

  
582 582
    @XmlAttribute(name = "iso639_1")
583 583
    //TODO create userDefinedType ?
584 584
    @Column(length=2)
......
589 589
//    @Column(length=3)
590 590
//    private String iso639_2;
591 591

  
592
//***** CONSTRUCTOR ***************************************/    
593
    
592
//***** CONSTRUCTOR ***************************************/
593

  
594 594
    //for hibernate use only
595 595
    @Deprecated
596 596
    protected Language() {
597 597
   		super(TermType.Language);
598 598
    };
599
    
599

  
600 600
    public Language(UUID uuid) {
601 601
        super(TermType.Language);
602 602
    	this.setUuid(uuid);
......
649 649
//			DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
650 650
//			vocabularyStore.initialize();
651 651
        }
652
        return (Language)termMap.get(uuid);
652
        return termMap.get(uuid);
653 653
    }
654 654

  
655 655

  
......
1206 1206
            }else{
1207 1207
                DefinedTermBase.readCsvLine(newInstance,csvLine,(Language)terms.get(Language.uuidEnglish), abbrevAsId);
1208 1208
            }
1209
            
1209

  
1210 1210
//          newInstance.setIso639_2(csvLine.get(4).trim());   //does not exist anymore
1211 1211
//          newInstance.setIdInVocabulary(csvLine.get(4).trim());  //same as abbrev
1212
            
1212

  
1213 1213
            newInstance.setIso639_1(csvLine.get(5).trim());
1214 1214
            //TODO could replace with generic validation
1215 1215
            if(iso639_1 != null && iso639_1.length() > 2){
......
1280 1280
            termMap = new HashMap<UUID, Language>();
1281 1281
        }
1282 1282
        for (Language term : termVocabulary.getTerms()){
1283
            termMap.put(term.getUuid(), (Language)term);
1283
            termMap.put(term.getUuid(), term);
1284 1284
        }
1285
        defaultLanguage = ENGLISH();        
1285
        defaultLanguage = ENGLISH();
1286 1286
        csvLanguage = ENGLISH();
1287 1287
        addLanguageForVocabularyRepresentation(termVocabulary);
1288 1288
    }
1289 1289

  
1290
    //FIXME: Following two methods are temporary and should be moved to more 
1290
    //FIXME: Following two methods are temporary and should be moved to more
1291 1291
    //       generic methods in the super classes
1292 1292
    /**
1293 1293
     * Gets the default language using the cache
1294
     * 
1294
     *
1295 1295
     * @return
1296 1296
     */
1297 1297
    public static Language getDefaultLanguage() {
1298 1298
    	return (Language)getCacher().load(uuidEnglish);
1299 1299
    }
1300
    
1300

  
1301 1301
    /**
1302
     * 
1303
     * 
1302
     *
1303
     *
1304 1304
     * @param uuid
1305 1305
     * @return
1306 1306
     */
1307 1307
    public static Language getLanguageFromUuid(UUID uuid) {
1308
    	return (Language)getCacher().load(uuid);
1308
        if(termMap == null || termMap.isEmpty()) {
1309
            return getTermByClassAndUUID(Language.class, uuid);
1310
        } else {
1311
            return termMap.get(uuid);
1312
        }
1309 1313
    }
1310 1314

  
1311 1315
    /**
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/MockCdmCacher.java
1
package eu.etaxonomy.cdm.model.common.init;
2

  
3
import java.util.Set;
4
import java.util.UUID;
5

  
6
import net.sf.ehcache.Cache;
7
import net.sf.ehcache.CacheManager;
8
import net.sf.ehcache.Element;
9
import net.sf.ehcache.config.CacheConfiguration;
10
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
11

  
12
import eu.etaxonomy.cdm.model.ICdmCacher;
13
import eu.etaxonomy.cdm.model.common.CdmBase;
14
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
15
import eu.etaxonomy.cdm.model.common.Language;
16

  
17
/**
18
 * Since cdmlib-model cannot access CdmCacher we need to create a mock class
19
 * for the tests.
20
 *
21
 * NOTES:
22
 *      - All terms are put into the cache in the constructor
23
 *      - The number of elements allowed in the cache is set to a big number - 10000
24
 *
25
 * FIXME : Once the CDMCacher is externalised this class should just subclass it.
26
 *
27
 * @author cmathew
28
 *
29
 */
30
public class MockCdmCacher implements ICdmCacher {
31

  
32
	private static final String DEFAULT_CACHE_NAME = "defaultCache";
33

  
34
	private static final String DEFAULT_CACHE_MGR_NAME = "defaultCacheManager";
35
	/**
36
	 * Constructor which initialises a singleton {@link net.sf.ehcache.CacheManager}
37
	 *
38
	 */
39
	public MockCdmCacher() {
40
		init();
41
	}
42

  
43
	/**
44
	 * Initialises an empty singleton {@link net.sf.ehcache.CacheManager} and
45
	 * sets itself as the cacher object in specific CDM Entity objects.
46
	 *
47
	 */
48
	private void init() {
49
		// Remove all caches
50
		getDefaultCacheManager().removalAll();
51
		// Create default cache
52
		getDefaultCacheManager().addCache(new Cache(getDefaultCacheConfiguration()));
53
		Set<Language> langList = Language.DEFAULT().getVocabulary().getTerms();
54
		for (Language lang : langList){
55
			put(lang.getUuid(),lang);
56
		}
57
		// We start first only with DefinedTermBase
58
		DefinedTermBase.setCacher(this);
59

  
60
	}
61

  
62
	/**
63
	 * Returns the singleton default cache manager.
64
	 *
65
	 * @return
66
	 */
67
	private static CacheManager getDefaultCacheManager() {
68
		// this ensures a singleton cache manager
69
		return CacheManager.create();
70
	}
71

  
72
	/**
73
	 * Returns the default cache configuration.
74
	 *
75
	 * @return
76
	 */
77
	private CacheConfiguration getDefaultCacheConfiguration() {
78
		return new CacheConfiguration(DEFAULT_CACHE_NAME, 10000)
79
	    .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
80
	    .eternal(false)
81
	    // default ttl and tti set to 2 hours
82
	    .timeToLiveSeconds(60*60*2)
83
	    .timeToIdleSeconds(60*60*2);
84

  
85
	}
86

  
87
	/**
88
	 * Returns the default cache
89
	 *
90
	 * @return
91
	 */
92
	private static Cache getDefaultCache() {
93
		return getDefaultCacheManager().getCache(DEFAULT_CACHE_NAME);
94
	}
95

  
96
	/**
97
	 * Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
98
	 * in the cache
99
	 *
100
	 * @param uuid
101
	 * @param cdmEntity
102
	 * @return
103
	 */
104
	@Override
105
    public CdmBase put(UUID uuid, CdmBase cdmEntity) {
106
	    CdmBase cachedCdmEntity = getFromCache(uuid);
107
        if(getFromCache(uuid) == null) {
108
            getDefaultCache().put(new Element(uuid, cdmEntity));
109
            return cdmEntity;
110
        } else {
111
            return cachedCdmEntity;
112
        }
113
	}
114

  
115
	/**
116
	 * Gets the cache element corresponding to the given {@link java.util.UUID}
117
	 *
118
	 * @param uuid
119
	 * @return
120
	 */
121
	private Element getCacheElement(UUID uuid) {
122
		return getDefaultCache().get(uuid);
123
	}
124

  
125
	/**
126
	 * Get CDM Entity for given {@link java.util.UUID} from the cache
127
	 *
128
	 * @param uuid
129
	 * @return
130
	 */
131
	private CdmBase getCdmEntity(UUID uuid) {
132
		return  (CdmBase)getDefaultCache().get(uuid).getObjectValue();
133
	}
134

  
135
	/* (non-Javadoc)
136
	 * @see eu.etaxonomy.cdm.remote.cache.ICdmCacher#load(java.util.UUID)
137
	 */
138

  
139
	@Override
140
    public CdmBase load(UUID uuid) {
141
		Element e = getCacheElement(uuid);
142
		CdmBase cdmEntity;
143
		if (e == null) {
144
			return null;
145
		} else {
146
		    return (CdmBase)e.getObjectValue();
147
		}
148
	}
149

  
150

  
151
	/* (non-Javadoc)
152
	 * @see eu.etaxonomy.cdm.model.ICdmCacher#getFromCache(java.util.UUID)
153
	 */
154
	@Override
155
    public CdmBase getFromCache(UUID uuid) {
156
		Element e = getCacheElement(uuid);
157
		CdmBase cdmEntity;
158
		if (e == null) {
159
			return null;
160
		} else {
161
		    return(CdmBase)e.getObjectValue();
162
		}
163
	}
164

  
165

  
166
	/* (non-Javadoc)
167
	 * @see eu.etaxonomy.cdm.model.ICdmCacher#exists(java.util.UUID)
168
	 */
169
	@Override
170
    public boolean exists(UUID uuid) {
171
		return getCacheElement(uuid) != null;
172
	}
173

  
174

  
175
	/* (non-Javadoc)
176
	 * @see eu.etaxonomy.cdm.model.ICdmCacher#existsAndIsNotNull(java.util.UUID)
177
	 */
178
	@Override
179
    public boolean existsAndIsNotNull(UUID uuid) {
180
		Element e = getCacheElement(uuid);
181
		CdmBase cdmEntity;
182
		if (e != null) {
183
			return (CdmBase)e.getObjectValue() != null;
184
		}
185
		return false;
186
	}
187

  
188
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationshipType.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
38 38
 * the taxon names involved in the name relationship or on decisions taken by
39 39
 * the competent authorities; they do not depend on the use made of these
40 40
 * taxon names in a particular reference or in a particular taxonomic treatment.
41
 * Most relationships are to be understood as 'is .... of': for instance 
41
 * Most relationships are to be understood as 'is .... of': for instance
42 42
 * <i>Linum radiola</i> L. is a replaced synonym of <i>Radiola linoides</i> Roth or
43 43
 * <i>Astragalus rhizanthus</i> Boiss. is a later homonym of
44
 * <i>Astragalus rhizanthus</i> Royle.  
44
 * <i>Astragalus rhizanthus</i> Royle.
45 45
 * <P>
46 46
 * A standard (ordered) list of name relationship type instances will be
47 47
 * automatically created as the project starts. But this class allows to extend
48 48
 * this standard list by creating new instances of additional name relationship
49
 * types if needed. 
49
 * types if needed.
50 50
 * <P>
51 51
 * This class corresponds partially to: <ul>
52 52
 * <li> TaxonRelationshipTerm and NomenclaturalNoteTypeTerm according to the TDWG ontology
53 53
 * <li> RelationshipType and NomenclaturalNoteType according to the TCS
54 54
 * </ul>
55
 * 
55
 *
56 56
 * @author m.doering
57 57
 * @created 08-Nov-2007 13:06:38
58 58
 */
......
80 80
	private static final UUID uuidBlockingNameFor = UUID.fromString("1dab357f-2e12-4511-97a4-e5153589e6a6");
81 81
	private static final UUID uuidLaterIsonym = UUID.fromString("29ab238d-598d-45b9-addd-003cf39ccc3e");
82 82
	private static final UUID uuidOriginalSpellingFor = UUID.fromString("264d2be4-e378-4168-9760-a9512ffbddc4");
83
	
84
	
83

  
84

  
85 85
	public static NameRelationshipType NewInstance(String term, String label, String labelAbbrev, boolean symmetric, boolean transitive) {
86 86
		return new NameRelationshipType(term, label, labelAbbrev, symmetric, transitive);
87 87
	}
88 88

  
89
	
90
	protected static Map<UUID, NameRelationshipType> termMap = null;		
91
	
89

  
90
	protected static Map<UUID, NameRelationshipType> termMap = null;
91

  
92 92
	protected static NameRelationshipType findTermByUuid(UUID uuid){
93
		if (termMap == null){
94
			return null;
93
		if (termMap == null || termMap.isEmpty()){
94
		    return getTermByClassAndUUID(NameRelationshipType.class, uuid);
95
		} else {
96
		    return termMap.get(uuid);
95 97
		}
96
		return (NameRelationshipType)termMap.get(uuid);
97 98
	}
98
	
99
	
100
//********************************** Constructor *********************************/	
99

  
100

  
101
//********************************** Constructor *********************************/
101 102

  
102 103
  	//for hibernate use only
103 104
  	@Deprecated
104 105
  	protected  NameRelationshipType() {
105 106
		super(TermType.NameRelationshipType);
106 107
	}
107
	
108
	/** 
108

  
109
	/**
109 110
	 * Class constructor: creates an additional name relationship type
110 111
	 * instance with a description, a label, a label abbreviation and the flags
111 112
	 * indicating whether <i>this</i> new name relationship type is symmetric and/or
112 113
	 * transitive.
113
	 * 
114
	 *
114 115
	 * @param	term  		 the string (in the default language) describing the
115
	 * 						 new name relationship type to be created 
116
	 * 						 new name relationship type to be created
116 117
	 * @param	label  		 the string identifying the new name relationship
117 118
	 * 						 type to be created
118 119
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
......
128 129
	}
129 130

  
130 131

  
131
	
132

  
132 133
//************************** METHODS ********************************
133
	
134

  
134 135
	/* (non-Javadoc)
135 136
	 * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
136 137
	 */
......
138 139
	public void resetTerms(){
139 140
		termMap = null;
140 141
	}
141
	
142

  
142 143
	// TODO this method should be moved to consistency proof classes
143 144
	/**
144 145
	 * Returns the boolean value indicating whether the nomenclatural status
......
154 155
	 */
155 156
	@Transient
156 157
	public boolean isInvalidType(){
157
		if (this.equals(VALIDATED_BY_NAME()) || 
158
		if (this.equals(VALIDATED_BY_NAME()) ||
158 159
				this.equals(LATER_VALIDATED_BY_NAME())
159 160
			){
160
			return true;	
161
			return true;
161 162
		}else{
162 163
			return false;
163 164
		}
......
178 179
	 */
179 180
	@Transient
180 181
	public boolean isLegitimateType(){
181
		if (this.equals(BASIONYM()) || 
182
				this.equals(REPLACED_SYNONYM()) || 
182
		if (this.equals(BASIONYM()) ||
183
				this.equals(REPLACED_SYNONYM()) ||
183 184
				this.equals(ALTERNATIVE_NAME()) ||
184 185
				this.equals(CONSERVED_AGAINST())
185 186
			){
186
			return true;	
187
			return true;
187 188
		}else{
188 189
			return false;
189 190
		}
......
206 207
	public boolean isIllegitimateType(){
207 208
		//TODO: implement isX method. Maybe as persistent class attribute?
208 209
		//TODO: RejectedInFavour,
209
		if (this.equals(LATER_HOMONYM()) || 
210
		if (this.equals(LATER_HOMONYM()) ||
210 211
				this.equals(TREATED_AS_LATER_HOMONYM())
211 212
			){
212
			return true;	
213
			return true;
213 214
		}else{
214 215
			return false;
215 216
		}
216 217
	}
217
	
218

  
218 219
	@Transient
219 220
	public boolean isBasionymRelation(){
220 221
		if (BASIONYM() == null){
......
222 223
		}
223 224
		return this.equals(BASIONYM());
224 225
	}
225
	
226

  
226 227
	@Transient
227 228
	public boolean isReplacedSynonymRelation(){
228 229
		if (REPLACED_SYNONYM() == null){
......
231 232
		return this.equals(REPLACED_SYNONYM());
232 233
	}
233 234

  
234
	
235

  
235 236
	/**
236 237
	 * Returns the "orthographic variant" name relationship type. The first
237
	 * {@link TaxonNameBase taxon name} involved in such a relationship is an 
238
	 * {@link TaxonNameBase taxon name} involved in such a relationship is an
238 239
	 * orthographic variant of the second taxon name. The two {@link TaxonNameBase taxon names}
239 240
	 * involved in such a relationship must have the same {@link NonViralName#getAuthorshipCache() authorship}
240 241
	 * and {@link Rank rank}, belong to the same {@link HomotypicalGroup homotypical group} and their name parts
......
248 249
	public static final NameRelationshipType ORTHOGRAPHIC_VARIANT(){
249 250
		  return findTermByUuid(uuidOrthographicVariant);
250 251
	}
251
	
252

  
252 253
	/**
253
	 * Returns the {@link TaxonNameBase taxon name} as it is spelled in the original 
254
	 * publication of the given name. The first (left) name in the relationship takes the role 
255
	 * of the original spelling whereas the second (right) name takes the role of the 
254
	 * Returns the {@link TaxonNameBase taxon name} as it is spelled in the original
255
	 * publication of the given name. The first (left) name in the relationship takes the role
256
	 * of the original spelling whereas the second (right) name takes the role of the
256 257
	 * current/correct spelling.<BR>
257 258
	 * Original spelling is a specialization of {@link #ORTHOGRAPHIC_VARIANT()}.
258 259
	 * <BR>
......
262 263
	public static final NameRelationshipType ORIGINAL_SPELLING(){
263 264
		return findTermByUuid(uuidOriginalSpellingFor);
264 265
	}
265
	
266

  
266 267
	/**
267 268
	 * Returns the "misspelling" name relationship type. The first
268
	 * {@link TaxonNameBase taxon name} involved in such a relationship is a 
269
	 * {@link TaxonNameBase taxon name} involved in such a relationship is a
269 270
	 * misspelling of the second taxon name. The two {@link TaxonNameBase taxon names}
270 271
	 * involved in such a relationship must have the same {@link NonViralName#getAuthorshipCache() authorship}
271 272
	 * and {@link Rank rank}, belong to the same {@link HomotypicalGroup homotypical group} and their name parts
272 273
	 * must be almost identical (so one usually does not differentiate them).<BR>
273 274
	 * For instance <i>Anhelica silvestris</i> L. is a misspelling of
274 275
	 * <i>Angelica silvestris</i> L.<BR>
275
	 * A misspelling is always accicentally (not on purpose). Therefore misspellings are a 
276
	 * subset of {@link #ORTHOGRAPHIC_VARIANT orthographic variants} and are complementary to 
276
	 * A misspelling is always accicentally (not on purpose). Therefore misspellings are a
277
	 * subset of {@link #ORTHOGRAPHIC_VARIANT orthographic variants} and are complementary to
277 278
	 * emendations. A misspelling is always an {@link #ORTHOGRAPHIC_VARIANT orthographic variant}, too.
278 279
	 * This type is symmetric and transitive but usually the misspelling relationships should be organized
279 280
	 * in a star schema with the correct variant in the middle and the misspellings pointing to it.
......
285 286
	}
286 287
	/**
287 288
	 * Returns the "emendation" name relationship type. The first
288
	 * {@link TaxonNameBase taxon name} involved in such a relationship is a 
289
	 * {@link TaxonNameBase taxon name} involved in such a relationship is a
289 290
	 * misspelling of the second taxon name. The two {@link TaxonNameBase taxon names}
290 291
	 * involved in such a relationship must have the same {@link NonViralName#getAuthorshipCache() authorship}
291 292
	 * and {@link Rank rank}, belong to the same {@link HomotypicalGroup homotypical group} and their name parts
292 293
	 * must be almost identical (so one usually does not differentiate them).<BR>
293 294
	 * For instance <i>Angelica silvestris</i> L. is a emendation of
294 295
	 * <i>Angelica sylvestris</i> L.<BR>
295
	 * The name corrected by an emendation has originally been used on purpose (not accidentially) 
296
	 * Therefore emendations are a subset of {@link #ORTHOGRAPHIC_VARIANT orthographic variants} and are 
297
	 * complementary to {@link #MISSPELLING missepllings}. An emendation is always an 
296
	 * The name corrected by an emendation has originally been used on purpose (not accidentially)
297
	 * Therefore emendations are a subset of {@link #ORTHOGRAPHIC_VARIANT orthographic variants} and are
298
	 * complementary to {@link #MISSPELLING missepllings}. An emendation is always an
298 299
	 * {@link #ORTHOGRAPHIC_VARIANT orthographic variant}, too.<BR>
299 300
	 * This type is symmetric and transitive but usually the misspelling relationships should be organized
300 301
	 * in a star schema with the correct variant in the middle and the misspellings pointing to it.
......
316 317
	 * For instance <i>Astragalus rhizanthus</i> Boiss. is a later homonym of
317 318
	 * <i>Astragalus rhizanthus</i> Royle.<BR>
318 319
	 * This type is not symmetric but transitive.
319
	 * 
320
	 *
320 321
	 * @see	NomenclaturalStatusType#isIllegitimateType()
321 322
	 * @see	NomenclaturalStatusType#isLegitimateType()
322 323
	 */
......
324 325
	  return findTermByUuid(uuidLaterHomonym);
325 326
	}
326 327

  
327
	
328

  
328 329
	/**
329 330
	 * Returns the "treated as later homonym" name relationship type. The first
330 331
	 * {@link TaxonNameBase taxon name} involved in such a relationship is
......
336 337
	 * taxon name is "illegitimate" and the second one is "legitimate" (this
337 338
	 * corresponds to "invalid" and "valid" in case of {@link ZoologicalName zoological names}).<BR>
338 339
	 * This type is not symmetric but transitive.
339
	 * 
340
	 *
340 341
	 * @see	#LATER_HOMONYM()
341 342
	 * @see	NomenclaturalStatusType#isIllegitimateType()
342 343
	 * @see	NomenclaturalStatusType#isLegitimateType()
......
344 345
	public static final NameRelationshipType TREATED_AS_LATER_HOMONYM(){
345 346
	  return findTermByUuid(uuidTreatedAsLaterHomonym);
346 347
	}
347
	
348

  
348 349
	/**
349 350
	 * Returns the "later isonym" name relationship type where the first
350 351
	 * {@link TaxonNameBase taxon name} involved has been published after the second taxon name.<BR>
351
	 * In contrast to the {@link #LATER_HOMONYM() later homonym} relationship the two 
352
	 * In contrast to the {@link #LATER_HOMONYM() later homonym} relationship the two
352 353
	 * {@link TaxonNameBase taxon names} involved have the type(s) so they belong to the
353 354
	 * same {@link HomotypicalGroup homotypical groups}. As later homonyms they have in general
354 355
	 * different {@link NonViralName#getAuthorshipCache() authorship} and their name parts
355 356
	 * must be (almost) identical, so one could be mistaken for the other one.<BR>
356 357
	 * Later isonyms are validly published names but with a wrong citation. So there are rather errors
357 358
	 * then independent names.<BR>
358
	 * Isonyms are handled in Article 6, Note 2 of the ICNAFP (Melbourne Code): 
359
	 * Isonyms are handled in Article 6, Note 2 of the ICNAFP (Melbourne Code):
359 360
	 * <code>When the same name, based on the same type, has been published independently at different
360
	 *  times perhaps by different authors, then only the earliest of these �isonyms� has 
361
	 *  nomenclatural status. The name is always to be cited from its original 
361
	 *  times perhaps by different authors, then only the earliest of these �isonyms� has
362
	 *  nomenclatural status. The name is always to be cited from its original
362 363
	 *  place of valid publication, and later isonyms may be disregarded (but see Art. 14.15).</code>
363 364
	 * <BR><BR>
364 365
	 * See discussion at: <a href=http://dev.e-taxonomy.eu/trac/ticket/2901>#2901</a>
365
	 * 
366
	 *
366 367
	 */
367 368
	public static final NameRelationshipType LATER_ISONYM(){
368 369
		return findTermByUuid(uuidLaterIsonym);
369 370
	}
370
	
371

  
371 372
	/**
372 373
	 * Returns the "alternative name" name relationship type. Both {@link TaxonNameBase taxon names}
373 374
	 * involved in such a relationship are family names. The first one is a
......
385 386
	  return findTermByUuid(uuidAlternativeName);
386 387
	}
387 388
	/**
388
	 * Returns the "basionym" name relationship type. The first {@link TaxonNameBase taxon name} 
389
	 * Returns the "basionym" name relationship type. The first {@link TaxonNameBase taxon name}
389 390
	 * involved in such a relationship is the "basionym" of the second taxon
390 391
	 * name. Both taxon names belong to the same {@link HomotypicalGroup homotypical group}).
391
	 * The basionym is the epithet-bringing taxon name (first taxon name 
392
	 * The basionym is the epithet-bringing taxon name (first taxon name
392 393
	 * ever validly published given to the same {@link Rank#isInfraGeneric() infrageneric}
393
	 * taxon, the epithet of which is the same as in the second taxon name 
394
	 * taxon, the epithet of which is the same as in the second taxon name
394 395
	 * originated through a reclassification).<BR>
395 396
	 * According to the ICBN the author of the basionym must be mentioned in the
396 397
	 * later taxon name (by placing it in parentheses before the authority of
......
402 403
	  return findTermByUuid(uuidBasionym);
403 404
	}
404 405
	/**
405
	 * Returns the "replaced synonym" name relationship type. The first 
406
	 * Returns the "replaced synonym" name relationship type. The first
406 407
	 * {@link TaxonNameBase taxon name} involved in such a relationship is the
407 408
	 * "replaced synonym" of the second taxon name. Both taxon names belong to
408 409
	 * the same {@link HomotypicalGroup homotypical group}. The replaced synonym is the
......
418 419
	 * of reclassification a taxon name <i>Cytisus biflorum</i> had been already
419 420
	 * published by L'H�r.<BR>
420 421
	 * This type is neither symmetric nor transitive.
421
	 * 
422
	 *
422 423
	 * @see #BASIONYM()
423 424
	 * @see #LATER_HOMONYM()
424 425
	 * @see NomenclaturalStatusType#NOVUM()
......
436 437
	 * For instance <i>Cephaloziella</i> (Spruce) Schiffn. is conserved against
437 438
	 * <i>Dichiton</i> Mont.<BR>
438 439
	 * This type is neither symmetric nor transitive.
439
	 * 
440
	 *
440 441
	 * @see NomenclaturalStatusType#CONSERVED()
441 442
	 * @see NomenclaturalStatusType#REJECTED()
442 443
	 * @see NomenclaturalStatusType#isLegitimateType()
......
452 453
	 * (earlier) taxon name was invalidly published whereas the second (later)
453 454
	 * taxon name is the one which was validly published for the first time.<BR>
454 455
	 * This type is neither symmetric nor transitive.
455
	 * 
456
	 *
456 457
	 * @see		NomenclaturalStatusType#isInvalidType()
457 458
	 * @see		NomenclaturalStatusType#VALID()
458 459
	 */
......
466 467
	 * (earlier) taxon name was invalidly published whereas the second (later)
467 468
	 * taxon name is the one which was validly published for the first time.<BR>
468 469
	 * This type is neither symmetric nor transitive.
469
	 * 
470
	 *
470 471
	 * @see		NomenclaturalStatusType#isInvalidType()
471 472
	 * @see		NomenclaturalStatusType#VALID()
472 473
	 */
473 474
	public static final NameRelationshipType LATER_VALIDATED_BY_NAME(){
474
	  return findTermByUuid(uuidLaterValidatedByName); 
475
	  return findTermByUuid(uuidLaterValidatedByName);
475 476
	}
476 477
	/**
477
	 * Returns the "blocking name" name relationship type. The first 
478
	 * Returns the "blocking name" name relationship type. The first
478 479
	 * {@link TaxonNameBase taxon name} involved in such a relationship is the
479 480
	 * "blocking name" for the second taxon name. Both taxon names belong to
480 481
	 * different {@link HomotypicalGroup homotypical groups}). The blocking taxon name is the
......
486 487
	 * <i>Cytisus fontanesii</i> Spach ("novum" taxon name) when reclassifying
487 488
	 * <i>Spartium biflorum</i> Desf. from <i>Spartium</i> to <i>Cytisus</i>.<BR>
488 489
	 * This type is neither symmetric nor transitive.
489
	 * 
490
	 *
490 491
	 * @see #REPLACED_SYNONYM()
491 492
	 * @see #LATER_HOMONYM()
492 493
	 * @see NomenclaturalStatusType#NOVUM()
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/Rank.java
219 219

  
220 220

  
221 221
    protected static Rank getTermByUuid(UUID uuid){
222
        if (termMap == null){
223
            return null;  //better return null then initialize the termMap in an unwanted way
222
        if (termMap == null || termMap.isEmpty()){
223
           return getTermByClassAndUUID(Rank.class, uuid);
224
        } else {
225
            return termMap.get(uuid);
224 226
        }
225
        return termMap.get(uuid);
226 227
    }
227 228

  
228 229
    public static final Rank EMPIRE(){
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/MatchStrategyConfigurator.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.strategy.match;
12

  
13
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
14
import eu.etaxonomy.cdm.model.name.NonViralName;
15
import eu.etaxonomy.cdm.model.reference.Reference;
16

  
17
/**
18
 * This class defines the MatchStrategies that will be used by the ParseHandler.
19
 *
20
 * @author n.hoffmann
21
 * @created Jan 22, 2010
22
 * @version 1.0
23
 */
24
public class MatchStrategyConfigurator {
25

  
26

  
27
    public enum MatchStrategy {
28
        NonViralName,
29
        TeamOrPerson,
30
        Reference
31
    }
32

  
33
    public static IMatchStrategy getMatchStrategy(MatchStrategy strategy) throws MatchException {
34
        switch(strategy) {
35
        case NonViralName :
36
            return NonViralNameMatchStrategy();
37
        case TeamOrPerson:
38
            return TeamOrPersonMatchStrategy();
39
        case Reference :
40
            return ReferenceMatchStrategy();
41
        default :
42
            return null;
43
        }
44
    }
45
	/**
46
	 * <p>NonViralNameMatchStrategy</p>
47
	 *
48
	 * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
49
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
50
	 */
51
	public static IMatchStrategy NonViralNameMatchStrategy() throws MatchException{
52
		return getDefaultNonViralNameMatchStrategy();// PreferencesUtil.getMatchStrategy(NonViralName.class);
53
	}
54

  
55
	/**
56
	 * <p>TeamOrPersonMatchStrategy</p>
57
	 *
58
	 * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
59
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
60
	 */
61
	public static IMatchStrategy TeamOrPersonMatchStrategy() throws MatchException{
62
		return null;// PreferencesUtil.getMatchStrategy(TeamOrPersonBase.class);
63
	}
64

  
65
	/**
66
	 * <p>ReferenceMatchStrategy</p>
67
	 *
68
	 * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
69
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
70
	 */
71
	public static IMatchStrategy ReferenceMatchStrategy() throws MatchException{
72
		return getDefaultReferenceMatchStrategy();// PreferencesUtil.getMatchStrategy(ReferenceBase.class);
73
	}
74

  
75
	/**
76
	 * <p>getDefaultNonViralNameMatchStrategy</p>
77
	 *
78
	 * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
79
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
80
	 */
81
	public static IMatchStrategy getDefaultNonViralNameMatchStrategy() throws MatchException{
82
		IMatchStrategy strategy = DefaultMatchStrategy.NewInstance(NonViralName.class);
83

  
84
		strategy.setMatchMode("nomenclaturalReference", MatchMode.IGNORE);
85
		strategy.setMatchMode("combinationAuthorTeam", MatchMode.IGNORE);
86
		strategy.setMatchMode("exCombinationAuthorTeam", MatchMode.IGNORE);
87
		strategy.setMatchMode("basionymAuthorTeam", MatchMode.IGNORE);
88
		strategy.setMatchMode("exBasionymAuthorTeam", MatchMode.IGNORE);
89

  
90
		return strategy;
91
	}
92

  
93
	/**
94
	 * <p>getDefaultTeamOrPersonMatchStrategy</p>
95
	 *
96
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
97
	 * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
98
	 */
99
	public static IMatchStrategy getDefaultTeamOrPersonMatchStrategy() throws MatchException{
100
		IMatchStrategy strategy = DefaultMatchStrategy.NewInstance(TeamOrPersonBase.class);
101

  
102
		return strategy;
103
	}
104

  
105

  
106
	/**
107
	 * <p>getDefaultReferenceMatchStrategy</p>
108
	 *
109
	 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
110
	 * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
111
	 */
112
	public static IMatchStrategy getDefaultReferenceMatchStrategy() throws MatchException{
113
		IMatchStrategy strategy = DefaultMatchStrategy.NewInstance(Reference.class);
114

  
115
		strategy.setMatchMode("title", MatchMode.EQUAL);
116
		strategy.setMatchMode("inReference", MatchMode.IGNORE);
117

  
118
		return strategy;
119
	}
120

  
121

  
122
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/CdmDataChangeEvent.java
1 1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
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.
8
 */
9 9

  
10 10
package eu.etaxonomy.cdm.persistence.hibernate;
11 11

  
12 12
import java.io.Serializable;
13
import java.util.Set;
13 14

  
14 15
import org.apache.log4j.Logger;
15 16
import org.hibernate.event.spi.AbstractEvent;
......
33 34
 * @version 1.0
34 35
 */
35 36
public class CdmDataChangeEvent extends AbstractEvent{
36
	private static final long serialVersionUID = 9113025682352080372L;
37
	private static final Logger logger = Logger.getLogger(CdmDataChangeEvent.class);
38

  
39
	/**
40
	 * The event types currently implemented
41
	 *
42
	 * @author n.hoffmann
43
	 * @created 25.03.2009
44
	 * @version 1.0
45
	 */
46
	public enum EventType {
47
		INSERT, LOAD, UPDATE, DELETE
48
	}
49

  
50
	private final CdmBase entity;
51
	private final EntityPersister persister;
52
	private final Object[] state;
53
	// for update only
54
	private Object[] oldState;
55
	private final Serializable id;
56
	protected final EventType eventType;
57

  
58
	/**
59
	 * @param source
60
	 */
61
	private CdmDataChangeEvent(
62
			CdmBase entity,
63
			Serializable id,
64
			Object[] state,
65
			Object[] oldState,
66
			EntityPersister persister,
67
			EventSource source,
68
			EventType eventType
69
	) {
70
		super(source);
71
		this.entity = entity;
72
		this.id = id;
73
		this.state = state;
74
		this.oldState = oldState;
75
		this.persister = persister;
76
		this.eventType = eventType;
77
	}
78

  
79
	public CdmBase getEntity() {
80
		return entity;
81
	}
82
	public Serializable getId() {
83
		return id;
84
	}
85
	public EntityPersister getPersister() {
86
		return persister;
87
	}
88
	public Object[] getState() {
89
		return state;
90
	}
91
	public Object[] getOldState() {
92
		if(oldState == null){
93
			oldState = state;
94
		}
95
		return oldState;
96
	}
97

  
98
	public EventType getEventType(){
99
		return eventType;
100
	}
101

  
102
	public boolean isInsert(){
103
		return eventType == EventType.INSERT;
104
	}
105

  
106
	public boolean isLoad(){
107
		return eventType == EventType.LOAD;
108
	}
109

  
110
	public boolean isUpdate(){
111
		return eventType == EventType.UPDATE;
112
	}
113

  
114
	public boolean isDelete(){
115
		return eventType == EventType.DELETE;
116
	}
117

  
118
	/**
119
	 * @param event
120
	 * @return
121
	 */
122
	public static CdmDataChangeEvent NewInstance(AbstractEvent event) {
123

  
124
		CdmDataChangeEvent mediationEvent = null;
125
		try{
126
			if(event instanceof PostInsertEvent){
127
				PostInsertEvent postEvent = (PostInsertEvent) event;
128
				mediationEvent = new CdmDataChangeEvent(
129
																(CdmBase)postEvent.getEntity(),
130
																postEvent.getId(),
131
																postEvent.getState(),
132
																null,
133
																postEvent.getPersister(),
134
																postEvent.getSession(),
135
																EventType.INSERT
136
																);
137
			}
138
			if(event instanceof PostLoadEvent){
139
				PostLoadEvent updateEvent = (PostLoadEvent) event;
140
				mediationEvent = new CdmDataChangeEvent(
141
																(CdmBase)updateEvent.getEntity(),
142
																updateEvent.getId(),
143
																null,
144
																null,
145
																updateEvent.getPersister(),
146
																updateEvent.getSession(),
147
																EventType.LOAD
148
																);
149
			}
150
			if(event instanceof PostUpdateEvent){
151
				PostUpdateEvent updateEvent = (PostUpdateEvent) event;
152
				mediationEvent = new CdmDataChangeEvent(
153
																(CdmBase)updateEvent.getEntity(),
154
																updateEvent.getId(),
155
																updateEvent.getState(),
156
																updateEvent.getOldState(),
157
																updateEvent.getPersister(),
158
																updateEvent.getSession(),
159
																EventType.UPDATE
160
																);
161
			}
162
			if(event instanceof PostDeleteEvent){
163
				PostDeleteEvent deleteEvent = (PostDeleteEvent) event;
164
				mediationEvent = new CdmDataChangeEvent(
165
																(CdmBase)deleteEvent.getEntity(),
166
																deleteEvent.getId(),
167
																deleteEvent.getDeletedState(),
168
																null,
169
																deleteEvent.getPersister(),
170
																deleteEvent.getSession(),
171
																EventType.DELETE
172
																);
173
			}
174
		}catch(ClassCastException e){
175
			// we are only interested in CdmBase entities, we have the try/catch block in case another entity slips through
176
			logger.warn("tried to instantiate event for non CdmBase entity");
177
		}
178

  
179
		return mediationEvent;
180
	}
181

  
182
	public static CdmDataChangeEvent NewInstance(CdmBase entity, EventType eventType) {
183
	    return new CdmDataChangeEvent(entity,
184
                null,
185
                null,
186
                null,
187
                null,
188
                null,
189
                eventType);
190
	}
37
    private static final long serialVersionUID = 9113025682352080372L;
38
    private static final Logger logger = Logger.getLogger(CdmDataChangeEvent.class);
39

  
40
    /**
41
     * The event types currently implemented
42
     *
43
     * @author n.hoffmann
44
     * @created 25.03.2009
45
     * @version 1.0
46
     */
47
    public enum EventType {
48
        INSERT, LOAD, UPDATE, DELETE
49
    }
50

  
51
    private final CdmBase entity;
52
    private final EntityPersister persister;
53
    private final Set<CdmBase> affectedObjects;
54

  
55

  
56
    private final Object[] state;
57
    // for update only
58
    private Object[] oldState;
59
    private final Serializable id;
60
    protected final EventType eventType;
61

  
62
    /**
63
     * @param source
64
     */
65
    private CdmDataChangeEvent(
66
            CdmBase entity,
67
            Serializable id,
68
            Object[] state,
69
            Object[] oldState,
70
            EntityPersister persister,
71
            EventSource source,
72
            EventType eventType
73
            ) {
74
        super(source);
75
        this.entity = entity;
76
        this.id = id;
77
        this.state = state;
78
        this.oldState = oldState;
79
        this.persister = persister;
80
        this.eventType = eventType;
81
        this.affectedObjects = null;
82
    }
83
    /**
84
     * @param source
85
     */
86
    private CdmDataChangeEvent(
87
            CdmBase entity,
88
            Set<CdmBase> affectedObjects,
89
            EventType eventType
90
            ) {
91
        super(null);
92
        this.entity = entity;
93
        this.persister = null;
94
        this.affectedObjects = affectedObjects;
95
        this.state = null;
96
        this.oldState = null;
97
        this.id = null;
98
        this.eventType = eventType;
99
    }
100

  
101
    public CdmBase getEntity() {
102
        return entity;
103
    }
104
    public Serializable getId() {
105
        return id;
106
    }
107
    public EntityPersister getPersister() {
108
        return persister;
109
    }
110
    public Object[] getState() {
111
        return state;
112
    }
113
    public Object[] getOldState() {
114
        if(oldState == null){
115
            oldState = state;
116
        }
117
        return oldState;
118
    }
119

  
120
    public Set<CdmBase> getAffectedObjects() {
121
        return affectedObjects;
122
    }
123

  
124
    public EventType getEventType(){
125
        return eventType;
126
    }
127

  
128
    public boolean isInsert(){
129
        return eventType == EventType.INSERT;
130
    }
131

  
132
    public boolean isLoad(){
133
        return eventType == EventType.LOAD;
134
    }
135

  
136
    public boolean isUpdate(){
137
        return eventType == EventType.UPDATE;
138
    }
139

  
140
    public boolean isDelete(){
141
        return eventType == EventType.DELETE;
142
    }
143

  
144
    /**
145
     * @param event
146
     * @return
147
     */
148
    public static CdmDataChangeEvent NewInstance(AbstractEvent event) {
149

  
150
        CdmDataChangeEvent mediationEvent = null;
151
        try{
152
            if(event instanceof PostInsertEvent){
153
                PostInsertEvent postEvent = (PostInsertEvent) event;
154
                mediationEvent = new CdmDataChangeEvent(
155
                        (CdmBase)postEvent.getEntity(),
156
                        postEvent.getId(),
157
                        postEvent.getState(),
158
                        null,
159
                        postEvent.getPersister(),
160
                        postEvent.getSession(),
161
                        EventType.INSERT
162
                        );
163
            }
164
            if(event instanceof PostLoadEvent){
165
                PostLoadEvent updateEvent = (PostLoadEvent) event;
166
                mediationEvent = new CdmDataChangeEvent(
167
                        (CdmBase)updateEvent.getEntity(),
168
                        updateEvent.getId(),
169
                        null,
170
                        null,
171
                        updateEvent.getPersister(),
172
                        updateEvent.getSession(),
173
                        EventType.LOAD
174
                        );
175
            }
176
            if(event instanceof PostUpdateEvent){
177
                PostUpdateEvent updateEvent = (PostUpdateEvent) event;
178
                mediationEvent = new CdmDataChangeEvent(
179
                        (CdmBase)updateEvent.getEntity(),
180
                        updateEvent.getId(),
181
                        updateEvent.getState(),
182
                        updateEvent.getOldState(),
183
                        updateEvent.getPersister(),
184
                        updateEvent.getSession(),
185
                        EventType.UPDATE
186
                        );
187
            }
188
            if(event instanceof PostDeleteEvent){
189
                PostDeleteEvent deleteEvent = (PostDeleteEvent) event;
190
                mediationEvent = new CdmDataChangeEvent(
191
                        (CdmBase)deleteEvent.getEntity(),
192
                        deleteEvent.getId(),
193
                        deleteEvent.getDeletedState(),
194
                        null,
195
                        deleteEvent.getPersister(),
196
                        deleteEvent.getSession(),
197
                        EventType.DELETE
198
                        );
199
            }
200
        }catch(ClassCastException e){
201
            // we are only interested in CdmBase entities, we have the try/catch block in case another entity slips through
202
            logger.warn("tried to instantiate event for non CdmBase entity");
203
        }
204

  
205
        return mediationEvent;
206
    }
207

  
208
    public static CdmDataChangeEvent NewInstance(CdmBase entity, Set<CdmBase> affectedObjects, EventType eventType) {
209

  
210
        return new CdmDataChangeEvent(entity, affectedObjects, eventType);
211
    }
191 212

  
192 213
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff