Project

General

Profile

« Previous | Next » 

Revision 6752

only handle 100 (consecutive!) docId generations per millisecond, otherwise the generated docid part is bigger than Long.MAX_VALUE and Metacat cannot fully handle that.

View differences:

src/edu/ucsb/nceas/metacat/util/DocumentUtil.java
61 61
public class DocumentUtil
62 62
{
63 63
	
64
    public static AbstractDatabase dbAdapter;
64
    private static int documentIdCounter = 0;
65

  
66
	public static AbstractDatabase dbAdapter;
65 67
    
66 68
    private static Logger logMetacat = Logger.getLogger(DocumentUtil.class);
67 69
    private static char separator = '.';
......
537 539
        calendar.setTime(trialTime);
538 540
        // using yyyymmddhhmmssmmm by convention (zero padding to preserve places)
539 541
        // will help with looking at logs and especially database tables.
540
        String randomStr = (new Double(Math.random())).toString();
541
        randomStr = randomStr.substring(randomStr.length() - 5); // last 5 characters
542
        docid.append(String.format("%04d%02d%02d%02d%02d%02d%03d%s",
542
        // for each millisecond we can support up to 99 before resetting to 0
543
        // NOTE: if you make it larger, docid is too big for a Long 
544
        if (documentIdCounter > 100) {
545
        	documentIdCounter = 0;
546
        }
547
        docid.append(String.format("%04d%02d%02d%02d%02d%02d%03d%02d",
543 548
        calendar.get(Calendar.YEAR),
544 549
        calendar.get(Calendar.MONTH) + 1,  // adjust 0-11 range to 1-12
545 550
        calendar.get(Calendar.DAY_OF_MONTH),
......
547 552
        calendar.get(Calendar.MINUTE),
548 553
        calendar.get(Calendar.SECOND),
549 554
        calendar.get(Calendar.MILLISECOND),
550
        randomStr)
555
        documentIdCounter++)
551 556
        );
552 557
        if (revision > 0) {
553 558
            docid.append(".").append(revision);

Also available in: Unified diff