2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.cdm
.persistence
.hibernate
;
12 import java
.io
.Serializable
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.hibernate
.EmptyInterceptor
;
16 import org
.hibernate
.Transaction
;
17 import org
.hibernate
.resource
.transaction
.spi
.TransactionStatus
;
18 import org
.hibernate
.type
.Type
;
19 import org
.springframework
.stereotype
.Component
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 public class CdmHibernateInterceptor
extends EmptyInterceptor
{
29 private static final long serialVersionUID
= 2536017420460052854L;
30 private static final Logger logger
= Logger
.getLogger(CdmHibernateInterceptor
.class);
32 //FIXME problem is circular dependency (see VocabularyStoreImpl.staticInitialized
34 // VocabularyStoreImpl vocabularyStore;
41 public void onDelete(Object entity
,
44 String
[] propertyNames
,
50 public boolean onFlushDirty(Object entity
,
52 Object
[] currentState
,
53 Object
[] previousState
,
54 String
[] propertyNames
,
56 if (logger
.isDebugEnabled()) {
57 logger
.debug("onFlushDirty...");
59 boolean result
= false;
60 if ( entity
instanceof CdmBase
) {
62 //result &= checkTransientDefinedTerms(currentState);
68 public boolean onLoad(Object entity
,
71 String
[] propertyNames
,
73 if ( entity
instanceof CdmBase
) {
74 if (logger
.isDebugEnabled()) {
75 logger
.debug("id = " +id
);
83 public boolean onSave(Object entity
,
86 String
[] propertyNames
,
88 if (logger
.isDebugEnabled()) {
89 logger
.debug("onSave...");
91 boolean result
= false;
92 if ( entity
instanceof CdmBase
) {
94 //result &= checkTransientDefinedTerms(state);
100 private boolean checkTransientDefinedTerms(Object
[] state
){
101 boolean result
= false;
102 // if (VocabularyStoreImpl.isInitialized()){
103 // //logger.debug("Save: " + entity);
105 // for (Object singleState : state){
107 // if (singleState instanceof DefinedTermBase){
108 // DefinedTermBase term = ((DefinedTermBase)singleState);
109 // if (term.getId() != 0){
112 // //logger.debug(" " + singleState.getClass());
113 // UUID uuid = term.getUuid();
114 // DefinedTermBase storedTermBase = VocabularyStoreImpl.getCurrentVocabularyStore().getTermByUuid(uuid);
115 // if (storedTermBase == null){
116 // logger.warn("DefinedTermBase with uuid "+ uuid +" could not be found in vocabulary store. Term stays transient.");
117 // }else if (uuid.equals(storedTermBase.getUuid())){
118 // logger.debug("Changed transient term");
119 // state[i] = storedTermBase;
122 // throw new IllegalStateException("UUID is not equal.");
128 // }else{ //not initialized
135 public void afterTransactionCompletion(Transaction tx
) {
136 if ( tx
.getStatus() == TransactionStatus
.COMMITTED
) {
137 logger
.debug("Creations: " + creates
+ ", Updates: " + updates
+ ", Loads: " + loads
);