Project

General

Profile

« Previous | Next » 

Revision 7151

[optionally] do not archive the xml_documents and xml_nodes to *_revisions when 'deleting' a document. This will effectively guarantee that the document/data cannot be retrieved after delete.
NOTE: D1 system metadata will persist (for now) so that the ID cannot be reused with the DataONE API but Metacat calls may allow the ID to be reused -- may need to reconsider this behavior.
https://redmine.dataone.org/issues/2677

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
3236 3236
     *            the ID of the document to be deleted from the database
3237 3237
     */
3238 3238
    public static void delete(String accnum, String user, 
3239
      String[] groups, String notifyServer, boolean removeFile)
3239
      String[] groups, String notifyServer, boolean removeAll)
3240 3240
      throws SQLException, InsufficientKarmaException, McdbDocNotFoundException,
3241 3241
      Exception
3242 3242
    {
......
3250 3250
            conn = DBConnectionPool.getDBConnection("DocumentImpl.delete");
3251 3251
            serialNumber = conn.getCheckOutSerialNumber();
3252 3252

  
3253
            // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV
3254
            // IN IT
3253
            // CLIENT SHOULD ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV
3255 3254
            //AccessionNumber ac = new AccessionNumber(accnum, "DELETE");
3256 3255
            String docid = DocumentUtil.getDocIdFromAccessionNumber(accnum);
3257 3256
            //String rev = ac.getRev();
3258 3257

  
3259 3258
            // Check if the document exists.
3260
            pstmt = conn.prepareStatement("SELECT * FROM xml_documents "
3261
                                          + "WHERE docid = ?");
3259
            pstmt = conn.prepareStatement("SELECT * FROM xml_documents WHERE docid = ?");
3262 3260
            pstmt.setString(1, docid);
3263 3261
            logMetacat.debug("DocumentImpl.delete - executing SQL: " + pstmt.toString());
3264 3262
            pstmt.execute();
......
3277 3275

  
3278 3276
            // get the type of deleting docid, this will be used in forcereplication
3279 3277
            String type = getDocTypeFromDB(conn, docid);
3280
            if (type != null && type.trim().equals("BIN"))
3281
            {
3282
              isXML = false;
3278
            if (type != null && type.trim().equals("BIN")) {
3279
            	isXML = false;
3283 3280
            }
3284 3281

  
3285
            logMetacat.info("DocumentImpl.delete - Start deleting doc " + 
3286
              docid + "...");
3282
            logMetacat.info("DocumentImpl.delete - Start deleting doc " + docid + "...");
3287 3283
            double start = System.currentTimeMillis()/1000;
3288 3284
            // check for 'write' permission for 'user' to delete this document
3289 3285
            if (!hasAllPermission(user, groups, accnum)) {
......
3296 3292
            }
3297 3293

  
3298 3294
            conn.setAutoCommit(false);
3299
            // Copy the record to the xml_revisions table
3300
            DocumentImpl.archiveDocAndNodesRevision(conn, docid, user, null);
3295
            
3296
            // Copy the record to the xml_revisions table if not a full delete
3297
            if (!removeAll) {
3298
            	DocumentImpl.archiveDocAndNodesRevision(conn, docid, user, null);
3299
                logMetacat.info("DocumentImpl.delete - calling archiveDocAndNodesRevision");
3300

  
3301
            }
3301 3302
            double afterArchiveDocAndNode = System.currentTimeMillis()/1000;
3302 3303
            logMetacat.info("DocumentImpl.delete - The time for archiveDocAndNodesRevision is "+(afterArchiveDocAndNode - start));
3304
            
3303 3305
            // Now delete it from the xml_index table
3304
//            boolean useXMLIndex = (new Boolean(PropertyService
3305
//                    .getProperty("database.usexmlindex"))).booleanValue();
3306

  
3307

  
3308

  
3309
           //if (useXMLIndex) {
3310
            pstmt = conn
3311
                    .prepareStatement("DELETE FROM xml_index WHERE docid = ?");
3306
            pstmt = conn.prepareStatement("DELETE FROM xml_index WHERE docid = ?");
3312 3307
            pstmt.setString(1, docid);
3313 3308
            logMetacat.debug("DocumentImpl.delete - executing SQL: " + pstmt.toString());
3314 3309
            pstmt.execute();
3315 3310
            pstmt.close();
3316 3311
            conn.increaseUsageCount(1);
3317
            //}
3312
            
3318 3313
            double afterDeleteIndex = System.currentTimeMillis()/1000;
3319 3314
            logMetacat.info("DocumentImpl.delete - The deleting xml_index time is "+(afterDeleteIndex - afterArchiveDocAndNode ));
3320 3315
            
......
3322 3317
            /*************** DO NOT DELETE ACCESS - need to archive this ******************/
3323 3318
            double afterDeleteXmlAccess2 = System.currentTimeMillis()/1000;
3324 3319
            /******* END DELETE ACCESS *************/            
3320
            
3325 3321
            // Delete enteries from xml_queryresult
3326

  
3327 3322
            try {
3328 3323
                XMLQueryresultAccess xmlQueryresultAccess = new XMLQueryresultAccess();
3329 3324
                xmlQueryresultAccess.deleteXMLQueryresulForDoc(docid);
......
3334 3329
            double afterDeleteQueryResult = System.currentTimeMillis()/1000;
3335 3330
            logMetacat.info("DocumentImpl.delete - The deleting xml_queryresult time is "+(afterDeleteQueryResult - afterDeleteXmlAccess2));
3336 3331
            // Delete it from relation table
3337
            pstmt = conn.prepareStatement(
3338
                    "DELETE FROM xml_relation WHERE docid = ?");
3332
            pstmt = conn.prepareStatement("DELETE FROM xml_relation WHERE docid = ?");
3339 3333
            //increase usage count
3340 3334
            pstmt.setString(1, docid);
3341 3335
            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
......
3343 3337
            pstmt.close();
3344 3338
            conn.increaseUsageCount(1);
3345 3339
            double afterXMLRelation = System.currentTimeMillis()/1000;
3346
            logMetacat.info("DocumentImpl.delete - The deleting time  relation is "+
3347
            		(afterXMLRelation - afterDeleteQueryResult) );
3340
            logMetacat.info("DocumentImpl.delete - The deleting time  relation is "+ (afterXMLRelation - afterDeleteQueryResult) );
3348 3341

  
3349 3342
            // Delete it from xml_path_index table
3350 3343
            logMetacat.info("DocumentImpl.delete - deleting from xml_path_index");
3351
            pstmt = conn.prepareStatement(
3352
                    "DELETE FROM xml_path_index WHERE docid = ?");
3344
            pstmt = conn.prepareStatement("DELETE FROM xml_path_index WHERE docid = ?");
3353 3345
            //increase usage count
3354 3346
            pstmt.setString(1, docid);
3355 3347
            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
......
3359 3351

  
3360 3352
            logMetacat.info("DocumentImpl.delete - deleting from xml_accesssubtree");
3361 3353
            // Delete it from xml_accesssubtree table
3362
            pstmt = conn.prepareStatement(
3363
                    "DELETE FROM xml_accesssubtree WHERE docid = ?");
3354
            pstmt = conn.prepareStatement("DELETE FROM xml_accesssubtree WHERE docid = ?");
3364 3355
            //increase usage count
3365 3356
            pstmt.setString(1, docid);
3366 3357
            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
3367 3358
            pstmt.execute();
3368 3359
            pstmt.close();
3369 3360
            conn.increaseUsageCount(1);
3370
            
3371
            /*logMetacat.info("DocumentImpl.delete - deleting from xml_index");
3372
            pstmt = conn.prepareStatement(
3373
                "DELETE FROM xml_index WHERE docid = ?");
3374
            pstmt.setString(1, docid);
3375
            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
3376
            pstmt.execute();
3377
            pstmt.close();*/
3378 3361

  
3379 3362
            // Delete it from xml_documents table
3380 3363
            logMetacat.info("DocumentImpl.delete - deleting from xml_documents");
3381
            pstmt = conn.prepareStatement(
3382
                    "DELETE FROM xml_documents WHERE docid = ?");
3364
            pstmt = conn.prepareStatement("DELETE FROM xml_documents WHERE docid = ?");
3383 3365
            pstmt.setString(1, docid);
3384 3366
            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
3385 3367
            pstmt.execute();
......
3390 3372
            logMetacat.info("DocumentImpl.delete - the time to delete  xml_path_index,  xml_accesssubtree, xml_documents time is "+ 
3391 3373
            		(afterDeleteDoc - afterXMLRelation ));
3392 3374
            // Delete the old nodes in xml_nodes table...
3393
                   pstmt = conn.prepareStatement("DELETE FROM xml_nodes "
3394
                                                   + "WHERE docid = ?");
3375
            pstmt = conn.prepareStatement("DELETE FROM xml_nodes WHERE docid = ?");
3395 3376

  
3396
                   // Increase dbconnection usage count
3397
                   conn.increaseUsageCount(1);
3398
                   // Bind the values to the query and execute it
3399
                   pstmt.setString(1, docid);
3400
                   logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
3401
                   pstmt.execute();
3402
                   pstmt.close();
3377
            // Increase dbconnection usage count
3378
            conn.increaseUsageCount(1);
3379
            // Bind the values to the query and execute it
3380
            pstmt.setString(1, docid);
3381
            logMetacat.debug("DocumentImpl.delete - running sql: " + pstmt.toString());
3382
            pstmt.execute();
3383
            pstmt.close();
3403 3384

  
3404 3385
            double afterDeleteXMLNodes = System.currentTimeMillis()/1000;
3405 3386
            logMetacat.info("DocumentImpl.delete - Deleting xml_nodes time is "+(afterDeleteXMLNodes-afterDeleteDoc));
......
3411 3392
                             accnum, ForceReplicationHandler.DELETE, isXML, notifyServer);
3412 3393
            logMetacat.debug("DocumentImpl.delete - ForceReplicationHandler created: " + frh.toString());
3413 3394
            // clear cache after inserting or updating a document
3414
            if (PropertyService.getProperty("database.queryCacheOn").equals("true"))
3415
            {
3416
              //System.out.println("the string stored into cache is "+ resultsetBuffer.toString());
3417
         	   DBQuery.clearQueryResultCache();
3395
            if (PropertyService.getProperty("database.queryCacheOn").equals("true")) {
3396
            	//System.out.println("the string stored into cache is "+ resultsetBuffer.toString());
3397
            	DBQuery.clearQueryResultCache();
3418 3398
            }
3419 3399
            
3420
            // remove the file if needed
3421
            if (removeFile) {
3400
            // remove the file if called for
3401
            if (removeAll) {
3422 3402
            	deleteFromFileSystem(accnum, isXML);
3423 3403
            }
3424 3404
            

Also available in: Unified diff