1

I have this block of code in a Java Method:

colVal = ve.getColumnValues();
    System.out.println("Got colVal");
    System.out.println("Col values = " + colVal.toString());
    try {
        Document pDoc = ve.getDocument();
        System.out.println("Start MyDate");
        DateTime dt = (DateTime) pDoc.getItemValueDateTimeArray("ExpPayDate").get(0);
        Date pDate = dt.toJavaDate();
        pItem.setMyDate(pDate);
    } catch (Exception e) {
                        // date error
    System.out.println("setMyDate Failed "+ e.toString());
    }

The log looks like this:

12/09/2015 02:49:59 PM  HTTP JVM: Got colVal
12/09/2015 02:49:59 PM  HTTP JVM: Col values = [1bp8frg61ze9s, 24/09/2015 12:00:00 PM MDT, , 0.0, ---, , --- No Agent ---, , ]

I use the ViewEntry because I need to maintain the view sort order. The problem with this is that the ve.getDocument() means an extra trip to the server and is could become fairly expensive. So I have tried to work just with the colVal.get(1), it is viewed as a Notes DataTime but colVal.get(1).toJavaDate() does not seem to be available.

Changed the code to try to get the value from the colVal:

System.out.println("Got colVal");
System.out.println("Col values = " + colVal.toString());
    try {
     System.out.println("Start MyDate");
    System.out.println("Get value from colVal " + colVal.get(1).toString());
                        //pItem.setMyDate(pDate);
    } catch (Exception e)
        System.out.println("setExpPayDate Failed "  + e.toString());
} 

When I run this "get value from colVal " causes an error :

12/09/2015 03:05:55 PM  HTTP JVM: Start MyDate
12/09/2015 03:05:55 PM  HTTP JVM: setMyDate Failed java.lang.ClassCastException: lotus.domino.local.DateTime incompatible with java.lang.String

I can do what I need from the document but can't seem to get there from the viewEntry and the ve.getColumnValues().

Bill F
  • 2,057
  • 3
  • 18
  • 39

1 Answers1

6

The immediate solution is that you need to cast the object to a DateTime to be able to call the toJavaDate method. For example:

DateTime dt = (DateTime)colVal.get(1);
Date date = dt.toJavaDate();

This is because the Vector returned by getColumnValues returns Object-typed values, since it can be mixed.

In this specific case, there's also a way to get the column value as a Date directly. If you call entry.setPreferJavaDates(true) before getting the column values, then date/time values will be represented as Date objects instead of DateTime. You'd still probably end up casting the column value to Date anyway, but that can be a small convenience. It also eliminates the need to do entry.recycle(colVal) inside the loop to make sure the DateTimes in the column values are recycled.

Jesse Gallagher
  • 4,461
  • 13
  • 11
  • Jesse -- that did it thanks. This is a code snippet: ViewEntryCollection veCol = vwPayment.getAllEntriesByKey(lKey); while (ve != null){ ViewEntry tVE = ve; colVal = ve.getColumnValues(); ve.setPreferJavaDates(true); PaymentItem pItem = new PaymentItem(); colVal = ve.getColumnValues(); Date dt = (Date) ve.getColumnValues().get(1); pItem.setExpPayDate(dt); pItem.setContract(colVal.get(7).toString()); ......... Utils.recycleObjects(pItem,ve); ve = veCol.getNextEntry(tVE); } veCol.recycle(); Is there anything else that needs to be recycled? As you said I should not need to recycle colVal. – Bill F Sep 14 '15 at 01:09
  • I think that recycling the view entry should come after fetching the next one, shouldn't it? Though if it works as-is, maybe not. I also don't imagine pItem needs recycling there - recycling is a Notes-object-specific thing due to their C-side handles. – Jesse Gallagher Sep 14 '15 at 01:54
  • I use this structure all the time. tVE = ve; do my stuff; ve.recycle(); ve = veCol.getNextEntry(tVE); is there a better way to do that? – Bill F Sep 14 '15 at 14:04
  • Nah, if it works, no reason to change it - I'd have thought there'd be an "object has been removed or recycled" exception, but it seems I was mistaken. – Jesse Gallagher Sep 14 '15 at 14:15