<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6794514250333471393</id><updated>2012-02-16T12:04:53.843-06:00</updated><category term='Web Services Interoperability'/><category term='WCF'/><category term='Java'/><title type='text'>Isthmus Architecture</title><subtitle type='html'>The blog of the Isthmus' Architecture Team</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://isthmuspuravida.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://isthmuspuravida.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Eliecer Leiton</name><uri>http://www.blogger.com/profile/08704934982771547622</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6794514250333471393.post-4290512233780193696</id><published>2008-06-27T09:47:00.009-06:00</published><updated>2008-07-10T08:08:37.630-06:00</updated><title type='text'>Grid Computing in the Enterprise World</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Highly scalable, maintainable and reliable applications is the &lt;i&gt;holy grail&lt;/i&gt; for any Enterprise Architect; although, hardware availability and high demand processing will restraint&lt;span style="COLOR: rgb(255,255,255)"&gt; the design&lt;/span&gt; capacity. Among the questions that come into mind when outlining an architecture for an &lt;?xml:namespace prefix = st1 /&gt;&lt;st1:city st="on"&gt;&lt;st1:place st="on"&gt;Enterprise&lt;/st1:place&gt;&lt;/st1:city&gt; system, would be: &lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;ul style="MARGIN-TOP: 0in" type="disc"&gt;&lt;li class="MsoNormal"&gt;&lt;i&gt;How transactional the data is?&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;i&gt;How many transactions per time unit will the system have to handle?&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;i&gt;Are there any data and time intensive process?&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;i&gt;How many concurrent users will operate the system?&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/li&gt;&lt;li class="MsoNormal"&gt;&lt;i&gt;Will be the users in a disconnected environment; therefore, getting the system to deal with outdated data?&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Note that in the first paragraph I use &lt;i&gt;holy grail &lt;/i&gt;to describe the pursuit of the three principles of enterprise architectures, some times the answers to the previous questions would lead to a solution that will attempt against one or many of the principles of scalability, maintainability or reliability; therefore, it becomes a &lt;i&gt;holy quest&lt;/i&gt; that many would consider impossible to reach. For example take a highly transactional web application, by definition highly transactional means data is updated following ACID principles ( Atomic, Consistency, Insolated, Durability), and by being a web application it has to work in a disconnected environment; thus, if two user are modifying the same data at the same time one of the two is guarantee to have outdated data.&lt;/p&gt;&lt;div style="TEXT-ALIGN: justify"&gt;&lt;/div&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Many of the problems in terms of data consistency have to be address during architecture design or can be address with a re-architecture of a system, if for some reason where not taken into consideration the first time. Once the factors inside the scope of data management and processing are addressed, the scalability of the system comes into play. Think about the scalability as your main line of defense against user demands for processing, if your system depends on a single player (a single piece of hardware) you will get a bigger player (better hardware) in an attempt to stop user progress (performance degradation), as show bellow:&lt;/p&gt;&lt;div style="TEXT-ALIGN: justify"&gt;&lt;/div&gt;&lt;p class="MsoNormal"&gt;&lt;?xml:namespace prefix = v /&gt;&lt;v:stroke joinstyle="miter"&gt;&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;v:f eqn="sum @0 1 0"&gt;&lt;v:f eqn="sum 0 0 @1"&gt;&lt;v:f eqn="prod @2 1 2"&gt;&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;v:f eqn="sum @0 0 1"&gt;&lt;v:f eqn="prod @6 1 2"&gt;&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;v:f eqn="sum @8 21600 0"&gt;&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;v:f eqn="sum @10 21600 0"&gt;&lt;v:path connecttype="rect" gradientshapeok="t" extrusionok="f"&gt;&lt;o:lock aspectratio="t" ext="edit"&gt;&lt;v:imagedata title="FootballImage2" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image001.jpg"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/SGUL60LgFPI/AAAAAAAAAEk/dmHVyQX54Ag/s1600-h/FootballImage2.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216588848445789426" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_dpLSImosLTU/SGUL60LgFPI/AAAAAAAAAEk/dmHVyQX54Ag/s320/FootballImage2.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;As you can notice a team of one would be outperformed if the user offensive grows beyond their strength; therefore, changing the defense by adding some help to our star player and organizing the defense in a pyramidal approach as shown below, will still depend on the correct organization and will be eventually overwhelmed by the offensive if one the defense players fails and moreover if the one failing is our star player.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="FootballImage3" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image002.jpg"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/SGUMYJGrYnI/AAAAAAAAAEs/hZ1RfkZSzZQ/s1600-h/FootballImage3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216589352278909554" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_dpLSImosLTU/SGUMYJGrYnI/AAAAAAAAAEs/hZ1RfkZSzZQ/s320/FootballImage3.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;For us looking to win the &lt;i&gt;super bowl of scalability&lt;/i&gt;; linear scalability should be our secret play; we should not depend on one star player, but in a team that can growth in number to stand the user offensive, all players should be the same and they all shall stand side by side with their peers and if one fails the next ones can close the gap leaved by their team mate; take a look into the following diagram on linear scalability defense play. If know our system as good as you should; you can know how many user hits the player on defense can handle; therefore, if having a projected growth of the offensive, we know &lt;i&gt;a priori&lt;/i&gt; how many new defense players we have to get into play.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="FootballImage4" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image003.jpg"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/SGUMeuakb9I/AAAAAAAAAE0/O_lZmhRzmao/s1600-h/FootballImage4.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216589465373667282" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_dpLSImosLTU/SGUMeuakb9I/AAAAAAAAAE0/O_lZmhRzmao/s320/FootballImage4.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Systems looking to get linear scalability into their game strategy, should be architecture in such a way that allows linearity on their processing, in terms of hardware, the linearity can be handle in home adding more hardware on your own data center or it can be handle by acquiring services for hardware &lt;i&gt;gridifiying&lt;/i&gt; company; we will talk about those later. In terms of processing, there are several solutions out in the market about process &lt;i&gt;gridifiying&lt;/i&gt; and we will look into one open source for Java in quick demo next. The framework presented here is &lt;a href="http://www.gridgain.com/"&gt;http://www.gridgain.com/&lt;/a&gt;, is a solution that requires no configuration, the code gets deployed automatically in the nodes of the grid and executed transparently as it where in a single JavaVM.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify"&gt;1. Get data from database, we are going to get the list of customers from a Northwind database in a Microsoft SQL Server 2005 using JPA.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image004.png"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/SGUMttpQhrI/AAAAAAAAAE8/SdsnJwlNP8o/s1600-h/001.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216589722864879282" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_dpLSImosLTU/SGUMttpQhrI/AAAAAAAAAE8/SdsnJwlNP8o/s320/001.JPG" border="0" /&gt;&lt;/a&gt;2. We have to create a task to process the data in the grid; we want to change the Region on the customers living in Germany, to do so we import the libraries from Gridgain into our Netbeans JavaSE project; thereafter, we create the task to inherit from GridTaskSplitAdapter&lt;list&gt;&lt;customers&gt;, List&lt;customers&gt;&gt; this adapter allows us to grid-enable the task in common split-aggregate way, by first splitting the collection into multiple Jobs and later aggregate the results back. The two generic types provided will determine the value given to the &lt;i&gt;split&lt;/i&gt; method and the return value from the &lt;i&gt;reduce&lt;/i&gt; method respectively. &lt;/customers&gt;&lt;/customers&gt;&lt;/list&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image006.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216589895913638866" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_dpLSImosLTU/SGUM3yTTC9I/AAAAAAAAAFE/JLpwb8X5mFI/s320/002.jpg" border="0" /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify"&gt;3. In the split method we create a job for each customer in the task and override the execute method for the job and add our processing logic inside. &lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image008.png"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/SGUM-Vq61vI/AAAAAAAAAFM/9BIT6dmuPHE/s1600-h/003.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216590008487171826" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_dpLSImosLTU/SGUM-Vq61vI/AAAAAAAAAFM/9BIT6dmuPHE/s320/003.jpg" border="0" /&gt;&lt;/a&gt;4. In the reduce method we get all the results and aggregate the data back into a new List&lt;customer&gt; object and return it. For the sake of simplicity we added some prints to see how the work is done in the different nodes of the grid.&lt;/customer&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image010.png"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/SGUNFVdNKMI/AAAAAAAAAFU/nWzX_sLBjj4/s1600-h/004.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216590128688736450" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_dpLSImosLTU/SGUNFVdNKMI/AAAAAAAAAFU/nWzX_sLBjj4/s320/004.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify"&gt;5. To test the tasks are performed by different nodes in the grid two more instances were created, plus the one being created when the application runs. Therefore, our grid topology will show three nodes, sharing the same CPUs and Network interface.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image012.png"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/SGUNM3ODz-I/AAAAAAAAAFc/zvbfJ7va9WA/s1600-h/005.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216590258011099106" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_dpLSImosLTU/SGUNM3ODz-I/AAAAAAAAAFc/zvbfJ7va9WA/s320/005.jpg" border="0" /&gt;&lt;/a&gt;6. When we run this demo we can see jobs being executed simultaneously in different nodes and finally in the main node we can see the aggregated data with the changes made to the customer regions. If you look into the Customer IDs is easy to notice the Customers being process by the nodes are different.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;v:imagedata title="" src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\02\clip_image014.png"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/SGUNWK6WpRI/AAAAAAAAAFk/bpPyrsnUD0Y/s1600-h/006.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216590417915979026" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_dpLSImosLTU/SGUNWK6WpRI/AAAAAAAAAFk/bpPyrsnUD0Y/s320/006.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;All nodes in our topology should get the same amount of jobs; depending in its load; therefore, linear scalability. The load will be evenly distributed in our grid if we need more processing will be just matter of adding new nodes; however, more nodes will require; eventually; more hardware, adding the extra hardware could be prove difficult due company policies and procurement delays; moreover, hardware gets outdated quickly and the investment in your datacenter fades away.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Hardware has become a simple commodity what really matter is processing, bandwidth and storage, many companies decided to outsource their entire datacenter; although, there is a new trend into managing datacenters, it goes beyond getting your hardware out to someone else’s facility but to virtualize the entire IT infrastructure; these could be bad news for your infrastructure team; no more wiring, no more A/C problems, no more midnight maintenance, no more corrupted backups, and a lot of other “no more”.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;In a virtual world everybody is happy; all the hassle is taken away from your server setup and maintenance, in matter of minutes you can have your own infrastructure; systems can growth beyond the projected demand by a click of a button and can be downsized when the waters come back to its channel. We get an Infrastructure that can growth with the minimum impact at the minimum cost; even better; we can return the processing and storage capacity when is needed no more. The best thing about it is that we get charged for what we use; meaning; that we will pay for the CPU minutes, the terabytes we store and the bandwidth we use.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Having someone so big (the virtualization company) dealing for better prices in servers, storage and bandwidth will translate in better and better prices for our systems, think outside de box, even the &lt;i&gt;Staging&lt;/i&gt; and &lt;i&gt;QA&lt;/i&gt; environments for your development teams can be virtualized; whenever a new project requires &lt;i&gt;Staging&lt;/i&gt; and &lt;i&gt;QA&lt;/i&gt; we can add two new servers; once again; with the click of a button.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;There are two big companies out in the market for this kind of services, with different approaches: &lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 79.5pt; TEXT-INDENT: -43.5pt; TEXT-ALIGN: justify"&gt;- Google with &lt;a href="http://code.google.com/appengine/"&gt;http://code.google.com/appengine/&lt;/a&gt; it allows run your applications in Google infrastructure it has several limitations the worth of mention is that Python is the only supported language and on top of that it is still on beta; it has some benefits if you want to interact with other Google services; although, this is not very helpful if you have applications in production already.&lt;/p&gt;&lt;p class="MsoNormal" style="MARGIN-LEFT: 79.5pt; TEXT-INDENT: -43.5pt; TEXT-ALIGN: justify"&gt;- Amazon with their web services ( &lt;a href="http://aws.amazon.com/"&gt;http://aws.amazon.com/&lt;/a&gt; ) this services allows access to Amazon infrastructure, it is a virtual environment to deploy any range of applications and supports deployment of different Operative System (with different amounts of effort in each case) and on top of that any application written in any language.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Finally I came across a third company that offers yet another different approach to scalable systems, I like this one more as an option for those having systems in production, it provides virtualization of Windows and Linux servers in a single infrastructure, very much alike any Enterprise Environment we have already, the company is &lt;a href="http://www.gogrid.com/"&gt;http://www.gogrid.com/&lt;/a&gt; they provide a web interface to manage the entire infrastructure allowing to add servers, load balancers, storage and private networks, pretty much as if your had physical access to the hardware.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;Even though some recommend Amazon and Google services for those having a new business ideas coming from the Web 2.0; in the other hand, GoGrid would be a good alternative for those having systems that can be easily scale depending only in the availability of hardware.&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="TEXT-ALIGN: justify"&gt;System willing to take advantage of the new trend in datacenters should architect their systems in such a way that it can be easily scale; either by using processing grids solutions such as the one presented before for Java or some alternative of an&lt;i&gt; “in house”&lt;/i&gt; architecture design to allow fast and easy deploy in a grid-enable environment.&lt;/p&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/v:imagedata&gt;&lt;/o:lock&gt;&lt;/v:path&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:f&gt;&lt;/v:stroke&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6794514250333471393-4290512233780193696?l=isthmuspuravida.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://isthmuspuravida.blogspot.com/feeds/4290512233780193696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6794514250333471393&amp;postID=4290512233780193696' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/4290512233780193696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/4290512233780193696'/><link rel='alternate' type='text/html' href='http://isthmuspuravida.blogspot.com/2008/06/grid-computing-in-enterprise-world.html' title='Grid Computing in the Enterprise World'/><author><name>Allan Cascante</name><uri>http://www.blogger.com/profile/17045029633237273305</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_dpLSImosLTU/SGUL60LgFPI/AAAAAAAAAEk/dmHVyQX54Ag/s72-c/FootballImage2.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6794514250333471393.post-7287217328193400509</id><published>2008-03-31T10:06:00.022-06:00</published><updated>2008-04-13T20:25:18.601-06:00</updated><title type='text'>Moving to C# 3.0</title><content type='html'>In order to accommodate new programming options and frameworks (such as LINQ) in .NET Framework 3.5, Microsoft added new capabilities and extensions to the C# language, resulting in C# 3.0. In this post we will have an overview of the most important modifications that were done, and how can they be used in our projects.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="FONT-WEIGHT: bold"&gt;Lambda Expressions&lt;/span&gt; &lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Lets imagine an scenario where we need a method signature to be implemented in different ways. For example a method signature to filter an array of chars, where the specific filtering implementation can vary depending on what needs to be filtered. In order to do this we will have a delegate that will indicate the work to be done:&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_-tXGR0Z9AiQ/R_E71dfz3aI/AAAAAAAAAAo/XWiYV_33FD0/s1600-h/uno.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5183990435717307810" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_-tXGR0Z9AiQ/R_E71dfz3aI/AAAAAAAAAAo/XWiYV_33FD0/s320/uno.JPG" border="0" /&gt;&lt;/a&gt;The solution in the days of C# 1.0 was to create a named method that will perform our filtering operation. We will then pass this method as the delegate. &lt;/p&gt;&lt;p align="left"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R_E9ANfz3bI/AAAAAAAAAAw/KP6s1iO-8fE/s1600-h/delegate.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5183991719912529330" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R_E9ANfz3bI/AAAAAAAAAAw/KP6s1iO-8fE/s320/delegate.JPG" border="0" /&gt;&lt;/a&gt;In order to avoid having to specifically create the method, the solution using the advantages of C# 2.0 was to use anonymous methods, but it turned out to be verbose and difficult to comprehend:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_-tXGR0Z9AiQ/R_E929fz3cI/AAAAAAAAAA4/XfoV6EMaGEw/s1600-h/anonymous.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5183992660510367170" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_-tXGR0Z9AiQ/R_E929fz3cI/AAAAAAAAAA4/XfoV6EMaGEw/s320/anonymous.JPG" border="0" /&gt;&lt;/a&gt;With C# 3.0 we have the option of using lambda expressions, which provides a nicer and more readable way of doing the same work. Lambda expressions take the following form: &lt;/p&gt;&lt;p align="center"&gt;&lt;span style="FONT-STYLE: italic"&gt;(param1, param2, ...) =&gt; { expr }&lt;/span&gt; &lt;/p&gt;&lt;p&gt;So to code the same filtering example using this new C# feature, we will need to do the following: &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R_E_5Nfz3dI/AAAAAAAAABA/NbcW86fQnQo/s1600-h/lambda.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5183994898188328402" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R_E_5Nfz3dI/AAAAAAAAABA/NbcW86fQnQo/s320/lambda.JPG" border="0" /&gt;&lt;/a&gt;Using lambda expressions will help us write less code and can help us make our code easier to understand, hence easier to maintain.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold;font-size:130%;" &gt;Anonymous Types&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It is a common scenario to have to create business entity classes to move information from the data layer into the presentation layer. But this could get very tiresome and code extensive if we need to create a huge amount of business entity classes because each method in the business layer returns different information. This gets worse if each of the business layer methods is called only once by a specific presentation layer action, because that will force us to have several business entity classes with little use.&lt;br /&gt;&lt;br /&gt;Anonymous types can help us deal with situations such as the one described above. They allow us to have methods returning unnamed business entities, without the need to specifically create the business entity class. Lets look at the following example:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_-tXGR0Z9AiQ/R_FIMdfz3eI/AAAAAAAAABI/7GbfFUv_klQ/s1600-h/var.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5184004024993832418" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_-tXGR0Z9AiQ/R_FIMdfz3eI/AAAAAAAAABI/7GbfFUv_klQ/s320/var.JPG" border="0" /&gt;&lt;/a&gt;This example shows us three things. First the use of the &lt;span style="FONT-WEIGHT: bold"&gt;var &lt;/span&gt;keyword, which is new to C# 3.0 and, amongst other things, allows us to declare variables of anonymous or unknown types. Second the use of the new initializers in C# 3.0, that help us avoid having to specifically create constructors for each of the classes we want to use, and let us initialize the attributes right away when we initialize the variable. Third the use of anonymous types, where in the example we are creating a unnamed type with the attributes &lt;span style="FONT-WEIGHT: bold"&gt;FirstName&lt;/span&gt; and &lt;span style="FONT-WEIGHT: bold"&gt;LastName&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Visual Studio 2008 provides IntelliSense for all &lt;span style="FONT-WEIGHT: bold"&gt;var &lt;/span&gt;datatypes, which helps the developer to know what does the variable contains once it has been initialized. Also there is compile time validation on the &lt;span style="FONT-WEIGHT: bold"&gt;var &lt;/span&gt;datatypes, that prevents programmers from assigning a different datataype to a &lt;span style="FONT-WEIGHT: bold"&gt;var &lt;/span&gt;variable that has already been initialized.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold;font-size:130%;" &gt;Extension methods&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There may be cases when we would like to add additional functionality to a particular class, but we do not have access to the source code, or maybe it's just not feasible to modify it. Those particular scenarios are an example of where extension methods may help us in our development.&lt;/p&gt;&lt;p&gt;Lets have a look at the following code: &lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R_FdlNfz3fI/AAAAAAAAABQ/Tus8wSHPv24/s1600-h/extensions.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5184027539939778034" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R_FdlNfz3fI/AAAAAAAAABQ/Tus8wSHPv24/s320/extensions.JPG" border="0" /&gt;&lt;/a&gt;As you may notice, we are creating a method called Invert, and we are extending the .NET framework &lt;strong&gt;&lt;em&gt;string &lt;/em&gt;&lt;/strong&gt;class adding this method as an extension method. It is easy to recognize extension methods since they all start with the keyword &lt;strong&gt;&lt;em&gt;this &lt;/em&gt;&lt;/strong&gt;as part of the parameters. &lt;/p&gt;&lt;p&gt;Having extended the &lt;strong&gt;&lt;em&gt;string &lt;/em&gt;&lt;/strong&gt;class with the Invert method, we are allowed now to call this method from any &lt;strong&gt;&lt;em&gt;string &lt;/em&gt;&lt;/strong&gt;attribute in our code.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Partial methods&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;If there is a need to have methods that may or may not be called, depending on the specific need of the developer, partial methods are the right choice.&lt;/p&gt;&lt;p&gt;The idea behind partial methods is to allow the developer to choose wither he wants to execute a method or not. If he provides the method, then it gets executed, if he does not create the method then it will be just like if the method didn't exist. This helps a lot for cases when we may need to have pre and post methods for some particular action. Lets take a look at the following code:&lt;/p&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5188909212448137682" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_-tXGR0Z9AiQ/SAK1b8u5IdI/AAAAAAAAABY/ZvqajBOIAIo/s320/partial1.JPG" border="0" /&gt;Here we have created a Log partial class that writes a log entry whenever the DoLog() method is executed. This class contains a PreLog and a PostLog partial methods, which for the moment doesn't have any functionality. This code compiles fine, and if we call the DoLog() method, the string "Doing my logging." will be the only thing printed to the console. The story changes if we add the following code to the mix:&lt;img id="BLOGGER_PHOTO_ID_5188910243240288738" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_-tXGR0Z9AiQ/SAK2X8u5IeI/AAAAAAAAABg/3w7RzPcOAUs/s320/partial2.JPG" border="0" /&gt;In this other partial class we are adding functionality to the Pre and Post partial methods we defined in the first partial class. Now that we have some code for both methods it will be executed. This means that whenever the DoLog() method is called, the following will be printed to the console:&lt;/p&gt;&lt;p align="center"&gt;&lt;em&gt;Doing pre-logging&lt;/em&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;em&gt;Doing my logging&lt;/em&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;em&gt;Doing post-logging&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Query expressions&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;There are two ways in which we may query IEnumerable data using LINQ: using dot notation or using query expressions. Lets look at the following example:&lt;/p&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5188914022811509234" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_-tXGR0Z9AiQ/SAK5z8u5IfI/AAAAAAAAABo/5uTbs3MIdfc/s320/query.JPG" border="0" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This code shows the different ways in which we may query the array of strings. As you may see, the do notation treat queries as regular methods, while query expressions use a syntax very similar to sql queries (but inverted). In the end they both perform the same since query expressions get compiled into dot notation expressions.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Conclusion&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;We have taken a quick look into the most significant modifications that took place to C# in the .NET framework 3.5. It is important to keep in mind that most of these changes where required for the Microsoft team to put in place what they had in mind for LINQ, so some of them may look a little awkward or unnatural. Whatever the reason, this new additions have taken place, and we certainly have to study them to understand them, and to be able to identify the scenarios where this new features will provide great advantage to any code we may write for our applications.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6794514250333471393-7287217328193400509?l=isthmuspuravida.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://isthmuspuravida.blogspot.com/feeds/7287217328193400509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6794514250333471393&amp;postID=7287217328193400509' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/7287217328193400509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/7287217328193400509'/><link rel='alternate' type='text/html' href='http://isthmuspuravida.blogspot.com/2008/03/using-c-30.html' title='Moving to C# 3.0'/><author><name>Eliecer Leiton</name><uri>http://www.blogger.com/profile/08704934982771547622</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_-tXGR0Z9AiQ/R_E71dfz3aI/AAAAAAAAAAo/XWiYV_33FD0/s72-c/uno.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6794514250333471393.post-8935319860419346963</id><published>2008-03-26T14:15:00.018-06:00</published><updated>2008-03-26T14:35:21.277-06:00</updated><title type='text'>Java Profiling</title><content type='html'>Since NetBeans 6.0 profiler is no longer a plug-in; therefore, is bundle as a basic component in the Platform. What implications does this have to NB users? Well in practical terms: none. However despite de IDE we are using we should address the fact that writing Java code should go beyond simple typing it as it would be coming from a memory dump; from your head; this statement is even truer when it comes to complex business logic. In the other hand; take source code from a CRUD application using JPA it has not much to optimize; all control has been taken from our hands and given to the compiler and the JPA framework.    &lt;p class="MsoNormal"&gt;In most cases there will be no need no optimization for common database access applications; eventually we might face a challenge beyond annotating POJO classes. It will depend on the nature of the application and the complexity of the business logic at hand or probably you will have to locate the piece that has to be optimized first; there is where the profiling facilities come at hand; so let’s take a look into NetBeans profiling.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;For matter of demo we will take one of the latest internal applications a Java Platform, Enterprise Edition called TestOnline currently at QA, the application architecture detailed in the following diagram is basically Isthmus standard architecture for Java Platform, Enterprise Edition applications. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="_x0000_i1025" type="#_x0000_t75" style="'width:6in;" ole=""&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image001.emz" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dpLSImosLTU/R-qvzpsZGbI/AAAAAAAAACo/sSA_6tv65BA/s1600-h/001.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_dpLSImosLTU/R-qvzpsZGbI/AAAAAAAAACo/sSA_6tv65BA/s320/001.JPG" alt="" id="BLOGGER_PHOTO_ID_5182147623143414194" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:oleobject type="Embed" progid="Visio.Drawing.11" shapeid="_x0000_i1025" drawaspect="Content" objectid="_1268045921"&gt;  &lt;/o:OLEObject&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Since we have the source code in a NetBeans’ project we can profile the application easily; however, any Java application can be profiled using NetBeans’ integrated profiler, so first we show how to profile the current project, then how to enable it for a previously compiled application.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;From the &lt;i style=""&gt;Profile&lt;/i&gt; menu we select the &lt;i style=""&gt;Profile Main Project&lt;/i&gt; menu option as shown in the following image:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1026" type="#_x0000_t75" style="'width:231.75pt;height:72.75pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image003.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R-qwOJsZGcI/AAAAAAAAACw/NlE05sJVwN0/s1600-h/002.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R-qwOJsZGcI/AAAAAAAAACw/NlE05sJVwN0/s320/002.JPG" alt="" id="BLOGGER_PHOTO_ID_5182148078409947586" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;After selecting this option the profiler will ask for confirmation since it has to modify the build script to enable profiling, so we click ok in the dialog shown in the following image:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1027" type="#_x0000_t75" style="'width:320.25pt;height:163.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image005.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R-qwUJsZGdI/AAAAAAAAAC4/oLUGjMDVFF4/s1600-h/003.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R-qwUJsZGdI/AAAAAAAAAC4/oLUGjMDVFF4/s320/003.JPG" alt="" id="BLOGGER_PHOTO_ID_5182148181489162706" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Thereafter NetBeans modified the build script, lets see what were the changes it did to our build file, this is very simple since the file is versioned under a SVN repository.&lt;span style=""&gt;  &lt;/span&gt;The change made to NetBeans &lt;i style=""&gt;build.xml&lt;/i&gt; is very simple it includes a newly created file called &lt;i style=""&gt;profiler-build-impl.xml&lt;/i&gt; this new file simply adds some information to run the Application Server with the extra parameters required to the profiler to be able to gather information, the parameter is the same we will manually add later to profile any precompiled application.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Now everything is almost set to start profiling our application; although, before we start the information recorded by the profiler can be customize for us to analyze later, the window opened for the options has three sections; first &lt;i style=""&gt;Monitor&lt;/i&gt; section as shown in the following image allows to enable monitoring for threads:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1028" type="#_x0000_t75" style="'width:324.75pt;height:103.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image007.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R-qwzJsZGeI/AAAAAAAAADA/cSwhFMVE-r4/s1600-h/004.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R-qwzJsZGeI/AAAAAAAAADA/cSwhFMVE-r4/s320/004.JPG" alt="" id="BLOGGER_PHOTO_ID_5182148714065107426" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Second the &lt;i style=""&gt;CPU&lt;/i&gt; section allows us to customize some more options, for this demo we will select the &lt;i style=""&gt;Entire Application&lt;/i&gt; option and basically left the other options with their default values.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1029" type="#_x0000_t75" style="'width:387.75pt;height:100.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image009.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R-qw8JsZGfI/AAAAAAAAADI/hb_H-8MbudM/s1600-h/005.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R-qw8JsZGfI/AAAAAAAAADI/hb_H-8MbudM/s320/005.JPG" alt="" id="BLOGGER_PHOTO_ID_5182148868683930098" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Finally we can modify the last option section; this section allows the modification of profiling parameters for memory for this test we will modify the default ones and select the option to &lt;i style=""&gt;Record both object creation and garbage collection&lt;/i&gt;.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1030" type="#_x0000_t75" style="'width:396pt;height:134.25pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image011.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R-qxC5sZGgI/AAAAAAAAADQ/Ir4G6IbiUis/s1600-h/006.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R-qxC5sZGgI/AAAAAAAAADQ/Ir4G6IbiUis/s320/006.JPG" alt="" id="BLOGGER_PHOTO_ID_5182148984648047106" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Finally all set clicking on &lt;i style=""&gt;Run&lt;/i&gt; button and after waiting for a while we see the following image in the NetBeans status bar. All the sections defined before will get the profiler to store different information; each one will help into analyzing the application in different ways, for this demo we will carry profiling in CPU for time on methods and Memory for object creation and GC.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1031" type="#_x0000_t75" style="'width:318pt;height:30.75pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image013.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R-qxMJsZGhI/AAAAAAAAADY/uk4LH_M60Kg/s1600-h/007.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R-qxMJsZGhI/AAAAAAAAADY/uk4LH_M60Kg/s320/007.JPG" alt="" id="BLOGGER_PHOTO_ID_5182149143561837074" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;The previous screenshot shows the AS is starting and therefore our application, the profiler adds some overhead to normal VM operation; therefore, it would take longer to almost any application to start. Another factor to take into consideration is that the AS that works the best with NetBeans’ profiler integration is the bundled GlashFish; although, any Java application should be able to provide profiling information including JBoss AS (as long they run on a Java VM supporting profiling); however, it may not work the integration easily; therefore, it should be done manually, for example the JBoss AS run.bat/sh script should be modified for the JVM to wait for profiler connections. &lt;span style=""&gt; &lt;/span&gt;The parameter is &lt;i style=""&gt;agentpath&lt;/i&gt; and it default is shown here for the NetBeans installed in the default location, one way to get the parameter to use is by means of NetBeans profiler, first select &lt;i style=""&gt;External Application&lt;/i&gt; in the &lt;i style=""&gt;Attach to&lt;/i&gt; combo in the &lt;i style=""&gt;Attach Profiler&lt;/i&gt; wizard (from the &lt;i style=""&gt;Attach Profiler&lt;/i&gt; submenu from the &lt;i style=""&gt;Profile&lt;/i&gt; menu); as seen in the following image.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1032" type="#_x0000_t75" style="'width:6in;height:123.75pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image015.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R-qx4ZsZGiI/AAAAAAAAADg/-76EpyPKHis/s1600-h/008.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R-qx4ZsZGiI/AAAAAAAAADg/-76EpyPKHis/s320/008.JPG" alt="" id="BLOGGER_PHOTO_ID_5182149903771048482" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Then click in the &lt;i style=""&gt;change&lt;/i&gt; link (if it is the first time you select to attach an external application the wizard will come out right away without having to click on change link); seen in the following image; &lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1033" type="#_x0000_t75" style="'width:261.75pt;height:48pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image017.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R-qyDJsZGjI/AAAAAAAAADo/ds0DRZ4nTfM/s1600-h/009.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R-qyDJsZGjI/AAAAAAAAADo/ds0DRZ4nTfM/s320/009.JPG" alt="" id="BLOGGER_PHOTO_ID_5182150088454642226" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;to change the attach mode, follow the wizard by first selecting the &lt;i style=""&gt;Target Type&lt;/i&gt; as &lt;i style=""&gt;Application&lt;/i&gt; &lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1034" type="#_x0000_t75" style="'width:6in;height:84pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image019.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R-qyI5sZGkI/AAAAAAAAADw/S9G4bSlhtWc/s1600-h/010.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R-qyI5sZGkI/AAAAAAAAADw/S9G4bSlhtWc/s320/010.JPG" alt="" id="BLOGGER_PHOTO_ID_5182150187238890050" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Click next Review &lt;i style=""&gt;Attach Settings&lt;/i&gt;, next again and in the &lt;i style=""&gt;Manual Integration&lt;/i&gt; step the parameter to add will show up as seen in the following image&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1035" type="#_x0000_t75" style="'width:373.5pt;height:240.75pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image021.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R-qyUJsZGlI/AAAAAAAAAD4/WQ9WKBfiVfE/s1600-h/011.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R-qyUJsZGlI/AAAAAAAAAD4/WQ9WKBfiVfE/s320/011.JPG" alt="" id="BLOGGER_PHOTO_ID_5182150380512418386" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Just select and copy the parameter to add when starting the Java (SE 5) application; it should read something similar to this:&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p style="font-style: italic;" class="MsoNormal"&gt;-agentpath:"C:\Program Files\NetBeans 6.0\profiler2\lib\deployed\jdk15\windows\profilerinterface.dll=\"C:\Program Files\NetBeans 6.0\profiler2\lib\"",5140&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;After adding this parameter the Java application should wait until the Profiler connects to it before starting; afterwards the Profiler starts getting profiling information from the application.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1036" type="#_x0000_t75" style="'width:431.25pt;height:210.75pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image023.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R-qyeZsZGmI/AAAAAAAAAEA/K36YSMvvX7o/s1600-h/012.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R-qyeZsZGmI/AAAAAAAAAEA/K36YSMvvX7o/s320/012.JPG" alt="" id="BLOGGER_PHOTO_ID_5182150556606077538" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;In order to show Profiler at work we added some silly code as seen bellow, this code will generate enough overhead; both, on GC and execution time.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1037" type="#_x0000_t75" style="'width:6in;height:195.75pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image025.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R-qyzZsZGnI/AAAAAAAAAEI/BXS9ifC9BQI/s1600-h/013.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R-qyzZsZGnI/AAAAAAAAAEI/BXS9ifC9BQI/s320/013.JPG" alt="" id="BLOGGER_PHOTO_ID_5182150917383330418" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Then we started the profiling session to track memory only, this mode allows us to take a look into object creation and garbage collection during the profiled session; although, for this particular example we had &lt;i style=""&gt;silly object creation section&lt;/i&gt; we tried the profiler and the results are showed in the next screenshot. &lt;span style=""&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1038" type="#_x0000_t75" style="'width:6in;height:219pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image027.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R-qy85sZGoI/AAAAAAAAAEQ/t5tUN6WJj90/s1600-h/014.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R-qy85sZGoI/AAAAAAAAAEQ/t5tUN6WJj90/s320/014.JPG" alt="" id="BLOGGER_PHOTO_ID_5182151080592087682" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;In the results from the Memory profiling session we can see the biggest number of allocated objects are &lt;i style=""&gt;Strings&lt;/i&gt; this seems logical since we create lots of this objects in the &lt;i style=""&gt;silly object creation section&lt;/i&gt;. Later we test the same application once again but we change the profiler to record execution time information.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1039" type="#_x0000_t75" style="'width:431.25pt;height:224.25pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\ACASCA~1\LOCALS~1\Temp\msohtml1\01\clip_image029.png" title=""&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R-qzE5sZGpI/AAAAAAAAAEY/GGZ5dHaeoyE/s1600-h/015.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R-qzE5sZGpI/AAAAAAAAAEY/GGZ5dHaeoyE/s320/015.JPG" alt="" id="BLOGGER_PHOTO_ID_5182151218031041170" border="0" /&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;This screenshot shows the information after the profiling session has ended; here we have several tabs and the one being shown is the &lt;i style=""&gt;Call Tree&lt;/i&gt; view, it shows a summary of the methods using most of the time; first it shows the one we modified with the &lt;i style=""&gt;silly code&lt;/i&gt;; this naïve code created lots of objects inside three nested &lt;i style=""&gt;for&lt;/i&gt; clauses creating enough overhead to become the most time consuming method in the application; it actually shows up as being called four times only, imaging how big this time might become if the system has 100 simultaneous clients. The second biggest time consuming method is the &lt;i style=""&gt;findEnabled&lt;/i&gt; this one shows up from a class &lt;i style=""&gt;$Proxy89&lt;/i&gt;; we have enough expertise in the code to point out this method is one in an EJB; that is why it shows up in a &lt;i style=""&gt;$Proxy&lt;/i&gt; class. This method does not have any complex business logic what it does is to query the data base to get a small set of data using JPA.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Now that we have located the candidates for optimization the work switches from profiling to coding; first we have to identify which of the methods will give the best results if optimized (reducing execution time) with the minor effort. After analyzing the code we found out the naïve code in the &lt;i style=""&gt;generateExam&lt;/i&gt; method; since it is pretty simple to fix we start the optimization work there. Then we can work in the next identified method; &lt;i style=""&gt;findEnabled&lt;/i&gt; for this particular one; it appears that the database query is the one adding most of the processing time; therefore; we can try to get some database expert to enhance our database or we can workout JPA to enhance the response time adding cache and some optimizations or perhaps creating an alternate query to the one being automatically created by JPA and run it using JDBC, but who knows maybe is not much we can do to optimize this method or the gain does not justify the effort.&lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;span style="font-weight: bold;"&gt;Outstanding Points&lt;/span&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;NetBean’s profiler could be of great help into identifying potential tuning candidates but good coding practices will save the day; even though; modern compilers and JVM&lt;span style=""&gt;  &lt;/span&gt;might work out some common coding performance killers.&lt;/p&gt;      &lt;p class="MsoNormal"&gt;Graphical profilers such as NetBeans’ could ease the work of identifying possible performance problems; however, most JVM come with command line options to allow profiling.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Profiler features shown in here are just a bit of what NetBeans’ profiler can do for us, graphs, drill-down and profiling points are part of the things available for us to ease the analysis of our applications, for a great demo on these features at work check out &lt;a href="http://www.netbeans.org/kb/60/java/profiler-screencast.html"&gt;http://www.netbeans.org/kb/60/java/profiler-screencast.html&lt;/a&gt;.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;References:&lt;/p&gt;&lt;p class="MsoNormal"&gt;[1] Shirazi, Jack; Java Performance Tuning Second Edition. O’Reilly Media, Inc.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6794514250333471393-8935319860419346963?l=isthmuspuravida.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://isthmuspuravida.blogspot.com/feeds/8935319860419346963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6794514250333471393&amp;postID=8935319860419346963' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/8935319860419346963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/8935319860419346963'/><link rel='alternate' type='text/html' href='http://isthmuspuravida.blogspot.com/2008/03/java-profiling.html' title='Java Profiling'/><author><name>Allan Cascante</name><uri>http://www.blogger.com/profile/17045029633237273305</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_dpLSImosLTU/R-qvzpsZGbI/AAAAAAAAACo/sSA_6tv65BA/s72-c/001.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6794514250333471393.post-8644772399936117532</id><published>2008-03-04T10:04:00.064-06:00</published><updated>2008-03-05T14:43:18.506-06:00</updated><title type='text'>Previewing the ASP.NET MVC Framework</title><content type='html'>Along with the release of Visual Studio 2008 some months ago, there has been a lot of complementary tools being developed by some teams at Microsoft; one of these tools is the ASP.NET 3.5 Extensions which provides new functionality being added not only to ASP.NET 3.5 but to ADO.NET 2008.&lt;br /&gt;&lt;br /&gt;Some of these features contempled in this pack are, for instance, new silverlight controls, ADO.NET Data Services, ADO.NET Entity Framework, ASP.NET AJAX back button support, ASP.NET Dynamic Data and last but not least the ASP.NET MVC Framework.&lt;br /&gt;&lt;br /&gt;Before we move forward, it's important to mention that this new fuctionality is in a "preview" state and therefore it is not officially supported by Microsoft.&lt;br /&gt;&lt;br /&gt;Now, let's concentrate on the ASP.NET MVC Framework.&lt;br /&gt;The MVC is a framework methodology that divides the implementation of a given application into three component roles: models, views and controllers.&lt;br /&gt;&lt;br /&gt;"Models" are the components of the application that are in charge for maintaining the state of the aplication. It could be persisting the state in a database or in memory.&lt;br /&gt;&lt;br /&gt;"Views" are the components in charge for displaying the application's user interface. Almost always the UI is a representation or reflection of what the model data does.&lt;br /&gt;&lt;br /&gt;"Controllers" are the components in charge for handling the user interaction, manipulating the model and lastly choosing a view to render.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Main features of the MVC Framework:&lt;/strong&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;It doesn't use postbacks or viewstate. In other words, this model is not attached to the traditional ASP.NET postback model and page lifecycle for interactions with the server. All the user interactions are routed to a controller class.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;It supports all the existing ASP.NET features such as output and data caching, membership and roles, Forms authentication, Windows authentication, URL authorization, session state management and other areas of ASP.NET.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;It gives support to the use of existing markup ASP.NET pages (.aspx files), user controls (.ascx files), and master page (.master files) as view templates.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;It contains a URL mapping component that enables you to build applications with clean URLs. The URL routing feature explicitly breaks the connection between physical files on disk and the URL that is used to access a given bit of functionality. This also helps the search engines. For instance, rather than access http://localhost/Products/ProductDetail.aspx?item=2 you now use http://localhost/Products/LaysFrieds.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Everything in the MVC framework is designed to be extensible. You can create your own view engine or URL routing policy, just to mention a couple.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Separation of the application tasks such as UI logic, input logic and business logic as well as testibility and test-driven development (TDD). Due to the loosely coupled model, running unit tests is quite easy.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;strong&gt;Creating a simple ASP.NET MVC Application&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;We'll create a basic application that displays a list of Products based on the category and subcategory chosen by the user. This sample will hopefully clear things up and set a way to start digesting this new ASP.NET feature.&lt;br /&gt;&lt;br /&gt;So, let's get started.&lt;br /&gt;Using Visual Studio 2008 let's create a project of type ASP.NET MVC Web Application.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_aDYXH27GXDk/R87G4GsJY-I/AAAAAAAAABw/6lwK7kZDV0s/s1600-h/IMAGE00.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174291689066030050" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aDYXH27GXDk/R87G4GsJY-I/AAAAAAAAABw/6lwK7kZDV0s/s320/IMAGE00.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After some seconds you'll get an already working project template that has a skeleton with a default page, also an index and about page.&lt;br /&gt;&lt;br /&gt;The default project template will look like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_aDYXH27GXDk/R87IB2sJY_I/AAAAAAAAAB4/RrE-sdVVNdY/s1600-h/IMAGE01.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174292956081382386" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_aDYXH27GXDk/R87IB2sJY_I/AAAAAAAAAB4/RrE-sdVVNdY/s320/IMAGE01.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;From now on you're all set to start working and modifying to your needs this simple template. Next, what we'll do is to create all the "Model" logic associated with our sample. All this logic should be placed in the Model folder defined by the template. For this sample I'm using the ADO.NET Entity Framework shipped in the same package as the ASP.NET MVC Framework. This will speed things up and it'll let us have a Data Access component up and running very quickly.&lt;br /&gt;I'm using the AdventureWorks database shipped with SQL Server 2005 and from there I'm only using three tables: ProductCategory, ProductSubCategory and Product.&lt;br /&gt;&lt;br /&gt;The model created by the Entity Framework looks like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_aDYXH27GXDk/R87J3GsJZAI/AAAAAAAAACA/nxKNkSXwuvE/s1600-h/IMAGE03.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174294970421044226" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aDYXH27GXDk/R87J3GsJZAI/AAAAAAAAACA/nxKNkSXwuvE/s320/IMAGE03.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;One important thing to remember is the routing model being used. Since this is a simple application I'm ok on using the one proposed by default by the project template which looks like the image below.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_aDYXH27GXDk/R87LmGsJZBI/AAAAAAAAACI/8Tbn6sfvM0I/s1600-h/IMAGE11.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174296877386523666" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_aDYXH27GXDk/R87LmGsJZBI/AAAAAAAAACI/8Tbn6sfvM0I/s320/IMAGE11.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What this is telling us is that rather than go with http://localhost/Products/SubCategories.aspx?id=2 as the URL for accessing a page, I'll respond to http://localhost/Products/SubCategories/2.&lt;br /&gt;&lt;br /&gt;Now that we're done with the Model, it's time to start coding the Controller that will act as the interperter and handler between the model and the view. We could say this is the heart of the framework. Application and data retrieval logic should only be written inside controller classes. Controller classes then choose which view to render.&lt;br /&gt;&lt;br /&gt;Let's then add a new file type of type MVC Controller Class underneath the folder named Controllers.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aDYXH27GXDk/R87OaWsJZCI/AAAAAAAAACQ/ZTCBQdtqHdg/s1600-h/IMAGE16.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174299974057944098" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aDYXH27GXDk/R87OaWsJZCI/AAAAAAAAACQ/ZTCBQdtqHdg/s320/IMAGE16.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;From there we start defining all the methods that will interact with our view.&lt;br /&gt;A way to define these methods is as follows:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aDYXH27GXDk/R87PzWsJZDI/AAAAAAAAACY/vUN-9NfyleY/s1600-h/IMAGE07.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174301503066301490" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aDYXH27GXDk/R87PzWsJZDI/AAAAAAAAACY/vUN-9NfyleY/s320/IMAGE07.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To make this post short, I'll only explain one of the three needed methods to have this application running as expected. Hopefully you'll get the idea and it'll be no problem implementing the others.&lt;br /&gt;&lt;br /&gt;What we do is to define an attribute (ControllerAction) for all those methods that will act as a controller. Then we implement the logic and after that we call the RenderView method that passes the data and calls the view.&lt;br /&gt;&lt;br /&gt;Finally, let's get into the view. No rocket science here. What we do first is to add a new item of type MVC View Content Page. This type of view will ask us for a Master Page. If you haven't notice it yet, there's a folder named Shared inside the Views folder. In this folder we put all the views that are common to the application and eventually could be reused.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aDYXH27GXDk/R87UqWsJZEI/AAAAAAAAACg/QJKKvbCZoUM/s1600-h/IMAGE05.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174306846005617730" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aDYXH27GXDk/R87UqWsJZEI/AAAAAAAAACg/QJKKvbCZoUM/s320/IMAGE05.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After adding the view, notice that the page inherets from System.Web.Mvc.ViewPage base class. This class provides some helper methods and properties. One of these properties is named "ViewData" which provides access to the view-specific data objects that the Controller passed as arguments to the RenderView() method.&lt;br /&gt;&lt;br /&gt;In order to access the data in ViewData we need to make the page inherets from ViewPage&amp;lt;T&amp;gt; where T is a strongly type, in this case, a List of Product Categories.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_aDYXH27GXDk/R87aQWsJZFI/AAAAAAAAACo/45DQUcGP2so/s1600-h/IMAGE08.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174312996398785618" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_aDYXH27GXDk/R87aQWsJZFI/AAAAAAAAACo/45DQUcGP2so/s320/IMAGE08.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This guarantee us to get full type-safety, intellisense, and compile-time checking within the view code.&lt;br /&gt;&lt;br /&gt;In the HTML part of the view we need to iterate through the ViewData object and use the ActionLink method of the Html object provided by the ViewPage class. The ActionLink method is a helper that generates HTML hyperlinks dynamically that link back to action methods on controllers.&lt;br /&gt;&lt;br /&gt;Let's write a foreach loop that generates a bulleted HTML category list like the image below.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_aDYXH27GXDk/R87a8msJZGI/AAAAAAAAACw/kWuVKfzkho4/s1600-h/IMAGE10.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5174313756607997026" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_aDYXH27GXDk/R87a8msJZGI/AAAAAAAAACw/kWuVKfzkho4/s320/IMAGE10.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;First of all, the MVC framework doesn't come as a replecement for the WebForms and its Page Controller Model. This is more an alternative way for those looking to implement the MVC approach. The fact that It'll facilitate you to develop a more clean application code as well as loosely coupled application with the adventage that this gives in terms of testability and test driven development is amazing.&lt;br /&gt;&lt;br /&gt;Now, one thing that, in my opinion needs more improvement is related with the way data is displayed. Having to iterate using in-line code and is not one of my favorites things to do. This reminds me of the spaghetti programming code that came along with the ASP programming model.&lt;br /&gt;&lt;br /&gt;Definately, there needs to be a more enhanced version of the ASP.NET MVC Framework that hopefully will act as those bindable, easy to use server controls available with the ASP.NET WebForms model.&lt;br /&gt;&lt;br /&gt;As of now, without a doubt, it's a promising framework that we'll certainly keep an eye on.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6794514250333471393-8644772399936117532?l=isthmuspuravida.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://isthmuspuravida.blogspot.com/feeds/8644772399936117532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6794514250333471393&amp;postID=8644772399936117532' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/8644772399936117532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/8644772399936117532'/><link rel='alternate' type='text/html' href='http://isthmuspuravida.blogspot.com/2008/03/previewing-aspnet-mvc-framework.html' title='Previewing the ASP.NET MVC Framework'/><author><name>Jeffrey Sánchez</name><uri>http://www.blogger.com/profile/10179430179981429709</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_aDYXH27GXDk/R87G4GsJY-I/AAAAAAAAABw/6lwK7kZDV0s/s72-c/IMAGE00.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6794514250333471393.post-7233495713835291648</id><published>2007-12-20T14:02:00.001-06:00</published><updated>2008-03-07T14:54:09.446-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web Services Interoperability'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Takes Two to Tango</title><content type='html'>Sun's Java Web Services engineers has been working since 2006 along with Microsoft's Windows Communication Foundation (WCF) engineers into integrating their WS-* enterprise features such as reliability messaging, security and atomic transactions. The main features targeted by Tango project are&lt;br /&gt;&lt;br /&gt;* Bootstrapping communication&lt;br /&gt;* Optimizing communication&lt;br /&gt;* Enabling reliability&lt;br /&gt;* Enabling atomic transactions&lt;br /&gt;* Securing communication&lt;br /&gt;&lt;br /&gt;It was said since the arising of WebServices that they were the solution to system integration; although, this statement is only true in part, the range of Languages and platforms lead to a wide variety of implementations all with inherited differences from the platforms that gave birth to each one of those. Even though, what ever I might state about the Web Services, from a business perspective they managed the differences and end up doing the job of overcoming the technical challenge of system integration; however, this ability came at a price which is either the need of some customization for cross platform WebService integration or the ability to integrate system written in the same platform only, leaving us only half way of what it was promised: full system cross platform integration.&lt;br /&gt;&lt;br /&gt;Customization being done to accommodate platform differences should had never been a problem; since, any body creating an implementation of a WebService infrastructure should had attend to the facto standards set; even if the implementors adhere to the standard; at most as possible; the platform itself could bring differences to the final product making it incompatible at some level with other implementations.&lt;br /&gt;&lt;br /&gt;We decided to try out the Tango implementation using NetBeans 6.0, the main advantage of using NetBeans as IDE is that it generates lots of boiler plate code speeding development of WebServices and clients in Java, so first we create a new Web Project for a simple Book Bid web service, such service emulates a business application that search books by name and returns the price in dolars to the client. Lets see how easy the creation of the Web Service  is in the following images.&lt;br /&gt;&lt;br /&gt;We first create the project and select a name, for this example I decided to call it BidBook.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R2w7gkqkFdI/AAAAAAAAAAM/R5TkofnRtN8/s1600-h/001-Creating+a+project.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R2w7gkqkFdI/AAAAAAAAAAM/R5TkofnRtN8/s320/001-Creating+a+project.png" alt="" id="BLOGGER_PHOTO_ID_5146553904961689042" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then I just added a new Web Service, I select the name BidBook and the Package and click Finish.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R2w7qkqkFeI/AAAAAAAAAAU/G-_9eAaj0MU/s1600-h/002-Creating+a+web+service+from+scratch.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R2w7qkqkFeI/AAAAAAAAAAU/G-_9eAaj0MU/s320/002-Creating+a+web+service+from+scratch.png" alt="" id="BLOGGER_PHOTO_ID_5146554076760380898" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After the web service has been created and new operation has to be added in the design screen BidBook Web Service.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dpLSImosLTU/R2w8NUqkFfI/AAAAAAAAAAc/ZRR9zb9pQ-A/s1600-h/003-web+service+created.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_dpLSImosLTU/R2w8NUqkFfI/AAAAAAAAAAc/ZRR9zb9pQ-A/s320/003-web+service+created.png" alt="" id="BLOGGER_PHOTO_ID_5146554673760835058" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;I added a new method named BidBook with a single parameter bookName and a return type of float to return the price in dolars, the we just click Ok button and NetBeans will create all the xml descriptors and Java classes with methods and correctly annotated corresponding to the new Web Service.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dpLSImosLTU/R2w8VUqkFgI/AAAAAAAAAAk/PHeJ4Y3TukQ/s1600-h/004-new+operation.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_dpLSImosLTU/R2w8VUqkFgI/AAAAAAAAAAk/PHeJ4Y3TukQ/s320/004-new+operation.png" alt="" id="BLOGGER_PHOTO_ID_5146554811199788546" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;At this point we are almost ready to use our newly created Web Service; however, before going any further lets add a bit of business logic to it so we change from Design view to Code view and customize the generated code as seen in&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R2w8gEqkFhI/AAAAAAAAAAs/bOHjJJ0GdMI/s1600-h/005-generated+code.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R2w8gEqkFhI/AAAAAAAAAAs/bOHjJJ0GdMI/s320/005-generated+code.png" alt="" id="BLOGGER_PHOTO_ID_5146554995883382290" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;with something as seen in the following image&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R2w8m0qkFiI/AAAAAAAAAA0/phhZ--PjQaI/s1600-h/006-added+business+logic.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R2w8m0qkFiI/AAAAAAAAAA0/phhZ--PjQaI/s320/006-added+business+logic.png" alt="" id="BLOGGER_PHOTO_ID_5146555111847499298" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;If we return to the design view the newly created method, coments parameters and so on will be displayed in the view&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R2w8u0qkFjI/AAAAAAAAAA8/p8fScCvDLkM/s1600-h/007-design+view+of+newly+created+buisines+logic.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R2w8u0qkFjI/AAAAAAAAAA8/p8fScCvDLkM/s320/007-design+view+of+newly+created+buisines+logic.png" alt="" id="BLOGGER_PHOTO_ID_5146555249286452786" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;All steps seen before are preatty much just supporting task for the main one at hand, wich is adding QoS to a Web Service, again NetBeans lend us a hand for the job, to add the configuration corresponding to the features we want to enable for this particular Web Service. In the Design View for it we select the options Reliable Message Delivery and Secure Service; we select this two just for demo purposes and left all advance features in their default values.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dpLSImosLTU/R2w85UqkFkI/AAAAAAAAABE/NHyS4kFnaMM/s1600-h/008-QOS.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_dpLSImosLTU/R2w85UqkFkI/AAAAAAAAABE/NHyS4kFnaMM/s320/008-QOS.png" alt="" id="BLOGGER_PHOTO_ID_5146555429675079234" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What NetBeans does for us in to add the correspondant information to the xml descriptor for the web service, later this information will be exposed along with the methods in the WSDL file used by consumers of the web service.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R2w9-kqkFlI/AAAAAAAAABM/jpmjt0hzJK4/s1600-h/009-ws-security-reliable.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R2w9-kqkFlI/AAAAAAAAABM/jpmjt0hzJK4/s320/009-ws-security-reliable.png" alt="" id="BLOGGER_PHOTO_ID_5146556619381020242" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;And we are done with our service and it now has reliable message delivery and security. Before moving away from the Java/J2EE world lets test this web service, to do so we first create a new project as a Java Application we named the project ClientBidBook and added the corresponding packaging later we add new Web Service Client&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_dpLSImosLTU/R2w_TUqkFmI/AAAAAAAAABU/n4JQCUP4dzY/s1600-h/011-client-create-service.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_dpLSImosLTU/R2w_TUqkFmI/AAAAAAAAABU/n4JQCUP4dzY/s320/011-client-create-service.png" alt="" id="BLOGGER_PHOTO_ID_5146558075374933602" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After NetBeans connects to the server and reads the WSDL contract for the selected service, a new proxy class will be created for us to use, this class is conceladed by NetBeans and what it shows is a tree view with all methods avaialable a drag n'drop in the main method of the application is enough for NetBeans to create the nescesary code to use the method.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R2w_fEqkFoI/AAAAAAAAABk/eWDxw1gPnQs/s1600-h/013-client-drag-n-drop-method-code.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R2w_fEqkFoI/AAAAAAAAABk/eWDxw1gPnQs/s320/013-client-drag-n-drop-method-code.png" alt="" id="BLOGGER_PHOTO_ID_5146558277238396546" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R2w_cEqkFnI/AAAAAAAAABc/4pkaUeIA8XA/s1600-h/012-client-drag-n-drop-method-reference-tree.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R2w_cEqkFnI/AAAAAAAAABc/4pkaUeIA8XA/s320/012-client-drag-n-drop-method-reference-tree.png" alt="" id="BLOGGER_PHOTO_ID_5146558225698788978" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Finally we start the application server and deploy our Web Service project (as easy as clicking run button on NetBeans) and later we run our client application and we get the following result:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R2w_r0qkFpI/AAAAAAAAABs/A0jXorXTav4/s1600-h/014-test-output-client.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R2w_r0qkFpI/AAAAAAAAABs/A0jXorXTav4/s320/014-test-output-client.png" alt="" id="BLOGGER_PHOTO_ID_5146558496281728658" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Now lets consume this web service from a .Net 3.0 application, using Visual Studio 2005 on a box with .Net Framework 3.0 we create a simple console application and named ClientBidBook as seeing in the following image&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R2xEMEqkFqI/AAAAAAAAAB0/d4Sw8erh1Gc/s1600-h/015-new-net-client.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R2xEMEqkFqI/AAAAAAAAAB0/d4Sw8erh1Gc/s320/015-new-net-client.png" alt="" id="BLOGGER_PHOTO_ID_5146563448379020962" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Later just add a Web Reference to the url of the running application server holding our Bid Book Web Service, after adding the reference all the proxy classes to consume the service will be created in our project&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_dpLSImosLTU/R2xEVkqkFrI/AAAAAAAAAB8/B3_5YcLBDhI/s1600-h/016-net-add-web-reference.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_dpLSImosLTU/R2xEVkqkFrI/AAAAAAAAAB8/B3_5YcLBDhI/s320/016-net-add-web-reference.png" alt="" id="BLOGGER_PHOTO_ID_5146563611587778226" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R2xEaEqkFsI/AAAAAAAAACE/rXzXyT6D87Y/s1600-h/017-added-web-reference.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R2xEaEqkFsI/AAAAAAAAACE/rXzXyT6D87Y/s320/017-added-web-reference.png" alt="" id="BLOGGER_PHOTO_ID_5146563688897189570" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The next step is simply using the proxy class in our project to do so we instantiate the BidBookService class and called the method BidBook with correspondent string with the name of the project.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_dpLSImosLTU/R2xEk0qkFtI/AAAAAAAAACM/2bWrtOdszQI/s1600-h/018-net-invoke-bid.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_dpLSImosLTU/R2xEk0qkFtI/AAAAAAAAACM/2bWrtOdszQI/s320/018-net-invoke-bid.png" alt="" id="BLOGGER_PHOTO_ID_5146563873580783314" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;For matter of testing we write the result to console and wait for a key press to be abble to see the results.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_dpLSImosLTU/R9Gq3szR8GI/AAAAAAAAACg/DerZktO0SIU/s1600-h/001.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_dpLSImosLTU/R9Gq3szR8GI/AAAAAAAAACg/DerZktO0SIU/s320/001.jpg" alt="" id="BLOGGER_PHOTO_ID_5175105320721182818" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And now we are done, from the previous demo I wanted to outline the following missing facts:&lt;br /&gt;&lt;br /&gt;* Integration it is feasible; however, complex data types should throughly  be tested to ensure seamesly integration (we didn't test it in this short demonstration).&lt;br /&gt;* Security and Reliability should be tested and confirmed.&lt;br /&gt;* The business logic behind of the Web Service should be part of business module and it can be as simple as exposing previous builded applications instead of creating a whole new infrastructure.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6794514250333471393-7233495713835291648?l=isthmuspuravida.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://isthmuspuravida.blogspot.com/feeds/7233495713835291648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6794514250333471393&amp;postID=7233495713835291648' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/7233495713835291648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/7233495713835291648'/><link rel='alternate' type='text/html' href='http://isthmuspuravida.blogspot.com/2007/12/takes-two-to-tango.html' title='Takes Two to Tango'/><author><name>Allan Cascante</name><uri>http://www.blogger.com/profile/17045029633237273305</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_dpLSImosLTU/R2w7gkqkFdI/AAAAAAAAAAM/R5TkofnRtN8/s72-c/001-Creating+a+project.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6794514250333471393.post-5759947216782757057</id><published>2007-12-20T13:25:00.000-06:00</published><updated>2007-12-27T18:00:48.122-06:00</updated><title type='text'>A look into LINQ to SQL</title><content type='html'>This November 2007 Microsoft released the .Net framework 3.5, and among the several additions incorporated in this release, probably the most significant is the Language Integrated Query (LINQ), which provides several enhancements in the way applications can be developed.&lt;br /&gt;&lt;br /&gt;In this post we will take a look into LINQ to SQL, which is the approach provided by LINQ to help developers accelerate the development of the data access layer.&lt;br /&gt;&lt;br /&gt;Probably the three most critical functionalities of the data access layer are transactions, concurrency, and efficiency.  We will take a look into how LINQ to SQL supports this.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;font-size:130%;" &gt;Getting started&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In order to see how to use LINQ, we will create a simple application that will allow us to create, edit and delete books, and assign categories to it. The database has 4 tables and one stored procedure.&lt;br /&gt;&lt;br /&gt;The first step is to create a new Class Library Project (Our data access layer project) and add a new LINQ to SQL class called Library.dbml to it.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R2rCmRYd9iI/AAAAAAAAAAM/3O4wQf9wOjs/s1600-h/1+-+New+Class.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R2rCmRYd9iI/AAAAAAAAAAM/3O4wQf9wOjs/s320/1+-+New+Class.JPG" alt="" id="BLOGGER_PHOTO_ID_5146139486981060130" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_-tXGR0Z9AiQ/R2rC2hYd9jI/AAAAAAAAAAU/QtyiXsW6JqQ/s1600-h/2+-+Server+Explorer.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_-tXGR0Z9AiQ/R2rC2hYd9jI/AAAAAAAAAAU/QtyiXsW6JqQ/s320/2+-+Server+Explorer.JPG" alt="" id="BLOGGER_PHOTO_ID_5146139766153934386" border="0" /&gt;&lt;/a&gt;As a next step, we need to connect to the Microsoft SQL Server 2005 database using Server Explorer in Microsoft Visual Studio 2008.&lt;br /&gt;&lt;br /&gt;This way we can see in our IDE all the tables and stored procedures available in our database.&lt;br /&gt;&lt;br /&gt;We need to drag and drop all of these tables into the left side of the design surface of the Library.dbml file we created.&lt;br /&gt;&lt;br /&gt;We also need to drag and drop the stored procedure into the right design surface of the Library.dbml file.&lt;br /&gt;&lt;br /&gt;Once this is done, our Library.dbml file should look like this:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_-tXGR0Z9AiQ/R2rDCBYd9kI/AAAAAAAAAAc/veX_DsLYWEA/s1600-h/3+-+dbml.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_-tXGR0Z9AiQ/R2rDCBYd9kI/AAAAAAAAAAc/veX_DsLYWEA/s320/3+-+dbml.JPG" alt="" id="BLOGGER_PHOTO_ID_5146139963722430018" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;When we dragged and dropped all this information into our dbml file, what we did was to create a DataContext that maps all the information related to the database itself, by using attributes inside our .NET code.  If we want to see the code generated by the designer, we only need to open the Library.designer.cs file nested under the Library.dbml file in our Solution Explorer.  As you may imagine, there are many attributes that can be used and specified for our applications to customize the database access, but for our example the default values will work just fine.&lt;br /&gt;&lt;br /&gt;This data context will allow us to use simple entities to access the database without having to write SQL code, as we will see ahead.  This shows us how easy it is to create a functional representation of our database, even without having to write code for our Data Access Layer.&lt;br /&gt;&lt;br /&gt;Next we create a new Class Library Project (Our business layer project) and add a new C# class called BookBL.cs to it.&lt;br /&gt;&lt;br /&gt;Here we will code all methods required by the presentation layer, in order to execute business operations and access the database layer.&lt;br /&gt;&lt;br /&gt;A method to add a new Book will look like this:&lt;br /&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;public&lt;/span&gt;&lt;span style=""&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt; addBook(&lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt; book)&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;    {&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt; db = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt;();&lt;br /&gt;db.Books.InsertOnSubmit(book);&lt;br /&gt;db.SubmitChanges();&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; book;&lt;br /&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  Here we create a new instance of the data context file we just created (Library.dbml).  We know it contains a Books entity because we mapped the Books table into our data context.  LINQ to SQL provides the method InsertOnSubmit in order to automatically store the book information for us, so we just call this method to add the new book.  At the end, we execute the method SubmitChanges, also provided by LINQ to SQL, in order to commit our changes into the database.  As you may see, we haven’t written any SQL code, and the LINQ to SQL framework has taken care of most of the data access work.&lt;br /&gt;&lt;br /&gt;Another interesting operation is to query the database.  For this we need to create a method called findByCategory in our BookBL.cs class that looks like this:&lt;br /&gt;&lt;p class="MsoNormal" style=""&gt;&lt;span style=""&gt;    public&lt;/span&gt;&lt;span style=""&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&lt;&lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt;&gt; findByCategory(&lt;span style="color:blue;"&gt;int&lt;/span&gt; id)&lt;br /&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt; db = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt;();&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; books =&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;from&lt;/span&gt; b &lt;span style="color:blue;"&gt;in&lt;/span&gt; db.Books&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;where&lt;/span&gt; b.Category.id == id&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;select&lt;/span&gt; b;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&lt;&lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt;&gt;(books);&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;book&gt;&lt;book&gt;Here we are using LINQ syntax in order to query the database.  We are storing the information retrieved from the database into a var datatype variable.  This isn’t a variable datatype as in the old days of VB 6; instead it is a generic datatype that will be strongly typed with the specific datatype resulting of the database query (in our example, it will be strongly typed with IQueryable&lt;book&gt;).  The compiler will restrict us what can we assign to this variable, and it will also provide intellisense to it.&lt;br /&gt;&lt;br /&gt;Another interesting thing to mention is that LINQ to SQL will allow us to execute stored procedures using LINQ syntax.  So for example if we wanted to rent a book using our rentBook stored procedure, we could invoke it this way:&lt;/book&gt;&lt;/book&gt;&lt;/book&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; rentBook(&lt;span style="color:blue;"&gt;int&lt;/span&gt; id)&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt; db = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt;();&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;db.rentBook(&lt;span style="color: rgb(163, 21, 21);"&gt;"anonymous"&lt;/span&gt;, id);&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;book&gt;&lt;book&gt;&lt;book&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;Transactions&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;LINQ to SQL also helps developers in this point.  By default, when the SubmitChanges method is called, if a transaction is not already in scope, the SubmitChanges method will automatically create a new transaction.  All database operations executed during a single SubmitChanges will be wrapped into a single transaction, and as such, if any error occurs, the whole operation is aborted.&lt;br /&gt;&lt;br /&gt;If we need to handle transactions at a higher level, or maybe even nest several SubmitChanges into a single transaction, we can make us of System Transactions, as int the following example:&lt;/book&gt;&lt;/book&gt;&lt;/book&gt;&lt;br /&gt;&lt;p class="MsoNormal" style="text-align: left;" align="left"&gt;&lt;span style=""&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt; addBook(&lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt; book)&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; (&lt;span style="color: rgb(43, 145, 175);"&gt;TransactionScope&lt;/span&gt; ts = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;TransactionScope&lt;/span&gt;())&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;{&lt;br /&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style=""&gt;          &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt; db = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt;();&lt;br /&gt;&lt;span style=""&gt;                &lt;/span&gt;db.Books.InsertOnSubmit(book);&lt;br /&gt;&lt;span style=""&gt;                &lt;/span&gt;db.SubmitChanges();&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; book;&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;}&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;book&gt;&lt;book&gt;&lt;book&gt;&lt;span style="font-weight: bold; font-style: italic;font-size:130%;" &gt;Concurrency&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It is possible to implement both Optimistic and Pessimistic concurrency for conflict resolutions when using LINQ to SQL.&lt;br /&gt;&lt;br /&gt;By default LINQ to SQL takes care of optimistic concurrency, providing two different options to handle it.&lt;br /&gt;&lt;br /&gt;One option is to provide a timestamp datatype column in the table were conflicts are expected.  Using this approach, the LINQ to SQL framework will automatically update the timestamp column with every insert / update commited into the database.  When someone tries to update a record by executing the SubmitChanges method, LINQ to SQL checks if the timestamp provided is valid.  If it is different to the current timestamp, it means someone previously updated the record, and because of this data needs to be refreshed, so a ChangeConflictException is thrown.&lt;br /&gt;&lt;br /&gt;So, a proper way to do an update operation is listed below, where we handle any possible ChangeConflictException:&lt;/book&gt;&lt;/book&gt;&lt;/book&gt;&lt;br /&gt;    &lt;p class="MsoNormal" style="text-align: left;" align="left"&gt;&lt;span style=""&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt; updateBook(&lt;span style="color: rgb(43, 145, 175);"&gt;Book&lt;/span&gt; book)&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;{&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt; db = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;LibraryDataContext&lt;/span&gt;();&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;db.Books.Attach(book, &lt;span style="color:blue;"&gt;true&lt;/span&gt;);&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;{&lt;br /&gt;&lt;span style=""&gt;                &lt;/span&gt;db.SubmitChanges();&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;}&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;catch&lt;/span&gt; (&lt;span style="color: rgb(43, 145, 175);"&gt;ChangeConflictException&lt;/span&gt; cce)&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;{&lt;br /&gt;&lt;span style=""&gt;                &lt;/span&gt;&lt;span style="color:blue;"&gt;throw&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataOutOfSyncException&lt;/span&gt;();&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: left;" align="left"&gt;&lt;span style=""&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; book;&lt;br /&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;        &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;book&gt;&lt;book&gt;&lt;book&gt;The other option of providing optimistic concurrency is by specifying which of the columns of a table should be checked for conflicts.  If the listed columns differ when making an update, then a ChangeConflictException will be thrown.&lt;br /&gt;&lt;br /&gt;To handle pessimistic concurrency, the only thing that needs to be done is to read the record, and then update it, but executing both operations inside a single System Transaction.&lt;br /&gt;&lt;br /&gt;&lt;/book&gt;&lt;/book&gt;&lt;/book&gt;&lt;span style="font-weight: bold; font-style: italic;font-size:130%;" &gt;Efficiency&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Object Relational Mapping solutions have always faced the challenge of generating efficient SQL statements.  Since this technology is not new, great improvements have been achieved towards this goal.  Even though, it is well known that for particular database operations that demand high optimization, the best solution is to manually create and tune the SQL statement.&lt;br /&gt;&lt;br /&gt;LINQ to SQL provides the feature to print out the SQL statements being generated, so that the developer can decide if the generated statements are good for the application, or if manual intervention is required.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;font-size:130%;" &gt;Conclusions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;LINQ to SQL is a very powerful solution that allows us to reduce the amount of code, and hence, the amount of time invested developing applications.  The data access layer is considerably automatized, and operations such as transactions and concurrency are easier to handle.&lt;br /&gt;&lt;br /&gt;All this ease of development comes with the price of not-optimized SQL statements being generated.  When choosing LINQ to SQL as the core data access technology we should study generated SQL statements to identify whether or not we need to manually enhance them.  Depending on the application, the SQL statements being generated may be just good for the job.&lt;br /&gt;&lt;br /&gt;Object Relational Mapping (ORM) solutions are not new, but LINQ to SQL is.  This means that it lacks many of the features that more mature frameworks such as Hibernate provide.  To tackle this, Microsoft is developing the ADO.NET Entity Framework as a separate addition to the .NET framework.  This new framework will provide more functionality to the mix, while making development a little bit more complex.&lt;br /&gt;&lt;br /&gt;This kind of ORM solutions have dominated the Java world for enterprise applications, and have done it for several years now.  It won't come as a surprise if something similar happens with .Net applications, so we should pay close attention to this kind of solutions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6794514250333471393-5759947216782757057?l=isthmuspuravida.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://isthmuspuravida.blogspot.com/feeds/5759947216782757057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6794514250333471393&amp;postID=5759947216782757057' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/5759947216782757057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6794514250333471393/posts/default/5759947216782757057'/><link rel='alternate' type='text/html' href='http://isthmuspuravida.blogspot.com/2007/12/look-into-linq-to-sql.html' title='A look into LINQ to SQL'/><author><name>Eliecer Leiton</name><uri>http://www.blogger.com/profile/08704934982771547622</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_-tXGR0Z9AiQ/R2rCmRYd9iI/AAAAAAAAAAM/3O4wQf9wOjs/s72-c/1+-+New+Class.JPG' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
