Project

General

Profile

Revision 1184c8e0

ID1184c8e0afa925a6c613665087a219f5bced64b4
Parent bf95f6e9
Child 208ded38

Added by Patrick Plitzner over 1 year ago

ref #7998 Add service method for UuidAndTitleCache by term type

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/ITermVocabularyDao.java
21 21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22 22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
23 23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
24 25
import eu.etaxonomy.cdm.persistence.query.OrderHint;
25 26

  
26 27

  
......
120 121
     */
121 122
    public List<TermVocabularyDto> findVocabularyDtoByTermType(TermType termType);
122 123

  
124
    /**
125
     *
126
     * Like {@link #getUuidAndTitleCache(Class, Integer, String)} but filtering
127
     * the results by {@link TermType} of the vocabularies.
128
     *
129
     *
130
     * @param clazz
131
     *            the (sub)class
132
     * @param termType
133
     *            the {@link TermType} of the vocabularies to be retrieved
134
     * @param limit
135
     *            max number of results
136
     * @param pattern
137
     *            search pattern
138
     * @return a list of {@link UuidAndTitleCache}
139
     *
140
     * @see #getUuidAndTitleCache(Class, Integer, String))
141
     */
142
    public <S extends TermVocabulary> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, TermType termType,
143
            Integer limit, String pattern);
123 144
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/TermVocabularyDaoImpl.java
20 20

  
21 21
import org.hibernate.Criteria;
22 22
import org.hibernate.Query;
23
import org.hibernate.Session;
23 24
import org.hibernate.criterion.Restrictions;
24 25
import org.hibernate.envers.query.AuditEntity;
25 26
import org.hibernate.envers.query.AuditQuery;
......
34 35
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
35 36
import eu.etaxonomy.cdm.persistence.dto.TermDto;
36 37
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
38
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
37 39
import eu.etaxonomy.cdm.persistence.query.OrderHint;
38 40

  
39 41
/**
......
294 296
        return new ArrayList<>(dtoMap.values());
295 297
    }
296 298

  
299
    @Override
300
    public <S extends TermVocabulary> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, TermType termType,
301
            Integer limit, String pattern) {
302
        if(termType==null){
303
            return getUuidAndTitleCache(clazz, limit, pattern);
304
        }
305
        Session session = getSession();
306
        Query query = null;
307
        if (pattern != null){
308
            query = session.createQuery(
309
                      " SELECT uuid, id, titleCache "
310
                    + " FROM " + clazz.getSimpleName()
311
                    + " WHERE titleCache LIKE :pattern "
312
                    + " AND termType = :termType");
313
            pattern = pattern.replace("*", "%");
314
            pattern = pattern.replace("?", "_");
315
            pattern = pattern + "%";
316
            query.setParameter("pattern", pattern);
317
        } else {
318
            query = session.createQuery(
319
                      " SELECT uuid, id, titleCache "
320
                    + " FROM  " + clazz.getSimpleName()
321
                    + " WHERE termType = :termType");
322
        }
323
        query.setParameter("termType", termType);
324
        if (limit != null){
325
           query.setMaxResults(limit);
326
        }
327
        return getUuidAndTitleCache(query);
328
    }
329

  
297 330
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IVocabularyService.java
20 20
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21 21
import eu.etaxonomy.cdm.persistence.dto.TermDto;
22 22
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
23
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
23 24
import eu.etaxonomy.cdm.persistence.query.OrderHint;
24 25

  
25 26
public interface IVocabularyService extends IIdentifiableEntityService<TermVocabulary> {
......
104 105
     */
105 106
    public TermDto addNewTerm(TermType termType, UUID vocabularyUUID);
106 107

  
108
    /**
109
     *
110
     * Like {@link #getUuidAndTitleCache(Class, Integer, String)} but filtering
111
     * the results by {@link TermType} of the vocabularies.
112
     *
113
     *
114
     * @param clazz
115
     *            the (sub)class
116
     * @param termType
117
     *            the {@link TermType} of the vocabularies to be retrieved
118
     * @param limit
119
     *            max number of results
120
     * @param pattern
121
     *            search pattern
122
     * @return a list of {@link UuidAndTitleCache}
123
     *
124
     * @see #getUuidAndTitleCache(Class, Integer, String))
125
     */
126
    public <S extends TermVocabulary> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, TermType termType,
127
            Integer limit, String pattern);
128

  
107 129
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/VocabularyServiceImpl.java
28 28
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
29 29
import eu.etaxonomy.cdm.persistence.dto.TermDto;
30 30
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
31
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
31 32
import eu.etaxonomy.cdm.persistence.query.OrderHint;
32 33
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
33 34

  
......
140 141
        dao.saveOrUpdate(vocabulary);
141 142
        return TermDto.fromTerm(term, true);
142 143
    }
144

  
145
    @Override
146
    public <S extends TermVocabulary> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, TermType termType,
147
            Integer limit, String pattern) {
148
        return dao.getUuidAndTitleCache(clazz, termType, limit, pattern);
149
    }
143 150
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)