Project

General

Profile

« Previous | Next » 

Revision ae79876f

Added by Katja Luther almost 8 years ago

Revert "fix getTaxonUUIDAndTitleCacheForClassification"

This reverts commit 65149714aee38dad433405eb78195ac1ef5c4da3.

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
256 256
        boolean doCount = false;
257 257
        List<UuidAndTitleCache<IdentifiableEntity>> resultObjects = new ArrayList<UuidAndTitleCache<IdentifiableEntity>>();
258 258
        if (doNamesWithoutTaxa){
259
            List<? extends TaxonNameBase<?,?>> nameResult = taxonNameDao.findByName(queryString,matchMode, null, null, null, null);
259
        	List<? extends TaxonNameBase<?,?>> nameResult = taxonNameDao.findByName(queryString,matchMode, null, null, null, null);
260 260

  
261
            for (TaxonNameBase name: nameResult){
262
                if (name.getTaxonBases().size() == 0){
263
                    resultObjects.add(new UuidAndTitleCache(TaxonNameBase.class, name.getUuid(), name.getId(), name.getTitleCache()));
264
                }
265
            }
266
            if (!doSynonyms && !doTaxa){
267
                return resultObjects;
268
            }
261
        	for (TaxonNameBase name: nameResult){
262
        		if (name.getTaxonBases().size() == 0){
263
        			resultObjects.add(new UuidAndTitleCache(TaxonNameBase.class, name.getUuid(), name.getId(), name.getTitleCache()));
264
        		}
265
        	}
266
        	if (!doSynonyms && !doTaxa){
267
        		return resultObjects;
268
        	}
269 269
        }
270 270
        Query query = prepareTaxaByNameForEditor(doTaxa, doSynonyms, doMisappliedNames, "nameCache", queryString, classification, matchMode, namedAreas, doCount);
271 271

  
......
776 776
                }else{
777 777
                    return null;
778 778
                }
779
            }   else{
779
            }	else{
780 780
                //only misappliedNames
781 781
                if (taxa.size()>0){
782 782
                    query.setParameterList("taxa", taxa );
......
823 823

  
824 824
        String what = "select";
825 825
        if (doNotReturnFullEntities){
826
            what += " t.uuid, t.id, t.titleCache, \'taxon\', case when t.taxonNodes is empty and t.relationsFromThisTaxon is empty and t.relationsToThisTaxon is empty then true else false end ";
826
        	what += " t.uuid, t.id, t.titleCache, \'taxon\', case when t.taxonNodes is empty and t.relationsFromThisTaxon is empty and t.relationsToThisTaxon is empty then true else false end ";
827 827
        }else {
828
            what += (doCount ? " count(t)": " t");
828
        	what += (doCount ? " count(t)": " t");
829 829
        }
830 830
        String hql= what + " from Taxon t " +
831 831
        "join t.descriptions d "+
......
975 975

  
976 976
        taxonBase.removeSources();
977 977

  
978
        if (taxonBase instanceof Taxon){ // is Taxon
978
        if (taxonBase instanceof Taxon){ //	is Taxon
979 979
            for (Iterator<TaxonRelationship> iterator = ((Taxon)taxonBase).getRelationsFromThisTaxon().iterator(); iterator.hasNext();){
980 980
                TaxonRelationship relationFromThisTaxon = iterator.next();
981 981

  
......
1169 1169
    }
1170 1170

  
1171 1171
    @Override
1172
    public int countTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet,   String infraSpecificEpithet, Rank rank) {
1173
        checkNotInPriorView("TaxonDaoHibernateImpl.countTaxaByName(Boolean accepted, String genusOrUninomial,   String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, Rank rank)");
1172
    public int countTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet,	String infraSpecificEpithet, Rank rank) {
1173
        checkNotInPriorView("TaxonDaoHibernateImpl.countTaxaByName(Boolean accepted, String genusOrUninomial,	String infraGenericEpithet, String specificEpithet,	String infraSpecificEpithet, Rank rank)");
1174 1174
        Criteria criteria = null;
1175 1175

  
1176 1176
        criteria = getSession().createCriteria(clazz);
......
1213 1213
    }
1214 1214

  
1215 1215
    @Override
1216
    public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, Rank rank, Integer pageSize,  Integer pageNumber) {
1217
        checkNotInPriorView("TaxonDaoHibernateImpl.findTaxaByName(Boolean accepted, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, Rank rank, Integer pageSize,  Integer pageNumber)");
1216
    public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, Rank rank, Integer pageSize,	Integer pageNumber) {
1217
        checkNotInPriorView("TaxonDaoHibernateImpl.findTaxaByName(Boolean accepted, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, Rank rank, Integer pageSize,	Integer pageNumber)");
1218 1218
        Criteria criteria = null;
1219 1219
        if (clazz == null){
1220 1220
            criteria = getSession().createCriteria(TaxonBase.class);
......
1640 1640

  
1641 1641

  
1642 1642

  
1643
/*  private void xxx(List<SynonymRelationship> synonymRelationships, HashMap <UUID, ZoologicalName> zooHashMap, SynonymRelationshipType type, String addString){
1643
/*	private void xxx(List<SynonymRelationship> synonymRelationships, HashMap <UUID, ZoologicalName> zooHashMap, SynonymRelationshipType type, String addString){
1644 1644

  
1645 1645
        for (SynonymRelationship synonymRelation:synonymRelationships){
1646 1646
            TaxonNameBase synName;
......
2007 2007
    private String[] createHQLString(boolean doTaxa, boolean doSynonyms, boolean doIncludeMisappliedNames, Classification classification,  Set<NamedArea> areasExpanded, MatchMode matchMode, String searchField){
2008 2008

  
2009 2009
           boolean doAreaRestriction = areasExpanded.size() > 0;
2010
           String   doAreaRestrictionSubSelect = "select %s.id from" +
2010
           String 	doAreaRestrictionSubSelect = "select %s.id from" +
2011 2011
                " Distribution e" +
2012 2012
                " join e.inDescription d" +
2013 2013
                " join d.taxon t" +
2014 2014
                (classification != null ? " join t.taxonNodes as tn " : " ");
2015 2015

  
2016
           String   doAreaRestrictionMisappliedNameSubSelect = "select %s.id from" +
2016
           String 	doAreaRestrictionMisappliedNameSubSelect = "select %s.id from" +
2017 2017
            " Distribution e" +
2018 2018
            " join e.inDescription d" +
2019 2019
            " join d.taxon t";
......
2023 2023

  
2024 2024
           String doTaxonNameJoin =   " join t.name n ";
2025 2025

  
2026
           String doSynonymNameJoin =   " join t.synonymRelations sr join sr.relatedFrom s join s.name sn";
2026
           String doSynonymNameJoin =  	" join t.synonymRelations sr join sr.relatedFrom s join s.name sn";
2027 2027

  
2028 2028
           String doMisappliedNamesJoin = " left join t.relationsFromThisTaxon as rft" +
2029 2029
                " left join rft.relatedTo as rt" +
......
2123 2123
        return result;
2124 2124
    }
2125 2125

  
2126
    @Override
2127
    public List<UuidAndTitleCache<IdentifiableEntity>> getTaxaByCommonNameForEditor(
2128
            String titleSearchStringSqlized, Classification classification,
2129
            MatchMode matchMode, Set namedAreas) {
2130
        List<Object> resultArray = new ArrayList<Object>();
2131
        Query query = prepareTaxaByCommonName(titleSearchStringSqlized, classification, matchMode, namedAreas, null, null, false, true);
2126
	@Override
2127
	public List<UuidAndTitleCache<IdentifiableEntity>> getTaxaByCommonNameForEditor(
2128
			String titleSearchStringSqlized, Classification classification,
2129
			MatchMode matchMode, Set namedAreas) {
2130
	    List<Object> resultArray = new ArrayList<Object>();
2131
		Query query = prepareTaxaByCommonName(titleSearchStringSqlized, classification, matchMode, namedAreas, null, null, false, true);
2132 2132
        if (query != null){
2133 2133
            resultArray = query.list();
2134 2134
            List<UuidAndTitleCache<IdentifiableEntity>> returnResult = new ArrayList<UuidAndTitleCache<IdentifiableEntity>>() ;
2135 2135
            Object[] result;
2136 2136
            for(int i = 0; i<resultArray.size();i++){
2137
                result = (Object[]) resultArray.get(i);
2138
                returnResult.add(new UuidAndTitleCache(Taxon.class, (UUID) result[0],(Integer)result[1], (String)result[2], new Boolean(result[4].toString())));
2137
            	result = (Object[]) resultArray.get(i);
2138
            	returnResult.add(new UuidAndTitleCache(Taxon.class, (UUID) result[0],(Integer)result[1], (String)result[2], new Boolean(result[4].toString())));
2139 2139
            }
2140 2140
            return returnResult;
2141 2141
        }
2142 2142

  
2143
        return null;
2144
    }
2143
		return null;
2144
	}
2145 2145

  
2146 2146

  
2147
    /**
2148
     * @param
2149
     * @see eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao#countByIdentifier(java.lang.Class, java.lang.String, eu.etaxonomy.cdm.model.common.DefinedTerm, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.persistence.query.MatchMode)
2150
     */
2151
    @Override
2152
    public <S extends TaxonBase> int countByIdentifier(Class<S> clazz,
2153
            String identifier, DefinedTerm identifierType, TaxonNode subtreeFilter, MatchMode matchmode) {
2154
        if (subtreeFilter == null){
2155
            return countByIdentifier(clazz, identifier, identifierType, matchmode);
2156
        }
2147
	/**
2148
	 * @param
2149
	 * @see eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao#countByIdentifier(java.lang.Class, java.lang.String, eu.etaxonomy.cdm.model.common.DefinedTerm, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.persistence.query.MatchMode)
2150
	 */
2151
	@Override
2152
	public <S extends TaxonBase> int countByIdentifier(Class<S> clazz,
2153
			String identifier, DefinedTerm identifierType, TaxonNode subtreeFilter, MatchMode matchmode) {
2154
		if (subtreeFilter == null){
2155
			return countByIdentifier(clazz, identifier, identifierType, matchmode);
2156
		}
2157 2157

  
2158
        Class<?> clazzParam = clazz == null ? type : clazz;
2159
        checkNotInPriorView("IdentifiableDaoBase.countByIdentifier(T clazz, String identifier, DefinedTerm identifierType, TaxonNode subMatchMode matchmode)");
2158
		Class<?> clazzParam = clazz == null ? type : clazz;
2159
		checkNotInPriorView("IdentifiableDaoBase.countByIdentifier(T clazz, String identifier, DefinedTerm identifierType, TaxonNode subMatchMode matchmode)");
2160 2160

  
2161
        boolean isTaxon = clazzParam == Taxon.class || clazzParam == TaxonBase.class;
2162
        boolean isSynonym = clazzParam == Synonym.class || clazzParam == TaxonBase.class;
2161
		boolean isTaxon = clazzParam == Taxon.class || clazzParam == TaxonBase.class;
2162
		boolean isSynonym = clazzParam == Synonym.class || clazzParam == TaxonBase.class;
2163 2163

  
2164
        getSession().update(subtreeFilter);  //to avoid LIE when retrieving treeindex
2165
        String filterStr = "'" + subtreeFilter.treeIndex() + "%%'";
2166
        String accTreeJoin = isTaxon? " LEFT JOIN c.taxonNodes tn  " : "";
2167
        String synTreeJoin = isSynonym ? " LEFT JOIN c.synonymRelations sr LEFT  JOIN sr.relatedTo as acc LEFT JOIN acc.taxonNodes synTn  " : "";
2168
        String accWhere = isTaxon ?  "tn.treeIndex like " + filterStr : "(1=0)";
2169
        String synWhere = isSynonym  ?  "synTn.treeIndex like " + filterStr : "(1=0)";
2164
		getSession().update(subtreeFilter);  //to avoid LIE when retrieving treeindex
2165
		String filterStr = "'" + subtreeFilter.treeIndex() + "%%'";
2166
		String accTreeJoin = isTaxon? " LEFT JOIN c.taxonNodes tn  " : "";
2167
		String synTreeJoin = isSynonym ? " LEFT JOIN c.synonymRelations sr LEFT  JOIN sr.relatedTo as acc LEFT JOIN acc.taxonNodes synTn  " : "";
2168
		String accWhere = isTaxon ?  "tn.treeIndex like " + filterStr : "(1=0)";
2169
		String synWhere = isSynonym  ?  "synTn.treeIndex like " + filterStr : "(1=0)";
2170 2170

  
2171
        String queryString = "SELECT count(*)  FROM %s as c " +
2171
		String queryString = "SELECT count(*)  FROM %s as c " +
2172 2172
                " INNER JOIN c.identifiers as ids " +
2173 2173
                accTreeJoin +
2174 2174
                synTreeJoin +
2175 2175
                " WHERE (1=1) " +
2176
                    "  AND ( " + accWhere + " OR " + synWhere + ")";
2177
        queryString = String.format(queryString, clazzParam.getSimpleName());
2176
                	"  AND ( " + accWhere + " OR " + synWhere + ")";
2177
		queryString = String.format(queryString, clazzParam.getSimpleName());
2178 2178

  
2179
        if (identifier != null){
2180
            if (matchmode == null || matchmode == MatchMode.EXACT){
2181
                queryString += " AND ids.identifier = '"  + identifier + "'";
2182
            }else {
2183
                queryString += " AND ids.identifier LIKE '" + matchmode.queryStringFrom(identifier)  + "'";
2184
            }
2185
        }
2186
        if (identifierType != null){
2187
            queryString += " AND ids.type = :type";
2179
		if (identifier != null){
2180
			if (matchmode == null || matchmode == MatchMode.EXACT){
2181
				queryString += " AND ids.identifier = '"  + identifier + "'";
2182
			}else {
2183
				queryString += " AND ids.identifier LIKE '" + matchmode.queryStringFrom(identifier)  + "'";
2184
			}
2185
		}
2186
		if (identifierType != null){
2187
        	queryString += " AND ids.type = :type";
2188 2188
        }
2189 2189

  
2190
        Query query = getSession().createQuery(queryString);
2190
		Query query = getSession().createQuery(queryString);
2191 2191
        if (identifierType != null){
2192
            query.setEntity("type", identifierType);
2192
        	query.setEntity("type", identifierType);
2193 2193
        }
2194 2194

  
2195
        Long c = (Long)query.uniqueResult();
2195
		Long c = (Long)query.uniqueResult();
2196 2196
        return c.intValue();
2197
    }
2198

  
2199
    @Override
2200
    public <S extends TaxonBase> List<Object[]> findByIdentifier(
2201
            Class<S> clazz, String identifier, DefinedTerm identifierType, TaxonNode subtreeFilter,
2202
            MatchMode matchmode, boolean includeEntity,
2203
            Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
2204

  
2205
        checkNotInPriorView("IdentifiableDaoBase.findByIdentifier(T clazz, String identifier, DefinedTerm identifierType, MatchMode matchmode, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)");
2206
        Class<?> clazzParam = clazz == null ? type : clazz;
2207

  
2208
        boolean isTaxon = clazzParam == Taxon.class || clazzParam == TaxonBase.class;
2209
        boolean isSynonym = clazzParam == Synonym.class || clazzParam == TaxonBase.class;
2210
        getSession().update(subtreeFilter);  //to avoid LIE when retrieving treeindex
2211
        String filterStr = "'" + subtreeFilter.treeIndex() + "%%'";
2212
        String accTreeJoin = isTaxon? " LEFT JOIN c.taxonNodes tn  " : "";
2213
        String synTreeJoin = isSynonym ? " LEFT JOIN c.synonymRelations sr LEFT  JOIN sr.relatedTo as acc LEFT JOIN acc.taxonNodes synTn  " : "";
2214
        String accWhere = isTaxon ?  "tn.treeIndex like " + filterStr : "(1=0)";
2215
        String synWhere = isSynonym  ?  "synTn.treeIndex like " + filterStr : "(1=0)";
2216

  
2217
        String queryString = "SELECT ids.type, ids.identifier, %s " +
2218
                " FROM %s as c " +
2197
	}
2198

  
2199
	@Override
2200
	public <S extends TaxonBase> List<Object[]> findByIdentifier(
2201
			Class<S> clazz, String identifier, DefinedTerm identifierType, TaxonNode subtreeFilter,
2202
			MatchMode matchmode, boolean includeEntity,
2203
			Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
2204

  
2205
		checkNotInPriorView("IdentifiableDaoBase.findByIdentifier(T clazz, String identifier, DefinedTerm identifierType, MatchMode matchmode, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)");
2206
		Class<?> clazzParam = clazz == null ? type : clazz;
2207

  
2208
		boolean isTaxon = clazzParam == Taxon.class || clazzParam == TaxonBase.class;
2209
		boolean isSynonym = clazzParam == Synonym.class || clazzParam == TaxonBase.class;
2210
		getSession().update(subtreeFilter);  //to avoid LIE when retrieving treeindex
2211
		String filterStr = "'" + subtreeFilter.treeIndex() + "%%'";
2212
		String accTreeJoin = isTaxon? " LEFT JOIN c.taxonNodes tn  " : "";
2213
		String synTreeJoin = isSynonym ? " LEFT JOIN c.synonymRelations sr LEFT  JOIN sr.relatedTo as acc LEFT JOIN acc.taxonNodes synTn  " : "";
2214
		String accWhere = isTaxon ?  "tn.treeIndex like " + filterStr : "(1=0)";
2215
		String synWhere = isSynonym  ?  "synTn.treeIndex like " + filterStr : "(1=0)";
2216

  
2217
		String queryString = "SELECT ids.type, ids.identifier, %s " +
2218
				" FROM %s as c " +
2219 2219
                " INNER JOIN c.identifiers as ids " +
2220 2220
                accTreeJoin +
2221
                synTreeJoin +
2221
				synTreeJoin +
2222 2222
                " WHERE (1=1) " +
2223
                    " AND ( " + accWhere + " OR " + synWhere + ")";
2224
        queryString = String.format(queryString, (includeEntity ? "c":"c.uuid, c.titleCache") , clazzParam.getSimpleName());
2225

  
2226
        //Matchmode and identifier
2227
        if (identifier != null){
2228
            if (matchmode == null || matchmode == MatchMode.EXACT){
2229
                queryString += " AND ids.identifier = '"  + identifier + "'";
2230
            }else {
2231
                queryString += " AND ids.identifier LIKE '" + matchmode.queryStringFrom(identifier)  + "'";
2232
            }
2233
        }
2223
                	" AND ( " + accWhere + " OR " + synWhere + ")";
2224
		queryString = String.format(queryString, (includeEntity ? "c":"c.uuid, c.titleCache") , clazzParam.getSimpleName());
2225

  
2226
		//Matchmode and identifier
2227
		if (identifier != null){
2228
			if (matchmode == null || matchmode == MatchMode.EXACT){
2229
				queryString += " AND ids.identifier = '"  + identifier + "'";
2230
			}else {
2231
				queryString += " AND ids.identifier LIKE '" + matchmode.queryStringFrom(identifier)  + "'";
2232
			}
2233
		}
2234 2234
        if (identifierType != null){
2235
            queryString += " AND ids.type = :type";
2235
        	queryString += " AND ids.type = :type";
2236 2236
        }
2237 2237
        //order
2238 2238
        queryString +=" ORDER BY ids.type.uuid, ids.identifier, c.uuid ";
2239 2239

  
2240
        Query query = getSession().createQuery(queryString);
2240
		Query query = getSession().createQuery(queryString);
2241 2241

  
2242
        //parameters
2243
        if (identifierType != null){
2244
            query.setEntity("type", identifierType);
2242
		//parameters
2243
		if (identifierType != null){
2244
        	query.setEntity("type", identifierType);
2245 2245
        }
2246 2246

  
2247 2247
        //paging
......
2250 2250
        List<Object[]> results = query.list();
2251 2251
        //initialize
2252 2252
        if (includeEntity){
2253
            List<S> entities = new ArrayList<S>();
2254
            for (Object[] result : results){
2255
                entities.add((S)result[2]);
2256
            }
2257
            defaultBeanInitializer.initializeAll(entities, propertyPaths);
2253
        	List<S> entities = new ArrayList<S>();
2254
        	for (Object[] result : results){
2255
        		entities.add((S)result[2]);
2256
        	}
2257
        	defaultBeanInitializer.initializeAll(entities, propertyPaths);
2258 2258
        }
2259 2259
        return results;
2260
    }
2260
	}
2261 2261

  
2262 2262
}

Also available in: Unified diff