<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
<channel>
<title>CodeStore.net comments on "Java: Test if a Document Exists in a Notes View"</title>
<description>Replies to blog "Java: Test if a Document Exists in a Notes View" on codestore.net.</description>
<link>http://www.codestore.net/</link>
<lastBuildDate>Sat, 25 Feb 2012 19:11:55 -0600</lastBuildDate>
<atom:link href="http://www.codestore.net/store.nsf/blog.xml?Open=20120223-0546" rel="self" type="application/rss+xml" />

<item>
	<title>Reply from Toby Samples</title>
	<pubDate>Sat, 25 Feb 2012 19:11:55 -0600</pubDate>
	<author>Toby Samples</author>
	<description><![CDATA[ 
		<p>This could change with different versions of domino, </p>
		<p>I know recently 852 and 853 they have made significant improvements to view navigator.</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=1EAFCFD55780E6AF862579B000069523"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument&amp;r=1EAFCFD55780E6AF862579B000069523#DOC_1EAFCFD5</link>
</item><item>
	<title>Reply from Richard Schwartz</title>
	<pubDate>Thu, 23 Feb 2012 12:59:51 -0600</pubDate>
	<author>Richard Schwartz</author>
	<description><![CDATA[ 
		<p>Another approach, which would work the same way for both views and folders is to create an empty NoteCollection object, use NoteCollection.add(doc) to put your document into the collection, and then use NoteCollection.intersect(view).  If your document is still in the NoteCollection, it was in the view.</p>
		<p>Or to do it in bulk instead of one document at a time, first define two NoteCollection objects nc1 and nc2, with both containing all documents using the setSelectDocuments(true) and buildCollection() methods.  Next call nc2.intersect(view) which gives you only the documents in the view. Finally, call nc1.remove(nc2), which gives you all the documents that were not in the view. </p>
		<p>If you have multiple views and/or folders to work with, you can do it in a loop.  I.e., after each remove(), call nc2.clearCollection, then call nc2.add(nc1) so once again you have two identical collections (all docs minus the ones that were removed in previous iterations), and repeat the process of intersecting and removing.</p>
		<p>Note that I haven't tried the bulk approach, but I have a feeling it should be significantly faster because it's never actually opening documents.  </p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=A1E7E4FDF34AED34862579AD00685B1F"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_A1E7E4FD</link>
</item><item>
	<title>Reply from Ulrich Krause</title>
	<pubDate>Thu, 23 Feb 2012 10:20:10 -0600</pubDate>
	<author>Ulrich Krause</author>
	<description><![CDATA[ 
		<p>I see. But I've found a passible use case. There is no @WichFolder in LS ( or XPages ). The code lets you build your own atWhichFolder( Document doc) method. </p>
		<p>Have done it in LS with NotesViewNavigator. It's time to compare both methods regarding performance</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=BB060F888EC2A152862579AD0059BCE1"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument&amp;r=BB060F888EC2A152862579AD0059BCE1#DOC_BB060F88</link>
</item><item>
	<title>Reply from Jake Howlett</title>
	<pubDate>Thu, 23 Feb 2012 08:50:08 -0600</pubDate>
	<author>Jake Howlett</author>
	<description><![CDATA[ 
		<p>Wowsers, that's some difference.</p>
		<p>You've convinced me to change my approach.</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=55B6C3A650896FF0862579AD00517E9B"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument&amp;r=55B6C3A650896FF0862579AD00517E9B#DOC_55B6C3A6</link>
</item><item>
	<title>Reply from Jake Howlett</title>
	<pubDate>Thu, 23 Feb 2012 08:47:28 -0600</pubDate>
	<author>Jake Howlett</author>
	<description><![CDATA[ 
		<p>Good point. You could, but then you've duplicated the code/logic. If the logic of the view changes you have to change it in the new view too.</p>
		<p>Like everything it's "horses for courses" and "more than one way to swing a cat".</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=D66C0870CFFB7F74862579AD00513FBB"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_D66C0870</link>
</item><item>
	<title>Reply from Jesse Gallagher</title>
	<pubDate>Thu, 23 Feb 2012 08:38:42 -0600</pubDate>
	<author>Jesse Gallagher</author>
	<description><![CDATA[ 
		<p>My curiosity piqued, I did indeed run some tests. I wrote an agent in our project-tracking database (95k documents) to test all documents against a view in four ways:</p>
		<p>1. The method you have above</p>
		<p>2. The method you have above changed to only fetch the selection formula once and then pass that in instead of the view</p>
		<p>3. A method that creates a view navigator from the view and uses .gotoEntry(doc) on that</p>
		<p>4. A method that takes an already-created navigator instead of the view</p>
		<p>Somewhat freakishly, the average run times of three attempts at each were about halved, each in order:</p>
		<p>1. 55-59s</p>
		<p>2. 30-31s</p>
		<p>3. 14-15s</p>
		<p>5. 6s</p>
		<p>So, at least if you're going to be running the method quite a few times, using the view navigator is much faster.</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=65E9F46704323EF0862579AD0050727C"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument&amp;r=65E9F46704323EF0862579AD0050727C#DOC_65E9F467</link>
</item><item>
	<title>Reply from Phil</title>
	<pubDate>Thu, 23 Feb 2012 08:27:03 -0600</pubDate>
	<author>Phil</author>
	<description><![CDATA[ 
		<p>Can't you just create a view that only shows the documents you require, then process that?</p>
		<p>To take your example above - SELECT !Form="Foo"</p>
		<p>Phil.</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=367D4384E57D67A8862579AD004F6091"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_367D4384</link>
</item><item>
	<title>Reply from Jake Howlett</title>
	<pubDate>Thu, 23 Feb 2012 07:14:34 -0600</pubDate>
	<author>Jake Howlett</author>
	<description><![CDATA[ 
		<p>Oooh, hadn't thought of that approach. Surely it would be slower to find the document in a ViewNavigator though!? Or would it depend on the complexity of the Selection Formula. If the formula were simply SELECT Form="Foo" then evaluate may win? If the formula were dozens of lines of code, perhaps not?</p>
		<p>I'll leave it with you if you want to look in to it any further ;)</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=BDBC9177A745697F862579AD0048BE53"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_BDBC9177</link>
</item><item>
	<title>Reply from Jake Howlett</title>
	<pubDate>Thu, 23 Feb 2012 07:12:10 -0600</pubDate>
	<author>Jake Howlett</author>
	<description><![CDATA[ 
		<p>It's hard to say what my exact use case was without breaking confidentiality agreements, but this is the 2nd time I've used the same approach. It is useful. Enough for me to think it worthy or posting here.</p>
		<p>Based on the principle that the selection formula for some views is representative of the business logic for a database, it shouldn't be too hard to think of a case where you need to check whether a document is in a view or not.</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=0B897CA90C213F84862579AD00488642"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_0B897CA9</link>
</item><item>
	<title>Reply from Jesse Gallagher</title>
	<pubDate>Thu, 23 Feb 2012 06:56:34 -0600</pubDate>
	<author>Jesse Gallagher</author>
	<description><![CDATA[ 
		<p>Oh, I like this method. Now it has me thinking about other ways to do it as well... namely, I wonder how the performance would compare to creating a ViewNavigator and calling .gotoEntry(doc). That's always seemed like a bizarre method to me, but I think I found it to be surprisingly fast when I tried it a while back.</p>
		<p>I also kind of wonder how it would work in oddball scenarios like a document qualifying for the selection formula but not visually showing up in the view because its parent isn't there.</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=633CBF1C1186A80E862579AD0047188A"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_633CBF1C</link>
</item><item>
	<title>Reply from Jake Howlett</title>
	<pubDate>Thu, 23 Feb 2012 06:37:24 -0600</pubDate>
	<author>Jake Howlett</author>
	<description><![CDATA[ 
		<p>Hi Hans-Peter,</p>
		<p>I bow down to your superior wisdom! Now you've explained it it makes sense. Without the explanation I'd expected the more obvious result of it returning either a 1 or 0 | "1" or "0" | "True" or "False" .</p>
		<p>Thanks for the explanation. I continue to learn.</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=759E1E14A9EB47F7862579AD004557C8"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_759E1E14</link>
</item><item>
	<title>Reply from Ulrich Krause</title>
	<pubDate>Thu, 23 Feb 2012 06:18:09 -0600</pubDate>
	<author>Ulrich Krause</author>
	<description><![CDATA[ 
		<p>What could be a use case for this?</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=25FB423AFE955A4F862579AD00439456"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_25FB423A</link>
</item><item>
	<title>Reply from Hans-Peter Kuessner</title>
	<pubDate>Thu, 23 Feb 2012 06:08:20 -0600</pubDate>
	<author>Hans-Peter Kuessner</author>
	<description><![CDATA[ 
		<p>Hi Jake,</p>
		<p>in formula language there is no "boolean" data type (nor "integer" or "real" etc.). There just is "number" and "string".</p>
		<p>And @True is a number (1), @False is 0. </p>
		<p>As you are evaluating in java, which has strong typing, you will get the number data type which should be able to hold the returned value - which is the double data type.</p>
		<p>To avoid this kind of trouble I tend to use formulas which return strings, e. g. by wrapping the formula into an </p>
		<p>@if (....; "1"; "0");</p>
		<p>Not pretty, but more reliable. I also like to wrap the formula with an @If (@IsError(...); ...), so that I can check the results - instead of the exception handling.</p>
		<p>@Formulas throwing errors are bad, not only in forms - you never know what is going on without catching the errors in every single formula...</p>
		<p>By the way:</p>
		<p>Your formula probably might not work for views with response hierarchies, e. g. selection formulas containing @Responses or @Descendants. But I haven't tested this.</p>
		<p>Hans-Peter</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=345A5F744BD1461D862579AD0042AE0F"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20120223-0546?OpenDocument#DOC_345A5F74</link>
</item>

</channel>
</rss> 
