<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Nesterovsky bros</title>
  <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/" />
  <link rel="self" href="http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2012-02-02T22:06:56.5062306-08:00</updated>
  <author>
    <name>Nesterovsky bros</name>
  </author>
  <subtitle />
  <id>http://www.nesterovsky-bros.com/weblog/</id>
  <generator uri="http://dasblog.info/" version="2.3.9074.18820">DasBlog</generator>
  <entry>
    <title>SQL Server, grouping ranges</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2012/02/01/SQLServerGroupingRanges.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,4deebb89-c120-4a3d-99f7-6fb4759471ca.aspx</id>
    <published>2012-02-01T12:34:09.848-08:00</published>
    <updated>2012-02-02T22:06:56.5062306-08:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A customer have a table with data stored by dates, and asked us to present data from
this table by sequential date ranges.
</p>
        <p>
This query sounded trivial but took us half a day to create such a select.
</p>
        <p>
For simplicity consider a table of integer numbers, and try to build a select that
returns pairs of continuous ranges of values.
</p>
        <p>
So, for an input like this:
</p>
        <p style="padding-left: 1em">
          <code>declare @values table<br />
(<br />
value int not null primary key<br />
);<br /><br />
insert into @values(value)<br />
select 1 union all select 2 union all select 3 union all<br />
select 5 union all select 6 union all<br />
select 8 union all<br />
select 10 union all<br />
select 12 union all select 13 union all select 14; </code>
        </p>
        <p>
You will have a following output:
</p>
        <pre style="padding-left: 1em">
low  high
---- ----
1    3
5    6
8    8
10   10
12   14</pre>
        <p>
Logic of the algorithms is like this:
</p>
        <ol style="list-style-type: lower-alpha">
          <li>
get a low bound of each range (a value without value - 1 in the source);</li>
          <li>
get a high bound of each range (a value without value + 1 in the source);</li>
          <li>
combine low and high bounds.</li>
        </ol>
        <p>
Following this logic we have built at least three different queries, where the shortest
one is:
</p>
        <p style="padding-left: 1em">
          <code> with source as<br />
(<br />
select * from @values<br />
)<br />
select 
<br />
l.value low,<br />
min(h.value) high<br />
from 
<br />
source l<br />
inner join<br />
source h<br />
on<br />
(l.value - 1 not in (select value from source)) and<br />
(h.value + 1 not in (select value from source)) and<br />
(h.value &gt;= l.value)<br />
group by<br />
l.value;</code>
        </p>
        <p>
          <img alt="execution plan" style="width: 100%; border: 1px solid black" src="content/binary/number-ranges-plan.jpg" />
        </p>
        <p>
Looking at this query it's hard to understand why it took so long to write so
simple code...
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=4deebb89-c120-4a3d-99f7-6fb4759471ca" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Again about cinematography.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2012/01/25/AgainAboutCinematography.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,a23cc7e7-d76b-4f52-9471-abd9beeaa151.aspx</id>
    <published>2012-01-25T12:57:35.811-08:00</published>
    <updated>2012-01-25T13:07:07.727763-08:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Some time ago our younger brother Aleksander had started studying of <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a23cc7e7-d76b-4f52-9471-abd9beeaa151&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f05%2f05%2fCinematography.aspx">cinematography</a>.
</p>
        <p>
Few days ago he started his own <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a23cc7e7-d76b-4f52-9471-abd9beeaa151&amp;url=http%3a%2f%2fwww.wix.com%2faleksan86%2fnesta" target="_blank">"multimedia"
blog</a> (you'll better understand me when you'll see it), where you can see his portfolio.
Aleksander's latest work was made with cooperation with Ilan Lahov, see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a23cc7e7-d76b-4f52-9471-abd9beeaa151&amp;url=http%3a%2f%2fwww.wix.com%2faleksan86%2fnesta%23!__bar-mitzvah" target="_blank">"Bar
mitzvah"</a>. This work demonstrates Aleksander's progress in this field.
</p>
        <p>
Our congratulations to <a href="mailto:aleksander@nesterovsky-bros.com">Aleksander</a>!
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=a23cc7e7-d76b-4f52-9471-abd9beeaa151" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Be aware, an antivirus is working here!</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2012/01/20/BeAwareAnAntivirusIsWorkingHere.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0ede73c9-1649-4252-9078-1a4f27d21838.aspx</id>
    <published>2012-01-20T08:47:58.865-08:00</published>
    <updated>2012-01-20T08:49:49.899597-08:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you're writing an application that deals with files in file system on Windows,
be sure that sooner or later you run into problems with antivirus software. 
</p>
        <p>
Our latest program that handles a lot of huge files and works as a Windows service,
it reports time to time about some strange errors. These errors look like the file
system disappeared on the fly, or, files were stolen by somebody else (after they
have been opened in exclusive mode by our application). 
</p>
We spent about two weeks in order to diagnose the cause of such behaviour, and then
came to conclusion that is a secret work of our antivirus. All such errors disappeared
as fog when the antivirus was configurated to skip folders with our files. 
<p></p><p>
Thus, keep in mind our experience and don't allow an ativirus to became an evil.
</p><img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0ede73c9-1649-4252-9078-1a4f27d21838" /></div>
    </content>
  </entry>
  <entry>
    <title>Analizing SQL</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2012/01/19/AnalizingSQL.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1f01d63b-7ec8-4ca2-a761-687d8c183bd3.aspx</id>
    <published>2012-01-19T13:12:11.08-08:00</published>
    <updated>2012-01-19T13:34:24.020859-08:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
While looking at some SQL we have realized that it can be considerably optimized.
</p>
        <p>
Consider a table source like this:
</p>
        <p style="padding-left: 1em">
          <code>with Data(ID, Type, SubType) 
<br />
(<br />
select 1, 'A', 'X'<br />
union all<br />
select 2, 'A', 'Y'<br />
union all<br />
select 3, 'A', 'Y'<br />
union all<br />
select 4, 'B', 'Z'<br />
union all<br />
select 5, 'B', 'Z'<br />
union all<br />
select 6, 'C', 'X'<br />
union all<br />
select 7, 'C', 'X'<br />
union all<br />
select 8, 'C', 'Z'<br />
union all<br />
select 9, 'C', 'X'<br />
union all<br />
select 10, 'C', 'X'<br />
)</code>
        </p>
        <p>
Suppose you want to group data by type, to calculate number of elements in each group
and to display sub type if all rows in a group are of the same sub type.
</p>
        <p>
Earlier we have written the code like this:
</p>
        <p style="padding-left: 1em">
          <code>select<br />
Type, 
<br />
case when count(distinct SubType) = 1 then min(SubType) end SubType,<br />
count(*) C<br />
from<br />
Data<br />
group by<br />
Type; </code>
        </p>
        <p>
Namely, we select <code>min(SybType)</code> provided that there is a single distinct <code>SubType</code>,
otherwise <code>null</code> is shown. That works perfectly, but algorithmically <code>count(distinct
SubType) = 1</code> needs to build a set of distinct values for each group just to
ask the size of this set. That is expensive!
</p>
        <p>
What we wanted can be expressed differently: if <code>min(SybType)</code> and <code> max(SybType)</code> are
the same then we want to display it, otherwise to show <code>null</code>. 
</p>
        <p>
That's the new version:
</p>
        <p style="padding-left: 1em">
          <code>select<br />
Type, 
<br />
case when min(SubType) = max(SubType) then min(SubType) end SubType,<br />
count(*) C<br />
from<br />
Data<br />
group by<br />
Type; </code>
        </p>
        <p>
Such a simple rewrite has cardinally simplified the execution plan:
</p>
        <p>
          <img alt="Execution plans" src="content/binary/group-by-plan.jpg" style="width: 100%;&#xA;      border: 1px solid black" />
        </p>
        <p>
Another bizarre problem we have discovered is that SQL Server 2008 R2 just does not
support the following:
</p>
        <p style="padding-left: 1em">
          <code>select<br />
count(distinct SubType) over(partition by Type)<br />
from<br />
Data </code>
        </p>
        <p>
That's really strange, but it's known bug (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1f01d63b-7ec8-4ca2-a761-687d8c183bd3&amp;url=http%3a%2f%2fconnect.microsoft.com%2fSQLServer%2ffeedback%2fdetails%2f254393%2fover-clause-enhancement-request-distinct-clause-for-aggregate-functions"> Microsoft
Connect</a>). 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1f01d63b-7ec8-4ca2-a761-687d8c183bd3" />
      </div>
    </content>
  </entry>
  <entry>
    <title>READ_COMMITTED_SNAPSHOT in SQL Server 2008 R2</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2012/01/13/READCOMMITTEDSNAPSHOTInSQLServer2008R2.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c712a85b-5b6d-4f56-a053-78aa1b7dff4f.aspx</id>
    <published>2012-01-13T05:43:56.952075-08:00</published>
    <updated>2012-01-13T05:43:56.952075-08:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A database we support for a client contains multi-billion row tables. Many users query
the data from that database, and it's permanently populated with a new data.
</p>
        <p>
Every day we load several millions rows of a new data. Such loads can lock tables
for a considerable time, so our loading procedures collect new data into intermediate
tables and insert it into a final destination by chunks, and usually after work hours.
</p>
        <p>
SQL Server 2008 R2 introduced <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c712a85b-5b6d-4f56-a053-78aa1b7dff4f&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms188277.aspx"> READ_COMMITTED_SNAPSHOT
database option</a>. This feature trades locks for an increased tempdb size (to store
row versions) and possible performance degradation during a transaction.
</p>
        <p>
When we have switched the database to that option we did not notice any considerable
performance change. Encouraged, we've decided to increase size of chunks of data
we insert at once. 
</p>
        <p>
Earlier we have found that when we insert no more than 1000 rows at once, users don't
notice impact, but for a bigger chunk sizes users start to complain on performance
degradation. This has probably happened due to locks escalations.
</p>
        <p>
Now, with chunks of 10000 or even 100000 rows we have found that no queries became
slower. But load process became several times faster.
</p>
        <p>
We were ready to pay for increased tempdb and transaction log size to increase performance,
but in our case we didn't approach limits assigned by the DBA. Another gain is
that we can easily load data at any time. This makes data we store more up to date.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c712a85b-5b6d-4f56-a053-78aa1b7dff4f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Fast Property Access in V8 JavaScript Engine</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/12/17/FastPropertyAccessInV8JavaScriptEngine.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,bef403f0-158f-477b-b322-47d66251cb6a.aspx</id>
    <published>2011-12-17T02:18:14.81-08:00</published>
    <updated>2011-12-17T03:08:01.1241355-08:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday, by accident, we've seen an article about some design principles of <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=bef403f0-158f-477b-b322-47d66251cb6a&amp;url=http%3a%2f%2fcode.google.com%2fapis%2fv8%2fdesign.html">V8
JavaScript Engine</a>. It made clearer what techniques are used in today's script
implementations.
</p>
        <p>
In particular V8 engine optimizes property access using "<span style="font-style: italic">dynamically
created hidden classes</span>". These are structures to store object's layout,
they are derived when ש new property is created (deleted) on the object. When code
accesses a property, and if a cached object's dynamic hidden class is available
at the code point then access time is comparable to one of native fields.
</p>
        <p>
In our opinion this tactics might lead to a proliferation of such dynamic hidden classes,
which requires a considerable housekeeping, which also slows property write access,
especially when it's written for the first time. 
</p>
        <p>
We would like to suggest a slightly different strategy, which exploits the cache matches,
and does not require a dynamic hidden classes. 
</p>
        <p>
Consider an implementation data type with following characteristics:
</p>
        <ul>
          <li>
object is implemented as a hash map of property id to property value: Map&lt;ID, Value&gt;;</li>
          <li>
it stores data as an array of pairs and can be accessed directly: Pair&lt;ID, Value&gt;
values[];</li>
          <li>
property index can be acquired with a method: int index(ID);</li>
        </ul>
        <p>
A pseudo code for the property access looks like this:
</p>
        <p style="padding-left: 1em">
          <code> pair = object.values[cachedIndex];<br /><br />
if (pair.ID == propertyID)<br />
{<br />
value = pair.Value;<br />
}<br />
else<br />
{<br />
// Cache miss.<br />
cachedIndex = object.index(propertyID);<br />
value = objec.values[cachedIndex].Value;<br />
}</code>
        </p>
        <p>
This approach brings us back to dictionary like implementation but with important
optimization of array speed access when property index is cached, and with no dynamic
hidden classes.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=bef403f0-158f-477b-b322-47d66251cb6a" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Saxon 9.4 is out</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/12/10/Saxon94IsOut.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,08d97135-32ca-4586-bdf4-410ef43f8ebe.aspx</id>
    <published>2011-12-10T04:16:28.754-08:00</published>
    <updated>2011-12-10T04:19:04.8086725-08:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p style="padding-left: 1em; font-style: italic">
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=08d97135-32ca-4586-bdf4-410ef43f8ebe&amp;url=http%3a%2f%2ftwitter.com%2f%23!%2fmichaelhkay%2fstatuses%2f145259939055673344">@michaelhkay
Saxon 9.4 is out.</a>
        </p>
        <p>
But why author does not state that HE version is still xslt/xpath 2.0, as neither
xslt maps, nor function items are supported.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=08d97135-32ca-4586-bdf4-410ef43f8ebe" />
      </div>
    </content>
  </entry>
  <entry>
    <title>SQL Server 2008 with(recompile) Next</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/12/03/SQLServer2008WithrecompileNext.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,49f851e0-8141-4827-852c-98161e14234e.aspx</id>
    <published>2011-12-03T07:06:44.313-08:00</published>
    <updated>2011-12-03T07:08:35.6601086-08:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently, we have found and reported the bug in the SQL Server 2008 (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=49f851e0-8141-4827-852c-98161e14234e&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f11%2f18%2fSQLServer2008Withrecompile.aspx">SQL
Server 2008 with(recompile)</a>, and also <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=49f851e0-8141-4827-852c-98161e14234e&amp;url=http%3a%2f%2fconnect.microsoft.com%2fSQLServer%2ffeedback%2fdetails%2f705658%2fwith-recompile-does-not-work-for-select-var">Microsoft
Connect</a>).
</p>
        <p>
Persons, who's responsible for the bug evaluation has closed it, as if "By Design".
This strange resolution, in our opinion, says about those persons only.
</p>
        <p>
Well, we shall try once more (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=49f851e0-8141-4827-852c-98161e14234e&amp;url=http%3a%2f%2fconnect.microsoft.com%2fSQLServer%2ffeedback%2fdetails%2f705658%2fwith-recompile-does-not-work-for-select-var">Microsoft
Connect</a>). We have posted another trivial demonstartion of the bug, where we show
that option(recompile) is not used, which leads to table scan (nothing worse can happen
for a huge table).
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=49f851e0-8141-4827-852c-98161e14234e" />
      </div>
    </content>
  </entry>
  <entry>
    <title>SQL Server 2008 with(recompile)</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/11/18/SQLServer2008Withrecompile.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,abae0d0b-73a8-4531-8aa6-147b0ba5586a.aspx</id>
    <published>2011-11-18T06:49:50.595-08:00</published>
    <updated>2011-11-18T07:29:10.6475906-08:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="html">  &lt;p&gt;
&lt;p&gt;
Recently we have introduced some stored procedure in the production and have found
that it performs incredibly slow.
&lt;/p&gt;
&lt;p&gt;
Our reasoning and tests in the development environment did not manifest any problem
at all.
&lt;/p&gt;
&lt;p&gt;
In essence that procedure executes some SELECT and returns a status as a signle output
variable. Procedure recieves several input parameters, and the SELECT statement uses &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=abae0d0b-73a8-4531-8aa6-147b0ba5586a&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms181714.aspx"&gt; with(recompile)
execution hint&lt;/a&gt; to optimize the performance for a specific parameters.
&lt;/p&gt;
&lt;p&gt;
We have analyzed the execution plan of that procedure and have found that it works
as if with(recompile) hint was not specified. Without that hint SELECT failed to use
index seek but rather used index scan.
&lt;/p&gt;
&lt;p&gt;
What we have lately found is that the same SELECT that produces result set instead
of reading result into a variable performs very well.
&lt;/p&gt;
&lt;p&gt;
We think that this is a bug in SQL Server 2008 R2 (and in SQL Server 2008).
&lt;/p&gt;
&lt;p&gt;
To demonstrate the problem you can run this test:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; -- Setup&lt;br /&gt;
create table dbo.Items&lt;br /&gt;
(&lt;br /&gt;
Item int not null primary key&lt;br /&gt;
);&lt;br /&gt;
go&lt;br /&gt;
&lt;br /&gt;
insert into dbo.Items&lt;br /&gt;
select 1&lt;br /&gt;
union all&lt;br /&gt;
select 2&lt;br /&gt;
union all&lt;br /&gt;
select 3&lt;br /&gt;
union all&lt;br /&gt;
select 4&lt;br /&gt;
union all&lt;br /&gt;
select 5&lt;br /&gt;
go&lt;br /&gt;
&lt;br /&gt;
create procedure dbo.GetMaxItem&lt;br /&gt;
(&lt;br /&gt;
@odd bit = null,&lt;br /&gt;
@result int output&lt;br /&gt;
)&lt;br /&gt;
as&lt;br /&gt;
begin&lt;br /&gt;
set nocount on;&lt;br /&gt;
&lt;br /&gt;
with Items as&lt;br /&gt;
(&lt;br /&gt;
select * from dbo.Items where @odd is null&lt;br /&gt;
union all&lt;br /&gt;
select * from dbo.Items where (@odd = 1) and ((Item &amp; 1) = 1)&lt;br /&gt;
union all&lt;br /&gt;
select * from dbo.Items where (@odd = 0) and ((Item &amp; 1) = 0)&lt;br /&gt;
)&lt;br /&gt;
select @result = max(Item) from Items&lt;br /&gt;
option(recompile);&lt;br /&gt;
end;&lt;br /&gt;
go&lt;br /&gt;
&lt;br /&gt;
create procedure dbo.GetMaxItem2&lt;br /&gt;
(&lt;br /&gt;
@odd bit = null,&lt;br /&gt;
@result int output&lt;br /&gt;
)&lt;br /&gt;
as&lt;br /&gt;
begin&lt;br /&gt;
set nocount on;&lt;br /&gt;
&lt;br /&gt;
declare @results table&lt;br /&gt;
(&lt;br /&gt;
Item int&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
with Items as&lt;br /&gt;
(&lt;br /&gt;
select * from dbo.Items where @odd is null&lt;br /&gt;
union all&lt;br /&gt;
select * from dbo.Items where (@odd = 1) and ((Item &amp; 1) = 1)&lt;br /&gt;
union all&lt;br /&gt;
select * from dbo.Items where (@odd = 0) and ((Item &amp; 1) = 0)&lt;br /&gt;
)&lt;br /&gt;
insert into @results&lt;br /&gt;
select max(Item) from Items&lt;br /&gt;
option(recompile);&lt;br /&gt;
&lt;br /&gt;
select @result = Item from @results;&lt;br /&gt;
end;&lt;br /&gt;
go&lt;br /&gt;
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Test with output into a variable:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;declare @result1 int;&lt;br /&gt;
&lt;br /&gt;
execute dbo.GetMaxItem @odd = null, @result = @result1 output &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img alt="Execution plan of dbo.GetMaxItem" src="content/binary/GetMaxItemSQL.JPG" style="width: 40em" /&gt;
&lt;/p&gt;
&lt;p&gt;
Test without output directly into a variable:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;declare @result2 int;&lt;br /&gt;
&lt;br /&gt;
execute dbo.GetMaxItem2 @odd = null, @result = @result2 output &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img alt="Execution plan of dbo.GetMaxItem2" src="content/binary/GetMaxItem2SQL.JPG" style="width: 40em" /&gt;
&lt;/p&gt;
&lt;p&gt;
Now, you can see the difference: the first execution plan uses startup expressions,
while the second optimizes execution branches, which are not really used. In our case
it was crucial, as the execition time difference was minutes (and more in future)
vs a split of second.
&lt;/p&gt;
&lt;p&gt;
See also &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=abae0d0b-73a8-4531-8aa6-147b0ba5586a&amp;amp;url=https%3a%2f%2fconnect.microsoft.com%2fSQLServer%2ffeedback%2fdetails%2f705658%2fwith-recompile-does-not-work-for-select-var"&gt;Microsoft
Connect Entry&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=abae0d0b-73a8-4531-8aa6-147b0ba5586a" /&gt;</content>
  </entry>
  <entry>
    <title>eXperanto project actual yet...</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/11/10/eXperantoProjectActualYet.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7a2cda28-6e38-48d8-a233-302ba6e1d75e.aspx</id>
    <published>2011-11-10T14:14:09.467-08:00</published>
    <updated>2011-11-10T21:11:03.9398052-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,NET.aspx" />
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A bit history: the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7a2cda28-6e38-48d8-a233-302ba6e1d75e&amp;url=http%3a%2f%2fwww.bphx.com%2fen%2fNewsEvents%2fPressReleases%2fPages%2f072902.aspx" target="_blank">first
release</a> of this solution was about 9.5 years ago...
</p>
        <p>
Today we've run into a strange situation. One of our clients ask us about automatic
conversion of data from mainframe (that were defined as COBOL copybooks) into XML
or Java/.NET objects. On our suggestion to use <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7a2cda28-6e38-48d8-a233-302ba6e1d75e&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdata%2fprojects.xml">eXperanto</a>,
which is well known to him, he stated that he wouldn't like to use a tool of a company
that is no more exists...
</p>
        <p>
The situation, in our opinion, become more strange when you consider the following:
</p>
        <ul>
          <li>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7a2cda28-6e38-48d8-a233-302ba6e1d75e&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdata%2fprojects.xml">eXperanto</a> (the
design-time tool and run-time libraries for Java and .NET) were developed, well tested,
and delivered by us to production already several years ago.</li>
          <li>
the client bought this set (the tool and libraries).</li>
          <li>
the set is in production yet already in another big company, and is used time to time
by our company in different migration projects.</li>
          <li>
the client talks with developers of this tool and run-time libraries, and he knows
about this fact.</li>
          <li>
the client uses widely open source solutions even without dedicated vendors or support
warranties.</li>
        </ul>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7a2cda28-6e38-48d8-a233-302ba6e1d75e" />
      </div>
    </content>
  </entry>
  <entry>
    <title>jQuery</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/10/28/jQuery.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</id>
    <published>2011-10-28T15:59:23.607-07:00</published>
    <updated>2011-10-28T16:05:03.3640122-07:00</updated>
    <category term="ASP.NET" label="ASP.NET" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ASPNET.aspx" />
    <category term="JSF and Facelets" label="JSF and Facelets" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,JSFAndFacelets.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
It has happened so, that we have never worked with jQuery, however were aware of it.
</p>
        <p>
In early 2000 we have developed a web application that contained rich javascript APIs,
including UI components. Later, we were actively practicing in ASP.NET, and later
in JSF.
</p>
        <p>
At present, looking at jQuery more closely we regret that we have failed to start
using it earlier.
</p>
        <p>
Separation of business logic and presentation is remarkable when one uses JSON web
services. In fact server part can be seen as a set of web services representing a
business logic and a set of resources: html, styles, scripts, others. Nor ASP.NET
or JSF approach such a consistent separation.
</p>
        <p>
The only trouble, in our opinion, is that jQuery has no standard data binding: a way
to bind JSON data to (and from) html controls. The technique that will probably be
standardized is called <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06&amp;url=https%3a%2f%2fgithub.com%2fBorisMoore%2fjsviews">jQuery
Templates or JsViews </a> .
</p>
        <p>
Unfortunatelly after reading about this <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06&amp;url=http%3a%2f%2fwiki.jqueryui.com%2fw%2fpage%2f37898666%2fTemplate">binding
API</a>, and being in love with Xslt and XQuery we just want to cry. We don't know
what would be the best solution for the task, but what we see looks uncomfortable
to us.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Funny, about yield return in java</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/10/16/FunnyAboutYieldReturnInJava.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,582c91ec-61fc-4bf4-a65c-bf410715a420.aspx</id>
    <published>2011-10-16T06:49:33.089-07:00</published>
    <updated>2011-10-18T12:28:03.5626746-07:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Incidentally, we have found one new implementation of yield return in java that is
in the development stage. Sources can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=582c91ec-61fc-4bf4-a65c-bf410715a420&amp;url=https%3a%2f%2fgithub.com%2fpeichhorn%2flombok-pg%2fzipball%2fmaster"> https://github.com/peichhorn/lombok-pg/zipball/master</a>.
Just to be sure we have copied those sources at other place <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=582c91ec-61fc-4bf4-a65c-bf410715a420&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fplagiarism%2fpeichhorn-lombok-pg-0.10.0-39-g384fb7b.zip"> peichhorn-lombok-pg-0.10.0-39-g384fb7b.zip</a> (you
may search "yield" in the archive).
</p>
        <p>
It's broken according to source tracker, but the funny thing is that sources, however
different, still resemble our yield return implementation (<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=582c91ec-61fc-4bf4-a65c-bf410715a420&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.jar">Yield.jar</a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=582c91ec-61fc-4bf4-a65c-bf410715a420&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.3.7.jar">Yield.3.7.jar</a> -
Indigo, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=582c91ec-61fc-4bf4-a65c-bf410715a420&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.zip">Yield.zip</a> -
sources) very much: variable names, error messages, algorithmic structure.
</p>
        <p>
Those programmers probably have forgotten good manners: to reference a base work,
at least.
</p>
        <p>
Well, we generously forgive them this blunder.
</p>
        <p>
P.S. our implementation, in contrast, works without bugs.
</p>
        <p>
P.P.S. misunderstanding is resolved. See comments.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=582c91ec-61fc-4bf4-a65c-bf410715a420" />
      </div>
    </content>
  </entry>
  <entry>
    <title>An XPath enumerator function</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/09/29/AnXPathEnumeratorFunction.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9c7823a7-6ac4-41ca-a75a-de10204879cd.aspx</id>
    <published>2011-09-29T04:56:05.05-07:00</published>
    <updated>2011-09-29T04:57:04.0072027-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A couple of weeks ago, we have suggested to introduce a enumerator function into the
XPath (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9c7823a7-6ac4-41ca-a75a-de10204879cd&amp;url=http%3a%2f%2fwww.w3.org%2fBugs%2fPublic%2fshow_bug.cgi%3fid%3d14152"> [F+O30]
A enumerator function</a>):
</p>
        <p style="font-style: italic; padding-left: 1em">
I would like the WG to consider an addition of a function that turns a sequence into
a enumeration of values.<br /><br />
Consider a function like this:  fn:enumerator($items as item()*) as function()
as item()<span style="font-weight: bold">?</span>;<br /><br />
alternatively, signature could be:<br /><br />
 fn:enumerator($items as function() as item()*) as function() as item()<span style="font-weight: bold">?</span>;<br /><br />
This function receives a sequence, and returns a function item, which upon N's
call shall return N's element of the original sequence. This way, a sequence of
items is turned into a function providing a enumeration of items of the sequence. 
<br /><br />
As an example consider two functions:<br /><br />
a) t:rand($seed as xs:double) as xs:double* - a function producing a random number
sequence;<br />
b) t:work($input as element()) as element() - a function that generates output from
it's input, and that needs random numbers in the course of the execution. 
<br /><br />
t:work() may contain a code like this:<br />
  let $rand := fn:enumerator(t:rand($seed)),<br /><br />
and later it can call $rand() to get a random numbers. 
<br /><br />
Enumerators will help to compose algorithms where one algorithm communicate with other
independant algorithms, thus making code simpler. The most obvious class of enumerators
are generators: ordered numbers, unique identifiers, random numbers. 
<br /><br />
Technically, <span style="font-weight: bold">function returned from</span> fn:enumerator()
is nondetermenistic, but its "side effect" is similar to a "side effect"
of a function generate-id() from a newly created node (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9c7823a7-6ac4-41ca-a75a-de10204879cd&amp;url=http%3a%2f%2fwww.w3.org%2fBugs%2fPublic%2fshow_bug.cgi%3fid%3d13747" title="RESOLVED LATER - [XPath 3.0] Determinism of expressions returning constructed nodes">bug
#13747</a>, and <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9c7823a7-6ac4-41ca-a75a-de10204879cd&amp;url=http%3a%2f%2fwww.w3.org%2fBugs%2fPublic%2fshow_bug.cgi%3fid%3d13494" title="NEW - Node uniqueness returned from XSLT function.">bug
#13494</a>). 
</p>
        <p>
The idea is inspired by a generator function, which returns a new value upon each
call. 
</p>
        <p>
Such function can be seen as a stateful object. But our goal is to look at it in a
more functional way. So, we look at the algorithm as a function that produces a sequence
of output, which is pure functional; and an enumerator that allows to iterate over
algorithm's output.
</p>
        <p>
This way, we see the function that implements an algorithm and the function that uses
it can be seen as two thread of functional programs that use messaging to communicate
to each other.
</p>
        <p>
Honestly, we doubt that WG will accept it, but it's interesting to watch the discussion.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9c7823a7-6ac4-41ca-a75a-de10204879cd" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Resolution of the Saxon optimizer bug</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/09/14/ResolutionOfTheSaxonOptimizerBug.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d0be8e77-04d9-47a0-840e-d62b1936b3ac.aspx</id>
    <published>2011-09-13T22:54:56.464-07:00</published>
    <updated>2011-09-13T23:14:52.9775176-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
More than month has passed since we have reported a problem to the saxon forum (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d0be8e77-04d9-47a0-840e-d62b1936b3ac&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f07%2f27%2fSaxonOptimizerBug.aspx"> Saxon
optimizer bug</a> and <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d0be8e77-04d9-47a0-840e-d62b1936b3ac&amp;url=http%3a%2f%2fsourceforge.net%2fprojects%2fsaxon%2fforums%2fforum%2f94027%2ftopic%2f4621860"> Saxon
9.2 generate-id() bug)</a>. 
</p>
        <p>
The essence of the problem is that we have constructed argumentless function to return
a unique identifiers each time function is called. To achieve the effect we have created
a temporary node and returned its <code>generate-id()</code> value.
</p>
        <p>
Such a function is nondetermenistic, as we cannot state that its result depends on
arguments only. This means that engine's optimizer is not free to reorder calls to
such a function. That's what happens in Saxon 9.2, and Saxon 9.3 where engine
elevates function call out of cycle thus producing invalid results.
</p>
        <p>
Michael Kay, the author of the Saxon engine, argued that this is "a gray area
of the xslt spec":
</p>
        <p style="padding-left: 1em; font-style: italic">
If the spec were stricter about defining exactly when you can rely on identity-dependent
operations then I would be obliged to follow it, but I think it's probably deliberate
that it currently allows implementations some latitude, effectively signalling to
users that they should avoid depending on this aspect of the behaviour. 
</p>
        <p>
He adviced to raise a bug in the w3c bugzilla to resolve the issue. In the end two
related bugs have been raised:
</p>
        <ul>
          <li>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d0be8e77-04d9-47a0-840e-d62b1936b3ac&amp;url=http%3a%2f%2fwww.w3.org%2fBugs%2fPublic%2fshow_bug.cgi%3fid%3d13494">Bug
13494</a> - Node uniqueness returned from XSLT function;</li>
          <li>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d0be8e77-04d9-47a0-840e-d62b1936b3ac&amp;url=http%3a%2f%2fwww.w3.org%2fBugs%2fPublic%2fshow_bug.cgi%3fid%3d13747">Bug
13747</a> - [XPath 3.0] Determinism of expressions returning constructed nodes.</li>
        </ul>
        <p>
Yesterday, the WG has resolved the issue:
</p>
        <p style="padding: 1em; font-style: italic">
The Working Group agreed that default behavior should continue to require these nodes
to be constructed with unique IDs. We believe that this is the kind of thing implementations
can do with annotations or declaration options, and it would be best to get implementation
experience with this before standardizing.
</p>
        <p>
This means that the technique we used to generate unique identifiers is correct and
the behaviour is well defined.
</p>
        <p>
The only problem is to wait when Saxon will fix its behaviour accordingly.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d0be8e77-04d9-47a0-840e-d62b1936b3ac" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Entity Framework and char parameters</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/09/06/EntityFrameworkAndCharParameters.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,243e0e15-c07d-4a6b-87f9-c0e89f52b781.aspx</id>
    <published>2011-09-06T14:11:38.155-07:00</published>
    <updated>2011-09-06T14:12:10.2735928-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,NET.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We're not big fans of <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=243e0e15-c07d-4a6b-87f9-c0e89f52b781&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb399572.aspx"> Entity
Framework</a>, as we don't directly expose the database structure to the client
program but rather through stored procedures and functions. So, EF for us is a tool
to expose those stored procedures as .NET wrappers. This limited use of EF still greatly
automates the data access code.
</p>
        <p>
But what we have lately found is that the EF has a problem with char parameters. Namely,
if you import a procedure say <code>MyProc</code> that accepts <code>char(1)</code>,
and then will call it through the generated wrapper, the you will see in sql profiler
that <code>char(1)</code> parameter is passed with many trailing spaces as if it were <code>char(8000)</code>.
There isn't necessity to prove that this is highly ineffective.
</p>
        <p>
We can see that the problem happens in VS 2010 designer rather than in the EF runtime,
as SP's parameters are not attributed with length, see model xml (*.edmx):
</p>
        <p style="padding-left: 1em">
          <code>&lt;Function Name="MyProc" Schema="Data"&gt; 
<br />
  ...<br />
  &lt;Parameter Name="recipientType" Type="char" Mode="In"
/&gt;<br />
  ...<br />
&lt;/Function&gt;</code>
        </p>
        <p>
while if we set:
</p>
        <p style="padding-left: 1em">
          <code>  &lt;Parameter Name="recipientType" Type="char" MaxLength="1"
Mode="In" /&gt;<br /></code>
        </p>
        <p>
the runtime starts working as expected. So the workaround is to fix model file manually.
</p>
        <p>
See also: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=243e0e15-c07d-4a6b-87f9-c0e89f52b781&amp;url=http%3a%2f%2fsocial.msdn.microsoft.com%2fForums%2fen-US%2fadodotnetentityframework%2fthread%2fa0b94f65-dc89-48f8-8b1a-a299fe0f6381%2f"> Stored
Proc and Char parm</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=243e0e15-c07d-4a6b-87f9-c0e89f52b781" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Masha</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/08/29/Masha.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9533804c-0be1-4e57-8cbc-764a1b66f53a.aspx</id>
    <published>2011-08-29T06:54:22.4889081-07:00</published>
    <updated>2011-08-29T06:54:22.4889081-07:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Please welcome a new human being Masha Vladimirovna Nesterovsky!
</p>
        <p>
          <img alt="Masha" src="http://www.nesterovsky-bros.com/weblog/images/Masha.jpg" style="padding: 2px; border: 1px solid red" />
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9533804c-0be1-4e57-8cbc-764a1b66f53a" />
      </div>
    </content>
  </entry>
  <entry>
    <title>View state access</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/08/28/ViewStateAccess.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,abbaf525-f50f-48f8-b54a-a01e1a9b6d95.aspx</id>
    <published>2011-08-28T12:35:13.8817052-07:00</published>
    <updated>2011-08-28T12:35:13.8817052-07:00</updated>
    <category term="ASP.NET" label="ASP.NET" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ASPNET.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <code>AjaxControlToolkit</code> has methods to access <code>ViewState</code>:
</p>
        <p style="padding-left: 1em">
          <code> protected V GetPropertyValue&lt;V&gt;(string propertyName, V nullValue)<br />
{<br />
  if (this.ViewState[propertyName] == null)<br />
  {<br />
    return nullValue;<br />
  }<br /><br />
  return (V) this.ViewState[propertyName];<br />
}<br /><br />
protected void SetPropertyValue&lt;V&gt;(string propertyName, V value)<br />
{<br />
  this.ViewState[propertyName] = value;<br />
}<br /><br />
...<br /><br />
public bool EnabledOnClient<br />
{<br />
  get { return base.GetPropertyValue<bool>
("EnabledOnClient", true); } 
<br />
  set { base.SetPropertyValue<bool>
("EnabledOnClient", value); }<br />
}
</bool></bool></code>
        </p>
        <p>
We find that code unnecessary complex and nonoptimal. Our code to access <code>ViewState</code> looks
like this:
</p>
        <p style="padding-left: 1em">
          <code>public bool EnabledOnClient<br />
{<br />
  get { return ViewState["EnabledOnClient"] as bool? ?? true); } 
<br />
  set { ViewState["EnabledOnClient"] = value; }<br />
}</code>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=abbaf525-f50f-48f8-b54a-a01e1a9b6d95" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Yield return update</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/08/28/YieldReturnUpdate.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,a2345b18-13e4-4f60-b798-4b28587a18cb.aspx</id>
    <published>2011-08-28T12:11:45.2886379-07:00</published>
    <updated>2011-08-28T12:11:45.2886379-07:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently one of users of <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f01%2f24%2fYieldReturnFeatureInJava.aspx">java
yield return annotation</a> has kindly informed us about some problem that happened
in his environment (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f02%2f05%2fJavasYieldReturnAnnotationUpdate.aspx"> Java's
@Yield return annotation update</a>).
</p>
        <p>
Incidentally we have never noticed the problem earlier. Along with this issue we have
found that eclipse compiler has changed in the Indigo in a way that we had to recompile
the source. Well, that's a price you have to pay when you access internal API.
</p>
        <p>
Updated sources can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.zip">Yield.zip</a>,
and compiled jars at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.jar">Yield.jar</a> (pre-Indigo),
and <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.3.7.jar"> Yield.3.7.jar</a> (Indigo
and probably higher).
</p>
        <p>
See also: 
</p>
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f01%2f24%2fYieldReturnFeatureInJava.aspx"> Yield
return feature in java</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f01%2f27%2fWhyYieldIteratorShouldBeCloseable.aspx"> Why
@Yield iterator should be Closeable</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f09%2f05%2fWhatYouCanDoWithJxom.aspx"> What
you can do with jxom.</a>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Windows Search complications</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/08/12/WindowsSearchComplications.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2aa6ae56-918f-4a58-b70b-1b3e442233e3.aspx</id>
    <published>2011-08-12T02:20:18.512-07:00</published>
    <updated>2011-08-12T05:56:35.2084233-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
1. query.dll vs tquery.dll
</p>
        <p>
We have installed <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2aa6ae56-918f-4a58-b70b-1b3e442233e3&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fff628790(v%3dVS.85).aspx"> Windows
Search 4</a> on a Windows 2003 server. The goal was to index huge compressed xml files
(see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2aa6ae56-918f-4a58-b70b-1b3e442233e3&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f07%2f13%2fWindowsSearchNotifications.aspx"> Windows
Search Notifications</a>). But for some reason it did not want to index content. 
</p>
        <p>
No "<code>select System.ItemUrl from SystemIndex where contains('...')</code>" has
ever returned a row.
</p>
        <p>
We thought that the problem was in our protocol handler, and tried to localize it,
but finally have discovered that Windows Search is not able to find anything within
text files.
</p>
        <p>
Registry comparision has shown that *.txt extension was indexed by the IFilter defined
in the query.dll, while on the other computers, where everything worked, the implementation
was in the tquery.dll.
</p>
        <p>
Both libraries were present on the Windows 2003 server, so we have corrected the registry
and everything has started to work.
</p>
        <p>
As far as we understand query.dll is part of legacy <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2aa6ae56-918f-4a58-b70b-1b3e442233e3&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms692582(v%3dvs.85).aspx"> Indexing
Service</a>, and tquery.dll is up to date implementation.
</p>
        <p>
2. Search index size
</p>
        <p>
We have to index a considerable amout of data. But before we can do it we have to
estimate the size of index.
</p>
        <p>
In the past it seems we saw somewhere a statement that search index needs a storage
that's about 10% of original data for its purposes. Unfortunatelly we cannot find
this estimation at present, neither we cannot find any other estimation. This complicates
our planning.
</p>
        <p>
To get empirical estimate we've indexed several thousands *.xml-gz files, which are
gz'ed big xmls. The total size of this files is about 4.5GB. Total uncompressed size
of xmls ~50GB. Xml contained about 10 millions pages of data.
</p>
        <p>
According to 10% criteria we had to arrive to ~5GB search index.
</p>
        <p>
But what we have discovered is that the index has grown to more than 50GB. That's
very disappointing. We cannot afford such expense, as we've commited test on a tiny
part of data, which increases over time.
</p>
        <p>
So, the solution is to find out what's wrong, and how can it be cured, or to fulltext
index only most recent subset of data.
</p>
        <p>
P.S. We have tried to mark folder with search index as compressed, but it did not
work.
</p>
        <p>
P.P.S. We have found the reference to Windows Search 4 index size estimation. It is
in <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2aa6ae56-918f-4a58-b70b-1b3e442233e3&amp;url=http%3a%2f%2fwww.microsoft.com%2fwindows%2fproducts%2fwinfamily%2fdesktopsearch%2ftechnicalresources%2ftechfaq.mspx" target="_blank">Windows
Search Frequently Asked Questions</a>, see answer on "What is average size of a user's
index?" question.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2aa6ae56-918f-4a58-b70b-1b3e442233e3" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Farewell to CME!</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/08/01/FarewellToCME.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d8f0f520-c6b3-49dc-8ac4-9524bf3ecf32.aspx</id>
    <published>2011-07-31T23:32:15.5870474-07:00</published>
    <updated>2011-07-31T23:32:15.5870474-07:00</updated>
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday (2011-07-31) we have finished the project (development and support) of the
modernization of Cool:GEN code base to java for the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d8f0f520-c6b3-49dc-8ac4-9524bf3ecf32&amp;url=http%3a%2f%2fwww.cmegroup.com%2f">Chicago
Mercantile Exchange</a>.
</p>
        <p>
It wasn't the first such project but definitely most interesting. We have migrated
and tested about 300 MB of source code. In the process of translation we have identified
many bugs that were present in the original code. Thanks to <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d8f0f520-c6b3-49dc-8ac4-9524bf3ecf32&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2flanguages-xom.zip"> languages-xom</a> that
task turned to be pure xslt.
</p>
        <p>
We hope that CME's developers are pleased with results.
</p>
        <p>
If you by chance is looking for Cool:GEN conversion to java, C#, or even COBOL (don't
understand why people still asking for COBOL) then you can start at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d8f0f520-c6b3-49dc-8ac4-9524bf3ecf32&amp;url=http%3a%2f%2fwww.bphx.com%2fen%2fSolutions%2fApplicationModernization%2fPages%2fCooLGen.aspx"> bphx</a> site.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d8f0f520-c6b3-49dc-8ac4-9524bf3ecf32" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Saxon optimizer bug</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/07/27/SaxonOptimizerBug.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d653df7e-7503-4213-8546-290c3863f0e2.aspx</id>
    <published>2011-07-27T13:02:38.0590169-07:00</published>
    <updated>2011-07-27T13:02:38.0590169-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
An xslt code that worked in the production for several years failed unexpectedly.
That's unusual, unfortunate but it happens.
</p>
        <p>
We started to analyze the problem, limited the code block and recreated it in the
simpe form. That's it:
</p>
        <p style="padding: 1em">
          <code>&lt;xsl:stylesheet version="2.0"<br />
xmlns:xsl="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d653df7e-7503-4213-8546-290c3863f0e2&amp;url=http%3a%2f%2fwww.w3.org%2f1999%2fXSL%2fTransform">http://www.w3.org/1999/XSL/Transform</a>"<br />
xmlns:xs="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d653df7e-7503-4213-8546-290c3863f0e2&amp;url=http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema">http://www.w3.org/2001/XMLSchema</a>"<br />
xmlns:t="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d653df7e-7503-4213-8546-290c3863f0e2&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fxslt%2fpublic">http://www.nesterovsky-bros.com/xslt/public</a>"<br />
exclude-result-prefixes="t xs"&gt;<br /><br />
&lt;xsl:template match="/" name="main"&gt;<br />
&lt;xsl:variable name="content"&gt;<br />
&lt;root&gt;<br />
&lt;xsl:for-each select="1 to 3"&gt;<br />
&lt;item/&gt;<br />
&lt;/xsl:for-each&gt;<br />
&lt;/root&gt;<br />
&lt;/xsl:variable&gt;<br /><br />
&lt;xsl:variable name="result"&gt;<br />
&lt;root&gt;<br />
&lt;xsl:for-each select="$content/root/item"&gt;<br />
&lt;section-ref name-ref="<span style="font-weight: bold">{t:generate-id()}.s</span>"/&gt;<br />
&lt;!--<br />
&lt;xsl:variable name="id" as="xs:string"<br />
select="t:generate-id()"/&gt;<br />
&lt;section-ref name-ref="{$id}.s"/&gt;<br />
--&gt;<br />
&lt;/xsl:for-each&gt;<br />
&lt;/root&gt;<br />
&lt;/xsl:variable&gt;<br /><br />
&lt;xsl:message select="$result"/&gt;<br />
&lt;/xsl:template&gt;<br /><br />
&lt;xsl:function name="t:generate-id" as="xs:string"&gt;<br />
&lt;xsl:variable name="element" as="element()"&gt;<br />
&lt;element/&gt;<br />
&lt;/xsl:variable&gt;<br /><br />
&lt;xsl:sequence select="generate-id($element)"/&gt;<br />
&lt;/xsl:function&gt;<br /><br />
&lt;/xsl:stylesheet&gt; </code>
        </p>
        <p>
This code performs some transformation and assigns unique values to <code>name-ref</code> attributes.
Values generated with <code>t:generate-id()</code> function are guaranteed to be unique,
as spec claims that every node has its unique <code>generate-id()</code> value.
</p>
        <p>
Imagine, what was our surprise to find that generated elements all have the same <code>name-ref</code>'s.
We studied code all over, and found no holes in our reasoning and implementation,
so our conlusion was: it's Saxon's bug!
</p>
        <p>
It's interesting enough that if we rewrite code a little (see commented part),
it starts to work properly, thus we suspect Saxon's optimizer.
</p>
        <p>
Well, in the course of development we have found and reported many Saxon bugs, but
how come that this little beetle was hiding so long.
</p>
        <p>
We've verified that the bug exists in the versions 9.2 and 9.3. Here is the bug
report: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d653df7e-7503-4213-8546-290c3863f0e2&amp;url=http%3a%2f%2fsourceforge.net%2fprojects%2fsaxon%2fforums%2fforum%2f94027%2ftopic%2f4621860"> Saxon
9.2 generate-id() bug</a>. 
</p>
        <p>
Unfortunatelly, it's there already for three days (2011-07-25 to 2011-07-27) without
any reaction. We hope this will change soon.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d653df7e-7503-4213-8546-290c3863f0e2" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Track stream position while writing xml</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/07/22/TrackStreamPositionWhileWritingXml.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6567b938-7961-435c-ae3b-2c3dc3e86e49.aspx</id>
    <published>2011-07-22T14:08:36.867-07:00</published>
    <updated>2011-07-23T02:47:22.1846494-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We needed to track a stream position during creation of xml file. This is to allow
random access to a huge xml file (the task is related to <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=6567b938-7961-435c-ae3b-2c3dc3e86e49&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f07%2f13%2fWindowsSearchNotifications.aspx"> WindowsSearch</a>).
</p>
        <p>
This is a simplified form of the xml:
</p>
        <p style="padding-left: 1em">
          <code>&lt;data&gt;<br />
  &lt;item&gt;...&lt;/item&gt;<br />
   ...<br />
  &lt;item&gt;...&lt;/item&gt; <br />
&lt;/data&gt;</code>
        </p>
        <p>
The goal was to have stream position of each item element. With this in mind, we've
decided to:
</p>
        <ul>
          <li>
open a stream, and then xml writer over it;</li>
          <li>
write data into xml writer;</li>
          <li>
call <code>Flush()</code> method of the xml writer before measuring stream offset;</li>
        </ul>
        <p>
That's a code sample:
</p>
        <p style="padding-left: 1em">
          <code>var stream = new MemoryStream();<br />
var writer = XmlWriter.Create(stream);<br /><br />
writer.WriteStartDocument();<br />
writer.WriteStartElement("data");<br /><br />
for(var i = 0; i &lt; 10; ++i)<br />
{<br />
  writer.Flush();<br /><br />
  Console.WriteLine("Flush offset: {0}, char: {1}",<br />
    stream.Position,<br />
    (char)stream.GetBuffer()[stream.Position - 1]);<br />
 <br />
  writer.WriteStartElement("item");<br />
  writer.WriteValue("item " + i);<br />
  writer.WriteEndElement();<br />
}<br /><br />
writer.WriteEndElement();<br />
writer.WriteEndDocument(); </code>
        </p>
        <p>
That's the output:
</p>
        <p style="padding-left: 1em">
          <code>Flush offset: 46, char: a<br />
Flush offset: 66, char: &gt;<br />
Flush offset: 85, char: &gt;<br />
Flush offset: 104, char: &gt;<br />
Flush offset: 123, char: &gt;<br />
Flush offset: 142, char: &gt;<br />
Flush offset: 161, char: &gt;<br />
Flush offset: 180, char: &gt;<br />
Flush offset: 199, char: &gt;<br />
Flush offset: 218, char: &gt;</code>
        </p>
        <p>
Funny, isn't it?
</p>
        <p>
After feeding the start tag <code>&lt;data&gt;</code>, and flushing xml writer we
observe that only <code>"&lt;data"</code> has been written down to the stream.
Well, <code>Flush()</code> have never promissed anything particular about the content
of the stream, so we cannot claim any violation, however we expected to see whole
start tag.
</p>
        <p>
Inspection of the implementation of xml writer reveals laziness during writting data
down the stream. In particular start tag is closed when one starts the content. This
is probably to implement empty tags: <code>&lt;data/&gt;</code>.
</p>
        <p>
To do the trick we had to issue empty content, moreover, to call a particular method
with particular parameters of the xml writer. So the code after the fix looks like
this:
</p>
        <p style="padding-left: 1em">
          <code> var stream = new MemoryStream();<br />
var writer = XmlWriter.Create(stream);<br /><br />
writer.WriteStartDocument();<br />
writer.WriteStartElement("data");<br /><br /><span style="color: red">char[] empty = { ' ' };</span><br /><br />
for(var i = 0; i &lt; 10; ++i)<br />
{<br />
  <span style="color: red">writer.WriteChars(empty, 0, 0);</span><br />
  writer.Flush();<br /><br />
  Console.WriteLine("Flush offset: {0}, char: {1}",<br />
    stream.Position,<br />
    (char)stream.GetBuffer()[stream.Position - 1]);<br /><br />
  writer.WriteStartElement("item");<br />
  writer.WriteValue("item " + i);<br />
  writer.WriteEndElement();<br />
}<br /><br />
writer.WriteEndElement();<br />
writer.WriteEndDocument(); </code>
        </p>
        <p>
And output is:
</p>
        <p style="padding-left: 1em">
          <code>
            <span style="color: red">Flush offset: 47, char: &gt;</span>
            <br />
Flush offset: 66, char: &gt;<br />
Flush offset: 85, char: &gt;<br />
Flush offset: 104, char: &gt;<br />
Flush offset: 123, char: &gt;<br />
Flush offset: 142, char: &gt;<br />
Flush offset: 161, char: &gt;<br />
Flush offset: 180, char: &gt;<br />
Flush offset: 199, char: &gt;<br />
Flush offset: 218, char: &gt;</code>
        </p>
        <p>
While this code works, we feel uneasy with it. 
</p>
        <p>
What's the better way to solve the task?
</p>
        <p style="direction: ltr">
          <span style="font-weight: bold">Update:</span> further analysis shows that it's only
possible behaviour, as after the call to write srart element, you either can write
attributes, content or end of element, so writer may write either space, <code>'&gt;'</code> or <code>'/&gt;'</code>.
The only question is why it takes <code>WriteChars(empty, 0, 0)</code> into account
and <code>WriteValue("")</code> it doesn't.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6567b938-7961-435c-ae3b-2c3dc3e86e49" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Windows Search Notifications</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/07/13/WindowsSearchNotifications.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5ee632a8-d163-4c67-b23e-ba9a19367737.aspx</id>
    <published>2011-07-13T13:21:00.271-07:00</published>
    <updated>2011-07-13T13:27:05.6269114-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
As you probably know we have implemented our custom Protocol Handler for the Windows
Search.
</p>
        <p>
It's called .xml-gz, and has a goal to index compressed xml files and to have
search results with a subtree precision. So, for xml:
</p>
        <p style="padding-left: 1em">
          <code>&lt;data&gt;<br />
&lt;item&gt;...&lt;/item&gt;<br />
&lt;item&gt;...&lt;/item&gt;<br />
...<br />
&lt;/data&gt;</code>
        </p>
        <p>
search finds results within <code>item</code> and returns xml's url and stream
offset of the item. Using ZLIB API we can compress data with stream bookmarks, so
fast random access to the data is possible.
</p>
        <p>
The only problem we have is about notification of changes (create, delete, update)
of such files.
</p>
        <p>
Spec describes several techniques (nothing has worked for us):
</p>
        <p>
1. Call <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ee632a8-d163-4c67-b23e-ba9a19367737&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fdd940339(VS.85).aspx">catalogManager.ReindexMatchingURLs()</a> -
it just returns without any impact.
</p>
        <p>
2.Call <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ee632a8-d163-4c67-b23e-ba9a19367737&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb231455(VS.85).aspx">changeSink.OnItemsChanged()</a> -
returns error.
</p>
        <p>
3. Implement <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ee632a8-d163-4c67-b23e-ba9a19367737&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb266526(VS.85).aspx"> .xml-gz
IFilter and call IGatherNotifyInline (see "<span style="font-style: italic"> have
your .zip urls indexed when they are created or modified</span>")</a> - that's
a mistery, as:
</p>
        <ul>
          <li style="list-style-type: lower-alpha">
you don't have item's url within IFilter, and 
</li>
          <li style="list-style-type: lower-alpha">
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ee632a8-d163-4c67-b23e-ba9a19367737&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb231470(VS.85).aspx">IGatherNotifyInline</a> is
not supported.</li>
        </ul>
        <p>
4. Implement root url in form <code>.xml-gz:///</code> and perform Windows Search:
</p>
        <p style="padding-left: 1em; font-style: italic">
          <code>SELECT<br />
System.ItemUrl, System.DateModified<br />
FROM<br />
SystemIndex WHERE System.FileExtension='.xml-gz' </code>
        </p>
        <p>
to find all <code>.xml-gz</code> sources. This is not reliable, as your protocol handler
can be (and is) called before file is indexed.
</p>
        <p>
So, the only reliable way to index your data is to (re-)add indexing rule for the
protocol handler, which in most cases reindexes everything.
</p>
        <p>
The only bearable solution we found is to define indexing rule in the form: <code>.xml-gz://file:d:/data/...</code> and
to use <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ee632a8-d163-4c67-b23e-ba9a19367737&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb775075(VS.85).aspx"> IShellFolder</a>(<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ee632a8-d163-4c67-b23e-ba9a19367737&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb775055(VS.85).aspx">2</a>)
interfaces to discover sub items and their modification times. This technique allows
minimal data scan when you're (re-)add indexing rule.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5ee632a8-d163-4c67-b23e-ba9a19367737" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Windows Search Query</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/07/09/WindowsSearchQuery.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0a60ff37-669c-4675-adeb-1763e1a2eb4b.aspx</id>
    <published>2011-07-09T03:01:36.072-07:00</published>
    <updated>2011-07-10T03:40:10.6730909-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Being unexperienced with Windows Search we tried to build queries to find data in
the huge storage. We needed to find a document that matches some name pattern and
contains some text.
</p>
        <p>
Our naive query was like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>select top 1000<br />
  System.ItemUrl<br />
from<br />
  SystemIndex<br />
where<br />
  scope = '...' and<br />
  System.ItemName like '...%' and<br />
  contains('...')</code>
        </p>
        <p>
In most cases this query returns nothing and runs very long. It's interesting to note
that it may start returning data if "<code>top</code>" clause is missing or uses a
bigger number, but in this cases query is slower even more.
</p>
        <p>
Next try was like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>select top 1000<br />
  System.ItemUrl<br />
from<br />
  SystemIndex<br />
where<br />
  scope = '...' and<br />
  System.ItemName &gt;= '...' and System.ItemName &lt; '...' and<br />
  contains('...')</code>
        </p>
        <p>
This query is also slow, but at least it returns some results.
</p>
        <p>
At some point we have started to question the  utility of Windows Search if it's
so slow, but then we have found that there is a property <code>System.ItemNameDisplay</code>,
which in our case coincides with the value of property <code>System.ItemName</code>,
so we have tried the query:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>select top 1000<br />
  System.ItemUrl<br />
from<br />
  SystemIndex<br />
where<br />
  scope = '...' and<br />
  System.ItemNameDisplay like '...%' and<br />
  contains('...')</code>
        </p>
        <p>
This query worked fast, and produced good results. This hints that search engine has
index on <code>System.ItemNameDisplay</code> in contrast to <code>System.ItemName</code> property.
</p>
        <p>
We've looked at property definitions:
</p>
        <p style="PADDING-LEFT: 1em; FONT-STYLE: italic">
          <b>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0a60ff37-669c-4675-adeb-1763e1a2eb4b&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb760770(VS.85).aspx">System.ItemNameDisplay</a>
          </b>
        </p>
        <p style="PADDING-LEFT: 1em; FONT-STYLE: italic">
The display name in "most complete" form. It is the unique representation of the item
name most appropriate for end users.
</p>
        <p style="PADDING-LEFT: 1em; FONT-STYLE: italic">
          <code>
            <strong>propertyDescription<br /></strong>    <strong>name</strong> = System.ItemNameDisplay<br />
    <strong>shellPKey</strong> = PKEY_ItemNameDisplay<br />
    <strong>formatID</strong> = B725F130-47EF-101A-A5F1-02608C9EEBAC<br />
    <strong>propID</strong> = 10<br />
    <strong>searchInfo<br /></strong>       <strong>inInvertedIndex</strong> = <span style="COLOR: red">true</span><br />
       <strong>isColumn</strong> = true<br />
       <strong>isColumnSparse</strong> = false<br />
       <strong>columnIndexType</strong> = OnDisk<br />
       <strong>maxSize</strong> = 128 </code>
        </p>
        <p style="PADDING-LEFT: 1em; FONT-STYLE: italic">
          <b>
            <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0a60ff37-669c-4675-adeb-1763e1a2eb4b&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb760768(VS.85).aspx">System.ItemName</a>
          </b>
        </p>
        <p style="PADDING-LEFT: 1em; FONT-STYLE: italic">
The base name of the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0a60ff37-669c-4675-adeb-1763e1a2eb4b&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb760770(VS.85).aspx">System.ItemNameDisplay</a> property.
</p>
        <p style="PADDING-LEFT: 1em; FONT-STYLE: italic">
          <code>
            <strong>propertyDescription<br /></strong>    <strong>name</strong> = System.ItemName<br />
    <strong>shellPKey</strong> = PKEY_ItemName<br />
    <strong>formatID</strong> = 6B8DA074-3B5C-43BC-886F-0A2CDCE00B6F<br />
    <strong>propID</strong> = 100<br />
    <strong>searchInfo<br /></strong>       <strong>inInvertedIndex</strong> = <span style="COLOR: red">false</span><br />
       <strong>isColumn</strong> = true<br />
       <strong>isColumnSparse</strong> = false<br />
       <strong>columnIndexType</strong> = OnDisk<br />
       <strong>maxSize</strong> = 128 </code>
        </p>
        <p>
Indeed, one property is indexed, while the other is not. 
</p>
        <p>
As with other databases, query is powerful when engine uses indices rather than performs
data scan. This is also correct for Windows Search.
</p>
        <p>
The differences in results that variations of query produce also manifests that Windows
Search nevertheless is very different from relational database.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0a60ff37-669c-4675-adeb-1763e1a2eb4b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Xml IFilter in WindowsSearch</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/07/05/XmlIFilterInWindowsSearch.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,171e8b16-be43-4a2b-a6d0-cdd490cf6231.aspx</id>
    <published>2011-07-05T13:31:47.942-07:00</published>
    <updated>2011-07-10T03:40:46.1495174-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have developed our custom <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=171e8b16-be43-4a2b-a6d0-cdd490cf6231&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb266526(VS.85).aspx">Windows
Search Protocol Handler</a>. The role of this component is to expose items of complex
content (or unusual storage) to Windows Search.
</p>
        <p>
You can think of some virtual folder, so a Protocol Handler allows to enumerate it's
files, file properties, and contents.
</p>
        <p>
The goal of our Protocol Handler is to represent some data structure as a set of xml
files. We expected that if we found a data within a folder with these files, then
a search within Protocol Handler's scope would bring the same (or almost the same)
results.
</p>
        <p>
Reality is different.
</p>
        <p>
For some reason .xml IFilter (a component to extract text data to index) works differently
with file system and with our storage. We cannot state that it does not work, but
for some reason many words that Windows Search finds within a file are never found
within Protocol Handler scope.
</p>
        <p>
We have observed that if, for purpose of indexing, we represent content xml items
as .txt files, then search works as expected. So, our workaround was to present only
xml's text data for the indexing, and to use .txt IFilter (this in fact roughly what
.xml IFilter does by itself).
</p>
        <p>
Is there a conclusion?
</p>
        <p>
Well, Windows Search is a black box probably containing bugs. Its behaviour is not
always obvious. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=171e8b16-be43-4a2b-a6d0-cdd490cf6231" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Notify Windows Search</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/06/24/NotifyWindowsSearch.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,91fd202e-9795-49af-bd11-25eea49be882.aspx</id>
    <published>2011-06-24T12:39:36.989-07:00</published>
    <updated>2011-07-10T03:46:10.3425069-07:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Let's put it blatantly: Windows Search 4 has design and implementation problems.
</p>
        <p>
You discover this immediatelly when you start implementing indexing of custom file
format.
</p>
        <p>
If you want to index simple file format then you need to imlement you <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=91fd202e-9795-49af-bd11-25eea49be882&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb266451(VS.85).aspx">IFilter</a> interface.
But if it has happened so that you want to index compound data then you should invent
you own <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=91fd202e-9795-49af-bd11-25eea49be882&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb266531(VS.85).aspx">protocols</a>.
</p>
        <p>
If you will fugure out how to implement your protocol to index that compound data,
then you will most probably stuck on the problem on how to notify indexer about the
changes.
</p>
        <p>
The problem is that Windows Search 4 has <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=91fd202e-9795-49af-bd11-25eea49be882&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb266422(VS.85).aspx">API
to reindex urls</a>, which simply does not work, or to <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=91fd202e-9795-49af-bd11-25eea49be882&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb231455(VS.85).aspx">notify
indexer about changes</a>, which throws an error (returns error HRESULT) for custom
protocols. At least, we were not able to make it run.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=91fd202e-9795-49af-bd11-25eea49be882" />
      </div>
    </content>
  </entry>
  <entry>
    <title>XML serialization of numbers in Java.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/06/16/XMLSerializationOfNumbersInJava.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c28b2736-46cd-43c4-b69a-a9c6dc0eb43d.aspx</id>
    <published>2011-06-16T15:14:36.991-07:00</published>
    <updated>2011-06-22T22:00:20.3526559-07:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
There is a problem with XML serialization of <code>BigDecimal</code> values, as we've
written in one of our previous articles <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c28b2736-46cd-43c4-b69a-a9c6dc0eb43d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f09%2f05%2fBigDecimalJAXBPotentialInteroperabilityProblems.aspx">"BigDecimal
+ JAXB =&gt; potential interoperability problems"</a>. And now we ran into issue with
serialization of <code>double</code> / <code>Double</code> values. All such values,
except zero, serialize in scientific format, even a value contains only integer part.
For example, <b>12</b> will be serialized as <b>1.2E+1</b>. Actually this is not contradicts
with <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c28b2736-46cd-43c4-b69a-a9c6dc0eb43d&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2f2001%2fREC-xmlschema-2-20010502%2f%23double" target="_blank">XML
schema definitions</a>.
</p>
        <p>
But what could be done, if you want to send/receive double and/or decimal values in
plain format. For example you want serialize a <code>double</code> / <code>BigDecimal</code> value <b>314.15926</b> in
XML as is. In this case you ought to use <code><a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c28b2736-46cd-43c4-b69a-a9c6dc0eb43d&amp;url=http%3a%2f%2fdownload.oracle.com%2fjavase%2f6%2fdocs%2fapi%2fjavax%2fxml%2fbind%2fannotation%2fadapters%2fXmlAdapter.html" target="_blank">javax.xml.bind.annotation.adapters.XmlAdapter</a></code>. 
</p>
        <p>
In order to solve this task we've created two descendants of XmlAdapter (the first
for <code>double</code> / <code>Double</code> and the second for <code>BigDecimal</code>), <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c28b2736-46cd-43c4-b69a-a9c6dc0eb43d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fNumericAdapters.zip" target="_blank">click
here to download the sources</a>.
</p>
        <p>
Applying these classes on properties or package level you may manage XML serialization
of numeric fields in your classes.
</p>
        <p>
See <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c28b2736-46cd-43c4-b69a-a9c6dc0eb43d&amp;url=http%3a%2f%2fstackoverflow.com%2fquestions%2f4148192%2fjaxb-how-to-customize-xml-serialization-of-double-fields" traget="_blank">this
article</a> for tips how to use custom XML serialization. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c28b2736-46cd-43c4-b69a-a9c6dc0eb43d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>A curious fact.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/06/02/ACuriousFact.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3ffa76d0-d264-4bd4-846c-a2ed8ed382b7.aspx</id>
    <published>2011-06-02T01:37:09.033-07:00</published>
    <updated>2011-06-02T01:38:37.2327509-07:00</updated>
    <category term="JSF and Facelets" label="JSF and Facelets" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,JSFAndFacelets.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Do you know that the best JSF/Facelets visual editor, in our opinion, is ... Microsoft
Visual Studio 2008? Another rather good JSF editor is presented in IBM RAD 7.xx. The
most popular, open source Java IDE Eclipse contains an ugly implementation of such
useful thing.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3ffa76d0-d264-4bd4-846c-a2ed8ed382b7" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Languages-XOM update</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/05/26/LanguagesXOMUpdate.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c8b061fa-7471-4601-8b19-2c5bf55ce9ea.aspx</id>
    <published>2011-05-25T22:15:11.541-07:00</published>
    <updated>2011-05-26T01:24:57.9065374-07:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We did not update <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c8b061fa-7471-4601-8b19-2c5bf55ce9ea&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2flanguages-xom.zip"> languages-xom</a> already
for many monthes but now we have found a severe bug in the jxom's algorithm for eliminating
unreachable code. The marked line were considered as unreachable:
</p>
        <p style="padding-left: 1em">
          <code>check:<br />
if (condition)<br />
{<br />
break check;<br />
}<br />
else<br />
{<br />
return;<br />
}<br /><br />
// due to bug the following was considered unreachable<br /><span style="color: red; font-weight: bold">expression;</span></code>
        </p>
        <p>
Bug is fixed.
</p>
        <p>
Current update contains other cosmetic fixes. 
</p>
        <p>
Please download xslt sources from <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c8b061fa-7471-4601-8b19-2c5bf55ce9ea&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2flanguages-xom.zip">languages-xom.zip</a>.
</p>
        <p>
Summary
</p>
        <p>
Languages XOM is a set of xml schemas and xslt stylesheets that allows:
</p>
        <ul>
          <li>
to define programs in xml form;</li>
          <li>
to perform transformations over code in xml form;</li>
          <li>
to generate sources.</li>
        </ul>
        <p>
Languages XOM includes:
</p>
        <ul>
          <li>
jxom - Java Xml Object model;</li>
          <li>
csharpxom - C# Xml Object Model;</li>
          <li>
cobolxom - COBOL Xml Object Model;</li>
          <li>
sqlxom - SQL Xml Object Model (including several sql dialects);</li>
          <li>
aspx - ASP.NET Object Model;</li>
        </ul>
        <p>
A proprietary part of languages XOM also includes XML Object Model for a language
named Cool:GEN. In fact the original purpose for this API was a generation of java/C#/COBOL
from Cool:GEN. For more details about Cool:GEN conversion please see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c8b061fa-7471-4601-8b19-2c5bf55ce9ea&amp;url=http%3a%2f%2fwww.bphx.com%2fen%2fSolutions%2fApplicationModernization%2fPages%2fCooLGen.aspx"> here</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c8b061fa-7471-4601-8b19-2c5bf55ce9ea" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Cinematography</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/05/05/Cinematography.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,13a3c6de-2c88-4d27-b4ef-779921588466.aspx</id>
    <published>2011-05-05T02:21:54.421-07:00</published>
    <updated>2012-01-25T12:36:50.224413-08:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Ladies and gentlemen!
</p>
        <p>
We are proud and would like to announce <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=13a3c6de-2c88-4d27-b4ef-779921588466&amp;url=http%3a%2f%2fwww.youtube.com%2fuser%2fNesterovskychess" target="_blank">few
works</a> of our younger brother Aleksander, who studies cinematography now.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=13a3c6de-2c88-4d27-b4ef-779921588466" />
      </div>
    </content>
  </entry>
  <entry>
    <title>A bug in XMLGregorianCalendar implementation.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/05/04/ABugInXMLGregorianCalendarImplementation.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b94eae0f-f7dc-4234-92cd-7ad127a20963.aspx</id>
    <published>2011-05-04T02:19:52.816-07:00</published>
    <updated>2011-05-04T02:24:22.9283179-07:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
As you may know, JAX-WS uses <code>javax.xml.datatype.XMLGregorianCalendar</code> abstract
class in order to present date/time data type fields. We have used this class rather
long time in happy ignorance without of any problem. Suddenly, few days ago, we ran
into a weird bug of its Sun’s implementation (<code>com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl</code>).
The bug appears whenever we try to convert an <code>XMLGregorianCalendar</code> instance
to a <code>java.util.GregorianCalendar</code> using <code>toGregorianCalendar()</code> method.
I’ve written a simple JUnit test in order to demonstrate this bug:
</p>
        <pre>
  @Test
  public void testXMLGregorianCalendar()
    throws Exception
  {    
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    XMLGregorianCalendar calendar = 
      javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar();

    calendar.setDay(1);
    calendar.setMonth(1);
    calendar.setYear(1);
    
    System.out.println("1: " + calendar.toString());

    System.out.println("2: " +
      formatter.format(calendar.toGregorianCalendar().getTime()));
    
    GregorianCalendar cal = new GregorianCalendar(
      calendar.getYear(), 
      calendar.getMonth() - 1, 
      calendar.getDay());
    
    cal.clear(Calendar.AM_PM);
    cal.clear(Calendar.HOUR_OF_DAY);
    cal.clear(Calendar.HOUR);
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MILLISECOND);

    System.out.println("3: " + formatter.format(cal.getTime()));
    
    /*
     * Output:
     * 
     * 1: 0001-01-01
     * 2: 0001-01-03 00:00:00
     * 3: 0001-01-01 00:00:00
     */
  }
</pre>
        <p>
As you see, the date <b>0001-01-01</b> is transformed to <b>0001-01-03</b> after call
of <code>toGregorianCalendar()</code> method (see output 2). 
</p>
        <p>
Moreover, if we’ll serialize this <code>XMLGregorianCalendar</code> instance to XML
we’ll see it as <b>0001-01-01+02:00</b> which is rather weird and could be potential
problem for interoperability between Java and other platforms. 
</p>
        <p>
          <b>Conclusion:</b> in order to convert <code>XMLGregorianCalendar</code> value to <code>GregorianCalendar</code> do
the following. Create a new instance of <code>GregorianCalendar</code> and just set
the corresponding fields with values from <code>XMLGregorianCalendar</code> instance. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=b94eae0f-f7dc-4234-92cd-7ad127a20963" />
      </div>
    </content>
  </entry>
  <entry>
    <title>AjaxControlToolkit nuisance</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/05/03/AjaxControlToolkitNuisance.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,14fc97f7-2481-4a91-abfc-b2d2ca4ed136.aspx</id>
    <published>2011-05-03T12:45:51.173-07:00</published>
    <updated>2011-05-03T13:05:20.9734869-07:00</updated>
    <category term="ASP.NET" label="ASP.NET" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ASPNET.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Already for a couple of days we're trying to create a UserControl containing a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=14fc97f7-2481-4a91-abfc-b2d2ca4ed136&amp;url=http%3a%2f%2fwww.asp.net%2fajax%2fajaxcontroltoolkit%2fsamples%2ftabs%2ftabs.aspx"> TabContainer</a>.
To achieve the goal we have created a page with a ToolkitScriptManager and a user
control itself.
</p>
        <p>
Page:
</p>
        <p style="padding-left: 1em">
          <code>&lt;form runat="server"&gt;<br />
&lt;ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/&gt;<br />
&lt;uc1:WebUserControl1 ID="WebUserControl11" runat="server" /&gt;<br />
&lt;/form&gt;</code>
        </p>
        <p>
User control:
</p>
        <p style="padding-left: 1em">
          <code>&lt;%@ Control Language="C#" %&gt; 
<br />
&lt;%@ Register<br />
Assembly="AjaxControlToolkit"<br />
Namespace="AjaxControlToolkit"<br />
TagPrefix="ajax" %&gt;<br /><br />
&lt;ajax:TabContainer ID="Tab" runat="server" Width="100%"&gt;<br />
&lt;ajax:TabPanel runat="server" HeaderText="Tab1" ID="Tab1"&gt;<br />
&lt;ContentTemplate&gt;Panel 1&lt;/ContentTemplate&gt;<br />
&lt;/ajax:TabPanel&gt;<br />
&lt;/ajax:TabContainer&gt;</code>
        </p>
        <p>
What could be more simple?
</p>
        <p>
But no, there is a problem. At run-time control works perfectly, but at the designer
it shows an error instead of a normal design view:
</p>
        <p style="padding-left: 1em;">
          <code>
            <span style="color: red">Error Rendering Control</span> - TabContainer1<br />
An unhandled exception has occurred.<br />
Could not find any resources appropriate for the specified culture or the neutral
culture. Make sure "AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly
embedded or linked into assembly "AjaxControlToolkit" at compile time, or that all
the satellite assemblies required are loadable and fully signed.</code>
        </p>
        <p>
That's a stupid error, which says nothing about the real problem reason. We had
to attach a debugger to a Visual Studio just to realize what the problem is.
</p>
        <p>
So, the error occurs at the following code of AjaxControlToolkit.ScriptControlBase:
</p>
        <p>
          <code>private void EnsureScriptManager()<br />
{<br />
if (this._scriptManager == null)<br />
{<br />
this._scriptManager = ScriptManager.GetCurrent(this.Page);<br /><br />
if (this._scriptManager == null)<br />
{<br />
throw new HttpException(Resources.E_NoScriptManager);<br />
}<br />
}<br />
} </code>
        </p>
        <p>
Originally, the problem is due to the fact that ScriptManager is not found, and code
wants to report an <code>HttpException</code>, but fun is that we recieve a different
exception, which is releted to a missing resouce text for a message <code>Resources.E_NoScriptManager</code>.
It turns out that <code>E_NoScriptManager</code> text is found neither in primary
no in resource assemblies.
</p>
        <p>
As for original problem, it's hard to say about reason of why ScriptManager is
not available at design time. We, however, observed that a ScriptManager registers
itself for a <code>ScriptManager.GetCurrent()</code> method at run-time only:
</p>
        <p style="padding-left: 1em">
          <code>protected internal override void OnInit(EventArgs e)<br />
{<br />
...<br />
if (!base.DesignMode)<br />
{<br />
... 
<br />
iPage.Items[typeof(ScriptManager)] = this;<br />
...<br />
}<br />
} </code>
        </p>
        <p>
So, it's not clear what they (toolkit's developers) expected to get at design
time.
</p>
        <p>
These observations leave uneasiness regarding the quality of the library.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=14fc97f7-2481-4a91-abfc-b2d2ca4ed136" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Again about Windows Search within SQL Server</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/04/26/AgainAboutWindowsSearchWithinSQLServer.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,f7c6c76b-ef5f-41c8-a892-68af10fb6ad0.aspx</id>
    <published>2011-04-26T01:26:10.698-07:00</published>
    <updated>2011-07-10T03:48:21.1881909-07:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Earlier, we have described <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f7c6c76b-ef5f-41c8-a892-68af10fb6ad0&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f03%2f04%2fCallingWindowsSearchFromSQLServer2008.aspx">an
approach to call Windows Search from SQL Server 2008</a>. But it has turned out that
our problem is more complicated...
</p>
        <p>
All has started from the initial task: 
</p>
        <ul>
          <li>
to allow free text search in a store of huge xml files; 
</li>
          <li>
files should be compressed, so these are *.xml.gz; 
</li>
          <li>
search results should be addressable to a fragment within xml. 
</li>
        </ul>
        <p>
Later we shall describe how we have solved this task, and now it's enough to say that
we have implemented <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f7c6c76b-ef5f-41c8-a892-68af10fb6ad0&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fbb266531(VS.85).aspx">a
Protocol Handler for Windows Search</a> named '.xml-gz:'. This way original file stored
say at 'file:///c:/store/data.xml-gz' is seen as a container by the Windows Search:
</p>
        <ul>
          <li>
.xml-gz:///file:c:/store/data.xml-gz/id1.xml 
</li>
          <li>
.xml-gz:///file:c:/store/data.xml-gz/id2.xml 
</li>
          <li>
... 
</li>
        </ul>
        <p>
This way search xml should be like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>select System.ItemUrl from SystemIndex where scope='.xml-gz:' and contains(...)</code>
        </p>
        <p>
Everything has worked during test: we have succeeded to issue Windows Search selects
from SQL Server and join results with other sql queries.
</p>
        <p>
But later on when we considered a runtime environment we have seen that our design
won't work. The reason is simple. Windows Search will work on a computer different
from those where SQL Servers run. So, the search query should look like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>select System.ItemUrl from Computer.SystemIndex where scope='.xml-gz:' and contains(...)</code>
        </p>
        <p>
Here we have realized the limitation of current (Windows Search 4) implementation:
remote search works for shared folders only, thus query may only look like:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>select System.ItemUrl from Computer.SystemIndex where scope='file://Computer/share/'
and contains(...)</code>
        </p>
        <p>
Notice that search restricts the scope to a file protocol, this way remoter search
will never return our results. The only way to search in our scope is to perform a
local search.
</p>
        <p>
We have considered following approaches to resolve the issue.
</p>
        <p>
The simplest one would be to access Search protocol on remote computer using a connection
string: "<code>Provider=Search.CollatorDSO;Data Source=Computer"</code> and use local
queries. This does not work, as provider simply disregards <code>Data Source</code> parameter.
</p>
        <p>
The other try was to use MS Remote OLEDB provider. We tried hard to configure it but
it always returns obscure error, and more than that it's deprecated (Microsoft claims
to remove it in future).
</p>
        <p>
So, we decided to forward request manually: 
</p>
        <ul>
          <li>
SQL Server calls a web service (through a CLR function); 
</li>
          <li>
Web service queries Windows Search locally. 
</li>
        </ul>
        <p>
Here we considered <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f7c6c76b-ef5f-41c8-a892-68af10fb6ad0&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fWCF_Data_Services">WCF
Data Services</a> and a custom web service.
</p>
        <p>
The advantage of WCF Data Services is that it's a technology that has ambitions of
a standard but it's rather complex task to create implementation that will talk with
Windows Search SQL dialect, so we have decided to build a primitive http handler to
get query parameter. That's trivial and also has a virtue of simple implementation
and high streamability.
</p>
        <p>
So, that's our http handler (WindowsSearch.ashx):
</p>
        <p style="PADDING-LEFT: 1em">
          <code>&lt;%@ WebHandler Language="C#" Class="WindowsSearch" %&gt;<br /><br />
using System;<br />
using System.Web;<br />
using System.Xml;<br />
using System.Text;<br />
using System.Data.OleDb;<br /><br />
/// &lt;summary&gt;<br />
/// A Windows Search request handler.<br />
/// &lt;/summary&gt;<br />
public class WindowsSearch: IHttpHandler<br />
{<br />
  /// &lt;summary&gt;<br />
  /// Handles the request.<br />
  /// &lt;/summary&gt;<br />
  /// &lt;param name="context"&gt;A request context.&lt;/param&gt;<br />
  public void ProcessRequest(HttpContext context) 
<br />
  {<br />
    var request = context.Request;<br />
    var query = request.Params["query"];<br />
    var response = context.Response;<br /><br />
    response.ContentType = "text/xml";<br />
    response.ContentEncoding = Encoding.UTF8;<br /><br />
    var writer = XmlWriter.Create(response.Output);<br /><br />
    writer.WriteStartDocument();<br />
    writer.WriteStartElement("resultset");<br /><br />
    if (!string.IsNullOrEmpty(query))<br />
    {<br />
      using(var connection = new OleDbConnection(provider))<br />
      using(var command = new OleDbCommand(query, connection))<br />
      {<br />
        connection.Open();<br /><br />
        using(var reader = command.ExecuteReader())<br />
        {<br />
          string[] names = null;<br /><br />
          while(reader.Read())<br />
          {<br />
            if (names == null)<br />
            {<br />
              names
= new string[reader.FieldCount];<br /><br />
              for
(int i = 0; i &lt; names.Length; ++i)<br />
              {<br />
               
names[i] = XmlConvert.EncodeLocalName(reader.GetName(i));<br />
              }<br />
            }<br /><br />
            writer.WriteStartElement("row");<br /><br />
            for(int i = 0;
i &lt; names.Length; ++i)<br />
            {<br />
              writer.WriteElementString(<br />
               
names[i], 
<br />
               
Convert.ToString(reader[i]));<br />
            }<br /><br />
            writer.WriteEndElement();<br />
          }<br />
        }<br />
      }<br />
    }<br /><br />
    writer.WriteEndElement();<br />
    writer.WriteEndDocument();<br /><br />
    writer.Flush();<br />
  }<br /><br />
  /// &lt;summary&gt;<br />
  /// Indicates that a handler is reusable.<br />
  /// &lt;/summary&gt;<br />
  public bool IsReusable { get { return true; } }<br /><br />
  /// &lt;summary&gt;<br />
  /// A connection string.<br />
  /// &lt;/summary&gt;<br />
  private const string provider =<br />
    "Provider=Search.CollatorDSO;" +<br />
    "Extended Properties='Application=Windows';" +<br />
    "OLE DB Services=-4";<br />
} </code>
        </p>
        <p>
And a SQL CLR function looks like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>using System;<br />
using System.Collections;<br />
using System.Collections.Generic;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Data.SqlTypes;<br />
using Microsoft.SqlServer.Server;<br />
using System.Net;<br />
using System.IO;<br />
using System.Xml;<br /><br />
/// &lt;summary&gt;<br />
/// A user defined function.<br />
/// &lt;/summary&gt;<br />
public class UserDefinedFunctions<br />
{<br />
  /// &lt;summary&gt;<br />
  /// A Windows Search returning result as xml strings.<br />
  /// &lt;/summary&gt;<br />
  /// &lt;param name="url"&gt;A search url.&lt;/param&gt;<br />
  /// &lt;param name="userName"&gt;A user name for a web request.&lt;/param&gt;<br />
  /// &lt;param name="password"&gt;A password for a web request.&lt;/param&gt;<br />
  /// &lt;param name="query"&gt;A Windows Search SQL.&lt;/param&gt;<br />
  /// &lt;returns&gt;A result rows.&lt;/returns&gt;<br />
  [SqlFunction(<br />
    IsDeterministic = false,<br />
    Name = "WindowsSearch",<br />
    FillRowMethodName = "FillWindowsSearch",<br />
    TableDefinition = "value nvarchar(max)")]<br />
  public static IEnumerable Search(<br />
    string url,<br />
    string userName,<br />
    string password,<br />
    string query)<br />
  {<br />
    return SearchEnumerator(url, userName, password, query);<br />
  }<br /><br />
  /// &lt;summary&gt;<br />
  /// A filler of WindowsSearch function.<br />
  /// &lt;/summary&gt;<br />
  /// &lt;param name="value"&gt;A value returned from the enumerator.&lt;/param&gt;<br />
  /// &lt;param name="row"&gt;An output value.&lt;/param&gt;<br />
  public static void FillWindowsSearch(object value, out string row)<br />
  {<br />
    row = (string)value;<br />
  }<br /><br />
  /// &lt;summary&gt;<br />
  /// Gets a search row enumerator.<br />
  /// &lt;/summary&gt;<br />
  /// &lt;param name="url"&gt;A search url.&lt;/param&gt;<br />
  /// &lt;param name="userName"&gt;A user name for a web request.&lt;/param&gt;<br />
  /// &lt;param name="password"&gt;A password for a web request.&lt;/param&gt;<br />
  /// &lt;param name="query"&gt;A Windows Search SQL.&lt;/param&gt;<br />
  /// &lt;returns&gt;A result rows.&lt;/returns&gt;<br />
  private static IEnumerable&lt;string&gt; SearchEnumerator(<br />
    string url,<br />
    string userName,<br />
    string password,<br />
    string query)<br />
  {<br />
    if (string.IsNullOrEmpty(url))<br />
    {<br />
      throw new ArgumentException("url");<br />
    }<br /><br />
    if (string.IsNullOrEmpty(query))<br />
    {<br />
      throw new ArgumentException("query");<br />
    }<br /><br />
    var requestUrl = url + "?query=" + Uri.EscapeDataString(query);<br /><br />
    var request = WebRequest.Create(requestUrl);<br /><br />
    request.Credentials = string.IsNullOrEmpty(userName) ?<br />
      CredentialCache.DefaultCredentials :<br />
      new NetworkCredential(userName, password);<br /><br />
    using(var response = request.GetResponse())<br />
    using(var stream = response.GetResponseStream())<br />
    using(var reader = XmlReader.Create(stream))<br />
    {<br />
      bool read = true;<br /><br />
      while(!read || reader.Read())<br />
      {<br />
        if ((reader.Depth == 1) &amp;&amp; reader.IsStartElement())<br />
        {<br />
          // Note that ReadInnerXml()
advances the reader similar to Read().<br />
          yield return reader.ReadInnerXml();<br /><br />
          read = false;<br />
        }<br />
        else<br />
        {<br />
          read = true;<br />
        }<br />
      }<br />
    }<br />
  }<br />
} </code>
        </p>
        <p>
And, finally, when you call this service from SQL Server you write query like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>with search as<br />
(<br />
  select<br />
    cast(value as xml) value<br />
  from<br />
    dbo.WindowsSearch<br />
    (<br />
      N'http://machine/WindowsSearchService/WindowsSearch.ashx',<br />
      null,<br />
      null,<br />
      N'<br />
        select 
<br />
          "System.ItemUrl" 
<br />
        from 
<br />
          SystemIndex 
<br />
        where 
<br />
          scope=''.xml-gz:'' and contains(''...'')'<br />
    )<br />
)<br />
select 
<br />
  value.value('/System.ItemUrl[1]', 'nvarchar(max)')<br />
from 
<br />
  search</code>
        </p>
        <p>
Design is not trivial but it works somehow.
</p>
        <p>
After dealing with all these problems some questions remain unanswered:
</p>
        <ul>
          <li>
Why SQL Server does not allow to query Windows Search directly? 
</li>
          <li>
Why Windows Search OLEDB provider does not support "Data Source" parameter? 
</li>
          <li>
Why Windows Search does not support custom protocols during remote search? 
</li>
          <li>
Why SQL Server does not support web request/web services natively? 
</li>
        </ul>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=f7c6c76b-ef5f-41c8-a892-68af10fb6ad0" />
      </div>
    </content>
  </entry>
  <entry>
    <title>VS 2008 SP1 and C++ run-time libraries or how to compile/install native code.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/04/14/VS2008SP1AndCRuntimeLibrariesOrHowToCompileinstallNativeCode.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7987fa4e-c581-49d2-ad23-d05cbb3df992.aspx</id>
    <published>2011-04-14T02:50:23.843-07:00</published>
    <updated>2011-04-19T00:32:59.5016164-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Hello everybody! You might think that we had died, since there were no articles in
our blog for a too long time, but no, we’re still alive…
</p>
        <p>
A month or so we were busy with Windows Search and stuff around it. Custom protocol
handlers, support of different file formats and data storages are very interesting
tasks, but this article discusses another issue.
</p>
        <p>
The issue is how to compile and install native code written in C++, which was built
under Visual Studio 2008 (SP1), on a clean computer.
</p>
        <p>
The problem is that native dlls now resolve the problem known as a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7987fa4e-c581-49d2-ad23-d05cbb3df992&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fDLL_hell">DLL
hell</a> using assembly manifests. This should help to discover and load the right
DLL. The problem is that there are many versions of CRT, MFC, ATL and other dlls,
and it's not trivial to create correct setup for a clean computer.
</p>
        <p>
In order to avoid annoying dll binding problems at run-time, please define <b> BIND_TO_CURRENT_CRT_VERSION</b> and/or
(<b>_BIND_TO_CURRENT_ATL_VERSION</b>, <b> _BIND_TO_CURRENT_MFC_VERSION</b>). Don’t
forget to make the same definitions for all configurations/target platforms you intend
to use. Build the project and check the resulting manifest file (just in case). It
should contain something like that:
</p>
        <code>&lt;?xml version='1.0' encoding='UTF-8' standalone='yes'?&gt;<br />
&lt;assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'&gt;<br />
  &lt;trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"&gt;<br />
    &lt;security&gt;<br />
      &lt;requestedPrivileges&gt;<br />
        &lt;requestedExecutionLevel level='asInvoker'
uiAccess='false' /&gt;<br />
      &lt;/requestedPrivileges&gt;<br />
    &lt;/security&gt;<br />
  &lt;/trustInfo&gt;<br />
  &lt;dependency&gt;<br />
    &lt;dependentAssembly&gt;<br />
      &lt;assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT'<br />
        version='9.0.30729.4148' processorArchitecture='x86'<br />
        publicKeyToken='1fc8b3b9a1e18e3b'
/&gt;<br />
    &lt;/dependentAssembly&gt;<br />
  &lt;/dependency&gt;<br />
&lt;/assembly&gt; </code>
        <p>
The version of dependent assembly gives you a clue what a native run-time version(s)
requires your application. The same thing you have to do for all your satellite projects.
</p>
        <p>
The next step is to create a proper setup project using VS wizard. 
</p>
        <p>
Right click on setup project and select “Add-&gt;Merge Module…”. Select “Microsoft_VC90_CRT_x86.msm”
or/and (“Microsoft_VC90_DebugCRT_x86.msm”, “Microsoft_VC90_ATL_x86.msm”, “Microsoft_VC90_MFC_x86.msm”…)
for installing of corresponding run-time libraries and “policy_9_0_Microsoft_VC90_CRT_x86.msm”
etc. for route calls of old version run-time libraries to the newest versions. Now
you're ready to build your setup project.
</p>
        <p>
You may also include “Visual C++ Runtime Libraries” to a setup prerequisites.
</p>
        <p>
As result, you'll get 2 files (setup.exe and Setup.msi) and an optional folder
(vcredist_x86) with C++ run-time redistributable libraries.
</p>
        <p>
          <b>Note: </b>only setup.exe installs those C++ run-time libraries.
</p>
        <div>
More info concerning this theme:
</div>
        <div>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7987fa4e-c581-49d2-ad23-d05cbb3df992&amp;url=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2flibrary%2fms235342(v%3dVS.90).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms235342(v=VS.90).aspx</a>
        </div>
        <div>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7987fa4e-c581-49d2-ad23-d05cbb3df992&amp;url=http%3a%2f%2fstackoverflow.com%2fquestions%2f59635%2fapp-does-not-run-with-vs-2008-sp1-dlls-previous-version-works-with-rtm-versions" target="_blank"> http://stackoverflow.com/questions/59635/app-does-not-run-with-vs-2008-sp1-dlls-previous-version-works-with-rtm-versions</a>
        </div>
        <div>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=7987fa4e-c581-49d2-ad23-d05cbb3df992&amp;url=http%3a%2f%2fsocial.msdn.microsoft.com%2fForums%2fen-US%2fvcgeneral%2fthread%2f867cf808-bf1f-4f4a-bde1-cd75d92d73ad" target="_blank"> http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/867cf808-bf1f-4f4a-bde1-cd75d92d73ad</a>
        </div>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7987fa4e-c581-49d2-ad23-d05cbb3df992" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Unescape in SQL Server</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/03/07/UnescapeInSQLServer.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8066eab0-7ff3-4c1b-aca9-fc20b2fea350.aspx</id>
    <published>2011-03-07T13:01:24.152-08:00</published>
    <updated>2011-03-07T13:11:14.3331337-08:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Let's assume you're loading data into a table using <code>BULK INSERT</code> from
tab separated file. Among others you have some <code>varchar</code> field, which may
contain any character. Content of such field is escaped with usual scheme:
</p>
        <ul>
          <li>
            <code>'\'</code> as <code>'\\'</code>;</li>
          <li>
            <code>char(13)</code> as <code>'\n'</code>;</li>
          <li>
            <code>char(10)</code> as <code>'\r'</code>;</li>
          <li>
            <code>char(9)</code> as <code>'\t'</code>;</li>
        </ul>
        <p>
But now, after loading, you want to unescape content back. How would you do it?
</p>
        <p>
Notice that: 
</p>
        <ul>
          <li>
            <code>'\t'</code> should be converted to a <code>char(9)</code>;</li>
          <li>
            <code>'\\t'</code> should be converted to a <code>'\t'</code>;</li>
          <li>
            <code>'\\\t'</code> should be converted to a <code>'\' + char(9)</code>;</li>
        </ul>
        <p>
It might be that you're smart and you will immediately think of correct algorithm,
but for us it took a while to come up with a neat solution:
</p>
        <p style="padding-left: 1em">
          <code> declare @value varchar(max);<br /><br />
set @value = ...<br /><br />
-- This unescapes the value<br />
set @value =<br />
replace<br />
( 
<br />
replace 
<br />
( 
<br />
replace 
<br />
( 
<br />
replace 
<br />
( 
<br />
replace(@value, '\\', '\ '),<br />
'\n', 
<br />
char(10) 
<br />
), 
<br />
'\r', 
<br />
char(13) 
<br />
), 
<br />
'\t', 
<br />
char(9)<br />
), 
<br />
'\ ', 
<br />
'\' 
<br />
);</code>
        </p>
        <p style="padding-left: 1em">
        </p>
        <p style="padding-left: 1em">
Do you know a better way?
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8066eab0-7ff3-4c1b-aca9-fc20b2fea350" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Calling Windows Search from SQL Server 2008</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/03/04/CallingWindowsSearchFromSQLServer2008.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,08d2a0a6-ab2d-420d-b22a-0f5fd28b7b48.aspx</id>
    <published>2011-03-04T01:22:49.22-08:00</published>
    <updated>2011-07-10T03:49:28.8605289-07:00</updated>
    <category term="SQL Server puzzle" label="SQL Server puzzle" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,SQLServerPuzzle.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="Window Search" label="Window Search" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,WindowSearch.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We were trying to query Windows Search from an SQL Server 2008.
</p>
        <p>
Documentation states that Windows Search is exposed as OLE DB datasource. This meant
that we could just query result like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>SELECT<br />
  *<br />
FROM 
<br />
  OPENROWSET(<br />
    'Search.CollatorDSO.1',<br />
    'Application=Windows',<br />
    'SELECT "System.ItemName", "System.FileName" FROM SystemIndex');</code>
        </p>
        <p>
But no, such select never works. Instead it returns obscure error messages:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>OLE DB provider "Search.CollatorDSO.1" for linked server "(null)" returned message
"Command was not prepared.".<br />
Msg 7399, Level 16, State 1, Line 1<br />
The OLE DB provider "Search.CollatorDSO.1" for linked server "(null)" reported an
error. Command was not prepared.<br />
Msg 7350, Level 16, State 2, Line 1<br />
Cannot get the column information from OLE DB provider "Search.CollatorDSO.1" for
linked server "(null)". </code>
        </p>
        <p>
Microsoft is silent about reasons of such behaviour. People came to a conclusion that
the problem is in the SQL Server, as one can query search results through OleDbConnection
without problems.
</p>
        <p>
This is very unfortunate, as it bans many use cases.
</p>
        <p>
As a workaround we have defined a CLR function wrapping Windows Search call and returning
rows as xml fragments. So now the query looks like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>select<br />
  <b>value.value('System.ItemName[1]', 'nvarchar(max)')</b> ItemName,<br />
  <b>value.value('System.FileName[1]', 'nvarchar(max)')</b> FileName<br />
from<br />
  dbo.WindowsSearch('SELECT "System.ItemName", "System.FileName" FROM SystemIndex')<br /></code>
        </p>
        <p>
Notice how we decompose xml fragment back to fields with the value() function.
</p>
        <p>
The C# function looks like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>using System;<br />
using System.Collections;<br />
using System.IO;<br />
using System.Xml;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Data.SqlTypes;<br />
using System.Data.OleDb;<br /><br />
using Microsoft.SqlServer.Server;<br /><br />
public class UserDefinedFunctions<br />
{<br />
  [SqlFunction(<br />
    FillRowMethodName = "FillSearch",<br />
    TableDefinition="value xml")]<br />
  public static IEnumerator WindowsSearch(SqlString query)<br />
  {<br />
    const string provider =<br />
      "Provider=Search.CollatorDSO;" +<br />
      "Extended Properties='Application=Windows';" +<br />
      "<b>OLE DB Services=-4</b>";<br /><br />
    var settings = new XmlWriterSettings<br />
    {<br />
      Indent = false,<br />
      CloseOutput = false,<br />
      ConformanceLevel = ConformanceLevel.Fragment,<br />
      OmitXmlDeclaration = true<br />
    };<br /><br />
    string[] names = null;<br /><br />
    using(var connection = new OleDbConnection(provider))<br />
    using(var command = new OleDbCommand(query.Value, connection))<br />
    {<br />
      connection.Open();<br /><br />
      using(var reader = command.ExecuteReader())<br />
      {<br />
        while(reader.Read())<br />
        {<br />
          if (names == null)<br />
          {<br />
            names = new string[reader.FieldCount];<br /><br />
            for (int i = 0;
i &lt; names.Length; ++i)<br />
            {<br />
              names[i]
= XmlConvert.EncodeLocalName(reader.GetName(i));<br />
            }<br />
          }<br /><br />
          var stream = new MemoryStream();<br />
          var writer = XmlWriter.Create(stream,
settings);<br /><br />
          for(int i = 0; i &lt; names.Length;
++i)<br />
          {<br />
            writer.WriteElementString(names[i],
Convert.ToString(reader[i]));<br />
          }<br /><br />
          writer.Close();<br /><br />
          yield return new SqlXml(stream);<br />
        }<br />
      }<br />
    }<br />
  }<br /><br />
  public static void FillSearch(object value, out SqlXml row)<br />
  {<br />
    row = (SqlXml)value;<br />
  }<br />
} </code>
        </p>
        <p>
Notes:
</p>
        <ul>
          <li>
 Notice the use of "<code><b>OLE DB Services=-4</b></code>" in provider string
to avoid transaction enlistment (required in SQL Server 2008). 
</li>
          <li>
Permission level of the project that defines this extension function should be set
to unsafe (see Project Properties/Database in Visual Studio) otherwise it does not
allow the use OLE DB. 
</li>
          <li>
SQL Server should be configured to allow CLR functions, see Server/Facets/Surface
Area Configuration/ClrIntegrationEnabled in Microsoft SQL Server Management Studio 
</li>
          <li>
Assembly should either be signed or a database should be marked as trustworthy, see
Database/Facets/Trustworthy in Microsoft SQL Server Management Studio. 
</li>
        </ul>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=08d2a0a6-ab2d-420d-b22a-0f5fd28b7b48" />
      </div>
    </content>
  </entry>
  <entry>
    <title>java web service session object (www.bing.com)</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/02/23/javaWebServiceSessionObjectWwwbingcom.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0c95c9de-19dd-4ba3-8923-639928f30895.aspx</id>
    <published>2011-02-23T03:33:37.217-08:00</published>
    <updated>2011-02-23T03:37:02.5313707-08:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A search "java web service session object" has reached our site.
</p>
        <p>
Unfortunately, we cannot help to the original searcher but a next one might find this
info usefull.
</p>
        <p>
To get http session in the web service you should add a field to your class that will
be populated with request context.
</p>
        <p style="padding-left: 1em">
          <code> @WebService<br />
public class MyService<br />
{<br />
  @WebMethod<br />
  public int method(String value)<br />
  {<br />
    MessageContext messageContext = context.getMessageContext();<br />
    HttpServletRequest request = 
<br />
      (HttpServletRequest)messageContext.get(MessageContext.SERVLET_REQUEST);<br />
    HttpSession session = request.getSession();<br /><br />
    // go ahead.<br />
  }<br /><br />
  // A web service context.<br />
  <b>@Resource<br />
  private WebServiceContext context;</b><br />
}</code>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0c95c9de-19dd-4ba3-8923-639928f30895" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Good and bad things in JAX-WS implementation.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/02/20/GoodAndBadThingsInJAXWSImplementation.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d56b2e61-6762-4f44-8058-12d5625658d8.aspx</id>
    <published>2011-02-20T02:20:12.849-08:00</published>
    <updated>2011-02-20T02:56:45.1393342-08:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last few days we were testing Java web-applications that expose web-services. During
these tests we've found few interesting features.
</p>
        <p>
The first feature allows to retrieve info about all endpoints supported by the web-application
on GET request. The feature works at least for <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d56b2e61-6762-4f44-8058-12d5625658d8&amp;url=http%3a%2f%2fjax-ws.java.net%2f2.1.7%2f" target="_blank">Metro
that implements JAX-WS API v2.x</a>. In order to get such info, a client sends any
endpoint's URL to the server. The result is an HTML page with a table. Each row of
such table contains an endpoint's data for each supported web-service method. This
feature may be used as a web-services discovery mechanism.
</p>
        <p>
The second feature is bad rather than good. JAX-WS API supposes that a developer annotates
classes and methods that he/she wants to expose as web-services. Then, an implementation
generates additional layer-bridge between developer's code and API that does all routine
work behind the scene. May be that was a good idea, but Metro's implementation is
imperfect. Metro dynamically generates such classes at run-time when a web-application
starts. Moreover, Metro does such generation for all classes at once. So, in our case,
when the generated web-based application contains dozens or even hundreds of web-services,
the application's startup takes a lot of time.
</p>
        <p>
Probably, Metro developers didn't want to deal with implementation of lazy algorithms,
when a web-service is generated and cached on demand. We hope this issue will be solved
in next releases.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d56b2e61-6762-4f44-8058-12d5625658d8" />
      </div>
    </content>
  </entry>
  <entry>
    <title>A simple cache for Java application #2</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/02/08/ASimpleCacheForJavaApplication2.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,cdf6ed65-8c21-49ed-92ac-93d3d6a3ea96.aspx</id>
    <published>2011-02-08T07:20:29.7489622-08:00</published>
    <updated>2011-02-08T07:20:29.7489622-08:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A while ago we have created <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cdf6ed65-8c21-49ed-92ac-93d3d6a3ea96&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f12%2f04%2fASimpleCacheForJavaApplication.aspx"> a
simple cache for Java application</a>. It was modelled like a <code>Map&lt;K, V&gt;</code>:
it cached values for keys.
</p>
        <p>
Use cases were:
</p>
        <p style="padding-left: 1em">
          <code>Cache&lt;String, Object&gt; cache = new Cache&lt;String, Object&gt;(); 
<br />
...<br />
instance = cache.get("key");<br />
cache.put("key", instance);</code>
        </p>
        <p>
But now we thought of different implementation like a <code>WeakReference&lt;V&gt;</code> and
with map access as additional utility methods.
</p>
        <p>
 Consider an examples:
</p>
        <p>
1. Free standing <code>CachedReference&lt;V&gt;</code> instance.
</p>
        <p style="padding-left: 1em">
          <code> CachedReference&lt;Data&gt; ref = new CachedReference&lt;Data&gt;(1000, true);<br />
...<br />
ref.set(data);<br />
...<br />
data = ref.get();</code>
        </p>
        <p>
2. Map of <code>CachedReference&lt;V&gt;</code> instances.
</p>
        <p style="padding-left: 1em">
          <code> ConcurrentHashMap&lt;String, CachedReference&lt;Data&gt;&gt; cache = 
<br />
  new ConcurrentHashMap&lt;String, CachedReference&lt;Data&gt;&gt;();<br /><br />
CachedReference.put(cache, "key", data, 1000, true);<br />
...<br />
data = CachedReference.get(cache, "key");</code>
        </p>
        <p>
The first case is faster than original <code>Cache&lt;K, V&gt;</code> as it does not
use any hash map at all. The later case provides the same performance as <code>Cache&lt;K,
V&gt;</code> but gives a better control over the storage. Incidentally, <code>CachedReference&lt;V&gt;</code> is
more compact than <code>Cache&lt;K, V&gt;</code>.
</p>
        <p>
The new implementation is <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cdf6ed65-8c21-49ed-92ac-93d3d6a3ea96&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fCachedReference.java.txt">CachedReference.java</a>,
the old one <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cdf6ed65-8c21-49ed-92ac-93d3d6a3ea96&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fCache.java.txt">Cache.java</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=cdf6ed65-8c21-49ed-92ac-93d3d6a3ea96" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Java's @Yield return annotation update</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/02/05/JavasYieldReturnAnnotationUpdate.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5ed4531a-dbbb-48b5-89d2-b58d1ed78df8.aspx</id>
    <published>2011-02-05T13:12:05.6450392-08:00</published>
    <updated>2011-02-05T13:12:05.6450392-08:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have updated <code>@Yield</code> annotation processor to support better debug info.
</p>
        <p>
Annotation processor can be downloaded from <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.zip">Yield.zip</a> or <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.jar">Yield.jar</a>.
</p>
        <p>
We also decided to consider jxom's state machine refactoring as obsolete as <code>@Yield</code> annotation
allows to achieve the same effect but with more clear code.
</p>
        <p>
JXOM can be downloaded from <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2flanguages-xom.zip"> languages-xom.zip</a></p>
        <p>
See also: 
</p>
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f01%2f24%2fYieldReturnFeatureInJava.aspx">Yield
return feature in java</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f01%2f27%2fWhyYieldIteratorShouldBeCloseable.aspx">Why
@Yield iterator should be Closeable</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f09%2f05%2fWhatYouCanDoWithJxom.aspx">What
you can do with jxom.</a>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Xslt 3.0 insights</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/02/03/Xslt30Insights.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,602f1d9d-bf21-4c55-86ef-c7d2ee403d6d.aspx</id>
    <published>2011-02-03T03:07:49.1258962-08:00</published>
    <updated>2011-02-03T03:07:49.1258962-08:00</updated>
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p style="padding-left: 1em; font-style: italic">
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d&amp;url=http%3a%2f%2ftwitter.com%2fmichaelhkay%2fstatuses%2f32946749697953793">michaelhkay</a>:
Just posted a new internal draft of XSLT 3.0. Moving forward on maps, nested sequences,
and JSON support.
</p>
        <p>
Hope they will finally appear there!
</p>
        <p>
See also: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f08%2f30%2fTuplesAndMapsNextTry.aspx">Tuples
and maps - next try</a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f07%2f10%2fTuplesAndMapsStatusCLOSEDWONTFIX.aspx"> Tuples
and maps - Status: CLOSED, WONTFIX</a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f05%2f18%2fTuplesAndMapsInSaxon.aspx"> Tuples
and maps in Saxon</a> and other blog posts on our site about immutable maps.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Why @Yield iterator should be Closeable</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/01/27/WhyYieldIteratorShouldBeCloseable.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1197c4e4-fb86-4007-8bf3-9d5bf7e79a52.aspx</id>
    <published>2011-01-27T02:33:54.981-08:00</published>
    <updated>2011-01-27T03:41:24.0753779-08:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A method pattern we have suggested to use along with <code>@Yield</code> annotation
brought funny questions like: "why should I mark my method with <code>@Yield</code> annotation
at all?"
</p>
        <p>
Well, in many cases you may live with <code>ArrayList</code> populated with data,
and then to perform iteration. But in some cases this approach is not practical either
due to amount of data or due to the time required to get first item.
</p>
        <p>
In later case you usually want to build an iterator that calculates items on demand.
The <code>@Yield</code> annotation is designed as a marker of such methods. They are
refactored into state machines at compilation time, where each addition to a result
list is transformed into a new item yielded by the iterator.
</p>
        <p>
So, if you have decided to use <code>@Yield</code> annotation then at some point you
will ask yourself what happens with resources acquired during iteration. Will resources
be released if iteration is interrupted in the middle due to exception or a break
statement? 
</p>
        <p>
To address the problem yield iterator implements <code>Closeable</code> interface.
</p>
        <p>
This way when you call <code>close()</code> before iteration reached the end, the
state machine works as if break statement of the method body is injected after the
yield point. Thus all finally blocks of the original method are executed and resources
are released.
</p>
        <p>
Consider an example of data iterator:
</p>
        <p style="padding-left: 1em">
          <code> @Yield<br />
public Iterable&lt;Data&gt; getData(final Connection connection)<br />
throws Exception<br />
{<br />
ArrayList&lt;Data&gt; result = new ArrayList&lt;Data&gt;();<br /><br />
PreparedStatement statement = 
<br />
connection.prepareStatement("select key, value from table");<br /><br />
try<br />
{<br />
ResultSet resultSet = statement.executeQuery();<br /><br />
try<br />
{<br />
while(resultSet.next())<br />
{<br />
Data data = new Data();<br /><br />
data.key = resultSet.getInt(1);<br />
data.value = resultSet.getString(2);<br /><br />
result.add(data); // yield point<br />
}<br />
}<br />
finally<br />
{<br />
resultSet.close();<br />
}<br />
}<br />
finally<br />
{<br />
statement.close();<br />
}<br /><br />
return result;<br />
}<br /><br />
private static void close(Object value)<br />
throws IOException<br />
{<br />
if (value instanceof Closeable)<br />
{<br />
Closeable closeable = (Closeable)value;<br /><br />
closeable.close();<br />
}<br />
}<br /><br />
public void daoAction(Connection connection)<br />
throws Exception<br />
{<br />
Iterable&lt;Data&gt; items = getData(connection);<br /><br />
try<br />
{<br />
for(Data data: items)<br />
{<br />
// do something that potentially throws exception.<br />
}<br />
}<br />
finally<br />
{<br />
close(items);<br />
}<br />
} </code>
        </p>
        <p>
          <code>getData()</code> iterates over sql data. During the lifecycle it creates and
releases <code>PreparedStatement</code> and <code>ResultSet</code>.
</p>
        <p>
          <code>daoAction()</code> iterates over results provided by <code>getData()</code> and
performs some actions that potentially throw an exception. The goal of <code>close()</code> is
to release opened sql resources in case of such an exception.
</p>
        <p>
Here you can inspect how state machine is implemented for such a method:
</p>
        <p style="padding-left: 1em">
          <code>@Yield()<br />
public static Iterable&lt;Data&gt; getData(final Connection connection)<br />
throws Exception 
<br />
{<br />
assert (java.util.ArrayList&lt;Data&gt;)(ArrayList&lt;Data&gt;)null == null;<br /><br />
class $state implements java.lang.Iterable&lt;Data&gt;, java.util.Iterator&lt;Data&gt;,
java.io.Closeable 
<br />
{<br />
public java.util.Iterator&lt;Data&gt; iterator() {<br />
if ($state$id == 0) {<br />
$state$id = 1;<br /><br />
return this;<br />
} else return new $state();<br />
}<br /><br />
public boolean hasNext() {<br />
if (!$state$nextDefined) {<br />
$state$hasNext = $state$next();<br />
$state$nextDefined = true;<br />
}<br /><br />
return $state$hasNext;<br />
}<br /><br />
public Data next() {<br />
if (!hasNext()) throw new java.util.NoSuchElementException();<br /><br />
$state$nextDefined = false;<br /><br />
return $state$next;<br />
}<br /><br />
public void remove() {<br />
throw new java.lang.UnsupportedOperationException();<br />
}<br /><br />
public void close() {<br />
do switch ($state$id) {<br />
case 3: 
<br />
$state$id2 = 8;<br />
$state$id = 5;<br /><br />
continue;<br />
default: 
<br />
$state$id = 8;<br /><br />
continue;<br />
} while ($state$next());<br />
}<br /><br />
private boolean $state$next() {<br />
java.lang.Throwable $state$exception;<br /><br />
while (true) {<br />
try {<br />
switch ($state$id) {<br />
case 0: 
<br />
$state$id = 1;<br />
case 1: 
<br />
statement = connection.prepareStatement("select key, value from table");<br />
$state$exception1 = null;<br />
$state$id1 = 8;<br />
$state$id = 2;<br />
case 2: 
<br />
resultSet = statement.executeQuery();<br />
$state$exception2 = null;<br />
$state$id2 = 6;<br />
$state$id = 3;<br />
case 3: 
<br />
if (!resultSet.next()) {<br />
$state$id = 4;<br /><br />
continue;<br />
}<br /><br />
data = new Data();<br />
data.key = resultSet.getInt(1);<br />
data.value = resultSet.getString(2);<br />
$state$next = data;<br />
$state$id = 3;<br /><br />
return true;<br />
case 4: 
<br />
$state$id = 5;<br />
case 5: 
<br />
{<br />
resultSet.close();<br />
}<br /><br />
if ($state$exception2 != null) {<br />
$state$exception = $state$exception2;<br /><br />
break;<br />
}<br /><br />
if ($state$id2 &gt; 7) {<br />
$state$id1 = $state$id2;<br />
$state$id = 7;<br />
} else $state$id = $state$id2;<br /><br />
continue;<br />
case 6: 
<br />
$state$id = 7;<br />
case 7: 
<br />
{<br />
statement.close();<br />
}<br /><br />
if ($state$exception1 != null) {<br />
$state$exception = $state$exception1;<br /><br />
break;<br />
}<br /><br />
$state$id = $state$id1;<br /><br />
continue;<br />
case 8: 
<br />
default: 
<br />
return false;<br />
}<br />
} catch (java.lang.Throwable e) {<br />
$state$exception = e;<br />
}<br /><br />
switch ($state$id) {<br />
case 3: 
<br />
case 4: 
<br />
$state$exception2 = $state$exception;<br />
$state$id = 5;<br /><br />
continue;<br />
case 2: 
<br />
case 5: 
<br />
case 6: 
<br />
$state$exception1 = $state$exception;<br />
$state$id = 7;<br /><br />
continue;<br />
default: 
<br />
$state$id = 8;<br /><br />
java.util.ConcurrentModificationException ce = new java.util.ConcurrentModificationException();<br /><br />
ce.initCause($state$exception);<br /><br />
throw ce;<br />
}<br />
}<br />
}<br /><br />
private PreparedStatement statement;<br />
private ResultSet resultSet;<br />
private Data data;<br />
private int $state$id;<br />
private boolean $state$hasNext;<br />
private boolean $state$nextDefined;<br />
private Data $state$next;<br />
private java.lang.Throwable $state$exception1;<br />
private int $state$id1;<br />
private java.lang.Throwable $state$exception2;<br />
private int $state$id2;<br />
}<br /><br />
return new $state();<br />
} </code>
        </p>
        <p>
Now, you can estimate for what it worth to write an algorithm as a sound state machine
comparing to the conventional implementation.
</p>
        <p>
Yield annotation processor can be downloaded from <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1197c4e4-fb86-4007-8bf3-9d5bf7e79a52&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.zip">Yield.zip</a> or <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1197c4e4-fb86-4007-8bf3-9d5bf7e79a52&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.jar">Yield.jar</a></p>
        <p>
See also <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1197c4e4-fb86-4007-8bf3-9d5bf7e79a52&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f01%2f24%2fYieldReturnFeatureInJava.aspx">Yield
return feature in java</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1197c4e4-fb86-4007-8bf3-9d5bf7e79a52" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Yield return feature in java</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/01/24/YieldReturnFeatureInJava.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0525e835-90bf-4889-8706-6b0432624e57.aspx</id>
    <published>2011-01-24T02:23:53.746-08:00</published>
    <updated>2011-01-24T02:55:02.0324834-08:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We're happy to announce that we have implemented <code>@Yield</code> annotation
both in javac and in eclipse compilers.
</p>
        <p>
This way you get built-in IDE support for the feature!
</p>
        <p>
To download yield annotation processor please use the following link: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0525e835-90bf-4889-8706-6b0432624e57&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.zip">Yield.zip</a></p>
        <p>
It contains both yield annotation processor, and a test project.
</p>
        <p>
If you do not want to compile the sources, you can download <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0525e835-90bf-4889-8706-6b0432624e57&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.jar">Yield.jar</a></p>
        <p>
        </p>
        <p>
We would like to reiterate on how <code>@Yield</code> annotation works:
</p>
        <ol>
          <li>
A developer defines a method that returns either <code>Iterator&lt;T&gt;</code> or <code>Iterable&lt;T&gt;</code> instance
and marks it with <code>@Yield</code> annotation.</li>
          <li>
A developer implements iteration logic following the pattern:<br /><ul><li>
declare a variable to accumulate results:<br /><code>ArrayList&lt;T&gt; items = new ArrayList&lt;T&gt;();</code></li><li>
use the following statement to add item to result:<br /><code>items.add(...);</code></li><li>
use<br /><code>return items;</code><br />
or<br /><code>return items.iterator();<br /></code>to return result;</li><li>
mark method's params, if any, as final.</li></ul></li>
          <li>
A devoloper ensures that yield annotation processor is available during compilation
(see details below).</li>
          <li>
            <code>YieldProcessor</code> rewrites method into a state machine at compilation time.</li>
        </ol>
        <p>
The following is an example of such a method:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>@Yield<br />
public static Iterable&lt;Integer&gt; generate(final int from, final int to)<br />
{<br />
ArrayList&lt;Integer&gt; items = new ArrayList&lt;Integer&gt;();<br /><br />
for(int i = from; i &lt; to; ++i)<br />
{<br />
items.add(i);<br />
}<br /><br />
return items;<br />
}</code>
        </p>
        <p>
The use is like this:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>for(int value: generate(7, 20))<br />
{<br />
System.out.println("generator: " + value);<br />
} </code>
        </p>
        <p>
Notice that method's implementation still will be correct in absence of <code> YieldProcessor</code>.
</p>
        <p>
Other important feature is that the state machine returned after the yield processor
is closeable.
</p>
        <p>
This means that if you're breaking the iteration before the end is reached you
can release resources acquired during the iteration.
</p>
        <p>
Consider the example where break exits iteration:
</p>
        <p style="PADDING-LEFT: 1em">
          <code>@Yield<br />
public static Iterable&lt;String&gt; resourceIteration()<br />
{<br />
ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;();<br /><br />
acquire();<br /><br />
try<br />
{<br />
for(int i = 0; i &lt; 100; ++i)<br />
{<br />
items.add(String.valueOf(i));<br />
}<br />
}<br />
finally<br />
{<br />
release();<br />
}<br /><br />
return items;<br />
}</code>
        </p>
        <p>
and the use
</p>
        <p style="PADDING-LEFT: 1em">
          <code>int i = 0;<br />
Iterable&lt;String&gt; iterator = resourceIteration();<br /><br />
try<br />
{<br />
for(String item: iterator)<br />
{<br />
System.out.println("item " + i + ":" + item);<br /><br />
if (i++ &gt; 30)<br />
{<br /><b>break</b>;<br />
}<br />
}<br />
}<br />
finally<br />
{<br />
close(iterator);<br />
}<br /><br />
...<br /><br />
private static &lt;T&gt; void close(T value)<br />
throws IOException<br />
{<br />
if (value instanceof Closeable)<br />
{<br />
Closeable closeable = (Closeable)value;<br /><br />
closeable.close();<br />
}<br />
} </code>
        </p>
        <p>
Close will execute all required finally blocks. This way resources will be released.
</p>
        <p>
        </p>
        <p>
To configure yield processor a developer needs to refer Yield.jar in build path, as
it contains <code>@Yield</code> annotation. For javac it's enough, as compiler
will find annotation processor automatically.
</p>
        <p>
Eclipse users need to open project properties and:
</p>
        <ul>
          <li>
go to the "Java Compiler"/"Annotation Processing" 
</li>
          <li>
mark "Enable project specific settings"</li>
          <li>
select "Java Compiler"/"Annotation Processing"/"Factory Path"</li>
          <li>
mark "Enable project specific settings"</li>
          <li>
add Yield.jar to the list of "plug-ins and JARs that contain annotation processors".</li>
        </ul>
        <p>
        </p>
        <p>
At the end we want to point that <code>@Yield</code> annotation is a syntactic suggar,
but it's important the way the foreach statement is important, as it helps to
write concise and an error free code.
</p>
        <p>
See also<br /><a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0525e835-90bf-4889-8706-6b0432624e57&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2011%2f01%2f11%2fYieldFeatureInJavaImplemented.aspx">Yield
feature in java implemented!</a><br /><a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0525e835-90bf-4889-8706-6b0432624e57&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f12%2f20%2fYieldFeatureInJava.aspx">Yield
feature in java</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0525e835-90bf-4889-8706-6b0432624e57" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Java XML Object Model Update</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/01/14/JavaXMLObjectModelUpdate.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,280d6e0d-1389-4566-9e0f-badef8530578.aspx</id>
    <published>2011-01-14T13:29:04.955-08:00</published>
    <updated>2011-01-14T13:41:13.0267542-08:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
For some reason we never knew about instance initializer in java; on the other hand
static initializer is well known.
</p>
        <p style="padding-left: 1em;">
          <code> class A<br />
{<br />
int x;<br />
static int y;<br /><br />
// This is an instance initializer.<br />
{<br />
x = 1;<br />
}<br /><br />
// This is a static initializer.<br />
static<br />
{<br />
y = 2;<br />
}<br />
}</code>
        </p>
        <p>
Worse, we have missed it in the java grammar when we were building jxom. This way
jxom was missing the feature.
</p>
        <p>
Today we fix the miss and introduce a schema element:
</p>
        <p style="padding-left: 1em">
          <code>&lt;class-initializer static="boolean"&gt;<br />
&lt;block&gt;<br />
...<br />
&lt;/block&gt;<br />
&lt;/class-initializer&gt;</code>
        </p>
        <p>
It superseeds:
</p>
        <p style="padding-left: 1em">
          <code>&lt;static&gt;<br />
&lt;block&gt;<br />
...<br />
&lt;/block&gt;<br />
&lt;/static&gt;</code>
        </p>
        <p>
that supported static initializers alone.
</p>
        <p>
Please update <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=280d6e0d-1389-4566-9e0f-badef8530578&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2flanguages-xom.zip"> languages-xom
xslt stylesheets</a>.
</p>
        <p>
P.S. Out of curiosity, did you ever see any use of instance initializers?
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=280d6e0d-1389-4566-9e0f-badef8530578" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Yield feature in java implemented!</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2011/01/11/YieldFeatureInJavaImplemented.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ebd5185f-fc37-4e82-b2bb-006387635512.aspx</id>
    <published>2011-01-11T08:08:41.586-08:00</published>
    <updated>2011-01-11T08:47:16.5209737-08:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We could not stand the temptation to implement the <code>@Yield</code> annotation
that we described <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ebd5185f-fc37-4e82-b2bb-006387635512&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2010%2f12%2f20%2fYieldFeatureInJava.aspx">earlier</a>.
</p>
        <p>
Idea is rather clear but people are saying that it's not an easy task to update
the sources.
</p>
        <p>
They were right!
</p>
        <p>
Implementation has its price, as we were forced to access JDK's classes of javac
compiler. As result, at present, we don't support other compilers such as EclipseCompiler.
We shall look later what can be done in this area.
</p>
        <p>
At present, annotation processor works perfectly when you run javac either from the
command line, from ant, or from other build tool.
</p>
        <p>
Here is an example of how method is refactored:
</p>
        <p style="padding-left: 1em">
          <code>@Yield<br />
public static Iterable&lt;Long&gt; fibonachi()<br />
{<br />
ArrayList&lt;Long&gt; items = new ArrayList&lt;Long&gt;();<br /><br />
long Ti = 0;<br />
long Ti1 = 1;<br /><br />
while(true)<br />
{<br />
items.add(Ti);<br /><br />
long value = Ti + Ti1;<br /><br />
Ti = Ti1;<br />
Ti1 = value;<br />
}<br />
}</code>
        </p>
        <p>
And that's how we transform it:
</p>
        <p style="padding-left: 1em">
          <code>@Yield()<br />
public static Iterable&lt;Long&gt; fibonachi() {<br />
assert (java.util.ArrayList&lt;Long&gt;)(ArrayList&lt;Long&gt;)null == null : null;<br /><br />
class $state$ implements java.lang.Iterable&lt;Long&gt;, java.util.Iterator&lt;Long&gt;,
java.io.Closeable {<br /><br />
public java.util.Iterator&lt;Long&gt; iterator() {<br />
if ($state$id == 0) {<br />
$state$id = 1;<br />
return this;<br />
} else return new $state$();<br />
}<br /><br />
public boolean hasNext() {<br />
if (!$state$nextDefined) {<br />
$state$hasNext = $state$next();<br />
$state$nextDefined = true;<br />
}<br /><br />
return $state$hasNext;<br />
}<br /><br />
public Long next() {<br />
if (!hasNext()) throw new java.util.NoSuchElementException();<br /><br />
$state$nextDefined = false;<br /><br />
return $state$next;<br />
}<br /><br />
public void remove() {<br />
throw new java.lang.UnsupportedOperationException();<br />
}<br /><br />
public void close() {<br />
$state$id = 5;<br />
}<br /><br />
private boolean $state$next() {<br />
while (true) switch ($state$id) {<br />
case 0:<br />
$state$id = 1;<br />
case 1:<br />
Ti = 0;<br />
Ti1 = 1;<br />
case 2: 
<br />
if (!true) {<br />
$state$id = 4;<br />
break;<br />
}<br /><br />
$state$next = Ti;<br />
$state$id = 3;<br /><br />
return true;<br />
case 3: 
<br />
value = Ti + Ti1;<br />
Ti = Ti1;<br />
Ti1 = value;<br />
$state$id = 2;<br /><br />
break;<br />
case 4: 
<br />
case 5: 
<br />
default: 
<br />
$state$id = 5;<br /><br />
return false;<br />
}<br />
}<br /><br />
private long Ti;<br />
private long Ti1;<br />
private long value;<br />
private int $state$id;<br />
private boolean $state$hasNext;<br />
private boolean $state$nextDefined;<br />
private Long $state$next;<br />
}<br /><br />
return new $state$();<br />
}</code>
        </p>
        <p>
Formatting is automatic, sorry, but anyway it's for diagnostics only. You will
never see this code.
</p>
        <p>
It's iteresting to say that this implementation is very precisely mimics <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ebd5185f-fc37-4e82-b2bb-006387635512&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f09%2f05%2fWhatYouCanDoWithJxom.aspx"> xslt
state machine implementation</a> we have done back in 2008.
</p>
        <p>
You can <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ebd5185f-fc37-4e82-b2bb-006387635512&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.zip"> download
YieldProcessor here</a>. We hope that someone will find our solution very interesting.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ebd5185f-fc37-4e82-b2bb-006387635512" />
      </div>
    </content>
  </entry>
  <entry>
    <title>A guest article about DB certification</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2010/12/22/AGuestArticleAboutDBCertification.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0ec082bb-83b9-4c85-9011-8e00fcf1f9ca.aspx</id>
    <published>2010-12-22T05:16:49.994-08:00</published>
    <updated>2010-12-22T05:20:49.8364423-08:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
You might be interested in the following article that was written in form of a little
guide. It can educate about new ways to learn SQL and hopefully may help someone to
get a job. See <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0ec082bb-83b9-4c85-9011-8e00fcf1f9ca&amp;url=http%3a%2f%2fwww.sqlcertification.net%2fms-sql-server-certification" target="_blank">"How
to get MS SQL certification"</a> that was written by Michele Rouse.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0ec082bb-83b9-4c85-9011-8e00fcf1f9ca" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Yield feature in java</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2010/12/20/YieldFeatureInJava.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,adb797fe-a781-423c-8dea-ea827d86241b.aspx</id>
    <published>2010-12-20T08:28:35.179-08:00</published>
    <updated>2011-01-12T00:59:36.7015182-08:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="html">&lt;p&gt;
Several times we have already wished to see &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=adb797fe-a781-423c-8dea-ea827d86241b&amp;amp;url=http%3a%2f%2fstackoverflow.com%2fquestions%2f1980953%2fis-there-a-java-equivalent-to-cs-yield-keyword"&gt; &lt;code&gt;yield&lt;/code&gt; feature
in java&lt;/a&gt; and all the time came to the same implementation: &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=adb797fe-a781-423c-8dea-ea827d86241b&amp;amp;url=http%3a%2f%2fcode.google.com%2fp%2finfomancers-collections%2f"&gt;infomancers-collections&lt;/a&gt;.
And every time with dissatisfaction turned away, and continued with regular iterators.
&lt;/p&gt;
&lt;p&gt;
Why? Well, in spite of the fact it's the best implementation of the feature we have
seen, it's still too heavy, as it's playing with java byte code at run-time.
&lt;/p&gt;
&lt;p&gt;
We never grasped the idea why it's done this way, while there is &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=adb797fe-a781-423c-8dea-ea827d86241b&amp;amp;url=http%3a%2f%2fdownload.oracle.com%2fjavase%2f1.5.0%2fdocs%2fguide%2fapt%2fGettingStarted.html"&gt;post-compile
time annotation processing in java&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
If we would implemented the yeild feature in java we would created a &lt;code&gt;@Yield&lt;/code&gt; annotation
and would demanded to implement some well defined code pattern like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; @Yield&lt;br /&gt;
Iteratable&amp;lt;String&gt; iterator()&lt;br /&gt;
{ 
&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
ArrayList&amp;lt;String&gt; list = new ArrayList&amp;lt;String&gt;();&lt;br /&gt;
&lt;br /&gt;&lt; 10; ++i)&lt;br /&gt;
for(int i = 0; i {&lt;br /&gt;
// list.add() plays the role of yield return.&lt;br /&gt;
list.add(String.valueOf(i));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
return list;&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
or
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; @Yield&lt;br /&gt;
Iterator&amp;lt;String&gt; iterator()&lt;br /&gt;
{&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
ArrayList&amp;lt;String&gt; list = new ArrayList&amp;lt;String&gt;();&lt;br /&gt;
&lt;br /&gt;&lt; 10; ++i)&lt;br /&gt;
for(int i = 0; i {&lt;br /&gt;
// list.add() plays the role of yield return.&lt;br /&gt;
list.add(String.valueOf(i));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
return list.iterator();&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Note that the code will work correctly even, if by mischance, post-compile-time processing
will not take place.
&lt;/p&gt;
&lt;p&gt;
At post comile time we would do all required refactoring to turn these implementations
into a state machines thus runtime would not contain any third party components.
&lt;/p&gt;
&lt;p&gt;
It's iteresting to recall that we have also implemented similar refactoring in pure
xslt.
&lt;/p&gt;
&lt;p&gt;
See &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=adb797fe-a781-423c-8dea-ea827d86241b&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f09%2f05%2fWhatYouCanDoWithJxom.aspx" rel="bookmark"&gt;What
you can do with jxom&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; implementation can be found at &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=adb797fe-a781-423c-8dea-ea827d86241b&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjava%2fYield.zip"&gt;Yield.zip&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=adb797fe-a781-423c-8dea-ea827d86241b" /&gt;</content>
  </entry>
  <entry>
    <title>Strange JAXB behaviour</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2010/12/11/StrangeJAXBBehaviour.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,83454782-f6aa-4aca-97d1-ae989fda46d9.aspx</id>
    <published>2010-12-11T00:48:00.973-08:00</published>
    <updated>2011-01-12T00:54:28.2081362-08:00</updated>
    <category term="Java" label="Java" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Java.aspx" />
    <category term="Thinking aloud" label="Thinking aloud" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,ThinkingAloud.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have a class <code>Beans</code> used to serialize a list of generic objects into
an xml. This is done like this:
</p>
        <p style="padding-left: 1em;">
          <code> public class Call<br />
{<br />
  public Beans input;<br />
  public Beans output;<br />
  ...<br />
}<br /><br />
@XmlJavaTypeAdapter(value = BeanAdapter.class) 
<br />
public class Beans 
<br />
{ 
<br />
  public List&lt;Object&gt; bean;<br />
} </code>
        </p>
        <p>
Thanks to <code>@XmlJavaTypeAdapter</code>, we're able to write xml in whatever form
we want.
</p>
        <p>
When we're serializing a <code>Call</code> instance:
</p>
        <p style="padding-left: 1em;">
          <code> Call call = ... 
<br />
Beans beans = ...;<br /><br />
call.setInput(beans); 
<br /><br />
JAXBContext context = ...;<br />
Marshaller marshaler = context.createMarshaller();<br />
ObjectFactory factory = ...;<br /><br />
marshaler.marshal(factory.createCall(call), result);</code>
        </p>
        <p>
things work as expected, meaning that <code>BeanAdapter</code> is used during xml
serialization. But if it's happened that you want to serialize a <code>Beans</code> instance
itself, you start getting problems with the serialization of unknown objects. That's
because JAXB does not use <code>BeanAdapter</code>.
</p>
        <p>
We have found a similar case "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=83454782-f6aa-4aca-97d1-ae989fda46d9&amp;url=http%3a%2f%2fmarkmail.org%2fmessage%2fiuje47wsfjmz6dp2">How
to assign an adapter to the root element?</a>", unfortunately with no satisfactory
explanation.
</p>
        <p>
That is strange. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=83454782-f6aa-4aca-97d1-ae989fda46d9" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Something else</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2010/11/23/SomethingElse.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,beda6dc9-a331-4247-8665-9a7fd98b267d.aspx</id>
    <published>2010-11-23T05:23:48.554-08:00</published>
    <updated>2010-11-23T05:25:53.9751475-08:00</updated>
    <author>
      <name>Arthur Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last Thursday, 18 Nov 2010, we with our colleagues from BluePhoenix were in a trip
at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=beda6dc9-a331-4247-8665-9a7fd98b267d&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fWadi_Qelt">Wadi
Kelt</a>. See our <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=beda6dc9-a331-4247-8665-9a7fd98b267d&amp;url=http%3a%2f%2fpicasaweb.google.com%2f109429665006344170020%2fADayOffAtWadiKelt18Nov2010">photo-report
here</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=beda6dc9-a331-4247-8665-9a7fd98b267d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>A shallow thoughts</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2010/11/18/AShallowThoughts.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ec1ae7ee-1c88-44a2-a6f1-d8a2f9ba5571.aspx</id>
    <published>2010-11-18T08:19:52.101-08:00</published>
    <updated>2010-11-18T10:10:45.2882545-08:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <author>
      <name>Vladimir Nesterovsky</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Michael Key, author of the Saxon xslt processor, being inspired by the GWT ideas,
has decided to compile Saxon HE into javascript. See <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ec1ae7ee-1c88-44a2-a6f1-d8a2f9ba5571&amp;url=http%3a%2f%2fsaxonica.blogharbor.com%2fblog%2f_archives%2f2010%2f11%2f16%2f4681337.html"> Compiling
Saxon using GWT</a>.
</p>
        <p>
The resulting script is about 1MB of size.
</p>
        <p>
But what we thought lately, that it's overkill to bring whole xslt engine on a client,
while it's possible to generate javascript from xslt the same way as he's building
java from xquery. This will probably require some runtime but of much lesser size.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ec1ae7ee-1c88-44a2-a6f1-d8a2f9ba5571" />
      </div>
    </content>
  </entry>
</feed>
