Coverage details for com.topcoder.document.index.persistence.impl.db.CommonDatabaseOperations

LineHitsSource
1 /*
2  * Copyright (C) 2006 TopCoder Inc., All Rights Reserved.
3  */
4 package com.topcoder.document.index.persistence.impl.db;
5  
6 import com.topcoder.document.index.CollectionIndex;
7 import com.topcoder.document.index.DocumentIndex;
8 import com.topcoder.document.index.persistence.IndexPersistenceException;
9 import com.topcoder.document.index.persistence.impl.Utils;
10 import com.topcoder.document.index.wordsource.WordSourceId;
11  
12 import java.sql.Connection;
13 import java.text.CollationKey;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.Locale;
19 import java.util.Map;
20 import java.util.Set;
21  
22  
23 /**
24  * This class contains the database operations that are common to both database persistence implementations. These
25  * methods have been factored out to reduce code redundancy. As these operation are quite specific to the persistence
26  * layer they have been factored into a different utility class instead of adding the operations to {@link
27  * DatabaseUtils} which does contain the more general and generic JDBC handling code.
28  *
29  * @author TCSDEVELOPER
30  * @version 1.0
31  */
32 class CommonDatabaseOperations {
33     /**
34      * As this class is a utility class, a private constructor is added to avoid class instantiation.
35      */
360    private CommonDatabaseOperations() {
37         //an empty private default constructor
380    }
39  
40     /**
41      * This method does query the database for a WordSourceId matching the given documentId String as described in CS
42      * 1.4.1.1.
43      *
44      * @param persistence the AbstractDBIndexPersistence instance that can be used to perform rollback operations on the
45      * given connection in case an error is encountered
46      * @param connection the connection to perform the necessary queries on
47      * @param documentId the document record id from which to create the WordSourceId
48      *
49      * @return the WordSourceId created for the given document id or <tt>null</tt> if no matching record existed in the
50      * database
51      *
52      * @throws IndexPersistenceException in case an error is encountered during database operations
53      * @throws IllegalArgumentException in case any arg is null or documentId is an empty (trim'd) String
54      */
55     static WordSourceId getWordSourceId(final AbstractDBIndexPersistence persistence,
56                                         final Connection connection, final String documentId)
57         throws IndexPersistenceException {
5856        if (documentId == null) {
592            throw new IllegalArgumentException("The parameter named [documentId] was null.");
60         }
6154        if (documentId.trim().length() == 0) {
622            throw new IllegalArgumentException("The parameter named [documentId] was an empty String.");
63         }
64  
6552        final Object[] queryArgsDocumentId = new Object[]{documentId};
66  
6752        final List result1 = DatabaseUtils.doQuery(connection, persistence,
68             "SELECT LOCALE,SOURCE_IDENTITY,CLASS_NAME FROM DOCUMENT WHERE DOCUMENT_ID=?",
69             queryArgsDocumentId,
70             new DatabaseUtils.DataType[]{
71                 DatabaseUtils.STRING_TYPE,
72                 DatabaseUtils.BYTE_ARRAY_TYPE,
73                 DatabaseUtils.STRING_TYPE}
74         );
75  
7648        if (result1.isEmpty()) {
77             // no record matched the id, so we return null here
782            return null;
79         }
80  
8146        final Object[] documentData = (Object[]) result1.get(0);
8246        final Object sourceIdentity = Utils.deSerializeObject((byte[]) documentData[1]);
83  
84         // build the locale from the locale string
8546        final String[] localeElements = ((String) documentData[0]).split("_");
86         final Locale locale;
8746        switch (localeElements.length) {
88         case 1:
890            locale = new Locale(localeElements[0]);
900            break;
91         case 2:
9246            locale = new Locale(localeElements[0], localeElements[1]);
9346            break;
94         case 3:
950            locale = new Locale(localeElements[0], localeElements[1], localeElements[2]);
960            break;
97         default:
980            persistence.rollbackTransaction(connection);
990            throw new IndexPersistenceException("Unexpected locale String [" + documentData[0]
100                 + "] encountered, was not parseable into a valid locale.");
101         }
102  
103         // fetch all delimiters
10446        final List result2 = DatabaseUtils.doSingleColumnQuery(connection, persistence,
105             "SELECT DELIMITER_ENTRY FROM DELIMITER WHERE DOCUMENT_ID=?",
106             queryArgsDocumentId,
107             DatabaseUtils.STRING_TYPE
108         );
10946        final String[] delimiters = (String[]) result2.toArray(new String[result2.size()]);
110  
111         //build WordSourceId
11246        return new WordSourceId(sourceIdentity, (String) documentData[2], delimiters, locale);
113     }
114  
115     /**
116      * This method does store the given document collection index in the persistence.
117      * <p/>
118      * CS section 1.4.3.1 describes the algorithm of this method.
119      *
120      * @param collectionIndex CollectionIndex to store
121      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
122      * perform rollback operations on the connection in case an error is encountered or commit
123      * the connection in case the operation has succeeded
124      *
125      * @throws IllegalArgumentException if any arg is <tt>null</tt>
126      * @throws IndexPersistenceException if fails to store document collection index or given index is already persisted
127      * or contains an unpersisted document index
128      */
129     static void addCollectionIndex(final AbstractDBIndexPersistence persistence, final CollectionIndex collectionIndex)
130         throws
131         IndexPersistenceException {
13238        if (collectionIndex == null) {
1334            throw new IllegalArgumentException("The parameter named [collectionIndex] was null.");
134         }
13534        if (persistence == null) {
1362            throw new IllegalArgumentException("The parameter named [persistence] was null.");
137         }
13832        final String collectionId = collectionIndex.getId();
13932        final Object[] collectionIdQueryArgs = new Object[]{collectionId};
14032        final Connection connection = persistence.getConnection();
14132        persistence.beginTransaction(connection);
142  
14332        final Integer count = (Integer) DatabaseUtils.doSingleValueQuery(connection, persistence,
144             "SELECT COUNT(*) FROM DOCUMENT_COLLECTION WHERE COLLECTION_ID=?", collectionIdQueryArgs,
145             DatabaseUtils.INTEGER_TYPE);
14632        if (count.intValue() > 0) {
1474            DatabaseUtils.closeSilently(connection);
1484            throw new IndexPersistenceException(
149                 "The given collection with the id [" + collectionId + "] does already exist in the persistence.");
150         }
15128        final Set allDocumentIds = collectionIndex.getAllDocumentIds();
15228        for (Iterator iterator = allDocumentIds.iterator(); iterator.hasNext();) {
15332            final WordSourceId sourceId = (WordSourceId) iterator.next();
15432            final String documentId = Utils.createIdString(sourceId);
15532            final Integer docCount = (Integer) DatabaseUtils.doSingleValueQuery(connection, persistence,
156                 "SELECT COUNT(*) from DOCUMENT WHERE DOCUMENT_ID=?",
157                 new Object[]{documentId}, DatabaseUtils.INTEGER_TYPE);
15832            if (docCount.intValue() == 0) {
1594                throw new IndexPersistenceException(
160                     "The given document index collection contains unpersisted documents.");
161             }
162         }
163  
16424        DatabaseUtils.doDMLQuery(connection, persistence,
165             "INSERT INTO DOCUMENT_COLLECTION (COLLECTION_ID) VALUES (?)",
166             collectionIdQueryArgs);
167  
16824        for (Iterator iterator = allDocumentIds.iterator(); iterator.hasNext();) {
16928            final WordSourceId sourceId = (WordSourceId) iterator.next();
17028            final String documentId = Utils.createIdString(sourceId);
17128            DatabaseUtils.doDMLQuery(connection, persistence,
172                 "INSERT INTO DOCUMENT_COLLECTION_DOCUMENT_XREF (COLLECTION_ID,DOCUMENT_ID) VALUES (?,?)",
173                 new Object[]{collectionId, documentId});
174             // Use count is maintained externally
175         }
176  
17724        persistence.commitTransaction(connection);
17824    }
179  
180     /**
181      * This method retrieves a document collection index with specified identifier. It does return <tt>null</tt> when
182      * collection with specified identifier is not found.
183      * <p/>
184      * CS section 1.4.3.2 describes the algorithm of this method.
185      *
186      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
187      * perform rollback operations on the connection in case an error is encountered or commit the
188      * connection in case the operation has succeeded. Furthermore this instance does retrieve the
189      * document instances from the persistent storage
190      * @param collectionId identifier of document collection index to retrieve
191      *
192      * @return CollectionIndex with specified identifier or <tt>null</tt> if the collection index with the given
193      * identifier was not found in persistence
194      *
195      * @throws IllegalArgumentException when collectionId is <tt>null</tt> or empty (trim'd) string or persistence is
196      * <tt>null</tt>
197      * @throws IndexPersistenceException when collection index can not be retrieved
198      */
199     static CollectionIndex getCollectionIndex(final AbstractDBIndexPersistence persistence, final String collectionId)
200         throws IndexPersistenceException {
20142        if (collectionId == null) {
2024            throw new IllegalArgumentException("The parameter named [collectionId] was null.");
203         }
20438        if (collectionId.trim().length() == 0) {
2054            throw new IllegalArgumentException("The parameter named [collectionId] was an empty String.");
206         }
20734        if (persistence == null) {
2082            throw new IllegalArgumentException("The parameter named [persistence] was null.");
209         }
210  
21132        final Object[] collectionIdQueryArgs = new Object[]{collectionId};
21232        final Connection connection = persistence.getConnection();
213  
214         //check whether collection exists, return null if not
21532        final Integer count = (Integer) DatabaseUtils.doSingleValueQuery(connection, persistence,
216             "SELECT COUNT(*) FROM DOCUMENT_COLLECTION WHERE COLLECTION_ID=?", collectionIdQueryArgs,
217             DatabaseUtils.INTEGER_TYPE);
21832        if (count.intValue() == 0) {
2198            DatabaseUtils.closeSilently(connection);
2208            return null;
221         }
222  
22324        final Map wordsOfCollection = new HashMap();
22424        final Set documentsOfCollection = new HashSet();
225  
22624        final List documentIds = DatabaseUtils.doSingleColumnQuery(connection, persistence,
227             "SELECT DOCUMENT_ID FROM DOCUMENT_COLLECTION_DOCUMENT_XREF where COLLECTION_ID=?",
228             collectionIdQueryArgs, DatabaseUtils.STRING_TYPE);
22924        for (Iterator iterator = documentIds.iterator(); iterator.hasNext();) {
23032            final String documentId = (String) iterator.next();
23132            final WordSourceId sourceId = getWordSourceId(persistence, connection, documentId);
23232            final DocumentIndex index = persistence.getDocumentIndex(sourceId);
233  
234             // add all words of the index to the collection's word-index
235             // map and add a reference to the current index
23632            final Set wordsOfIndex = index.getWords().keySet();
23732            for (Iterator iterator2 = wordsOfIndex.iterator(); iterator2.hasNext();) {
23896                final CollationKey collationKey = (CollationKey) iterator2.next();
23996                Set documentsCotainingWord = (Set) wordsOfCollection.get(collationKey);
24096                if (documentsCotainingWord == null) {
24172                    documentsCotainingWord = new HashSet();
24272                    wordsOfCollection.put(collationKey, documentsCotainingWord);
243                 }
24496                documentsCotainingWord.add(sourceId);
245             }
246             // add document to collection's contained documents set
24732            documentsOfCollection.add(sourceId);
248         }
249         // build the collection object and return it
25024        DatabaseUtils.closeSilently(connection);
25124        return new CollectionIndex(null, wordsOfCollection, documentsOfCollection, collectionId);
252     }
253  
254     /**
255      * This method does remove the document collection index with specified identifier from the persistence.
256      * <p/>
257      * CS section 1.4.3.4 describes the algorithm of this method.
258      *
259      * @param collectionId Identifier of document collection index to remove
260      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
261      * perform rollback operations on the connection in case an error is encountered or commit the
262      * connection in case the operation has succeeded
263      *
264      * @throws IllegalArgumentException when collectionId is <tt>null</tt> or empty (trim'd) string or persistence is
265      * <tt>null</tt>
266      * @throws IndexPersistenceException when fails to remove CollectionIndex with given identifier from database, or
267      * when collection with that specific identifier did not exist in database
268      */
269     static void removeCollectionIndex(final AbstractDBIndexPersistence persistence, final String collectionId)
270         throws IndexPersistenceException {
27118        if (collectionId == null) {
2724            throw new IllegalArgumentException("The parameter named [collectionId] was null.");
273         }
27414        if (collectionId.trim().length() == 0) {
2754            throw new IllegalArgumentException("The parameter named [collectionId] was an empty String.");
276         }
27710        if (persistence == null) {
2782            throw new IllegalArgumentException("The parameter named [persistence] was null.");
279         }
280  
2818        final Connection connection = persistence.getConnection();
2828        persistence.beginTransaction(connection);
283  
2848        final Object[] queryArgsCollectionId = new Object[]{collectionId};
2858        DatabaseUtils.doDMLQuery(connection, persistence,
286             "DELETE FROM DOCUMENT_COLLECTION_DOCUMENT_XREF WHERE COLLECTION_ID=?", queryArgsCollectionId);
2878        final int updateCount = DatabaseUtils.doDMLQuery(connection, persistence,
288             "DELETE FROM DOCUMENT_COLLECTION WHERE COLLECTION_ID=?", queryArgsCollectionId);
2898        if (updateCount == 0) {
2904            persistence.rollbackTransaction(connection);
2914            throw new IndexPersistenceException(
292                 "The collection with the given id [" + collectionId + "] did not exist in the database.");
293         }
2944        persistence.commitTransaction(connection);
295         //counts are not updated as indexer implementation is responsible for that
2964    }
297  
298     /**
299      * This method does update specified CollectionIndex in the persistence.
300      * <p/>
301      * CS section 1.4.3.3 describes the algorithm of this method.
302      *
303      * @param collectionIndex CollectionIndex to update
304      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
305      * perform rollback operations on the connection in case an error is encountered or commit
306      * the connection in case the operation has succeeded
307      *
308      * @throws IllegalArgumentException if any parameter is <tt>null</tt>
309      * @throws IndexPersistenceException if any error happens when updating the collection index in the persistence,
310      * this includes the case, when the specified collectionIndex is not found in the
311      * persistence
312      */
313     static void updateCollectionIndex(final AbstractDBIndexPersistence persistence,
314                                       final CollectionIndex collectionIndex) throws
315         IndexPersistenceException {
31614        if (collectionIndex == null) {
3174            throw new IllegalArgumentException("The parameter named [collectionIndex] was null.");
318         }
31910        if (persistence == null) {
3202            throw new IllegalArgumentException("The parameter named [persistence] was null.");
321         }
322  
3238        final String collectionId = collectionIndex.getId();
3248        final Object[] collectionIdQueryArgs = new Object[]{collectionId};
3258        final Connection connection = persistence.getConnection();
326  
327         //check whether collection exists, throw exception if not
3288        final Integer count = (Integer) DatabaseUtils.doSingleValueQuery(connection, persistence,
329             "SELECT COUNT(*) FROM DOCUMENT_COLLECTION WHERE COLLECTION_ID=?", collectionIdQueryArgs,
330             DatabaseUtils.INTEGER_TYPE);
3318        if (count.intValue() == 0) {
3324            DatabaseUtils.closeSilently(connection);
3334            throw new IndexPersistenceException(
334                 "The given collection with the id [" + collectionId + "] did not exist in the persistence.");
335         }
336  
337         //delete all currently existent records
3384        DatabaseUtils.doDMLQuery(connection, persistence,
339             "DELETE FROM DOCUMENT_COLLECTION_DOCUMENT_XREF WHERE COLLECTION_ID=?", collectionIdQueryArgs);
340  
341         // newly insert all records
3424        final Set allDocumentIds = collectionIndex.getAllDocumentIds();
3434        for (Iterator iterator = allDocumentIds.iterator(); iterator.hasNext();) {
3448            final WordSourceId sourceId = (WordSourceId) iterator.next();
3458            final String documentId = Utils.createIdString(sourceId);
3468            DatabaseUtils.doDMLQuery(connection, persistence,
347                 "INSERT INTO DOCUMENT_COLLECTION_DOCUMENT_XREF (COLLECTION_ID,DOCUMENT_ID) VALUES (?,?)",
348                 new Object[]{collectionId, documentId});
349             // Use count is maintained externally
350         }
3514        persistence.commitTransaction(connection);
3524    }
353  
354     /**
355      * This method increases the use count value for document index with specified WordSourceId by the given amount.
356      *
357      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
358      * perform rollback operations on the connection in case an error is encountered or commit the
359      * connection in case the operation has succeeded
360      * @param wordSourceId WordSourceId of document index of which to update use count
361      * @param amount the amount by which to increase the document use count, may also be a negative integer, then
362      * the result is a decreased use count
363      *
364      * @throws IllegalArgumentException if wordSourceId is <tt>null</tt>
365      * @throws IndexPersistenceException when fails to increase document index use count in the persistence or the
366      * document with the given wordSourceId does not exist in persistence
367      */
368     static void increaseDocumentUseCount(final AbstractDBIndexPersistence persistence, final WordSourceId wordSourceId,
369                                          final int amount) throws IndexPersistenceException {
37048        if (wordSourceId == null) {
3716            throw new IllegalArgumentException("The parameter named [wordSourceId] was null.");
372         }
37342        if (persistence == null) {
3742            throw new IllegalArgumentException("The parameter named [persistence] was null.");
375         }
376  
37740        final String documentId = Utils.createIdString(wordSourceId);
37840        final Connection connection = persistence.getConnection();
37940        persistence.beginTransaction(connection);
38040        final int useCount = getUseCount(persistence, connection, documentId);
38134        setUseCount(persistence, connection, useCount + amount, documentId);
38234        persistence.commitTransaction(connection);
38334    }
384  
385     /**
386      * This method does return the set of WordSourceId of documents that exist in this persistence instance.
387      * <p/>
388      * CS section 1.4.1.1 describes the algorithm of this method.
389      *
390      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
391      * perform rollback operations on the connection in case an error is encountered or commit the
392      * connection in case the operation has succeeded
393      *
394      * @return set of WordSourceId of documents that exist in this persistence
395      *
396      * @throws IllegalArgumentException in case the given persistence is <tt>null</tt>
397      * @throws IndexPersistenceException when the retrieval fails
398      */
399     static Set getIndexedDocuments(final AbstractDBIndexPersistence persistence) throws IndexPersistenceException {
40014        if (persistence == null) {
4012            throw new IllegalArgumentException("The parameter named [persistence] was null.");
402         }
403  
40412        final Connection connection = persistence.getConnection();
40512        final List result = DatabaseUtils.doSingleColumnQuery(connection, persistence,
406             "SELECT DOCUMENT_ID FROM DOCUMENT", new Object[0], DatabaseUtils.STRING_TYPE);
407  
40812        final Set ret = new HashSet(result.size());
40912        for (Iterator iterator = result.iterator(); iterator.hasNext();) {
41012            final String documentId = (String) iterator.next();
41112            ret.add(getWordSourceId(persistence, connection, documentId));
412         }
41312        DatabaseUtils.closeSilently(connection);
41412        return ret;
415     }
416  
417     /**
418      * This method does return the use count of the document index with the given id.
419      *
420      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
421      * perform rollback operations on the connection in case an error is encountered or commit the
422      * connection in case the operation has succeeded
423      * @param wordSourceId WordSourceId of document index of which to retrieve use count
424      *
425      * @return the use count of the document identified by the given id
426      *
427      * @throws IllegalArgumentException if any arg is <tt>null</tt>
428      * @throws IndexPersistenceException when fails to retrieve document index use count in the persistence or the
429      * document with the given id does not exist in the persistence
430      */
431     static int getDocumentUseCount(final AbstractDBIndexPersistence persistence, final WordSourceId wordSourceId)
432         throws IndexPersistenceException {
43368        if (wordSourceId == null) {
4344            throw new IllegalArgumentException("The parameter named [wordSourceId] was null.");
435         }
43664        if (persistence == null) {
4372            throw new IllegalArgumentException("The parameter named [persistence] was null.");
438         }
439  
44062        final String documentId = Utils.createIdString(wordSourceId);
44162        final Connection connection = persistence.getConnection();
44262        final int useCount = getUseCount(persistence, connection, documentId);
44356        DatabaseUtils.closeSilently(connection);
44456        return useCount;
445     }
446  
447     /**
448      * This method does persist the document header data stored in the given WordSourceId into a new record in the
449      * DOCUMENT table.
450      * <p/>
451      * CS section 1.4.1.3 (steps 2 and 3) describes the algorithm of this method.
452      *
453      * @param persistence the AbstractDBIndexPersistence instance that can be used to perform rollback operations on the
454      * connection in case an error is encountered
455      * @param sourceId the source identity representing the document to be persisted
456      * @param connection the connection on which to perform the database operation
457      *
458      * @return the calculated id string representing the given wordSourceId as database key
459      *
460      * @throws IllegalArgumentException in case any arg is <tt>null</tt>
461      * @throws com.topcoder.document.index.persistence.IndexPersistenceException
462      * when fails to add DocumentIndex to the persistence or given index is already
463      * persisted
464      */
465  
466     static String insertDocumentHeaderData(final AbstractDBIndexPersistence persistence, final WordSourceId sourceId,
467                                            final Connection connection) throws
468         IndexPersistenceException {
46980        if (persistence == null) {
4702            throw new IllegalArgumentException("The parameter named [persistence] was null.");
471         }
47278        if (sourceId == null) {
4732            throw new IllegalArgumentException("The parameter named [sourceId] was null.");
474         }
47576        if (connection == null) {
4762            throw new IllegalArgumentException("The parameter named [connection] was null.");
477         }
478  
479         // the validity of these values (CS 1.4.1.3) is guaranteed by the final class
480         // WordSourceId and its constructor logic
48174        final Locale locale = sourceId.getSourceLocale();
48274        final String[] delimiters = sourceId.getDelimiters();
483  
48474        final String documentId = Utils.createIdString(sourceId);
48574        final byte[] sourceIdentityBinary = Utils.serializeObject(sourceId.getSourceIdentity());
48674        final Integer count = (Integer) DatabaseUtils.doSingleValueQuery(connection, persistence,
487             "SELECT COUNT(*) from DOCUMENT WHERE DOCUMENT_ID=?",
488             new Object[]{documentId}, DatabaseUtils.INTEGER_TYPE);
48974        if (count.intValue() > 0) {
4904            throw new IndexPersistenceException("The given document index does already exist in the database.");
491         }
492         // create the DOCUMENT record
49370        DatabaseUtils.doDMLQuery(connection, persistence,
494             "INSERT INTO DOCUMENT (DOCUMENT_ID,LOCALE,SOURCE_IDENTITY,CLASS_NAME,USE_COUNT) VALUES (?,?,?,?,?)",
495             new Object[]{
496                 documentId,
497                 locale.toString(),
498                 sourceIdentityBinary,
499                 sourceId.getSourceClassName(),
500                 new Integer(0)
501             });
502  
503         // insert the DELIMITERs
504292        for (int i = 0; i < delimiters.length; i++) {
505  
506222            DatabaseUtils.doDMLQuery(connection, persistence,
507                 "INSERT INTO DELIMITER (DOCUMENT_ID,DELIMITER_ENTRY) VALUES (?,?)",
508                 new Object[]{
509                     documentId,
510                     delimiters[i]
511                 });
512         }
51370        return documentId;
514     }
515  
516     /**
517      * This method sets the use count value for document index with specified documentId to the given value.
518      *
519      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
520      * perform rollback operations on the connection in case an error is encountered or commit the
521      * connection in case the operation has succeeded
522      * @param connection the connection on which to operate
523      * @param documentId id of document index of which to update use count
524      * @param newUseCount new use count value
525      *
526      * @throws IllegalArgumentException if wordSourceId is <tt>null</tt>
527      * @throws IndexPersistenceException when fails to increase document index use count in the persistence or the
528      * document with the given wordSourceId does not exist in persistence
529      */
530     private static void setUseCount(final AbstractDBIndexPersistence persistence, final Connection connection,
531                                     final int newUseCount,
532                                     final String documentId) throws IndexPersistenceException {
53334        DatabaseUtils.doDMLQuery(connection, persistence, "UPDATE DOCUMENT SET USE_COUNT=? WHERE DOCUMENT_ID=?",
534             new Object[]{new Integer(newUseCount), documentId});
53534    }
536  
537     /**
538      * This method retrieves the use count value for document index with specified WordSourceId.
539      *
540      * @param persistence the AbstractDBIndexPersistence instance that can be used to obtain a database connection,
541      * perform rollback operations on the connection in case an error is encountered or commit the
542      * connection in case the operation has succeeded
543      * @param connection the connection on which to operate
544      * @param documentId id of document index of which to retrieve use count
545      *
546      * @return the use count of the document with the given id
547      *
548      * @throws IllegalArgumentException if wordSourceId is <tt>null</tt>
549      * @throws IndexPersistenceException when fails to increase document index use count in the persistence or the
550      * document with the given wordSourceId does not exist in persistence
551      */
552     private static int getUseCount(final AbstractDBIndexPersistence persistence, final Connection connection,
553                                    final String documentId)
554         throws IndexPersistenceException {
555         //check whether document exists, throw exception if not
556102        final List result = DatabaseUtils.doQuery(connection, persistence,
557             "SELECT USE_COUNT FROM DOCUMENT WHERE DOCUMENT_ID=?",
558             new Object[]{documentId},
559             new DatabaseUtils.DataType[]{DatabaseUtils.INTEGER_TYPE});
560102        if (result.isEmpty()) {
56112            DatabaseUtils.closeSilently(connection);
56212            throw new IndexPersistenceException(
563                 "The given document with the database id [" + documentId + "] did not exist in the persistence.");
564         }
565  
56690        return ((Integer) ((Object[]) result.get(0))[0]).intValue();
567     }
568  
569 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.