Project

General

Profile

« Previous | Next » 

Revision 6836

Added by Chris Jones over 12 years ago

Minor formatting for querySystemMetadata().

View differences:

src/edu/ucsb/nceas/metacat/IdentifierManager.java
1384 1384
     * @throws ServiceException 
1385 1385
     * @throws PropertyNotFoundException 
1386 1386
     */
1387
    public ObjectList querySystemMetadata(Date startTime, Date endTime, 
1388
            ObjectFormatIdentifier objectFormatId, boolean replicaStatus, int start, int count) throws SQLException, PropertyNotFoundException, ServiceException
1389
    {
1387
    public ObjectList querySystemMetadata(Date startTime, Date endTime,
1388
        ObjectFormatIdentifier objectFormatId, boolean replicaStatus,
1389
        int start, int count) 
1390
        throws SQLException, PropertyNotFoundException, ServiceException {
1390 1391
        ObjectList ol = new ObjectList();
1391 1392
        int total = 0;
1392 1393
        DBConnection dbConn = null;
1393 1394
        int serialNumber = -1;
1394
        
1395

  
1395 1396
        try {
1396
            String sql = "select guid, date_uploaded, rights_holder, checksum, " +
1397
                "checksum_algorithm, origin_member_node, authoritive_member_node, " +
1398
                "date_modified, submitter, object_format, size from systemmetadata";
1399
            
1397
            String sql = "select guid, date_uploaded, rights_holder, checksum, "
1398
                    + "checksum_algorithm, origin_member_node, authoritive_member_node, "
1399
                    + "date_modified, submitter, object_format, size from systemmetadata";
1400

  
1400 1401
            boolean f1 = false;
1401 1402
            boolean f2 = false;
1402 1403
            boolean f3 = false;
1403
            
1404

  
1404 1405
            if (startTime != null) {
1405 1406
                sql += " where systemmetadata.date_modified >= ?";
1406 1407
                f1 = true;
1407 1408
            }
1408
            
1409

  
1409 1410
            if (endTime != null) {
1410 1411
                if (!f1) {
1411 1412
                    sql += " where systemmetadata.date_modified < ?";
1412
                }
1413
                else {
1413
                } else {
1414 1414
                    sql += " and systemmetadata.date_modified < ?";
1415 1415
                }
1416 1416
                f2 = true;
1417 1417
            }
1418
            
1418

  
1419 1419
            if (objectFormatId != null) {
1420 1420
                if (!f1 && !f2) {
1421 1421
                    sql += " where object_format = ?";
1422
                }
1423
                else {
1422
                } else {
1424 1423
                    sql += " and object_format = ?";
1425 1424
                }
1426 1425
                f3 = true;
1427 1426
            }
1428
            
1427

  
1429 1428
            if (replicaStatus) {
1430 1429
                String currentNodeId = PropertyService.getInstance().getProperty("dataone.memberNodeId");
1431 1430
                if (!f1 && !f2 && !f3) {
1432
                    sql += " where authoritive_member_node != '" + currentNodeId.trim() + "'";
1431
                    sql += " where authoritive_member_node != '" +
1432
                        currentNodeId.trim() + "'";
1433
                } else {
1434
                    sql += " and authoritive_member_node != '" +
1435
                        currentNodeId.trim() + "'";
1433 1436
                }
1434
                else {
1435
                    sql += " and authoritive_member_node != '" + currentNodeId.trim() + "'";
1436
                }
1437 1437
            }
1438
            
1438

  
1439 1439
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.querySystemMetadata");
1440 1440
            serialNumber = dbConn.getCheckOutSerialNumber();
1441 1441
            PreparedStatement stmt = dbConn.prepareStatement(sql);
1442
            
1442

  
1443 1443
            if (f1 && f2 && f3) {
1444 1444
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
1445 1445
                stmt.setTimestamp(2, new Timestamp(endTime.getTime()));
1446 1446
                stmt.setString(3, objectFormatId.getValue());
1447
            }
1448
            else if (f1 && f2 && !f3) {
1447
            } else if (f1 && f2 && !f3) {
1449 1448
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
1450 1449
                stmt.setTimestamp(2, new Timestamp(endTime.getTime()));
1451
            }
1452
            else if (f1 && !f2 && f3) {
1450
            } else if (f1 && !f2 && f3) {
1453 1451
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
1454 1452
                stmt.setString(2, objectFormatId.getValue());
1455
            }
1456
            else if (f1 && !f2 && !f3) {
1453
            } else if (f1 && !f2 && !f3) {
1457 1454
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
1458
            }
1459
            else if (!f1 && f2 && f3) {
1455
            } else if (!f1 && f2 && f3) {
1460 1456
                stmt.setTimestamp(1, new Timestamp(endTime.getTime()));
1461 1457
                stmt.setString(2, objectFormatId.getValue());
1462
            }
1463
            else if (!f1 && !f2 && f3) {
1458
            } else if (!f1 && !f2 && f3) {
1464 1459
                stmt.setString(1, objectFormatId.getValue());
1465
            }
1466
            else if (!f1 && f2 && !f3) {
1460
            } else if (!f1 && f2 && !f3) {
1467 1461
                stmt.setTimestamp(1, new Timestamp(endTime.getTime()));
1468 1462
            }
1469
            
1470
            //logMetacat.debug("LISTOBJECTS QUERY: " + stmt.toString());
1471
            
1463

  
1464
            // logMetacat.debug("LISTOBJECTS QUERY: " + stmt.toString());
1465

  
1472 1466
            ResultSet rs = stmt.executeQuery();
1473
            for (int i=0; i<start; i++) {
1467
            for (int i = 0; i < start; i++) {
1474 1468
                if (rs.next()) {
1475 1469
                    total++;
1476 1470
                } else {
1477 1471
                    break;
1478 1472
                }
1479 1473
            }
1480
            
1474

  
1481 1475
            int countIndex = 0;
1482
                        
1483
            while (rs.next()) {
1476

  
1477
            while (rs.next()) {                
1484 1478
                total++;
1485 1479
                if (countIndex >= count) {
1486
                	// allow unlimited (negative number for count)
1487
                	if (count > 0) {
1488
                		break;
1489
                	}
1480
                    // allow unlimited (negative number for count)
1481
                    if (count > 0) {
1482
                        break;
1483
                    }
1490 1484
                }
1491
                                
1485

  
1492 1486
                String guid = rs.getString(1);
1493
                //logMetacat.debug("query found doc with guid " + guid);
1494
                //Timestamp dateUploaded = rs.getTimestamp(2);
1495
                //String rightsHolder = rs.getString(3);
1487
                // logMetacat.debug("query found doc with guid " + guid);
1488
                // Timestamp dateUploaded = rs.getTimestamp(2);
1489
                // String rightsHolder = rs.getString(3);
1496 1490
                String checksum = rs.getString(4);
1497 1491
                String checksumAlgorithm = rs.getString(5);
1498
                //String originMemberNode = rs.getString(6);
1499
                //String authoritiveMemberNode = rs.getString(7);
1492
                // String originMemberNode = rs.getString(6);
1493
                // String authoritiveMemberNode = rs.getString(7);
1500 1494
                Timestamp dateModified = rs.getTimestamp(8);
1501
                //String submitter = rs.getString(9);
1495
                // String submitter = rs.getString(9);
1502 1496
                String fmtidStr = rs.getString(10);
1503 1497
                String sz = rs.getString(11);
1504 1498
                BigInteger size = new BigInteger("0");
1505
                
1499

  
1506 1500
                if (sz != null && !sz.trim().equals("")) {
1507 1501
                    size = new BigInteger(rs.getString(11));
1508 1502
                }
1509
                
1503

  
1510 1504
                ObjectInfo oi = new ObjectInfo();
1511
                
1505

  
1512 1506
                Identifier id = new Identifier();
1513 1507
                id.setValue(guid);
1514 1508
                oi.setIdentifier(id);
1515
                
1509

  
1516 1510
                if (dateModified != null) {
1517
                	oi.setDateSysMetadataModified(new Date(dateModified.getTime()));
1511
                    oi.setDateSysMetadataModified(new Date(dateModified.getTime()));
1518 1512
                }
1519
                
1513

  
1520 1514
                Checksum cs = new Checksum();
1521 1515
                cs.setValue(checksum);
1522 1516
                try {
1523
                	//cs.setAlgorithm(ChecksumAlgorithm.valueOf(checksumAlgorithm));
1517
                    // cs.setAlgorithm(ChecksumAlgorithm.valueOf(checksumAlgorithm));
1524 1518
                    cs.setAlgorithm(checksumAlgorithm);
1525 1519
                } catch (Exception e) {
1526
					logMetacat.error("could not parse checksum algorithm", e);
1527
					continue;
1528
				}
1520
                    logMetacat.error("could not parse checksum algorithm", e);
1521
                    continue;
1522
                }
1529 1523
                oi.setChecksum(cs);
1530
                
1524

  
1531 1525
                // set the format type
1532 1526
                ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
1533
            	fmtid.setValue(fmtidStr);
1527
                fmtid.setValue(fmtidStr);
1534 1528
                oi.setFormatId(fmtid);
1535
                
1536
//                try {
1537
//	                oi.setFmtid(ObjectFormatCache.getInstance().getFormat(fmtidStr).getFmtid());
1538
//                } catch (NotFound e) {
1539
//                	logMetacat.error("could not find object format: " + fmtidStr, e);
1540
//                	// skip this one
1541
//                	continue;
1542
//				}
1543
                                
1529

  
1544 1530
                oi.setSize(size);
1545
                
1531

  
1546 1532
                ol.addObjectInfo(oi);
1547 1533
                countIndex++;
1548 1534
            }
1549
            
1535

  
1550 1536
            // expend the resultset to get the total count of possible rows
1551
            while (rs.next()) { 
1537
            while (rs.next()) {
1552 1538
                total++;
1553 1539
            }
1554 1540
        }
1555
        
1541

  
1556 1542
        finally {
1557 1543
            // Return database connection to the pool
1558 1544
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1559 1545
        }
1560
        
1546

  
1561 1547
        ol.setStart(start);
1562 1548
        ol.setCount(ol.sizeObjectInfoList());
1563 1549
        ol.setTotal(total);
1564
        
1550

  
1565 1551
        return ol;
1566 1552
    }
1567 1553
    

Also available in: Unified diff