Project

General

Profile

« Previous | Next » 

Revision a43f5d4e

Added by Katja Luther about 6 years ago

move getUuidAndTitleCache methods to identifiableDao

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IAnnotatableDao.java
16 16
import eu.etaxonomy.cdm.model.common.Marker;
17 17
import eu.etaxonomy.cdm.model.common.MarkerType;
18 18
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
19
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
20 19
import eu.etaxonomy.cdm.persistence.query.OrderHint;
21 20

  
22 21
/**
......
92 91
	 */
93 92
	public int countMarkers(Class<? extends T> clazz, Boolean technical);
94 93

  
95
    /**
96
     * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
97
     * Retrieving this list is considered to be significantly faster than initializing the fully fledged buiseness
98
     * objects. To be used in cases where you want to present large amount of data and provide details after
99
     * a selection has been made.
100
     *
101
     * @return a list of <code>UuidAndTitleCache</code> instances
102
     * @see #getUuidAndTitleCache(Class, Integer, String)
103
     */
104
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(Integer limit, String pattern);
105

  
106
    /**
107
     * Like {@link #getUuidAndTitleCache(Integer, String)} but searching only on a subclass
108
     * of the type handled by the DAO.
109
     *
110
     * @param clazz the (sub)class
111
     * @param limit max number of results
112
     * @param pattern search pattern
113 94

  
114
     * @see #getUuidAndTitleCache(Integer, String)
115
     */
116
    public <S extends T> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, Integer limit, String pattern);
117

  
118

  
119
    /**
120
     * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
121
     * Retrieving this list is considered to be significantly faster than initializing the fully fledged buiseness
122
     * objects. To be used in cases where you want to present large amount of data and provide details after
123
     * a selection has been made.
124
     *
125
     * @return a list of <code>UuidAndTitleCache</code> instances
126
     */
127
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache();
128 95
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IIdentifiableDao.java
22 22
import eu.etaxonomy.cdm.model.common.MarkerType;
23 23
import eu.etaxonomy.cdm.model.media.Rights;
24 24
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
25
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
25 26
import eu.etaxonomy.cdm.persistence.query.MatchMode;
26 27
import eu.etaxonomy.cdm.persistence.query.OrderHint;
27 28

  
......
232 233
    public <S extends T> List<Object[]> findByMarker(Class<S> clazz, MarkerType markerType, Boolean markerValue, boolean includeEntity,
233 234
            Integer pageSize, Integer pageNumber, List<String> propertyPaths);
234 235

  
236
    /**
237
     * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
238
     * Retrieving this list is considered to be significantly faster than initializing the fully fledged buiseness
239
     * objects. To be used in cases where you want to present large amount of data and provide details after
240
     * a selection has been made.
241
     *
242
     * @return a list of <code>UuidAndTitleCache</code> instances
243
     * @see #getUuidAndTitleCache(Class, Integer, String)
244
     */
245
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(Integer limit, String pattern);
246

  
247
    /**
248
     * Like {@link #getUuidAndTitleCache(Integer, String)} but searching only on a subclass
249
     * of the type handled by the DAO.
250
     *
251
     * @param clazz the (sub)class
252
     * @param limit max number of results
253
     * @param pattern search pattern
254

  
255
     * @see #getUuidAndTitleCache(Integer, String)
256
     */
257
    public <S extends T> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, Integer limit, String pattern);
258

  
259

  
260
    /**
261
     * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
262
     * Retrieving this list is considered to be significantly faster than initializing the fully fledged buiseness
263
     * objects. To be used in cases where you want to present large amount of data and provide details after
264
     * a selection has been made.
265
     *
266
     * @return a list of <code>UuidAndTitleCache</code> instances
267
     */
268
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache();
269

  
235 270
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/AnnotatableDaoImpl.java
9 9

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

  
12
import java.util.ArrayList;
13 12
import java.util.List;
14
import java.util.UUID;
15 13

  
16 14
import org.apache.log4j.Logger;
17 15
import org.hibernate.Query;
18
import org.hibernate.Session;
19 16

  
20 17
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
21 18
import eu.etaxonomy.cdm.model.common.Annotation;
22
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
23 19
import eu.etaxonomy.cdm.model.common.Marker;
24 20
import eu.etaxonomy.cdm.model.common.MarkerType;
25 21
import eu.etaxonomy.cdm.persistence.dao.common.IAnnotatableDao;
26
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
27 22
import eu.etaxonomy.cdm.persistence.query.OrderHint;
28 23
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
29 24

  
......
232 227
		return result;
233 228
	}
234 229

  
235
    @Override
236
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(Integer limit, String pattern){
237
        return getUuidAndTitleCache(type, limit, pattern);
238
    }
239

  
240

  
241
    @Override
242
    public <S extends T> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, Integer limit, String pattern){
243
        Session session = getSession();
244
        Query query = null;
245
        if (pattern != null){
246
            query = session.createQuery("select uuid, id, titleCache from " + clazz.getSimpleName() +" where titleCache like :pattern");
247
            pattern = pattern.replace("*", "%");
248
            pattern = pattern.replace("?", "_");
249
            pattern = pattern + "%";
250
            query.setParameter("pattern", pattern);
251
        } else {
252
            query = session.createQuery("select uuid, id, titleCache from " + clazz.getSimpleName() );
253
        }
254
        if (limit != null){
255
           query.setMaxResults(limit);
256
        }
257
        return getUuidAndTitleCache(query);
258
    }
259

  
260 230

  
261
    @Override
262
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(){
263
        return getUuidAndTitleCache(type, null, null);
264
    }
265

  
266
    protected <E extends IAnnotatableEntity> List<UuidAndTitleCache<E>> getUuidAndAbbrevTitleCache(Query query){
267
        List<UuidAndTitleCache<E>> list = new ArrayList<UuidAndTitleCache<E>>();
268

  
269
        List<Object[]> result = query.list();
270

  
271
        for(Object[] object : result){
272
            list.add(new UuidAndTitleCache<E>((UUID) object[0],(Integer) object[1], (String) object[3], (String) object[2]));
273
        }
274
        return list;
275
    }
276

  
277
    protected <E extends IAnnotatableEntity> List<UuidAndTitleCache<E>> getUuidAndTitleCache(Query query){
278
        List<UuidAndTitleCache<E>> list = new ArrayList<UuidAndTitleCache<E>>();
279

  
280
        List<Object[]> result = query.list();
281

  
282
        for(Object[] object : result){
283
            list.add(new UuidAndTitleCache<E>((UUID) object[0],(Integer) object[1], (String) object[2]));
284
        }
285
        return list;
286
    }
287 231

  
288 232
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/IdentifiableDaoBase.java
33 33
import eu.etaxonomy.cdm.model.common.CdmBase;
34 34
import eu.etaxonomy.cdm.model.common.Credit;
35 35
import eu.etaxonomy.cdm.model.common.DefinedTerm;
36
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
36 37
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
37 38
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
38 39
import eu.etaxonomy.cdm.model.common.LSID;
......
40 41
import eu.etaxonomy.cdm.model.media.Rights;
41 42
import eu.etaxonomy.cdm.persistence.dao.QueryParseException;
42 43
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
44
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
43 45
import eu.etaxonomy.cdm.persistence.query.MatchMode;
44 46
import eu.etaxonomy.cdm.persistence.query.OrderHint;
45 47

  
......
610 612
        return results;
611 613
    }
612 614

  
615
    @Override
616
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(Integer limit, String pattern){
617
        return getUuidAndTitleCache(type, limit, pattern);
618
    }
619

  
620

  
621
    @Override
622
    public <S extends T> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, Integer limit, String pattern){
623
        Session session = getSession();
624
        Query query = null;
625
        if (pattern != null){
626
            query = session.createQuery("select uuid, id, titleCache from " + clazz.getSimpleName() +" where titleCache like :pattern");
627
            pattern = pattern.replace("*", "%");
628
            pattern = pattern.replace("?", "_");
629
            pattern = pattern + "%";
630
            query.setParameter("pattern", pattern);
631
        } else {
632
            query = session.createQuery("select uuid, id, titleCache from " + clazz.getSimpleName() );
633
        }
634
        if (limit != null){
635
           query.setMaxResults(limit);
636
        }
637
        return getUuidAndTitleCache(query);
638
    }
639

  
640

  
641
    @Override
642
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(){
643
        return getUuidAndTitleCache(type, null, null);
644
    }
645

  
646
    protected <E extends IAnnotatableEntity> List<UuidAndTitleCache<E>> getUuidAndAbbrevTitleCache(Query query){
647
        List<UuidAndTitleCache<E>> list = new ArrayList<UuidAndTitleCache<E>>();
648

  
649
        List<Object[]> result = query.list();
650

  
651
        for(Object[] object : result){
652
            list.add(new UuidAndTitleCache<E>((UUID) object[0],(Integer) object[1], (String) object[3], (String) object[2]));
653
        }
654
        return list;
655
    }
656

  
657
    protected <E extends IAnnotatableEntity> List<UuidAndTitleCache<E>> getUuidAndTitleCache(Query query){
658
        List<UuidAndTitleCache<E>> list = new ArrayList<UuidAndTitleCache<E>>();
659

  
660
        List<Object[]> result = query.list();
661

  
662
        for(Object[] object : result){
663
            list.add(new UuidAndTitleCache<E>((UUID) object[0],(Integer) object[1], (String) object[2]));
664
        }
665
        return list;
666
    }
667

  
613 668
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/molecular/PrimerDaoHibernateImpl.java
71 71
        return findByParam(Primer.class, "label", queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
72 72
    }
73 73

  
74
    /**
75
     * {@inheritDoc}
76
     */
77
    @Override
78
    public List<UuidAndTitleCache<Primer>> getPrimerUuidAndTitleCache(Integer limitOfInitialElements, String pattern) {
79

  
80
        Session session = getSession();
81

  
82
        String queryString = "SELECT uuid, id, label FROM Prime ";
83

  
84
        if ( pattern != null){
85
            queryString += " WHERE ";
86
            queryString += " titleCache LIKE :pattern";
87

  
88
        }
89

  
90
        Query query;
91
        query = session.createQuery(queryString);
92

  
93

  
94
        if (limitOfInitialElements != null){
95
            query.setMaxResults(limitOfInitialElements);
96
        }
97
        if (pattern != null){
98
              pattern = pattern.replace("*", "%");
99
              pattern = pattern.replace("?", "_");
100
              pattern = pattern + "%";
101
              query.setParameter("pattern", pattern);
102
        }
103

  
104
        @SuppressWarnings("unchecked")
105
        List<Object[]> result = query.list();
106
        List<UuidAndTitleCache<Primer>> list = new ArrayList<>();
107
        for(Object[] object : result){
108
            list.add(new UuidAndTitleCache<Primer>(Primer.class, (UUID) object[0],(Integer)object[1], (String)object[2]));
109
        }
110

  
111
        return list;
112
    }
113

  
74 114
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/molecular/IPrimerDao.java
63 63
    public List<Primer> findByTitle(String queryString, MatchMode matchmode, List<Criterion> criteria,
64 64
            Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
65 65

  
66

  
67
    /**
68
     * @param limitOfInitialElements
69
     * @param pattern
70
     * @return
71
     */
72
    public List<UuidAndTitleCache<Primer>> getPrimerUuidAndTitleCache(Integer limitOfInitialElements, String pattern);
73

  
66 74
}

Also available in: Unified diff