tag:blogger.com,1999:blog-252236812024-03-08T08:22:43.536-06:00The eye sees only what the mind is prepared to comprehend<p>This blog will be about... Software Engineering... Object Oriented Analysis... Database Development, etc</p>
<p>
I believe that imagination is stronger than knowledge -- myth is more potent than history -- dreams are more powerful than facts -- hope always triumphs over experience -- laughter is the cure for grief -- love is stronger than death.
</p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.comBlogger111125tag:blogger.com,1999:blog-25223681.post-49473396614787107122012-11-30T00:53:00.000-06:002012-11-30T08:56:00.422-06:00SQL 2012 Bug: NVarchar changes where evaluation order<p>Today I arrived late at my house because my team had a big problem migrating a stored procedure from SQL Server 2000 to SQL Server 2012. Countless hours lost trying to find out what we could be have been doing wrong...<br><br>On the end, in turned out, all the trouble was because of a bug in SQL Server 2012.<br><br>Here is what we found, lets say you have a table "T_1":<br><br><span style="font-family: courier new, courier, monospace">CREATE TABLE [dbo].[T_1](<br>[C] [nvarchar](50) NULL<br>)</span><br><span style="font-family: courier new, courier, monospace"><br></span>Now, lets say you add some rows to it.<br><br><span style="font-family: courier new, courier, monospace">INSERT INTO [dbo].[T_1] ([C]) VALUES ('P')</span><br><span style="font-family: 'Courier New', courier, monospace">INSERT INTO [dbo].[T_1] ([C]) VALUES ('Q')</span><span style="font-family: courier new, courier, monospace"><br></span><span style="font-family: 'Courier New', courier, monospace">INSERT INTO [dbo].[T_1] ([C]) VALUES ('R')</span><span style="font-family: courier new, courier, monospace"><br></span><br><br>Now write this query:<br><br><span style="font-family: courier new, courier, monospace">select * from T_1 where ISNUMERIC(C)=1 and CONVERT(float,C)=0.0</span><br><br>And you will get a nice error message:<br><br><br><span style="font-family: arial, helvetica, sans-serif; color: red">Msg 8114, Level 16, State 5, Line 1</span><br><span style="font-family: arial, helvetica, sans-serif; color: red">Error converting data type nvarchar to float.</span><br><br>¿What is the bug? You shouldn't be getting an error message! the "Error converting data type nvarchar to float." is generated by the CONVERT(float,C)=0, but SQL should never run that code because ISNUMERIC(C)=1 evaluates to false, and if the first part of an "and" is false, there is no point in executing the second part, <b>the result is going to be false anyway</b>.<br><br><br>Well you might say, maybe SQLServer has always done things this way... well, no, it has not. In SQL 2000, that query executes correctly!<br><br>And in SQL 2012, there is a workaround, just change from nvarchar to varchar:<br><br><br><span style="font-family: courier new, courier, monospace">CREATE TABLE [dbo].[T_2](<br>[C] [varchar](50) NULL<br>)</span><br><br><br><span style="font-family: courier new, courier, monospace">INSERT INTO [dbo].[T_2] ([C]) VALUES ('P')</span><br><span style="font-family: 'Courier New', courier, monospace">INSERT INTO [dbo].[T_2] ([C]) VALUES ('Q')</span><span style="font-family: courier new, courier, monospace"><br></span><span style="font-family: 'Courier New', courier, monospace">INSERT INTO [dbo].[T_2] ([C]) VALUES ('R')</span><span style="font-family: courier new, courier, monospace"><br></span><br><span style="font-family: courier new, courier, monospace"><br></span><br>Now if we write (note we are now working with the table T_2 that uses varchar) :<br><br><span style="font-family: 'Courier New', courier, monospace">select * from T_1 where ISNUMERIC(C)=1 and CONVERT(float,C)=0.0</span><br><br>We will get <b>no error.</b><br><b><br></b>Why is this happening then?<br><br>It seems to be a bug in SQL Server 2012 execution plan:</p> <p> </p> <p><a href="http://lh4.ggpht.com/-7R59wPKcfTU/ULhfalmdpII/AAAAAAAAAEQ/KlQrNSvEH28/s1600-h/image%25255B3%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://lh5.ggpht.com/-1UBFJoA-h90/ULhfbYbf1II/AAAAAAAAAEY/tEuCbE0KxWU/image_thumb%25255B1%25255D.png?imgmax=800" width="327" height="171"></a></p> <p> </p> <p>As you can see in the image, SQL 2012 <strong>inverts the predicate</strong> when working with nvarchar!</p> <p>On the other hand, for T_2 the table with a varchar column:</p> <p><a href="http://lh6.ggpht.com/-N9lXn09Eq1w/ULhfcO79YKI/AAAAAAAAAEg/rIKu3r8k0lw/s1600-h/image%25255B7%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://lh4.ggpht.com/-pAx0TRpx4rk/ULhfdPYvhbI/AAAAAAAAAEo/F9DqY4wzHqA/image_thumb%25255B3%25255D.png?imgmax=800" width="327" height="147"></a></p> <p>As you can see, here the the order of evaluation is preserved, and things work like they should.</p> <p>Now what can we do if we are not allowed to change the type of the column in the table?</p> <p>I tried using a CTE, but it does not work, the execution plan is the same faulty one:</p> <p><font face="Courier New">with V_1 as (select * from T_1 where ISNUMERIC(C)=1)<br>select * from V_1 where CONVERT(float,C)=0.0</font></p> <p>Using a subquery also fails:</p> <p><font face="Courier New">select * from (select C from T_1 where ISNUMERIC(C)=1) V_1 where CONVERT(float,C)=0.0</font></p> <p>We can change the type explicitly to varchar in the query, <strong>that fixes the problem</strong>:</p> <p><font face="Courier New">select * from T_1 where ISNUMERIC(C)=1 and CONVERT(float,convert(varchar(100),C))=0.0</font></p> <p>But, what if we actually have an Unicode string with chars that will get damaged by a conversion to varchar?</p> <p>I shouldn’t be a problem…. What do you think? any other workaround?</p> <p>UPDATE: I have submitted this bug to Microsoft Connect, <a href="https://connect.microsoft.com/SQLServer/feedback/details/772990/nvarchar-changes-where-conditional-evaluation-order">click here to see my bug report</a></p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-87579035226738093252010-10-19T15:54:00.001-05:002010-10-19T15:55:27.872-05:00Web Slices: you need to use Alternative Display Source or javascript will not work<p>If your WebSlices use the <strong>Basic Web Slice</strong> model, javascript will <strong>not</strong> work (this file is WebSlice.html):</p> <html xmlns="<a href="http://www.w3.org/1999/xhtml"">http://www.w3.org/1999/xhtml"</a>> <br /><head runat="server"> <br />    <title></title> <br /></head> <br /><body> <br /> <p><div class="hslice" id="SliceID"> <br />     <span class="entry-title">Title of the web slice</span> <br />     <div class="entry-content">Preview of the <a href="#" onclick="document.getElementById('Message').innerHTML='Hello'; return false;">web</a> slice <br />       <div id="Message"></div> <br />     </div> <br />     <p> <br />     Hola Rebanadas Web! <br />     </p> <br />  </div></p> <p></body> <br /></html></p> <p> you have to use <strong>Alternative Display Source</strong> to make javascript work (this file is WebSlice.html):</p> <p><html xmlns="<a href="http://www.w3.org/1999/xhtml"">http://www.w3.org/1999/xhtml"</a>> <br /><head runat="server"> <br />    <title></title> <br /></head> <br /><body></p> <p><div class="hslice" id="SliceID"> <br />      <span class="entry-title">Title of the web slice</span> <br />      <a rel="entry-content" href="AlternativeDisplay.html" style="display:none;">Alternative Display Source</a> <br />      <p> <br />      Hola Rebanadas Web! <br />      </p> <br />   </div></body> <br /></html></p> <p> </p> <p>and in the file AlternativeDisplay.html you put the code that use to be in WebSlice.html (and that needs to use javascript):</p> <p><html xmlns="<a href="http://www.w3.org/1999/xhtml"">http://www.w3.org/1999/xhtml"</a>> <br /><head runat="server"> <br />    <title></title> <br /></head> <br /><body> <br />     <div class="entry-content">Preview of the <a href="#" onclick="document.getElementById('Message').innerHTML='Hello'; return false;">web</a> slice <br />        <div id="Message"></div> <br />      </div> </p> <p></body> <br /></html></p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-14698875760620204452010-08-02T15:54:00.001-05:002010-08-03T13:42:23.865-05:00How to migrate your local user profile to the domain<p>Apparently, there is no easy way (<a href="http://www.ehow.com/how_5315456_convert-local-account-domain-account.html">this</a> or <a href="http://msmvps.com/blogs/clustering/archive/2004/10/06/15096.aspx">this</a> do NOT work), there use to be a tool to do this (Moveuser.exe), but it <a href="http://support.microsoft.com/kb/930955">stopped working with Windows Vista</a>.</p> <p>The way to do it now is to write a VBScript that uses WMI, happily, I have found someone that has already done it <a href="http://tacklebox.cns.ohiou.edu/Moveuser/">here</a>.</p> <p>It basically seems to be using the <a href="http://msdn.microsoft.com/en-us/library/ee886408%28v=VS.85%29.aspx">ChangeOwner Method of the Win32_UserProfile Class</a>, one problem I have found so far is that if the profile to be “moved” in to the domain is heavy (many Gbytes of weight) the ChangeOwner method can take a really long time to do its job. A possible solution then is to move the files outside of the profile dir, run the migration process, and copy the files back (you might need to change the permission information of those files to be able to copy them back)</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-6918565208983386152010-07-16T17:35:00.001-05:002010-07-22T08:48:16.160-05:00How to move C:\Users to D:\Users<p>There is no user friendly way to move your C:\Users folder to D:\ but the user unfriendly way to do it is not too hard (<em>it was a little hard to discover, I learned how to do this when I decided that I wanted to have C:\Winnt\Profiles dir at a different location, after I lost most of my data when my main disk failed, back when Windows NT 4.0 was the latest and greatest OS from Microsoft</em>)</p> <p>Basically, after you installed Windows (this instructions are for Windows 7 but the general approach is valid since Windows NT 4.0)  you have to:</p> <ol> <li>Login with “WhatEverIsYourUserName” account. </li> <li>Run the Command Prompt (cmd.exe) as an Administrator </li> <li><a href="http://lh4.ggpht.com/_yBIcMbSPmVc/TEYX6A5Z9LI/AAAAAAAAADA/8KJSxY90MfA/s1600-h/image%5B3%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_yBIcMbSPmVc/TEYX6RvhxhI/AAAAAAAAADE/1zreUJtONew/image_thumb.png?imgmax=800" width="244" height="153" /></a> </li> <li>Copy the C:\Users\ folder to D:\Users using <a href="http://en.wikipedia.org/wiki/Robocopy">Robocopy</a> <br /> <pre>robocopy C:\Users D:\Users /E /COPYALL /R:0 /Z /XJ</pre><br /> </li><br /><br /> <li>Open <a href="http://en.wikipedia.org/wiki/Windows_Registry">regedit</a> and modify the ProfileList entry so that it looks like this: </li><br /></ol><br /><br /><p><a href="http://lh5.ggpht.com/_yBIcMbSPmVc/TEDiqlmqS-I/AAAAAAAAACQ/KjAVgo-ziWw/s1600-h/image%5B3%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_yBIcMbSPmVc/TEDirMm-oxI/AAAAAAAAACU/vL7KsrR-liw/image_thumb%5B1%5D.png?imgmax=800" width="800" height="269" /></a> </p><br /><br /><ol><br /> <li>Create a new (<em>Administrator</em>) Windows account that you will use to test the configuration change <br /><br /> <br /> <a href="http://lh4.ggpht.com/_yBIcMbSPmVc/TEDirWNyETI/AAAAAAAAACY/CmHJ0GfTKQU/s1600-h/image%5B11%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_yBIcMbSPmVc/TEDir7BU77I/AAAAAAAAACc/_x6JOHQB5q8/image_thumb%5B5%5D.png?imgmax=800" width="509" height="424" /></a> </li><br /><br /> <li>Restart </li><br /><br /> <li>Login with the “Test” Windows account </li><br /><br /> <li>Delete C:\Users </li><br /><br /> <li>See that the  Start menu still works (<strong>if you made a mistake, your Start menu is now empty</strong>) </li><br /><br /> <li>Delete the registry Key for your “WhatEverIsYourUserName” account (if you still want to use it). (<em>The registry Key is the yellow folder with the S-1-5… name that contains the value ProfileImagePath that points your now obsolete C:\ folder, remember,  you have to delete the whole folder/key, not just the ProfileImagePath value</em>): <br /><br /> <br /> <img border="0" alt="[image[23].png]" src="http://lh4.ggpht.com/_yBIcMbSPmVc/TEDkGfR2fdI/AAAAAAAAACw/FVJ8qj0VRto/s1600/image%5B23%5D.png" /> </li><br /><br /> <li>Log out </li><br /><br /> <li>Now log in with your “WhatEverIsYourUserName” account </li><br /><br /> <li>If you take a look at the registry now, it will look like this (The value in ProfileImagePath now starts with “D:\” instead of “C:\”): <br /> <br /> <a href="http://lh4.ggpht.com/_yBIcMbSPmVc/TEDkHLpXMKI/AAAAAAAAAC4/A8azMIUZF90/s1600-h/image%5B27%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_yBIcMbSPmVc/TEDkHpi7iGI/AAAAAAAAAC8/Db52Pk70ftI/image_thumb%5B13%5D.png?imgmax=800" width="644" height="212" /></a> </li><br /><br /> <li>Now you can delete the test account. </li><br /></ol><br /><br /><p>And that is it, now the users accounts live in D:\Users\</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-85840000218004984542010-07-08T11:45:00.006-05:002010-11-11T12:53:37.414-06:00Recover sa accountToday, a friend from the office locked himself out of SqlServer 2008 R2 Express, somehow he managed to remove the windows Administrator account form the list of sysadmin accounts in the SqlServer express installed in a development server. <br />
<br />
I thought there was no way to recover from a mistake a like that, but another friend found the way and gave us a link <a href="http://www.eggheadcafe.com/software/aspnet/34150451/enable-the-sa-account-or.aspx">with the solution</a>. <br />
<br />
Basically, we need to stop the SqlService, and restart it in "single user mode" and "minimal config mode" <br />
<br />
<pre>sqlservr.exe -m -r -s SQLEXPRESS
</pre><br />
And the open another command window and run this commands:<br />
<br />
<pre>osql -E -S .\SQLEXPRESS
exec sp_password @new='changeme', @loginame='sa'
go
alter login sa enable
go
exit
</pre><br />
And that was it. Remember, without the special "-m -r" options, the osql commands will fail.<br />
<br />
<b>NOTE</b>: In case your SQL Server is <b>not </b>configured to use <b>Mixed Mode </b>for authentication, you may also need to make <a href="http://support.microsoft.com/kb/285097">some modification to the registry settings</a>.<br />
<br />
Basically you need to find the registry entry for the instance:<br />
<br />
Default instance: <br />
<pre>HKLM\Software\Microsoft\MSSqlserver\MSSqlServer\LoginMode
</pre><br />
Named instance:<br />
<pre>HKLM\Software\Microsoft\Microsoft SQL Server\Instance Name\MSSQLServer\LoginMode
</pre><br />
<div class="indent"><span class="userInput">And change the value of LoginMode to <b>2</b>.</span></div>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-83676470168982307182010-03-15T19:18:00.002-06:002010-05-06T12:07:25.312-05:00Formulating Expressions a Step at a Time: Lazy Evaluation<p>I am reading this <a href="http://my.safaribooksonline.com/9780596155865">book</a>, and I found the section with the title “Formulating Expressions a Step at a Time” particularly interesting:</p> <p>First, the book shows you this the query for the sentence "Get pairs of supplier numbers such that the suppliers concerned are collocated (i.e., are in the same city)" written in <a href="http://en.wikipedia.org/wiki/D_%28data_language_specification%29">Tutorial D</a>:</p> <pre>( ( ( S RENAME ( SNO AS SA ) ) { SA , CITY } JOIN<br /> ( S RENAME ( SNO AS SB ) ) { SB , CITY } )<br /> WHERE SA < SB ) { SA , SB }</pre><p>And then it proceeds to show you how to write this query in a more readable (step by step) way:</p><pre>WITH ( S RENAME ( SNO AS SA ) ) { SA , CITY } AS R1 ,<br /> ( S RENAME ( SNO AS SB ) ) { SB , CITY } AS R2 ,<br /> R1 JOIN R2 AS R3 ,<br /> R3 WHERE SA < SB AS R4 :<br /> R4 { SA, SB }</pre><p>Finally, it shows you how to write this query in SQL:</p><pre>WITH T1 AS ( SELECT SNO AS SA , CITY<br /> FROM S ) ,<br /> T2 AS ( SELECT SNO AS SB , CITY<br /> FROM S ) ,<br /> T3 AS ( SELECT *<br /> FROM T1 NATURAL JOIN T2 ) ,<br /> T4 AS ( SELECT *<br /> FROM T3<br /> WHERE SA < SB )<br /> SELECT SA , SB<br /> FROM T4</pre><p>Thanks to the “<strong>with</strong>” keyword, both in SQL and in Tutorial D, it is possible to deal with this query in a “step by step” way, instead of having to deal with it a single hard to write and hard to read expression (<em>note that this is <strong>not</strong> a recursive query, so the <strong>with</strong> keyword is not being used for that in this examples</em>)</p><p>Sadly, so far I have been unable to find a equivalent for this syntax in Dataphor… While it is possible to write something like (I am not 100% confident the syntax is right, but I think it should give you the general idea):</p><pre>var R1 := S {SNO SA}<br />var R2 := S {SNO SB}<br />var R3 := R2 JOIN R3<br />var R4 := R3 WHERE SA < SB<br />select R4 {SA, SB}</pre><p>In Dataphor, the variables (R1, R2, etc) are not lazily evaluated, and therefore the performance is not as good, as in, for example, the SQL case (I ran a similar example in SqlServer, and the expressions were evaluated lazily, at the end, instead of one by one, resulting in far better performance). Maybe I am doing something wrong?</p><p>I wonder how hard would it be to make Dataphor generate SQL using the WITH keyword with those databases that support it (so far the latest versions of SQLServer (2008) and Oracle (10 & 11) seem to support this syntax)… I guess it is time to ask the Dataphor authors… </p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com1tag:blogger.com,1999:blog-25223681.post-27126683850121208722010-03-04T19:24:00.001-06:002010-03-04T19:25:37.794-06:00Null versus None<p><a href="http://en.wikipedia.org/wiki/None">None means Nothing</a>, Nothing is a concept that describes the absence of anything at all. Nothing is sometimes confused with Null, but they are very different concepts because Nothing means absence of anything, while Null means unknown (you do not know if there is a thing or not). </p> <p>For Nothing, the normal Two valued logic applies (<em>Nothing=Nothing : true, Nothing = Something : false</em>), for Null, <a href="http://en.wikipedia.org/wiki/Ternary_logic">Three valued logic</a> is necessary(Null=Null:<strong>unknown</strong>, Null=Something:<strong>unknown</strong>). Unfortunately, this 2 concepts have been used interchangeably without much thought, to point where the most common use for Null in relational databases is to mean Nothing (even when Null was designed to represent unknown by Codd). This confusion is aggravated by the fact that many mainstream application languages (Java, C#, C, etc) use the <strong>null</strong> keyword to mean uninitialized variable which easily maps to the interpretation that null means the variable is pointing to "nothing" (no object). </p> <p>But for databases, Null was not invented to represent nothingness, <a href="http://en.wikipedia.org/wiki/Null_%28SQL%29">was invented to represent that the value of something was not known</a> (maybe be something, maybe nothing, we just <strong>do not know</strong>).</p> <p>Now that Chris Date wants Null to be removed from Relational Databases, so that the incongruence and confusion brought in by Three valued logic is eliminated, the developers, accustomed to use Null to represent Nothing, resist to the idea asking: How am I going to represent the fact that a Person is not married? I use to do that by marking the Marriage Date? as a nullable Date. Now what? I need to split the table into 2 tables just to represent the fact that the Marriage Date? is not mandatory? That of course seems like the obvious, elegant (<em>if <strong>extremely cumbersome</strong> answer</em>). But the practical developer refuses to get into that trouble, it is just too much effort, it is simple easier to continue using Null. But... what about Nothing? why not just simply add "Nothing" as a possible value for to the Date domain? That way it is possible to say that the Person has no Marriage Date?, and still stay inside the realm of two valued logic. </p> <p>Is this solution, in any way in conflict with <a href="http://www.thethirdmanifesto.com/">The Third Manifesto</a>? I really would like to know… I wonder what will be the opinion of the community in the  <a href="http://c2.com/cgi-bin/wiki?NullVersusNone">C2 Wiki</a></p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com1tag:blogger.com,1999:blog-25223681.post-73248068617812519942010-02-25T23:50:00.001-06:002010-09-11T10:38:56.980-05:00Find me a circle<p>A circle is a simple shape of Euclidean geometry consisting of those points in a plane which are equidistant from a given point called the center. The common distance of the points of a circle from its center is called its radius. </p> <p>But Circles can not, and do not exist in reality, anything that seems to be a Circle is actually a polygon with a very high number of sides... the closest to a Circle that we can get is to have each side of the polygon the size of <a href="http://en.wikipedia.org/wiki/Planck_length">quantum distance</a>. </p> <p>Just try and draw a Circle in <a href="http://www.gimp.org/">The Gimp</a> (or in <a href="http://www.getpaint.net/">Paint.NET</a>).</p> <p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_yBIcMbSPmVc/S4dmNky2j1I/AAAAAAAAAB0/aagx0P6c05Q/image_thumb%5B18%5D.png?imgmax=800" width="56" height="56" /></p> <p>Now zoom 600% in to it. You will see it is actually a polygon, composed of thousands of little pixels, the same is true for "circles" in reality, they are composed of thousands of little quantum pixels. </p> <p><a href="http://lh6.ggpht.com/_yBIcMbSPmVc/S4dmOJc6vnI/AAAAAAAAAB4/4gX-dz28gDY/s1600-h/image%5B29%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_yBIcMbSPmVc/S4dmP0wvgpI/AAAAAAAAAB8/ig44rkT6HYk/image_thumb%5B19%5D.png?imgmax=800" width="244" height="243" /></a> </p> <p>So, Circles do not exist, they are just a math abstraction. And that is why we end up needing unattainable numbers like Pi to deal with the area inside of a circle... because there is no such thing as the area inside of a circle (because there are no circles). </p> <p>The area inside of anything in reality, that looks like a circle, can be calculated by dividing it in "quantum pixel areas", and the adding those areas to get the total area inside of the supposed circle. Now, that would require a lot of effort, that is the reason we believe in circles, because they are a very useful abstraction (even if it is an abstraction that fails and produces Pi as a result of its failure) </p> <p>Among Archimedes mathematical accomplishments is the computation of pi, he used the method of exhaustion as a way to compute the area inside a circle by filling the circle with a polygon of a greater and greater number of sides. The quotient formed by the area of this polygon divided by the square of the circle radius can be made arbitrarily close to Pi as the number of polygon sides becomes large, proving that the area inside the circle of radius r is Pi * (r*r),Pi being defined as the ratio of the circumference to the diameter. </p> <p>When a circle's diameter is 1 unit, its circumference is Pi units. Why Pi is such simple concept but such a strange "number"? because Circles do not exist, Pi is an example of a Mathematics (Geometry?) abstraction leak. </p> <p>As we increase the number of sides, we approximate more, and more to the circle, but we can never really have a circle. </p> <p><a href="http://lh5.ggpht.com/_yBIcMbSPmVc/S4dlEtZ7SYI/AAAAAAAAACA/8_sOxKdBwKA/s1600-h/image%5B23%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_yBIcMbSPmVc/S4dlFghxPVI/AAAAAAAAACE/f8lJnGooZg8/image_thumb%5B17%5D.png?imgmax=800" width="504" height="171" /></a> </p> <p>This is why we can never know the complete value of Pi, because there is now way to have a circle in a discrete quantum based reality, "circles" are a good model for this things with too many sides to count easily, but circles are just a model, not a reality</p> <p></p> <p></p> <p></p> <p>That is something, that as software developers we should always keep in mind: The Map (the Model) is not The Territory (the Reality)</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-87932513964055279632010-01-26T23:11:00.001-06:002010-01-26T23:20:00.677-06:00Pagination in Dataphor<p>First I created this operator: </p> <pre>create operator GetNext(var AID :Integer) : System.Integer <br />begin <br />AID:= AID+1; <br />result:=AID; <br />end ;</pre><br /><br /><p>and then I used it: </p><br /><br /><pre>var id := 0; <br />select SomeTable add {GetNext(id) rowid}; </pre><br /><br /><p>It is nice, but it would be better if there were a way to do this without having to create an operator myself (it should already include one that does this) <br /> <br />Now If I want to do pagination, all I have to do is write:</p><br /><br /><pre>var id := 0; <br />select SomeTable add {GetNext(id) rowid} where rowid between 2 and 5;</pre><br /><br /><p>That will return rows between 2 and 5 from the “SomeTable” table.</p><br /><br /><p>Now one of the most interesting feaures about Dataphor, are relvars (relational variables), that make it possible to do this:</p><br /><br /><pre>var SomeComplexQuery := SomeTable where …...<br />var id := 0;<br />select SomeComplexQuery add {GetNext(id) rowid} where rowid between 2 and 5;</pre><br /><br /><p>That way, pagination can be added to a query of arbitrary complexity with minimum effort.</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-8090423429667283432009-12-19T07:31:00.001-06:002009-12-19T11:41:39.499-06:00Dataphor: How to create a table with a primary key<p>Creating a table in Dataphor is easy:</p> <pre><p>create table Debt <br />{ <br />    ID : Integer,<br /><br />    key { ID },<br />};</p></pre><br /><br /><p>That translates (when using MSSQL as storage) into (if we ask MSSQL to provide us with the SQL DDL):</p><br /><br /><pre><p>CREATE TABLE [dbo].[Debt]( <br />    [ID] [int] NOT NULL <br /><br />)<br /></p><p> </p><p>CREATE UNIQUE CLUSTERED INDEX [UIDX_Debt_ID] ON [dbo].[Debt] <br />( <br />    [ID] ASC <br /><br />)</p></pre><br /><br /><p>It is important to note that D4 does not have the concept of a <strong>primary key</strong>, and that the “key” keyword results in a unique index, that while for all uses and purposes can work as a primary key, it is not recognized as such by MSSQL. It is possible to have several different “keys” in a Dataphor table.</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-3376645436004916422009-11-24T06:36:00.002-06:002010-02-18T18:45:42.801-06:00Scala is not mature enough for Weld<p><a href="http://www.scala-lang.org/">Scala</a> is not mature enough for <a href="http://www.seamframework.org/Weld">Weld</a> (<em>or any other reflection related operation</em>). Turns out that one of the feature that make Scala so interesting (<em>closures</em>) is also a source of incompatibility (<em>the internal anonymous class files that generate are invalid</em>) </p> <p>So, if for example, I have a code like this (inside any method in a class): </p> <pre>val classNames = Conversions.convertList(names).reduceLeft[String] { (acc, n) =><br /> acc + ", " + n<br />}</pre><br /><br /><p>That generates an inner class that makes Java reflection unusable: </p><br /><br /><pre>java.lang.IncompatibleClassChangeError: com.googlecode.solder.dwr.WeldContainer and com.googlecode.solder.dwr.WeldContainer$$anonfun$getClasses$1 disagree on InnerClasses attribute<br /> at java.lang.Class.getDeclaringClass(Native Method)<br /> at java.lang.Class.getEnclosingClass(Class.java:1085)<br /> at java.lang.Class.getSimpleBinaryName(Class.java:1220)<br /> at java.lang.Class.getSimpleName(Class.java:1112)<br /> at org.jboss.weld.util.Names.typeToString(Names.java:251)<br /> at org.jboss.weld.util.Names.classToString(Names.java:263)<br /> at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:151)<br /> at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:133)<br /> at org.jboss.weld.resources.ClassTransformer$2.call(ClassTransformer.java:72)<br /> at org.jboss.weld.resources.ClassTransformer$2.call(ClassTransformer.java:68)<br /> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)<br /> at java.util.concurrent.FutureTask.run(FutureTask.java:138)<br /> at org.jboss.weld.util.collections.ConcurrentCache.putIfAbsent(ConcurrentCache.java:125)<br /> at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:67)<br /> at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:59)<br /> at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:86)<br /> at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:134)<br /> at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:367)<br /> at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:158)<br /> at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)<br /> at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)<br /> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)<br /> at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)<br /> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)<br /> at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)<br /> at org.apache.catalina.core.StandardService.start(StandardService.java:516)<br /> at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)<br /> at org.apache.catalina.startup.Catalina.start(Catalina.java:578)<br /> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br /> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br /> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br /> at java.lang.reflect.Method.invoke(Method.java:597)<br /> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)<br /> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)</pre><br /><br /><p>Apparently this is a <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1167">known problem</a> since 2008-08-03 (16 months so far) and AFAIK they are not in a hurry to fix it. </p><br /><br /><p>I guess that means I am going to have to start removing Scala from <a href="http://code.google.com/p/solder/">my Weld project</a>. I am sad about this because Scala is IMO a really beautiful language, that feels much cleaner than Java, but if the <tt>.class</tt> files that it generates are not compatible with the rest of Java... it is just useless for me. </p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-4225591334500256412009-11-16T13:10:00.004-06:002010-02-18T18:46:41.935-06:00Playing with Weld and Scala to create a new framework for JSPsToday I built my first "serious" example using <a href="http://seamframework.org/Weld">Weld</a> and <a href="http://www.scala-lang.org/">Scala</a>.<br />You can take a look at it in <a href="http://code.google.com/p/solder/">here.</a><br />So far, Weld looks like really good framework, I am still not able to say that it will replace Spring as my "glue framework", but that could certainly become true.<br />Scala also looks interesting (this also my first "serious" attempt at doing something with Scala), but the support for Scala in Eclipse is very fragile... the plug-in still needs a lot of polishing (no refatoring, no quickfixes, and the syntax coloring and cursor control sometimes goes crazy). I would not recommend the Scala plugin in Eclipse for "real work", but for hobbing is fine. (I wonder if the support for Scala in the Netbeans or the opensourced version of IntelliJ is better).<br /><a href="http://code.google.com/p/solder/"> </a>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-87623417673323777352009-11-06T20:14:00.003-06:002009-11-13T11:08:09.620-06:00JPA Myth: EclipseLink and Hibernate are compatible. Not true: Hibernate does NOT follow the JPA Spec<p>Please take a look at the Hibernate JIRA issue <a href="http://opensource.atlassian.com/projects/hibernate/browse/EJB-441">EJB-441</a>, seen it? </p> <p>Now, please tell me if this is correct:</p> <p>According to Gavin King (author of Hibernate) <a href="http://opensource.atlassian.com/projects/hibernate/browse/EJB-419">the JPA spec the @Column(nullable=false) is just a schema generation hint</a>, and therefore JPA implementations should NOT use it for object level validation.</p> <p>I think that means that if an entity object with a null property marked with the @Column(nullable=false) is persisted using entityManager.persist() it should crash with a java.sql.SQLException as the root exception, thrown when the "<strong>INSERT</strong>" statement failed after it was sent to the database by the JDBC driver (<em>as it happens in EclipseLink</em>), and not because some implementation specific mechanism "pre-validated" it and prevented it from reaching the database (<em>as it happens in Hibernate thanks to org.hibernate.engine.Nullability.checkNullability</em>).</p> <p>Is that correct? Because I don’t know anymore!</p> <p>Lets say that is correct, does that means that the following is correct too?:</p> <p>Validation should be entirely the responsibility of the JSR-303, and the properties of an entity should <strong>only</strong> be checked for <strong>nullability</strong> before sending to the database <em>if a <a href="http://jcp.org/en/jsr/summary?id=303">JSR-303</a> implementation is there to indicate that</em>.</p> <p>Is that true? And if it is, then:</p> <p>What is exactly the difference between <em>@Basic(optional=<strong>true</strong>) and @Column(nullable=<strong>true</strong>)</em>? What happens when this 2 are applied to the same property, but they contradict each other? (As in : <em>@Basic(optional=<strong>false</strong>)</em> and @Column(<strong>nullable=true</strong>) or in <em>@Basic(<strong>optional=true</strong>)</em> and <em>@Column(<strong>nullable=false</strong>)</em></p> <p>I could not find a statisfactory answer in the spec documentation, would <strong>anyone</strong> be so kind as to resolve this issue? Because it Hibernate Forums they have decided that the way to deal with this inconsistencies and contradictions in Hibernate and in the JPA standard is <a href="https://forum.hibernate.org/viewtopic.php?t=995684&start=0&postdays=0&postorder=asc&highlight=entitymanager+persist">to plain ignore me</a> since May of 2009.</p> <p>As you can see I tried to raise the issue with 2 JIRAS, forum post and easy to reproduce unit-tests, but nothing seems to work… what should I do then?</p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com7tag:blogger.com,1999:blog-25223681.post-65326007782151738372009-10-26T08:07:00.001-06:002009-10-26T08:08:00.877-06:00How to have an auto incrementing assembly version number (Visual Studio)?<p>The assembly version did not auto increment… why? if I was using AssemblyVersion correcty? (The “*” indicates which part of the version string you want to have autoincremented)</p> <p>[assembly: AssemblyVersion("1.0.*")]</p> <p>Well, it turns out the problem is that I was also using:</p> <p>[assembly: AssemblyFileVersion("1.0.*")]</p> <p>All I had to do is comment the line with AssemblyFileVersion in my AssemblyInfo.cs file, and it started working:</p> <p>[assembly: AssemblyVersion("1.0.*")] <br /><font color="#808080">//[assembly: AssemblyFileVersion("1.0.*")]</font></p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-22524372582388737672009-09-15T11:14:00.001-05:002009-09-16T14:03:51.660-05:00Can I use JConsole to monitor an application through a firewall?<div></div> <p>A fragment of JConsole documentation (bold type emphasis added by me):</p> <p>The <tt>com.sun.management.jmxremote.port</tt> management property specifies the port where the RMI Registry can be reached but the ports where the <tt>RMIServer</tt> and<tt>RMIConnection</tt> remote objects are exported is chosen by the RMI stack. <strong>To export the remote objects (<tt>RMIServer</tt> and <tt>RMIConnection</tt>) on a given port you need to create your own RMI connector server programmatically</strong>, as described in the section</p> <p><i>Mimicking Out-of-the-Box Management Using the JMX Remote API</i> in the <a href="http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html#gdfvv">Java SE Monitoring and Management Guide</a>.</p> <p>I actually need to write code to be able to monitor a Java application through a firewall! Talk about an unfinished product! and Sun guys even have the nerve to act surprised angry when  people say that Java is over-engineered.</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-65345749378673322542009-09-08T09:39:00.005-05:002009-09-16T14:05:58.977-05:00Simplicity and Hubris: Web vs Enterprise Development<p align="justify">I would find it really funny that most people <a href="http://stuffthathappens.com/blog/2008/03/05/simplicity/">do not understand the difference</a> between <a href="http://unqualified-reservations.blogspot.com/2009/07/wolfram-alpha-and-hubristic-user.html">intelligent and control interfaces</a> if would not mean that lots of time and money are wasted trying to make intelligent interfaces work as control interfaces, or Web 2.0 Internet solutions work for Enterprise intranet problems. <br /> <br />It is the typical "since Google/Apple/Facebook/Twitter/SomeFreeAndPublicWebSite uses it for X/Y/Z/Q it should be great for the system I am building" syndrome. <br /> <br />Well, it might be great for them when they are trying to solve the X/Y/Z/Q problem, but as it turns out, many developers do not work at places that build the kind of systems this companies build, and are not trying to solve the kind of problems this companies are trying to solve. <br /> <br />Some people think that since our problems do not seem as technologically  impressive as those targeted by free public websites they must be easier, or that since a solution worked for the super huge public web site X then it should also work for the tiny intranet system we are building, well, the truth is that most of the times this solutions do not help at all. Please don't get me wrong, some of their ideas are usable, but we need to remember that in the dreaded Intr<strong>a</strong>net Enterprise development world rules are very different: <br /></p> <ul> <li> <div align="justify">We do <span style="font-weight: bold">not have huge hardware resources </span>at our disposal</div> </li> <li> <div align="justify">We do <span style="font-weight: bold">not have a huge budget </span>and the hiring power to get the best and only the best experts to work with us</div> </li> <li> <div align="justify">Our systems are <span style="font-weight: bold">not </span>of the"just register in this form this once and after this use the site with the mouse" kind, our users <span style="font-weight: bold">hate the mouse</span>, because they are going to be capturing data all day, and for that, <span style="font-weight: bold">the keyboard is king </span>(and the mouse is irrelevant)</div> </li> <li> <div align="justify">We need to <span style="font-weight: bold">interact directly with "special hardware"</span> (such as scanners, printers, finger print readers etc) and browsers do not know how to talk to those, <span style="font-weight: bold">a browser can not even print with precision</span> without help from <span style="font-weight: bold">Acrobat Reader</span>.</div> </li> <li> <div align="justify">We need the <span style="font-weight: bold">behavior </span>of our systems to be <span style="font-weight: bold">consistent and always the same </span>(Web Search engine users do not care if the search results present different information or the same information in different order as long as the "relevant" stuff is in the first pages, Enterprise users expect search results to be exactly the same as last time, unless they have done something to alter that, and when they do, the change they expect is predictable)</div> </li> <li> <div align="justify">Our users want <span style="font-weight: bold">access to their data now</span>, and do not care for excuses like "sorry but there is no access to the super massively great cloud because our infinitum connection/cable modem/whatever is failing"</div> </li> <li> <div align="justify">Our users want <span style="font-weight: bold">data to be confidential </span>(although they <span style="font-weight: bold">do not even understand the meaning of security and its costs</span>). Having all your data "in the cloud" sounds great, until the country where the clouds exists decides that it wants to apply "economic sanctions" to yours and begins by forbidding you access to the data in the cloud because the company that owns it is controlled by their laws.<span style="font-weight: bold"> The day I see Google store its internal mission critical strategic information in Amazon's servers or vice-versa is the day I will believe that the Cloud is a safe place to store that kind of information.</span> <br /></div> </li> </ul> <p align="justify">All those "Web 2.0" companies have done little to help this stuff (In fact, they have created lots of problems, by forcing us intranet Enterprise developers to use primitive runtime platforms (web browsers) to deliver our applications . It is not that they are evil, it is just that they are not targeting the kind of problems Enterprise developers need to solve. And I hate when I see people recommending approaches that worked fine for this companies for problems that just can not be solved with them. </p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-84420596838887900482009-08-30T22:47:00.001-05:002009-08-30T22:49:58.194-05:00How can I use PowerShell to delete all the files with a particular extension<p>Just run the command:</p> <pre>get-childitem rootdir -include *.extension -recurse | foreach ($_) {remove-item $_.fullname}</pre><br /><br /><p>And that is it. Thanks <a href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct06/hey1023.mspx">Scripting Guy</a>.</p><br /><br /><p>This is specially useful for me because very often, after I make changes in project reference in VS.NET some .dll files are left “out of sync” and and make parts your project act as if you did not re-compiled them. Sadly there is no easy way to tell VS.NET to get rid of all the .dll files that may be causing problems.</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-58320490500229293312009-08-30T12:55:00.003-05:002010-01-05T13:33:16.093-06:00Make that PDF secure: Toy Security<p>Make that PDF secure! That is one of the funniest requests I have received from a boss at one of my jobs… I answered by asking: “Secure? How secure?” and my boss told me: well, I want the user to be unable to modify it, copy it or print it.</p> <p>Why do I say that this request is funny? Well, because this was a web application, the typical HTML+JavaScript+JSON/XML+Choose-the-Server-Side-Tech-You-Like application. Now, of course you can not really “display” a PDF with that technology, you need to have a PDF viewer like Acrobat Reader so that your user can “see” the PDF, and, of course, all the indented users for this intranet web applications had it installed.</p> <p>My boss had read that Acrobat had an option to make a PDF read-only with a password, and that it was even possible to “protect” the document so that it could not be printed… sounds like the solution… no? well, first of all , if you can see it, it means that the structure of the document is available to the reader, which means that the document is not really encrypted, and that means the any tool capable of reading and writing .pdf will be able to remove the password without even worrying about trying to guess it using a brute force (or even an heuristic) attack.</p> <p>What can you do then? Well you can actually encrypt it… that will prevent the user from modifying it… but it will also prevent it from being seen… unless the user has the password… which also means he/she can un-encrypt the document and remove the protection.</p> <p>There is no thing that can be done then? well, if security of this document is actually a priority, you could create a custom reader unable to print… that should work should it? Well, not exactly, the user can always just press the “printscreen” key that is available in all keyboards and get a copy of the document… I have read that it is possible to install some DRM level protections in some OSes that could detect that, but when you take it to that level, a new questions is brought in to the table: is it worth the cost? does the document actually needs that kind of security? if not, it means this is a case of toy security, your boss just wants this feature because it sounds like a feature that “would impress the user” but not something that is really required by the application, he/she has not really give this features (and its implications) some thought.</p> <p>Lets say that at my boss says: “Yes, that level of security is really needed” (very unlikely, but could happen), well, that brings in the next question: what if the user just goes, takes one of then great modern digital cameras, and takes the picture from the screen monitor? (and then spends a few days retouching it in the Gimp or Photoshop).That means it will be able to steal the information, and even be able to print it. How can you prevent that from happening? How can you make a document that is actually secure even after that?</p> <p>Well, the answer is that if what you want to prevent is the theft of information, the only way is to not allow the user to see the document, if the user can see it, the user can copy it, one way of another (there is even the possibility that the user has photographic memory) and there is no way you can make the user “forget” that he saw the document.</p> <p>But lets say that what you want to do is detect if a document is a forgery that is, right at the moment that you see it printed on a paper, you want to be able to know if it came from your system (and it was altered by someone after it was copied or not)… the only way to do that, is embedding the same information that the document has in a 2D barcode (including something that uniquely identifies the document), and also embed in another barcode a digital signature that is able to validate the data. That is the only way I know you can demonstrate that the document is a forgery… obviously, by the time you have explained this to you boss (if he/she has managed to make sense from it) the most likely thing is that he/she is unwilling to ask you to do all that it is needed to achieve this goal, mostly because it is nothing like what he/she wanted in the first place: it something much more abstract, and requires a barcode reader to verify the document.</p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-42280634788046868762009-08-22T13:59:00.001-05:002009-08-22T14:01:51.983-05:00How to find files containing a string with Powershell<p>A while ago a wrote a small post to remind me of <a href="http://luxspes.blogspot.com/2008/01/how-to-find-files-containing-string.html">How to find files containing a string in Unix</a>.</p> <p>Now, I have learned how to do pretty much the same thing but with <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">Powershell</a>:</p> <pre>get-childitem {directory} –include {file pattern} -recurse | select-string -pattern "{string to Find}" -casesensitive</pre><br /><br /><p>You can write a path in {directory} or nothing to use the current directory.</p> Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-39179018807197721592009-08-14T08:58:00.001-05:002010-02-18T18:48:35.959-06:00Understanding REST Verbs and its relationship with CRUDI used to believe that REST verbs mapped to CRUD operations more or less like this: <p>GET -> Read <br />DELETE -> Delete <br />POST->Insert/Update <br />PUT ->Insert/Update</p> <p>Yes, I mapped both POST and PUT map to the same CRUD operation, but now I am not that sure this mapping is completely right… </p> <p>I have learned that the difference between POST and PUT is the URI, in PUT the URI identifies the entity enclosed with the request (the entity you wan to Insert or Update), while in POST the URI identifies the resource that will handle the enclosed entity.</p> <p>So, POST is like saying "Resource X, do something with this Entity", while PUT is more like "Insert/Update this Entity as Resource X"</p> <p>So POST is more like “Tell ‘X’ to do something with ‘E’” and that has really no direct mapping with a CRUD operation… of course, a POST, internally, can do one, or many of the CRUD operations using the data of the entity that is being passed to it as a parameter… Does that mean that POST maps to all CRUD operations?</p> <p>I guess I need to learn more about this…</p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-72056902981355908632009-06-13T11:10:00.002-05:002010-02-18T18:49:22.501-06:00Greenspuns Tenth Rule Of Programming and ADO.NET Data Services<p></p> <p>This is a humorous observation once made by <a href="http://c2.com/cgi-bin/wiki?PhilipGreenspun">Philip Greenspun</a>: </p> <dl><dt><br /></dt><dd><em>Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of <a href="http://c2.com/cgi-bin/wiki?CommonLisp">CommonLisp</a>.</em></dd></dl> <p>Or the database variant (<a href="http://c2.com/cgi-bin/wiki?GreencoddsTenthRuleOfProgramming" target="_blank">Greencodds Tenth Rule Of Programming</a>):</p> <blockquote> <p><em>Every sufficiently complex application/language/tool will either have to use a database or reinvent one the hard way</em></p> </blockquote> <p>I sometimes I feel that:</p> <p></p> <dd><em>Any sufficiently complicated procedural api contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of query language.</em></dd> <p></p> <p>Take for example, Web Services, they started a procedural thing where people created their own custom verbs for each service, then people realized that the semantics of HTTP constitutes a coordination language which is is sufficiently for any computational communication pattern, they realized that GET / PUT / POST / were enough for any program, but they again forgot about the query part, so after a while they <a href="http://luxspes.blogspot.com/2007/08/rest-dataservice-it-was-so-obvious.html" target="_blank">reinvented a query language</a> (like SQL) by creating create a query language based on URL query strings, as in <a href="http://msdn.microsoft.com/en-us/data/bb931106.aspx" target="_blank">ADO.NET Data Services</a>)</p> <p>Sometimes I feel all IT industry is like a dog chasing its own tail… we invent Cobol to handle data procedurally only to invent SQL to handle data declaratively only to invent stored procedures and web services to handle it procedurally to then invent REST to handle it declaratively I wonder what will be the name of the procedural silver bullet that will replace REST…</p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-16174094495391818452009-06-07T18:27:00.002-05:002010-02-18T18:50:03.154-06:00JEE Development Deployment: In the order wrong<p>So, you start a new we project in Eclipse 3.4.1 (or in Netbeans 6.5.1) and you run it, what happens is that basically the project gets copied in to the directory the application server uses to “keep” the applications it runs, then the application server starts, looks in to its directory for applications and starts your application, and you are able to see your project,if you are using Tomcat, or JBoss as lot people do, you will be able to see you web project on port 8080. Right? Wrong!</p> <p>what really happens is that then the application server starts and then the project gets copied in to the directory the application server uses to “keep” the applications it runs, then the IDE opens the web browser, that connects to the port 8080 using an url that includes the context of the application, its “name” so to speak, and then, the application server then realizes there a new application with that name in on its “directory applications” and starts it.</p> <p>Noticed the difference: </p> <p>What one typically believes it happens:</p> <ol> <li>the project gets copied in to the directory the application server uses to “keep” the applications it runs </li> <li>the IDE starts the application server </li> <li>looks in to its directory for applications and starts your application… </li> <li>now you will be able to see you web project on port 8080 </li> </ol> <p>What really happens:</p> <ol> <li>the IDE starts the application server </li> <li>the project gets copied in to the directory the application server uses to “keep” the applications it runs </li> <li>then the IDE opens the web browser, that connects to the port 8080 using an url that includes the context of the application </li> <li>the application server then realizes there a new application with that name in on its “directory applications” and starts it </li> </ol> <p>Now, why is it so important to understand in what order this happens?</p> <p>Well, because during development this processes is repeated again and again, until the application reach a point where it can be delivered to the customer the problem is that some times, one of the iterations of this process ends with an application so dysfunctional that it is able to crash the application server (and that will not stop until we get a <a href="http://luxspes.blogspot.com/2008/08/j2ee-application-servers-and-eclipse.html" target="_blank">real virtual machine for java</a>).</p> <p>But until we do get a better virtual machine, there is a more pressing problem, if we deploy an application that crashes the application server, the order in which the process is currently done makes it impossible to deploy the fixed version, unless we delete the previous version completely. Why do I say that: well lets analyze it, lets say we start with a fresh application server, where we have never installed our application:</p> <ol> <li>then the application server starts </li> <li>the project gets copied in to the directory the application server uses to “keep” the applications it runs </li> <li>then the IDE opens the web browser, that connects to the port 8080 using an url that includes the context of the application </li> <li>the application server then realizes there a new application with that name in on its “directory applications” and starts it </li> </ol> <p>This first version of our application is far from finished, but it does not have any bug capable of crashing the application server, so we add som more functionality, and we ask the IDE to run our application again, and what does the IDE do?:</p> <ol> <li>then the application server starts </li> <li>since the application server already knows it has our (failed) application installed, it does not need a visit from the browser to start it, in starts it immediately </li> <li>the project gets copied in to the directory the application server uses to “keep” the applications it runs, since the application is already there, only the changed files are copied </li> <li>if the changes are of a particular kind (alterations to web.xml for example) the applications server restarts the application so that it starts working with the new configuration </li> <li>then the IDE opens the web browser, that connects to the port 8080 using an url that includes the context of the application </li> </ol> <p>This second version of our application actually has a nasty bug, so after step 4, the application server hangs, and we are forced to kill it using the services provided by the operating system to deal with misbehaving processes, then we go back to our code, fix the problem, and we ask the IDE to run our application again, and what does the IDE do?:</p> <ol> <li>the IDE starts the application server </li> <li>since the application server already knows it has our (failed) application installed, it does not need a visit from the browser to start it, in starts it immediately </li> <li>The application server hangs. </li> </ol> <p>And that is it, the project files are never copied in to the directory the application server uses to “keep” the applications it runs, the critical problem here is that the IDE seems to wait for the application server to start correctly before copying the new files (it should copy them any way, that of course would not prevent it from hanging, but, after we had killed the process, the next time we ran the application server, if we had fixed the bug, it would not hang any more… but even then the behavior would be anti-intuitive, why the process is not like this is a mystery to me:</p> <ol> <li>the project gets copied in to the directory the application server uses to “keep” the applications it runs, since the application is already there, only the changed files are copied </li> <li>the IDE starts the application server </li> <li>since the application server already knows it has our (failed) application installed, it does not need a visit from the browser to start it, in starts it immediately </li> <li>Since we have fixed the bug, everything runs fine </li> </ol> <p>Do you know why it does not work like this? If you do, please… would you explain it to me?</p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-79174165132469117772009-04-23T08:07:00.002-05:002010-02-18T18:50:43.512-06:00Client side caching: Typical omission in server side component models?<p>It seems like a simple problem, but it is not (to day, I have not been able to find a way to do this without complex Javascript coding): </p> <ol> <li>You have chained comboboxes: County and State. </li> <li>You select USA in the Country combobox, and its 50 States are loaded in the States Combo (roundtrip to the server to fetch them) </li> <li>You select Mexico in the Country combobox, and its 32 States are loaded in the States Combo (roundtrip to the server to fetch them) </li> <li>Now you select USA in the Country combobox again... how do I tell the server side component framework that I do not want it to go to the server for them, since it went for them the last time I selected USA, I want it to use that as a cache and do not go for them until I tell it to do so? </li> </ol> <p>I provided this use case as just one illustration of a broader class of <b>client </b><b>side </b><b>caching</b> scenarios, support for this kind of scenario might not be need for all use cases, I might not be needed, for example, for user self-registration... sadly, I do not build that kind of application where I work now, the kind of application I have to build is the kind where the UI is used repeatedly: Yes, I build those dreaded "<strong>enterprise level</strong>" applications used internally by a big organization.</p> <p>This kind of optimization might seem silly for the typical web application where the user rarely uses the same form more than once, but for enterprise applications, this behavior can be the difference between an application that is perceived to be responsive and useful, and an application that is perceived to be cumbersome and useless.</p> <p>This can not be done with “user code” in AribaWeb. It can not be done in JSF, and it can not be done in ASP.NET. But is extremely easy to do if you code in JavaScript and use ExtJS, or Cappucchino.</p> <p>I wonder... Is this problem really impossible to solve in a declarative way using server side component models? is this really the insurmountable frontier for server based frameworks? or could someone create a trick that made this work? </p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-37181246816891487832009-04-18T22:08:00.002-05:002010-02-18T18:52:12.748-06:00Inversion of re-render (subscription based re-rendering): Why it can not be this way?<p>Anyone that has used <a href="http://www.jboss.org/jbossrichfaces/" target="_blank">Richfaces</a> knows that to rerender something, one needs to refer to it by id. </p> <p>Now, this is (in my opinion) an useful approach but also a very limited one, specially if componentization and code reuse are important goals during development </p> <p>Lets say I build a page (lets call it root page), that has a subview with a modalPanel, that includes a facelet component, that has a subview with modalPanel that includes another facelet component, and, when something is done here, I one another control, in the root page to be rerendered </p> <p>Now, I could of course pass along the ids of the component I need to be re-rendered, but... what if I need another component to be re-rendered too? do I pass along its id too? and what if the other component is also inside (a different) subview with a modalPanel, that includes a different facelet component... then all this id "passing" gets really messy, and creates dependencies in components that could otherwise be decoupled... and to make things worse, using meaningful ids in JSF is not considered a good practice, because meaningful ids (specially if used in name container like the subviews) rapidly increase the size of the pages (because they concatenate to ids of all the contained controls), contributing to bandwidth waste . </p> <p>Now, I have a proposal, what if re-rendering were to work in an "inversed" way: instead of "A" saying that it will re-render "B", we say that "B" will be re-rendered when something (maybe "A") says so by broadcasting event "C". </p> <p>This would mean that "A" no longer needs to know the name of "B" and "B" wouldn’t need to know the name of "A" either, it would only need to know that it should re-render itself it something, somewhere broadcasted the event "C" </p> <p>Am I making sense here? Is this doable? Or am I not seeing a major limitation in JSF technology that prevents this from being built? (I am no expert in JSF, so I really can not say, but I do know that an event subscription based re-rendering engine would be a really nice tool to have)</p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0tag:blogger.com,1999:blog-25223681.post-60780075546425898782009-03-16T10:43:00.003-06:002010-02-18T18:53:31.773-06:00EntityManager.persist: ¿What does/should it mean?<p>Lets say you are presented with the following JPA @Entity:</p> <pre><p>@Entity<br />public class Customer { </p><p> private Long id;<br />private String name;</p><p> @Id<br />@GeneratedValue(strategy=GenerationType.AUTO)<br />public Long getId() {<br /> return id;<br />} </p><p> public void setId(Long id) {<br /> this.id = id;<br />}<br /></p><p> @Column(nullable=false)<br />public String getName() {<br /> return name;<br />} </p><p> public void setName(String name) {<br /> this.name = name;<br />}<br />}</p> </pre><br /><br /><p>And then the following test</p><br /><br /><pre><p> @Test<br />public void persistCustomerInTransaction() throws Exception {<br /> factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);</p><p> EntityManager em = factory.createEntityManager();</p><p> em.getTransaction().begin();</p><p> Customer customer = new Customer();</p><p> em.persist(customer);em.getTransaction().commit();</p><p> em.close(); </p><p> }</p></pre><br /><br /><p>And the following question: Where does it crash?:</p><br /><br /><ol><br /> <li>At the line em.persist(customer); because the name is configured as nullable=false, and we are trying to persist the Customer instance with a null value in the name property </li><br /><br /> <li>em.getTransaction().commit(); because the name is configured as nullable=false, and we are trying to commit the transaction with a null value in the name property </li><br /></ol><br /><br /><p>Turns out… that the answer depends on the JPA provider you are using!!!! If using Hibernate, it crashes at em.persist, but if using EclipseLink, it crashes at em.getTransaction().commit.</p><br /><br /><p>Now, this might seem irrelevant, but it is in fact very important, because EclipseLink behavior means that constraint validations are deferred until the point where the transaction is committed, and that means that the developer has a lot more freedom to manipulate its persistent objects: they can be in any (possibly invalid) state while they are being manipulated by the business logic of the application, and they only have to be “right” the moment one needs to commit them to the database (not before), this is specially useful, for example, when building a wizard like UI (or a plain simple CRUD UI with support for full object graphs) with EclipseLink, I can persist my objects as soon as I want, and if want to, for example, run some validation logic at the end, all I have to do is ask the EclipseLink to give a list of all the objects that are going to be written in to the database, with Hibernate, the entityManager does not help me manage new object instances, I have to manage them myself.</p><br /><br /><p>What I find really surprising is that AFAIK there should be some kind of test to ensure that all JPA are compatible (<em>something called the TCK?),</em> and I think that this kind of discrepancy should be detected by those tests... shouldn't it?<br /><br /><br />I think this support for deferred validation, and an API to get will be inserted, will be updated or will be deleted, will be very important to really integrate JPA with something like JSR 330, so that validation can really integrate with the lifecycle of a persistent POJO. </p>Luxspeshttp://www.blogger.com/profile/16636706720254040664noreply@blogger.com0