Project

General

Profile

Revision d8456478

IDd84564781b41119d446967dd1f1b8ae88286455b
Parent 9a21de1f
Child ea33ac4f

Added by Andreas Müller about 2 years ago

use long instead of int (cont.)

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/ICdmGenericDao.java
333 333
     * @param referencedCdmBase
334 334
     * @return
335 335
     */
336
    public Long getReferencingObjectsCount(CdmBase referencedCdmBase);
336
    public long getReferencingObjectsCount(CdmBase referencedCdmBase);
337 337

  
338 338

  
339 339

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImpl.java
214 214
	}
215 215

  
216 216
	@Override
217
    public Long getReferencingObjectsCount(CdmBase referencedCdmBase){
217
    public long getReferencingObjectsCount(CdmBase referencedCdmBase){
218 218
        long result = 0;
219 219
        if (referencedCdmBase == null) {
220
            return null;
220
            return 0;
221 221
        }
222 222
        try {
223 223

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DaoBase.java
141 141
            }
142 142
        }
143 143
    }
144
    protected void addPageSizeAndNumber(FullTextQuery query, Integer pageSize, Integer pageNumber) {
145
        if(pageSize != null) {
146
            query.setMaxResults(pageSize);
147
            if(pageNumber != null) {
148
                query.setFirstResult(pageNumber * pageSize);
149
            } else {
150
                query.setFirstResult(0);
151
            }
152
        }
153
    }
144 154

  
145 155
    protected void addPageSizeAndNumber(AuditQuery query, Integer pageSize, Integer pageNumber) {
146 156
        if(pageSize != null) {
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionElementDaoImpl.java
79 79
    }
80 80

  
81 81
    @Override
82
    public List<Media> getMedia(DescriptionElementBase descriptionElement,	Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
82
    public List<Media> getMedia(DescriptionElementBase descriptionElement, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
83 83
        AuditEvent auditEvent = getAuditEventFromContext();
84 84
        if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
85 85
            Query query = getSession().createQuery("select media from DescriptionElementBase descriptionElement join descriptionElement.media media where descriptionElement = :descriptionElement order by index(media)");
86 86
            query.setParameter("descriptionElement", descriptionElement);
87 87

  
88
            if(pageSize != null) {
89
                query.setMaxResults(pageSize);
90
                if(pageNumber != null) {
91
                    query.setFirstResult(pageNumber * pageSize);
92
                } else {
93
                    query.setFirstResult(0);
94
                }
95
            }
88
            addPageSizeAndNumber(query, pageSize, pageNumber);
96 89

  
97 90
            @SuppressWarnings("unchecked")
98 91
            List<Media> results = query.list();
......
101 94
        } else {
102 95
            // Horribly inefficient, I know, but hard to do at the moment with envers.
103 96
            // FIXME Improve this (by improving envers)
104
            List<String> pPaths = new ArrayList<String>();
97
            List<String> pPaths = new ArrayList<>();
105 98
            propertyPaths.add("media");
106 99
            DescriptionElementBase d = super.load(descriptionElement.getUuid(), pPaths);
107
            List<Media> results = new ArrayList<Media>();
100
            List<Media> results = new ArrayList<>();
108 101
            results.addAll(d.getMedia());
109 102
            if(pageSize != null) {
110 103
                int fromIndex = 0;
......
112 105
                if(pageNumber != null) {
113 106
                    // if the page is out of scope
114 107
                    if(results.size() < (pageNumber * pageSize)) {
115
                        return new ArrayList<Media>();
108
                        return new ArrayList<>();
116 109
                    }
117 110
                    fromIndex =   pageNumber * pageSize;
118 111
                }
......
140 133
            }
141 134
            addOrder(fullTextQuery,orderHints);
142 135

  
143
            if(pageSize != null) {
144
                fullTextQuery.setMaxResults(pageSize);
145
                if(pageNumber != null) {
146
                    fullTextQuery.setFirstResult(pageNumber * pageSize);
147
                } else {
148
                    fullTextQuery.setFirstResult(0);
149
                }
150
            }
136
            addPageSizeAndNumber(fullTextQuery, pageSize, pageNumber);
151 137

  
152 138
            @SuppressWarnings("unchecked")
153 139
            List<DescriptionElementBase> results = fullTextQuery.list();
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/CommonServiceImpl.java
104 104
    }
105 105

  
106 106
    @Override
107
    public Long getReferencingObjectsCount(CdmBase referencedCdmBase){
107
    public long getReferencingObjectsCount(CdmBase referencedCdmBase){
108 108
        return this.genericDao.getReferencingObjectsCount(referencedCdmBase);
109 109
    }
110 110

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ICommonService.java
371 371
     * @param referencedCdmBase
372 372
     * @return
373 373
     */
374
    public Long getReferencingObjectsCount(CdmBase referencedCdmBase);
374
    public long getReferencingObjectsCount(CdmBase referencedCdmBase);
375 375

  
376 376

  
377 377
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)