<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5741401390511285234</atom:id><lastBuildDate>Mon, 28 Nov 2011 00:34:30 +0000</lastBuildDate><category>Stripes</category><category>Overview</category><category>RMDB</category><category>Struts</category><category>Research</category><category>Problem-solving</category><category>Technology</category><category>Eclipse</category><category>Hibernate</category><category>Patterns</category><category>Spring</category><category>JUnit</category><category>Software Frameworks</category><category>Oracle</category><category>Java</category><category>J2EE</category><category>Interview</category><category>News</category><category>Google</category><category>Ajax</category><category>Programming</category><category>Theory</category><category>Testing</category><title>IT Efforts</title><description>This blog covers developing Web-applications based on the latest Java IT technology, popular Open Source Projects, IDE and Software Frameworks the same as Eclipse, Hibernate, Spring, Struts, Maven, etc...</description><link>http://itefforts.blogspot.com/</link><managingEditor>noreply@blogger.com (IT Efforts)</managingEditor><generator>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blogspot/TIsO" /><feedburner:info uri="blogspot/tiso" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-2972000703200619221</guid><pubDate>Wed, 27 Feb 2008 15:49:00 +0000</pubDate><atom:updated>2008-02-27T07:52:04.741-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Technology</category><category domain="http://www.blogger.com/atom/ns#">RMDB</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><title>10 important things using Hibernate/JPA</title><description>&lt;p&gt;&lt;strong&gt;1) Become friends with the DBAs.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;There is a tendency for some Java developers to marginalize the importance of DBAs. This is a huge mistake - a good working relationship with the keepers of the data is critical to success with any ORM technology. This is important for two reasons:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;DBAs alone usually can’t make your Hibernate efforts successful, but they often can make them fail.  &lt;li&gt;They usually have really good insight into the database itself, good modelling practices, and any pitfalls or shortcuts for you. I can think of several instances where a timely suggestion from a DBA saved us days and gave us an elegant solution.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;In most cases, having good DBAs and having good relationships with them is highly critical to the success of your ORM efforts. Plus, database guys are usually pretty cool people :)&lt;/p&gt; &lt;p&gt;&lt;strong&gt;2) Use (and enforce) good naming standards from the beginning.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Who knew naming standards discussions could be so contentious? One of the things we try to accomplish with ORM tools is to make our data model more meaningful, which makes it easier for developers to use and helps avoid confusion. To this end, how we name entities and attributes is very important. I have naming standards I like and think are best, but I won’t try to push them on you here. The important thing is that you decide on something upfront and get everyone to use it. Actually, this should extend beyond just naming standards and should be inclusive of other standards as well (ie, Boolean vs “Y/N” or 0/1, primitive vs Object, Integer vs Long, etc).&lt;br&gt;&lt;strong&gt;&lt;br&gt;3) Don’t try to map every attribute (and association).&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;We started out trying to use tools like Dali to map everything on a table quickly (some tables had several hundred columns!). This turned out to be a bad idea. Why? Since we were on a shared, legacy database, there were a ton of fields we didn’t care about and never used. Mapping them led to performance issues and confusion.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;4) Let the database do the things it is good at.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;We really wanted to have a good, clean data model, and so we avoided at all costs writing extra queries to fetch things pertinent to an object or using stored procedures or functions at all. This was also a mistake - databases are good for stuff other than just holding the data Hibernate creates and reads :) For example, we had one object that had a status associated with it. The status was used all over the app so it had to be performant, but we also didn’t want to have to make a separate query every time we needed it. The problem is, the status was derived based on some calculations that operated on several one-to-many relationships. Pulling back all that data as part of each load of the object would have been way to expensive. Working with one of our database guys (see #1), we found a sql function we could use to get the status very quickly. We mapped this to a status attribute using @Formula and had everything we wanted - it was part of the domain model still, and was very performant. Sometimes little compromises like this can yield big dividends.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;5) Break up the database.&lt;br&gt;&lt;/strong&gt;&lt;br&gt;When we first started, I wanted to model the whole databse in Hibernate at the beginning. This turns out to have been really impractical for a few reasons:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;a) It was a huge job and would have consumed weeks of time while the customer would have seen no actual work being done.  &lt;li&gt;b) I was unlikely to get it right the first time, meaning developers would have to change it anyway as we got started.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;There is a tendency to want to map the whole thing out before starting, but a lot of times you just have to work on it as you go. I did find it useful to break it up into pieces and try to do a whole piece at a time as we went - which really seems to have helped.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;6) Watch out for triggers.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Watch out for database triggers for two reasons:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;a) They can do sneaky things behind the scenes that can lead you to pulling your hair out, wondering what happened.  &lt;li&gt;b) Sometimes they do stuff that you need to replicate on the Hibernate side. Several times before we fully learned this lesson, we missed some important things that triggers were doing and almost caused ourselves some real grief.&lt;br&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;7) Shy away from tools to auto-generate your model.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Yeah, they can save time (although we found Dali to be terribly buggy at the time we used it), but you end up having to re-do a lot of it anyway. It doesn’t take that long to map them by hand, and it gives you a chance to familiarize yourself with the data more as you do it.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;8) Use NamedQueries where you can.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;It is easy to just pound a query out in-line, but in a lot of cases it is better to use NamedQueries. This helps to do two things:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;a) It fosters more re-use, since the named queries are generally located in central places in the code.  &lt;li&gt;b) Your queries get validated on startup, making it so errors in the queries (especially down the road when they can get messed up by model or table changes) discovered much more quickly.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;It sometimes takes a bit of getting used to (and strong-arming!), but it is worth the effort.&lt;br&gt;&lt;strong&gt;&lt;br&gt;9) Manage Expectations.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;This is probably important to keep in mind for any new framework, technology, or even concept. For some reason, people tend to get sold on certain features that simply don’t exist, or are highly exaggerated. Sometimes it is small and understandable (ie, underestimating the actual work required to map stuff in Hibernate), and sometimes I have no idea how they came up with such ideas (ie, that Hibernate can somehow manage schema revisioning). At any rate, finding out what the expectations are and then managing them can be really important. If your team thinks that Hibernate will make DBAs completely obsolete (usually quite false) and fires them all, you will probably have a big problem on your hands.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;10) Use rich domain modeling.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;One of the sadder things I’ve seen with projects that use Hibernate (and in some cases, I’ve seen it because I’ve done it!) is when the domain objects become no more than simple containers of data. The goal of tools like Hibernate is to let us use data in an object-oriented fashion - simply mapping the data only gets us halfway there. As I’ve made conscious efforts to practice rich domain modeling, I’ve noticed that we reuse a lot more code, our other layers become less cluttered, and our code is more testable and easier to refactor. &lt;/p&gt; &lt;p style="font-size: 80%" align="right"&gt;Source: &lt;a title="Reference Guide" href="http://www.spenceruresk.com" rel="nofollow"&gt;SpencerUresk&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-2972000703200619221?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/naAqUE0QpeI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/naAqUE0QpeI/10-important-things-using-hibernatejpa.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>2</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2008/02/10-important-things-using-hibernatejpa.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-2842262739224030149</guid><pubDate>Wed, 16 Jan 2008 14:21:00 +0000</pubDate><atom:updated>2008-01-16T06:21:21.995-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Technology</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Overview</category><category domain="http://www.blogger.com/atom/ns#">J2EE</category><category domain="http://www.blogger.com/atom/ns#">Spring</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><title>Acegi Security for Spring Framework</title><description>&lt;img style="padding-right: 10px; padding-left: 0px; float: left; padding-bottom: 0px; padding-top: 0px" src="http://acegisecurity.org/images/logo.gif"&gt;&lt;a title="Acegi Security" href="http://acegisecurity.org/" rel="nofollow"&gt;Acegi Security&lt;/a&gt; provides comprehensive security services for J2EE-based enterprise software applications. There is a particular emphasis on supporting projects built using The Spring Framework, which is the leading J2EE solution for enterprise software development. If you're not using Spring for developing enterprise applications, we warmly encourage you to take a closer look at it. Some familiarity with Spring - and in particular dependency injection principles - will help you get up to speed with Acegi Security more easily.  &lt;p&gt;People use Acegi Security for many reasons, but most are drawn to the project after finding the security features of J2EE's Servlet Specification or EJB Specification lack the depth required for typical enterprise application scenarios. Whilst mentioning these standards, it's important to recognise that they are not portable at a WAR or EAR level. Therefore, if you switch server environments, it is typically a lot of work to reconfigure your application's security in the new target environment. Using Acegi Security overcomes these problems, and also brings you dozens of other useful, entirely customisable security features.&lt;/p&gt; &lt;p&gt;As you probably know, security comprises two major operations. The first is known as "authentication", which is the process of establishing a principal is who they claim to be. A "principal" generally means a user, device or some other system which can perform an action in your application. "Authorization" refers to the process of deciding whether a principal is allowed to perform an action in your application. To arrive at the point where an authorization decision is needed, the identity of the principal has already been established by the authentication process. These concepts are common, and not at all specific to Acegi Security.&lt;/p&gt; &lt;p&gt;At an authentication level, Acegi Security supports a wide range of authentication models. Most of these authentication models are either provided by third parties, or are developed by relevant standards bodies such as the Internet Engineering Task Force. In addition, Acegi Security provides its own set of authentication features. Specifically, Acegi Security currently supports authentication with all of these technologies:&lt;/p&gt; &lt;div class="itemizedlist"&gt; &lt;ul type="disc" compact&gt; &lt;li&gt; &lt;p&gt;HTTP BASIC authentication headers (an IEFT RFC-based standard)&lt;/p&gt; &lt;li&gt; &lt;p&gt;HTTP Digest authentication headers (an IEFT RFC-based standard)&lt;/p&gt; &lt;li&gt; &lt;p&gt;HTTP X.509 client certificate exchange (an IEFT RFC-based standard)&lt;/p&gt; &lt;li&gt; &lt;p&gt;LDAP (a very common approach to cross-platform authentication needs, especially in large environments)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Form-based authentication (for simple user interface needs)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Computer Associates Siteminder&lt;/p&gt; &lt;li&gt; &lt;p&gt;JA-SIG Central Authentication Service (otherwise known as CAS, which is a popular open source single sign on system)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Transparent authentication context propagation for Remote Method Invocation (RMI) and HttpInvoker (a Spring remoting protocol)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Automatic "remember-me" authentication (so you can tick a box to avoid re-authentication for a predetermined period of time)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Anonymous authentication (allowing every call to automatically assume a particular security identity)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Run-as authentication (which is useful if one call should proceed with a different security identity)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Java Authentication and Authorization Service (JAAS)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Container integration with JBoss, Jetty, Resin and Tomcat (so you can still use Container Manager Authentication if desired)&lt;/p&gt; &lt;li&gt; &lt;p&gt;Your own authentication systems (see below)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt; &lt;p&gt;Many independent software vendors (ISVs) adopt Acegi Security because of this rich choice of authentication models. Doing so allows them to quickly integrate their solutions with whatever their end clients need, without undertaking a lot of engineering or requiring the client to change their environment. If none of the above authentication mechanisms suit your needs, Acegi Security is an open platform and it is quite simple to write your own authentication mechanism. Many corporate users of Acegi Security need to integrate with "legacy" systems that don't follow any particular security standards, and Acegi Security is happy to "play nicely" with such systems.&lt;/p&gt; &lt;p&gt;Sometimes the mere process of authentication isn't enough. Sometimes you need to also differentiate security based on the way a principal is interacting with your application. For example, you might want to ensure requests only arrive over HTTPS, in order to protect passwords from eavesdropping or end users from man-in-the-middle attacks. Or, you might want to ensure that an actual human being is making the requests and not some robot or other automated process. This is especially helpful to protect password recovery processes from brute force attacks, or simply to make it harder for people to duplicate your application's key content. To help you achieve these goals, Acegi Security fully supports automatic "channel security", together with JCaptcha integration for human user detection.&lt;/p&gt; &lt;p&gt;Irrespective of how authentication was undertaken, Acegi Security provides a deep set of authorization capabilities. There are three main areas of interest in respect of authorization, these being authorizing web requests, authorizing methods can be invoked, and authorizing access to individual domain object instances. To help you understand the differences, consider the authorization capabilities found in the Servlet Specification web pattern security, EJB Container Managed Security and file system security respectively. Acegi Security provides deep capabilities in all of these important areas, which we'll explore later in this reference guide.&lt;/p&gt; &lt;p style="font-size: 80%" align="right"&gt;Source: &lt;a title="Reference Guide" href="http://acegisecurity.org/reference.html" rel="nofollow"&gt;Official Reference Guide&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-2842262739224030149?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/tAA4wBcW0NE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/tAA4wBcW0NE/acegi-security-for-spring-framework.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2008/01/acegi-security-for-spring-framework.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-5087912573310955353</guid><pubDate>Sun, 16 Dec 2007 15:17:00 +0000</pubDate><atom:updated>2007-12-17T07:26:31.087-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Interview</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><title>Interview with Gavin King, founder of Hibernate project</title><description>&lt;img style="float: left; padding: 0 10px 0 0;" border="0" src="http://www.javafree.com.br/dependencias/entrevistas/gavin/gavin.jpg"&gt;&lt;i&gt;&lt;a rel="nofollow" href="http://in.relation.to/Bloggers/Gavin"&gt;Gavin King&lt;/a&gt; is the founder of the &lt;a rel="nofollow" href="http://hibernate.org"&gt;Hibernate&lt;/a&gt; project, a object / relational mapping framework for Java. Currently, he works full time in the project, paid by the JBoss Group. In this interview, Gavin King talks about his entering in the JBoss Group, and the Hibernate Project, what's new in version 3 and the integration of the framework with the new features of Java 5. &lt;/i&gt;&lt;p&gt;  &lt;strong&gt; 1. Please, tell us a little about yourself and your 'real' job.  &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; I live in Melbourne, Australia and I've been working in IT - mostly Java - for about five years now. For the past year my &amp;quot;real&amp;quot; job has been Hibernate. I'm a rare example of a developer who is paid to write open source software. In fact, myself, Christian Bauer, Steve Ebersole and Max Andersen now all work for JBoss, developing Hibernate and providing commercial services. I'm also an active member of the JSR-220 (EJB 3.0) spec committee. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 2. In your opinion, Hibernate become so successful? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; Hibernate became successful because it solves a very common problem reasonably elegantly, because it is an open source solution, and because it is practical. We took seriously the idea that OO and relational technologies should work smoothly together. And we allowed our project to be driven by user requirements. We also knew that great technology is useless if you can't explain it. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 3. What was your main motivation when you created Hibernate? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; I wanted to solve an interesting problem, a problem that affected me personally. I was frustrated with working with EJB 2 style entity beans and brittle handwritten persistence layers. &lt;/p&gt; &lt;p&gt; Also, I wanted to win an argument with my then-boss; -) &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 4. What benefits your decision of joining the JBoss Group may bring to the Hibernate project? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; In the long run, it's simply not possible to do a project with the scope of Hibernate in your spare time. By the time I joined JBoss, I was spending so much time responding to questions from users and fixing minor bugs, that there was no time left for sleeping, let alone improving Hibernate. So working for JBoss has made it possible for Hibernate to continue to exist and grow. It also allows us to actually get out there in the field, speaking at conferences and JUGs, working on site with Hibernate users, and participating in the JCP. &lt;/p&gt; &lt;p&gt; From the point of view of Hibernate users, they get not just a better product (due to having four fulltime developers), but also the opportunity to get training and buy 24 / 7 production support. Not everyone cares about these things, but a lot of people do, especially in larger organizations. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 5. How do you see other ORM tools like OJB, JDO and Toplink? Do you evaluate or spend time looking at feature of those products? Why people would choose Hibernate? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; Um, traditionally, no, we did not pay that much attention - I was much more comfortable being guided by request from users, than by &amp;quot;what the other guys got&amp;quot;. However, more recently, we have done some feature-by-feature competitive evaluations of the two leading commercial ORM solutions, just to make sure we didn't miss anything. This has had some influence upon the feature list of Hibernate3, where there are a couple of features that I would describe as being more useful for marketing than for practical purposes. &lt;/p&gt; &lt;p&gt; The Hibernate3 core is the most powerful ORM engine in the world - and it will take a little while for others to catch up. However, we've realized more recently that there is more than just the runtime engine to think about and over the next year there will be a lot more focus upon polishing and in some cases rewriting our development-time toolset. Max is leading that effort. Hibernate will evolve into a suite of products that address the whole problem of writing Java applications which use relational data. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 6. How do you see alternatives to relational databases, like XML and OO databases, or Prevayler? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; We don't see them; -) &lt;/p&gt; &lt;p&gt; Truly, the relational data model is a wonderful innovation, and it would be an absolute disaster to replace it with flawed persistence technologies like XMLDBs or OODBMS. Fortunately, that simply won't happen, since there is simply no industry interest or momentum behind either. &lt;/p&gt; &lt;p&gt; Technologies like OODBMS sacrifice sound, application technology agnostic data management for sort-term convenience (convenience for one single application, written using one particular programming language). Relational technology essentially completely replaced network or hierarchical database technology, and there were excellent reasons why that happened. We should most certainly not be reviving either of those discredited approaches by slapping on the latest buzzwords (OO, XML, etc) as window dressing. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 7. Are there any changes you would like to see in the JDBC API to make Hibernate better and faster? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; It would be great to be able to batch together different SQL statements using the JDBC batch update API (at present, you can only batch multiple parameter sets for the same statement). &lt;/p&gt; &lt;p&gt; However, rather than seeing many new features in JDBC, I would be incredibly happy if vendors would simply provide complete, reliable implementations of the features that are already there in JDBC 3. It's actually quite disgraceful how broken the JDBC drivers of certain big-name RDBMS vendors are. They don't seem to care. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 8. Is there any plan to make Hibernate compliant with the JDO Spec? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; No. Hibernate will provide an implementation of the EJB3 EntityManager defined by the JSR-220 specification. Sun has just announced that the scope of JSR-220 will be expanded to cover operation outside the traditional monolithic J2EE container. &lt;/p&gt; &lt;p&gt; We don't see any future for JDO. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 9. Do you foresee the upcoming release of EJB3 reducing the need for Hibernate? Are there any benefits of using both, like in a BMP environment? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; EJB 3.0 is a specification. Hibernate will be an implementation of that specification. So you can use both at the same time; -) Alternatively, we intend that some people, who don't care about standards as much, will continue to use Hibernate-specific APIs, especially for functionality that is not yet standardized by JSR-220. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 10. Could you tell us about what's new in Hibernate 3, and the benefits these changes will bring to users? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; The biggest, most innovative new thing is the support for parameterized &amp;quot;filters&amp;quot;. This feature let's you see an object graph that is just a subset of the total data in the database. This is incredibly useful when dealing with temporal, versioned, regional, or permissioned data. In fact, I expect that most business domains have usecases for this feature and that it will soon be considered an indispensable feature of Hibernate. &lt;/p&gt; &lt;p&gt; We have done a huge amount of work on adding greater mapping flexibility, to support more complex (or even broken) relational models. This takes the form of a number of small new features, that are really most significant when taken together. Hibernate is now able to handle just about any crazy thing you are likely to find in a legacy database. &lt;/p&gt; &lt;p&gt; In addition, it is now possible to override any SQL statement that Hibernate generates with your own hand-written SQL. This gives your DBA the freedom to hand-tune the SQL when necessary. &lt;/p&gt; &lt;p&gt; Some further major changes in Hibernate3 were designed to align us more closely with JSR-220. &lt;/p&gt; &lt;p&gt; Finally, we put a huge amount of thought into what small changes we could make that would make Hibernate easier to use for beginners. Hopefully that will reduce the incidence of certain FAQs in the Hibernate forum! &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 11. How about Metadata in Java 5.0? Do you have plans to support it? It is a real alternative to hbm.xml? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; Absolutely! Emmanuel Bernard is working on implementing the EJB 3.0 ORM metadata for Hibernate, and adding Hibernate-specific extensions. &lt;/p&gt; &lt;p&gt; We've seen how many people like to use XDoclet annotations to express their Hibernate mappings, and so I'm quite certain that even more people will feel comfortable using JSR-175 annotations. &lt;/p&gt; &lt;p&gt; In fact, I fully expect that this will be the most common way to use ORM in the future. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 12. How can Generics change our Hibernate code? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; Not a great deal. Hibernate can already persist templated collections, so you can get a bit more strongly typed in your domain model. Templated collections could even help Hibernate guess the type of an association and reduce the amount of metadata you have to write. However, I don't think this is an especially significant new feature in the context of ORM. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 13. Which of Tiger's new features are more likely to be used in the Hibernate code base in the future? Why? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; Well, we are a bit stuck. We can't use many of the new features, because Hibernate needs to stay source-level compatible with older JDKs. The annotations stuff is okay, because we can provide it as an add-on package. &lt;/p&gt; &lt;p&gt; Certainly, annotations are the most significant new feature of Java 5, and it's very likely that they will completely change the way we write code. &lt;/p&gt; &lt;p&gt; &lt;strong&gt; 14. What do you do in your free time? &lt;/strong&gt; &lt;/p&gt; &lt;p&gt; Retail therapy. &lt;/p&gt;&lt;p style="font-size: 80%" align="right"&gt;Source: &lt;a rel="nofollow" title="simoes.org" href="http://www.javafree.org" rel="nofollow"&gt;www.javafree.org&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-5087912573310955353?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/4oJWEAy1B1w" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/4oJWEAy1B1w/interview-with-gavin-king-founder-of.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/12/interview-with-gavin-king-founder-of.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-3365679905523579762</guid><pubDate>Wed, 14 Nov 2007 12:03:00 +0000</pubDate><atom:updated>2007-11-14T05:22:33.404-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">J2EE</category><category domain="http://www.blogger.com/atom/ns#">Patterns</category><title>EJB Programming Restrictions</title><description>&lt;ol&gt; &lt;li&gt;Using static, nonfinal fields. Declaring all static fields in the EJB component as final is recommended. That ensures consistent runtime semantics so that EJB containers have the flexibility to distribute instances across multiple JVMs. &lt;li&gt;Using thread synchronization primitives to synchronize multiple instance execution. By avoiding that feature, you allow the EJB container flexibility to distribute instances across multiple JVMs. &lt;li&gt;Using AWT functionality for keyboard input/display output. That restriction exists because server-side business components are meant to provide business functionality that excludes user interface and keyboard I/O functionality. &lt;li&gt;Using file access/java.io operations. EJB business components are meant to use resource managers such as JDBC to store and retrieve application data rather than the file system APIs. Also, deployment tools provide the facility for storing environment entry elements (env-entry) into the deployment descriptor, so that EJB components can perform environment entry lookups in a standardized manner via the environment-naming context. Thus, the need to use file system-based property files is mostly eliminated. &lt;li&gt;Listening to or accepting socket connections, or using a socket for multicast. EJB components are not meant to provide network socket server functionality; however, the architecture lets EJB components act as a socket client or RMI clients and thus communicate with code outside the container's managed environment. &lt;li&gt;Using the Reflection API to query classes that are not otherwise accessible to the EJB component due to Java's security rules. That restriction enforces Java platform security. &lt;li&gt;Attempting to create or obtain a class loader, set or create a new security manager, stop the JVM, change the input, output, and error streams. That restriction enforces security and maintains the EJB container's ability to manage the runtime environment. &lt;li&gt;Setting the socket factory used by the URL's ServerSocket, Socket, or stream handler. By avoiding that feature, you also enforce security and maintain the EJB container's ability to manage the runtime environment. &lt;li&gt;Starting, stopping, or managing threads in any way. That restriction eliminates the possibility of conflicts with the EJB container's responsibilities of managing locking, threading, and concurrency issues. &lt;li&gt;By restricting your use of features 10-16, you aim to plug potential security holes: &lt;li&gt;Reading or writing a file descriptor directly. &lt;li&gt;Obtaining security policy information for a particular code source. &lt;li&gt;Loading native libraries. &lt;li&gt;Accessing packages and classes that the usual rules of Java make unavailable. &lt;li&gt;Defining a class in a package. &lt;li&gt;Accessing or modifying security configuration objects (Policy, Security, Provider, Signer, and Identity). &lt;li&gt;Using the subclass and object substitution features of the Java Serialization protocol. &lt;li&gt;Passing the this reference as an argument or returning the this reference as a result. Instead, you must use the result of the getEJBObject() available in SessionContext or EntityContext.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-3365679905523579762?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/qmIvxyS-hzM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/qmIvxyS-hzM/ejb-programming-restrictions.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>2</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/11/ejb-programming-restrictions.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-4491672302368928143</guid><pubDate>Fri, 05 Oct 2007 15:31:00 +0000</pubDate><atom:updated>2007-10-05T08:44:24.933-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Technology</category><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Research</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><title>Understanding "inverse" mapping attribute</title><description>&lt;h4&gt;Generality&lt;/h4&gt;&lt;p&gt;This page intends to give an internal view and understanding of &lt;tt&gt;inverse=&amp;quot;true&amp;quot;&lt;/tt&gt;. Please, please, please read the Hibernate reference guide and especially:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Mapping a collection&lt;/li&gt;&lt;li&gt;Bidirectional Association&lt;/li&gt;&lt;li&gt;Parent Child Relationships&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;and the FAQs (the official ones and the one from the Wiki) before reading this.&lt;/p&gt;&lt;p&gt;Inverse defines which side is responsible of the association maintenance. The side having &lt;tt&gt;inverse=&amp;quot;false&amp;quot;&lt;/tt&gt; (default value) has this responsibility (and will create the appropriate SQL query - insert, update or delete). Changes made to the association on the side of the &lt;tt&gt;inverse=&amp;quot;true&amp;quot;&lt;/tt&gt; are not persisted in DB.&lt;/p&gt;&lt;p&gt;Inverse attribute is not related in any way to the navigation through relationship. It is related to the way hibernate generate SQL queries to update association data. Association data are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;a column in the one-to-many association&lt;/li&gt;&lt;li&gt;a row in the association table in a many-to-many association&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Monodirectional association is managed by the only side available through navigation. When association is bidirectional, choosing the manager side allow better SQL optimization, this is the recommended behaviour.&lt;/p&gt;&lt;a name="A3"&gt;&lt;/a&gt;&lt;h4&gt;one-to-many sample&lt;/h4&gt;&lt;p&gt;Let's have a look at a simple one-to-many sample. Setting inverse=&amp;quot;true&amp;quot; is recommanded and allow SQL optimization.&lt;/p&gt;&lt;p&gt;Note that &lt;tt&gt;&amp;lt;many-to-one&amp;gt;&lt;/tt&gt; is &lt;strong&gt;always&lt;/strong&gt; &lt;tt&gt;inverse=&amp;quot;false&amp;quot;&lt;/tt&gt; (the attribute does not exist).&lt;/p&gt;&lt;pre class="code"&gt;&amp;lt;class name=&amp;quot;net.sf.test.Parent&amp;quot; table=&amp;quot;parent&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;id name=&amp;quot;id&amp;quot; column=&amp;quot;id&amp;quot; type=&amp;quot;long&amp;quot; unsaved-value=&amp;quot;null&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;generator class=&amp;quot;sequence&amp;quot;&amp;gt;&lt;br /&gt;      &amp;lt;param name=&amp;quot;sequence&amp;quot;&amp;gt;SEQ_DEFAULT&amp;lt;/param&amp;gt;&lt;br /&gt;    &amp;lt;/generator&amp;gt;&lt;br /&gt;  &amp;lt;/id&amp;gt;&lt;br /&gt;  &amp;lt;set name=&amp;quot;children&amp;quot; lazy=&amp;quot;true&amp;quot; inverse=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;      &amp;lt;key column=&amp;quot;parent_id&amp;quot;/&amp;gt;&lt;br /&gt;      &amp;lt;one-to-many class=&amp;quot;net.sf.test.Child&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;/set&amp;gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;class name=&amp;quot;net.sf.test.Child&amp;quot; table=&amp;quot;child&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;id name=&amp;quot;id&amp;quot; column=&amp;quot;id&amp;quot; type=&amp;quot;long&amp;quot; unsaved-value=&amp;quot;null&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;generator class=&amp;quot;sequence&amp;quot;&amp;gt;&lt;br /&gt;      &amp;lt;param name=&amp;quot;sequence&amp;quot;&amp;gt;SEQ_DEFAULT&amp;lt;/param&amp;gt;&lt;br /&gt;    &amp;lt;/generator&amp;gt;&lt;br /&gt;  &amp;lt;/id&amp;gt;&lt;br /&gt;  &amp;lt;many-to-one name=&amp;quot;parent&amp;quot; column=&amp;quot;parent_id&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The &lt;tt&gt;inverse=&amp;quot;true&amp;quot;&lt;/tt&gt; is set to the one side.&lt;/p&gt;&lt;a name="A4"&gt;&lt;/a&gt;&lt;h4&gt;Proper code&lt;/h4&gt;&lt;pre class="code"&gt;Parent p = new Parent();&lt;br /&gt;Child c = new Child();&lt;br /&gt;p.setChildren(new HashSet());&lt;br /&gt;p.getChildren().add(c);&lt;br /&gt;c.setParent(p);&lt;br /&gt;&lt;br /&gt;session.save(p);&lt;br /&gt;session.save(c);&lt;br /&gt;session.flush();&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select SEQ_DEFAULT.nextval from dual&lt;br /&gt;Hibernate: select SEQ_DEFAULT.nextval from dual&lt;br /&gt;Hibernate: insert into parent (id) values (?)&lt;br /&gt;Hibernate: insert into child (parent_id, id) values (?, ?)&lt;/pre&gt;&lt;p&gt;Hibernate insert parent then insert child. Note that my DB has a not null FK constraint on Child(parent_id), inserts work fine because I set &lt;tt&gt;&amp;lt;many-to-one not-null=&amp;quot;true&amp;quot;&lt;/tt&gt;&lt;/p&gt;&lt;p&gt;Note that I explicitly save parent and child objets. A better way is to use the &lt;tt&gt;cascade=&amp;quot;save-update&amp;quot;&lt;/tt&gt; element. I didn't do it to keep this explanation easier to understand and avoid concepts mismatch.&lt;/p&gt;&lt;a name="A5"&gt;&lt;/a&gt;&lt;h4&gt;inverse=&amp;quot;true&amp;quot; sample&lt;/h4&gt;&lt;a name="A6"&gt;&lt;/a&gt;&lt;h4&gt;Insert&lt;/h4&gt;&lt;pre class="code"&gt;Parent p = new Parent();&lt;br /&gt;Child c = new Child();&lt;br /&gt;p.setChildren(new HashSet());&lt;br /&gt;p.getChildren().add(c);&lt;br /&gt;c.setParent(p);&lt;br /&gt;&lt;br /&gt;session.save(p);&lt;br /&gt;session.flush(); //flush to DB&lt;br /&gt;System.out.println(&amp;quot;Parent saved&amp;quot;);&lt;br /&gt;&lt;br /&gt;session.save(c);&lt;br /&gt;System.out.println(&amp;quot;Child saved&amp;quot;);&lt;br /&gt;session.flush(); //flush to DB&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select SEQ_DEFAULT.nextval from dual&lt;br /&gt;Hibernate: insert into parent (id) values (?)&lt;br /&gt;Parent saved&lt;br /&gt;Hibernate: select SEQ_DEFAULT.nextval from dual&lt;br /&gt;Hibernate: insert into child (parent_id, id) values (?, ?)&lt;br /&gt;Child saved&lt;/pre&gt;&lt;p&gt;As you can see the relationship (incarnated by the parent_id column) is set during the child save : this is of the child responsibility. When saving parent, nothing is done on the relationship.&lt;/p&gt;&lt;a name="A7"&gt;&lt;/a&gt;&lt;h4&gt;Update&lt;/h4&gt;&lt;p&gt;Let's have a look at a relationship update&lt;/p&gt;&lt;pre class="code"&gt;Parent p = (Parent) session.load(Parent.class, parentId);&lt;br /&gt;Parent p2 = (Parent) session.load(Parent.class, parentId2);&lt;br /&gt;        &lt;br /&gt;c = (Child) session.find(&lt;br /&gt;            &amp;quot;from Child as child where child.parent = ?&amp;quot;,&lt;br /&gt;            p, Hibernate.entity(Parent.class)).get(0);&lt;br /&gt;&lt;br /&gt;// change parent of child c from p to p2&lt;br /&gt;p.getChildren().remove(c);&lt;br /&gt;p2.getChildren().add(c);&lt;br /&gt;c.setParent(p2);&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=? //get parent 1&lt;br /&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=? //get parent 2&lt;br /&gt;Hibernate: select child0_.id as id, child0_.parent_id as parent_id from child child0_ where (child0_.parent_id=? ) //get children of parent 1&lt;br /&gt;&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;//load childrens of Parent 1 and 2 (can't avoid this with set, see FAQ)&lt;br /&gt;&lt;br /&gt;Hibernate: update child set parent_id=? where id=?&lt;/pre&gt;&lt;p&gt;After a proper Java setting of the Parent child relationship (both side), Hibernate, set parent_id column to the proper value. As you can see, only 1 update is executed.&lt;/p&gt;&lt;p&gt;Now, we'll see inverse=&amp;quot;true&amp;quot; in action ;-)&lt;/p&gt;&lt;pre class="code"&gt;Parent p = (Parent) session.load(Parent.class, parentId);&lt;br /&gt;Parent p2 = (Parent) session.load(Parent.class, parentId2);&lt;br /&gt;        &lt;br /&gt;c = (Child) session.find(&lt;br /&gt;            &amp;quot;from Child as child where child.parent = ?&amp;quot;,&lt;br /&gt;            p, Hibernate.entity(Parent.class)).get(0);&lt;br /&gt;&lt;br /&gt;c.setParent(p2);&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=? //get parent 1&lt;br /&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=? //get parent 2&lt;br /&gt;Hibernate: select child0_.id as id, child0_.parent_id as parent_id from child child0_ where (child0_.parent_id=? ) //get children &lt;br /&gt;&lt;br /&gt;Hibernate: update child set parent_id=? where id=?&lt;/pre&gt;&lt;p&gt;The relationship is updated because I change it on the child side. Note that the object tree is not consistent with the Database (children collections are not up to date). This is not recommanded.&lt;/p&gt;&lt;p&gt;On the contrary,&lt;/p&gt;&lt;pre class="code"&gt;Parent p = (Parent) session.load(Parent.class, parentId);&lt;br /&gt;Parent p2 = (Parent) session.load(Parent.class, parentId2);&lt;br /&gt;        &lt;br /&gt;c = (Child) session.find(&lt;br /&gt;            &amp;quot;from Child as child where child.parent = ?&amp;quot;,&lt;br /&gt;            p, Hibernate.entity(Parent.class)).get(0);&lt;br /&gt;&lt;br /&gt;p.getChildren().remove(c);&lt;br /&gt;p2.getChildren().add(p);&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=? //get parent 1&lt;br /&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=? //get parent 2&lt;br /&gt;Hibernate: select child0_.id as id, child0_.parent_id as parent_id from child child0_ where (child0_.parent_id=? ) //get children &lt;br /&gt;&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;//load childrens of Parent 1 and 2 (can't avoid this see FAQ)&lt;/pre&gt;&lt;p&gt;Relationship update is not executed because update is only done on the parent side.&lt;/p&gt;&lt;a name="A8"&gt;&lt;/a&gt;&lt;h4&gt;inverse=&amp;quot;false&amp;quot;&lt;/h4&gt;&lt;p&gt;&lt;tt&gt;inverse=&amp;quot;false&amp;quot;&lt;/tt&gt; (the default value) is not optimized for bidirectional relationships.&lt;/p&gt;&lt;pre class="code"&gt;&amp;lt;class name=&amp;quot;net.sf.test.Parent&amp;quot; table=&amp;quot;parent&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;id name=&amp;quot;id&amp;quot; column=&amp;quot;id&amp;quot; type=&amp;quot;long&amp;quot; unsaved-value=&amp;quot;null&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;generator class=&amp;quot;sequence&amp;quot;&amp;gt;&lt;br /&gt;      &amp;lt;param name=&amp;quot;sequence&amp;quot;&amp;gt;SEQ_DEFAULT&amp;lt;/param&amp;gt;&lt;br /&gt;    &amp;lt;/generator&amp;gt;&lt;br /&gt;  &amp;lt;/id&amp;gt;&lt;br /&gt;  &amp;lt;set name=&amp;quot;children&amp;quot; lazy=&amp;quot;true&amp;quot; inverse=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;      &amp;lt;key column=&amp;quot;parent_id&amp;quot;/&amp;gt;&lt;br /&gt;      &amp;lt;one-to-many class=&amp;quot;net.sf.test.Child&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;/set&amp;gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;class name=&amp;quot;net.sf.test.Child&amp;quot; table=&amp;quot;child&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;id name=&amp;quot;id&amp;quot; column=&amp;quot;id&amp;quot; type=&amp;quot;long&amp;quot; unsaved-value=&amp;quot;null&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;generator class=&amp;quot;sequence&amp;quot;&amp;gt;&lt;br /&gt;      &amp;lt;param name=&amp;quot;sequence&amp;quot;&amp;gt;SEQ_DEFAULT&amp;lt;/param&amp;gt;&lt;br /&gt;    &amp;lt;/generator&amp;gt;&lt;br /&gt;  &amp;lt;/id&amp;gt;&lt;br /&gt;  &amp;lt;many-to-one name=&amp;quot;parent&amp;quot; column=&amp;quot;parent_id&amp;quot; not-null=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The &lt;tt&gt;inverse=&amp;quot;false&amp;quot;&lt;/tt&gt; is set to the one side.&lt;/p&gt;&lt;a name="A9"&gt;&lt;/a&gt;&lt;h4&gt;insert&lt;/h4&gt;&lt;pre class="code"&gt;Parent p = new Parent();&lt;br /&gt;Child c = new Child();&lt;br /&gt;p.setChildren(new HashSet());&lt;br /&gt;p.getChildren().add(c);&lt;br /&gt;c.setParent(p);&lt;br /&gt;&lt;br /&gt;session.save(p);&lt;br /&gt;session.save(c);&lt;br /&gt;session.flush();&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select SEQ_DEFAULT.nextval from dual&lt;br /&gt;Hibernate: select SEQ_DEFAULT.nextval from dual&lt;br /&gt;Hibernate: insert into parent (id) values (?)&lt;br /&gt;Hibernate: insert into child (parent_id, id) values (?, ?)&lt;br /&gt;Hibernate: update child set parent_id=? where id=?&lt;/pre&gt;&lt;p&gt;Parent is responsible of the relationship. Hibernate insert parent, insert child then update the relationship (as a request to the parent). Two SQL orders are executed (one insert and one update) instead of one.&lt;/p&gt;&lt;p&gt;Note that I cannot do a flush between session.save(p) and session.save(c) because, parent, which is responsible of the relationship, needs a persistent child to play with.&lt;/p&gt;&lt;a name="A10"&gt;&lt;/a&gt;&lt;h4&gt;update&lt;/h4&gt;&lt;p&gt;Let's have a look at a relationship update&lt;/p&gt;&lt;pre class="code"&gt;Parent p = (Parent) session.load(Parent.class, parentId);&lt;br /&gt;Parent p2 = (Parent) session.load(Parent.class, parentId2);&lt;br /&gt;        &lt;br /&gt;c = (Child) session.find(&lt;br /&gt;            &amp;quot;from Child as child where child.parent = ?&amp;quot;,&lt;br /&gt;            p, Hibernate.entity(Parent.class)).get(0);&lt;br /&gt;&lt;br /&gt;p.getChildren().remove(c);&lt;br /&gt;p2.getChildren().add(c);&lt;br /&gt;c.setParent(p2);&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=?    //get parent 1&lt;br /&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=?    //get parent 2&lt;br /&gt;Hibernate: select child0_.id as id, child0_.parent_id as parent_id from child child0_ where (child0_.parent_id=? )&lt;br /&gt;//get first child for parent 1&lt;br /&gt;&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;//load childrens of Parent 1 and 2 (can't avoid this see FAQ)&lt;br /&gt;&lt;br /&gt;Hibernate: update child set parent_id=? where id=?               // child.setParent&lt;br /&gt;Hibernate: update child set parent_id=null where parent_id=?     //remove&lt;br /&gt;Hibernate: update child set parent_id=? where id=?               // add&lt;/pre&gt;&lt;p&gt;As you can see, having set &lt;tt&gt;inverse=&amp;quot;true&amp;quot;&lt;/tt&gt; allow the relationship to be managed by the parent side AND the child side. Several updates to the association data are done. This is inefficient considering the &lt;tt&gt;inverse=&amp;quot;true&amp;quot;&lt;/tt&gt; equivalent.&lt;/p&gt;&lt;pre class="code"&gt;Parent p = (Parent) session.load(Parent.class, parentId);&lt;br /&gt;Parent p2 = (Parent) session.load(Parent.class, parentId2);&lt;br /&gt;        &lt;br /&gt;c = (Child) session.find(&lt;br /&gt;            &amp;quot;from Child as child where child.parent = ?&amp;quot;,&lt;br /&gt;            p, Hibernate.entity(Parent.class)).get(0);&lt;br /&gt;&lt;br /&gt;p2.getChildren().add(c);&lt;/pre&gt;&lt;p&gt;Will do the following SQL queries&lt;/p&gt;&lt;pre class="code"&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=?    //get parent 1&lt;br /&gt;Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=?    //get parent 2&lt;br /&gt;Hibernate: select child0_.id as id, child0_.parent_id as parent_id from child child0_ where (child0_.parent_id=? )&lt;br /&gt;//get first child for parent 1&lt;br /&gt;&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;Hibernate: select child0_.id as id__, child0_.id as id, child0_.parent_id as parent_id from child child0_ where child0_.parent_id=?&lt;br /&gt;//load childrens of Parent 1 and 2 (can't avoid this see FAQ)&lt;br /&gt;&lt;br /&gt;Hibernate: update child set parent_id=? where id=?               // add&lt;/pre&gt;&lt;p&gt;The relationship is properly set but the object model is in inconsistent state. This is not recommanded.&lt;/p&gt;&lt;a name="A11"&gt;&lt;/a&gt;&lt;h4&gt;Conclusion&lt;/h4&gt;&lt;p&gt;Using and understanding &lt;tt&gt;inverse=&amp;quot;true&amp;quot;&lt;/tt&gt; is essential to optimize your code. Prefer using &lt;tt&gt;inverse=&amp;quot;true&amp;quot;&lt;/tt&gt; on bidirectional association.  After this tutorial it will be soooo easy ;-)&lt;/p&gt;&lt;p style="font-size: 80%" align="right"&gt;Source: &lt;a title="simoes.org" href="http://simoes.org/docs/hibernate-2.1/155.html" rel="nofollow"&gt;simoes.org&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-4491672302368928143?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/NWqOInf4klw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/NWqOInf4klw/understanding-mapping-attribute.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>2</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/10/understanding-mapping-attribute.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-3249052009225345775</guid><pubDate>Tue, 25 Sep 2007 08:52:00 +0000</pubDate><atom:updated>2007-09-25T01:52:11.797-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Overview</category><category domain="http://www.blogger.com/atom/ns#">News</category><category domain="http://www.blogger.com/atom/ns#">Ajax</category><title>The Dojo 1.0 release will be available in October</title><description>&lt;p&gt;&lt;strong&gt;PALO ALTO, Sep 17, 2007:&lt;/strong&gt; The open source Dojo Toolkit is receiving a new grid widget thanks to the generous support and collaboration of the Dojo Community. The Dojo Grid is a key component for Ajax and web application developers because it is able to handle large amounts of information efficiently and intuitively. The companies in this relationship are making a financial and/or engineering contribution to improve and update the grid in time for the Dojo 1.0 release in October.&lt;/p&gt;&lt;p&gt;&amp;ldquo;We determined that Dojo needed a new grid widget and rather than starting from scratch, we approached the TurboAjax Group about making its feature-rich grid open source and part of the Dojo Toolkit,&amp;rdquo; said Dylan Schiemann, CEO of SitePen, Inc. "This grid benefits SitePen&amp;rsquo;s clients and is a great way to advance the Open Web."&lt;/p&gt;&lt;p&gt; TurboGrid is a high-performance grid widget that was originally created to work with the 0.4 version of the Dojo Toolkit. The grid is being updated to work with the latest Dojo features and will now be an official part of the Dojo Toolkit.&lt;/p&gt;&lt;p&gt; &amp;ldquo;We couldn&amp;rsquo;t be more thrilled about moving TurboGrid to the Dojo Foundation. This is a unique opportunity where a collection of companies have come together to open source a quality component that is the key to building data-rich applications,&amp;rdquo; said Scott Miles of the TurboAjax Group.&lt;/p&gt;&lt;p&gt;The Dojo Grid Widget features integration with Dojo&amp;rsquo;s flexible dojo.data infrastructure, which allows multiple widgets and visualization components to efficiently access large volumes of data. The donated grid supports advanced features such as virtual scrolling, row and column locking, complex cell and row formatting and custom cell editors. The Dojo Grid will also include full accessibility and internationalization support. &lt;/p&gt;&lt;p&gt;&amp;ldquo;We&amp;rsquo;re both users of the Dojo Toolkit and supporters of the Dojo Foundation. TurboGrid is a great opportunity for the community to work together in moving Dojo to the next level,&amp;rdquo; said Coach Wei, CTO and founder of Nexaweb. &amp;ldquo;Being a strong supporter as well as adopter of open source and open standards, Nexaweb is pleased to contribute to this effort in making Ajax development more efficient, structured, and maintainable for the web 2.0 community.&amp;rdquo;&lt;/p&gt;&lt;p&gt;&amp;ldquo;Mozilla and the Dojo Foundation share a commitment to advancing the Open Web,&amp;rdquo; said Mike Shaver, chief evangelist at the Mozilla Corporation. &amp;ldquo;We&amp;rsquo;re glad for the opportunity to join with other contributors to ensure that there are great tools for building accessible, robust applications for the web.&amp;rdquo;&lt;/p&gt;&lt;p&gt;&amp;ldquo;Redfin had been looking for a grid widget that worked with Dojo for the new version of our real estate web application,&amp;rdquo; said Sasha Aickin, engineering manager, Redfin. &amp;ldquo;The opportunity to contribute to an effort and share development risk across the community is a key benefit of building our application with open source technology including the Dojo Toolkit.&amp;rdquo;&lt;/p&gt;&lt;p&gt; &amp;ldquo;This new Grid, coupled with the underlying dojo.data AJAX infrastructure enables an entirely new class of Rich Information Applications,&amp;rdquo; said Chris Marino, CEO of SnapLogic. &amp;ldquo;Our users are looking for ways to build applications on top of their SnapLogic data services that can more easily access and present their data, and Dojo 1.0 is a giant step forward.&amp;rdquo;&lt;/p&gt;&lt;p&gt;&amp;ldquo;This is excellent code and an amazing show of generosity from the organizations who made it happen,&amp;rdquo; said Alex Russell, President of the Dojo Foundation. &amp;ldquo;This is the most capable Open Source web-based grid component available anywhere, and it will form the backbone of applications for years to come. We couldn&amp;rsquo;t be happier that this donation is happening in time to include the Grid in Dojo&amp;rsquo;s upcoming 1.0 release.&amp;rdquo; &lt;/p&gt;&lt;p&gt;The Dojo Grid will be available in October.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-3249052009225345775?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/PbHiursS4Lw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/PbHiursS4Lw/dojo-10-release-will-be-available-in.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>2</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/09/dojo-10-release-will-be-available-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-2951912862451633071</guid><pubDate>Tue, 25 Sep 2007 08:33:00 +0000</pubDate><atom:updated>2007-09-25T01:37:40.330-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Research</category><title>Java: Few important points when it comes to Strings</title><description>&lt;p&gt;How many times have you coded a check for String being null or empty? Countless times, right? I have. We use some ready-to-use classes from open source frameworks or we write our own StringUtils class. More or less they all implement the same thing and it always looks similar to the following code snippet:&lt;/p&gt;&lt;pre&gt;String s = ...&lt;br /&gt;if (s == null || s.equals(""))...&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;or similar to the following, which trims leading and ending whitespaces&lt;/p&gt;&lt;pre&gt;String s = ...&lt;br /&gt;if (s == null || s.trim().equals(""))...&lt;/pre&gt;&lt;p&gt;Of course you could also do this:&lt;/p&gt;&lt;code&gt;"".equals(s)&lt;/code&gt;&lt;p&gt;which is a case when you do not care if String s is null and you don't have to worry about NPE as if won't happen ("" is never null, whereas s could be). But that's another story.&lt;/p&gt;&lt;p&gt;I have had "extra" warnings turned on in my IDE for couple of days. But today my IDE suprised me when it highlighted&lt;/p&gt;&lt;code&gt;[1] s.equals("")&lt;/code&gt;&lt;p&gt;and suggested that I could optimize it by making it to&lt;/p&gt;&lt;code&gt;[2] s.length() == 0&lt;/code&gt;&lt;p&gt;And guess what?! The IDE was right! I looked at the suggested code briefly, gave it a bit of thought and agreed that it would probably be faster. Method [1] creates a new instance of the String (an empty String, yes I know that all instances of "" would be caught during compilation and optimized and that they all would refer to the same instance). Just to be on the safe side I looked at the source of the String class.&lt;/p&gt;&lt;p&gt;And here is what I found. The length() method returns and integer primitive, which is not calculated with each method call to length(). It is rather a member variable (or constant, as Strings are invariants) of String class that is calculated when new String instance is created. So this method would be super fast.&lt;/p&gt;&lt;pre&gt;public int length() {&lt;br /&gt;	return count;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;On the other side, there is the equals() method, which is fast as well, but not as fast as length method. It has to do a check for class, class casting and comparison of count members (that's what length method returns).&lt;/p&gt;&lt;pre&gt;public boolean equals(Object anObject) {&lt;br /&gt;	if (! (anObject instanceof String))&lt;br /&gt;		return false;&lt;br /&gt;	String str2 = (String) anObject;&lt;br /&gt;	if (count != str2.count)&lt;br /&gt;		return false;&lt;br /&gt;	if (value == str2.value &amp;amp;&amp;amp; offset == str2.offset)&lt;br /&gt;		return true;&lt;br /&gt;	int i = count;&lt;br /&gt;        int x = offset;&lt;br /&gt;        int y = str2.offset;&lt;br /&gt;        while (--i &amp;gt;= 0)&lt;br /&gt;          if (value[x++] != str2.value[y++])&lt;br /&gt;            return false;&lt;br /&gt;        return true;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;And remember the few important points when it comes to Strings:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Do not compare Strings with == operator&lt;/b&gt;. Unless you want to compare the object references. Use equals() method.&lt;li&gt;&lt;b&gt;Do not construct new instances like new String("abc")&lt;/b&gt;. Simple "abc" will do, unless you really mean that you need a new instance of String with same value.&lt;li&gt;&lt;b&gt;Do not concatenate Strings in loops using + operator&lt;/b&gt;. It's faster to use StringBuffer (or StringBuilder, which is in Tiger and is not synchronized) append() and then toString() methods instead. The plus (+) operator constructs new String object each time.&lt;/li&gt;&lt;/ul&gt;&lt;p style="font-size: 80%" align="right"&gt;Source: &lt;a title="hanuska.blogspot.com" href="http://hanuska.blogspot.com/" rel="nofollow"&gt;hanuska.blogspot.com&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-2951912862451633071?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/LzwUaJ5R89A" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/LzwUaJ5R89A/java-few-important-points-when-it-comes.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>8</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/09/java-few-important-points-when-it-comes.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-9222884125393238837</guid><pubDate>Tue, 11 Sep 2007 10:39:00 +0000</pubDate><atom:updated>2007-11-05T07:40:20.237-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Theory</category><category domain="http://www.blogger.com/atom/ns#">Overview</category><category domain="http://www.blogger.com/atom/ns#">J2EE</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><title>CMP-EJB vs. Hibernate</title><description>&lt;p&gt;The J2EE field is agog with excitement about a very popular Open Source technology - &lt;b&gt;Hibernate&lt;/b&gt;. This technology being elevated to the status of JCP standard. Feedback from J2EE programmers in industry says that knowledge of &lt;b&gt;Hibernate&lt;/b&gt; is mandatory for all J2EE aspirants. &lt;/p&gt; &lt;p&gt;&lt;b&gt;Hibernate&lt;/b&gt; is an &lt;b&gt;ORM&lt;/b&gt; Object-Relational-Mapping technology. It is an Open-Source and free technology, developed in &lt;b&gt;SourceForge. net&lt;/b&gt;. There have been a number of such ORM technologies,in recent past. . &lt;b&gt;TopLink&lt;/b&gt; is one such tool, subsequently adopted by Oracle and so proprietary. &lt;b&gt;&lt;b&gt;Hibernate&lt;/b&gt;&lt;/b&gt; from SourceForge and &lt;b&gt;OJB&lt;/b&gt;(Object-Relational-Bridge) from Apache are two well known ORM tools, open-source and free. &lt;b&gt;JDO&lt;/b&gt;, also falls within the same category. &lt;br&gt;&lt;br&gt;&lt;b&gt;Gavin King&lt;/b&gt; is the lead for &lt;b&gt;Hibernate&lt;/b&gt; and &lt;b&gt;Craig Russell &amp;amp; David Jordan&lt;/b&gt;, the lead authors for SUN-sponsored JDO effort. Due to some technical problems, it appears that the majority in JCP favours &lt;b&gt;Hibernate&lt;/b&gt; today instead of JDO. At first reading though, the difference is not, all that apparent. The syntax and the approach appear to be almost same, but &lt;b&gt;Hibernate&lt;/b&gt; syntax is easier to learn. &amp;nbsp;&lt;br&gt;&lt;br&gt;It is interesting to note that Craig Russell works for SUN and Gavin King is now with JBoss. It shows that JCP is a democratic community and SUN is not dictating terms except to protect the language and its enterprise-level users. &lt;br&gt;&lt;br&gt;&lt;b&gt;EJB-3&lt;/b&gt;, is the latest version and it is heavily influenced by &lt;b&gt;Hibernate&lt;/b&gt;. Some readers equate EJB-3 with &lt;b&gt;Hibernate&lt;/b&gt;. Oracle supports EJB-3 proposals and as it is the main Database company in j2ee world, EJB-3 has bright future. J2EE by its very name is an Enterprise level technology, and as EJB is the essence of such Enterprise applications, because of the built-in container services offered, the significance of the surging interest in &lt;b&gt;Hibernate&lt;/b&gt; can be really appreciated only in association with EJB and hence a detour into EJB is inevitable. &lt;br&gt;&lt;br&gt;EJB has three types. One type is the SESSION BEAN, residing in ENTERPRISE container, which can be thought of as a function-bean, invoked in RMI-IIOP style. Such session-bean, may be either stateless or stateful. The stateless bean working in Enterprise container has an exact counter-part in Microsoft COM+(MTS), but the other types are said to be available in MS platform only through third-party extensions. &lt;/p&gt; &lt;p&gt;ORM tools have been sometimes used along with Session beans. The only problem till recently was that they were proprietory and rather costly. But nowadays, very reliable open-source ORM tools are available, and even Richard Monson Haefel approves this method as a safe and productive alternative to Entity beans. &lt;br&gt;&lt;br&gt;The other branch, the ENTITY BEAN has been less lucky. EJB-1. 1, EJB-2. 0 and then EJB-2. 1, have meant a number of changes in the specification relating to Entity Beans. &lt;br&gt;We can say that an Entity bean is an 'Attribute bean' or 'property-bean', with setter and getter methods, invoked in RMI-IIOP style and persisted in Enterprise container. The pattern of defining a typical Javabean is a recurring theme in Java. The same style occurs in BDK, EJB-Entity beans, Struts, JSF and now in &lt;b&gt;Hibernate&lt;/b&gt; too. So, it is very important and elegant. &lt;br&gt;&lt;br&gt;The third branch is Messaging paradigm and MDB. An Enterprise by its very name implies huge number of customers and concurrent transactions, RPC style being like telephone call, could result in 'line-engaged!' problem. If the call involves the called person referring to some records before replying, it leads to line- blocking. But, messaging style, as in email, atleast ensures that the message has been sent. It is evident that dubbing RPC( read 'telephone') as unsuitable, is over-statement. Sometimes, we desire immediate response,too. By the same token, even XML webservice, if it is really serious, should adopt messaging style and it does. MDB (Message-Driven bean) has weathered the storm and is in fact gaining more and more acceptance. &lt;br&gt;&lt;br&gt;So, why is it that Entity beans alone were found wanting and the specification keeps on changing?&lt;br&gt;Entity beans are of two types. CMP &amp;amp; BMP. &lt;br&gt;CMP stands for Container-Managed Persistence and BMP stands for Bean-managed persistence. Theoretically, the EJB specification does not say anything about the method to be adopted in persisting objects for permanent storage and retrieval. It could be simple object serialization. The database may be object-database or Object-relational database or XML. In practice, however, a database has always meant a Relational Database and its SQL. &lt;br&gt;&lt;br&gt;In &lt;b&gt;CMP&lt;/b&gt;, the coder deals with objects, only in memory. He creates new objects, modifies them, deletes them and views them, all in memory. The task of saving these objects in memory ,to the relational database table is done by the container, &lt;b&gt;automatically&lt;/b&gt;. The coder does not write any sql-related code for this. &lt;br&gt;&lt;br&gt;In BMP, the coder has to write the sql to persist the object in memory to the relational database. &lt;br&gt;&lt;br&gt;CMP in EJB1. 1 was suitable for simple tables, without complex relationships to other tables. CMP avoids all references to the underlying database. So, it is more portable. There is no vendor-lock-in. CMP can persist data to Object- databases also, besides Relational databases. &lt;br&gt;&lt;br&gt;But, CMP is not always suitable. If the database is some legacy type, which cannot be used with SQL, the database company gives a proprietory code for persistence and such code has to be used in our program to persist data. The facilities given in CMP originally were found to be too elementary and there were complaints. &lt;br&gt;&lt;br&gt;But, what matters is that CMP makes use of ORM concepts, though the implementation left much to be desired. It did not expose how the EJB vendor implements it. Weblogic, Oracle, IBM WebSphere, SUN , JBoss, each may implement CMP in any way that they deem fit. Except in special circumstances, it will be better to use CMP, not merely because, it makes the code more portable &amp;amp; is easy to write. Much more important reason is that the EJB container can optimize the performace dramatically, if we adopt CMP. So the developer community wanted to adopt CMP but found it unsuitable for really complex jobs.&lt;br&gt;&lt;br&gt;Even with all these improvements, CMP was found to be less than the ultimate solution. There was no spossibility for Inheritance. &amp;nbsp;&lt;/p&gt; &lt;p&gt;Though the container services provided by the EJB container are indispensable in a truly large enterprise application, the J2EE camp is almost vertically split into WebTier &amp;amp; EJB-Tier votaries. The WebTier supporters claim that EJB with its steep learning curve and error prone development environment for developers is not really necessary for most applications. And they would like to have an ORM tool, built into the J2EE specification. For afterall, ORM task is not specific to EJB alone. Even Servlets and JSP could use them. In fact, they have been using them, though the J2EE specification was silent about it. ORM tools like &lt;b&gt;OJB, JDO and &lt;b&gt;Hibernate&lt;/b&gt;&lt;/b&gt; can be used not only in EJB containers but in webcontainer and even in standalone containers. Gavin King makes it a special point in favour of &lt;b&gt;Hibernate&lt;/b&gt;. Making such a tool, a J2EE standard, would make development tasks far easier ,to develop either web-tier application or ejb-tier application. saving us from the medley of classpath to required jars. &lt;br&gt;&lt;br&gt;In a scathing attack on the complexity and questionable performance of EJB &lt;b&gt;Entity beans&lt;/b&gt;, Rod Johnson, prophesies, that in a few years time, J2EE will cease to include EJB. Whether, we agree or not, it is worth looking into the criticisms against EJB Entity beans, raised by him. ( 'J2EE Development without EJB' - Wrox/Wiley/DreamTech-2004). For, he is proposing the Spring Framework as an alternative to EJB container and the idea is gaining ground. J2EE developers and students may have to re-orient themselves rather abruptly, to remain relevant to industry.&lt;/p&gt; &lt;p style="font-size: 80%" align="right"&gt;Source: &lt;a title="hanuska.blogspot.com" href="http://in.geocities.com/rsramsam" rel="nofollow"&gt;in.geocities.com/rsramsam&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-9222884125393238837?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/Oso3x1XDFrI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/Oso3x1XDFrI/cmp-ejb-vs-hibernate.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>3</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/09/cmp-ejb-vs-hibernate.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-8984667726502619182</guid><pubDate>Fri, 07 Sep 2007 08:00:00 +0000</pubDate><atom:updated>2007-09-07T02:28:47.153-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Technology</category><category domain="http://www.blogger.com/atom/ns#">Theory</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Overview</category><title>What is Java technology?</title><description>&lt;p&gt;Java technology is both a high-level, object-oriented programming language and a platform. Java technology is based on the concept of a single Java Virtual Machine (JVM) -- a translator between the language and the underlying software and hardware. All implementations of the programming language must emulate the JVM, enabling Java programs to run on any system that has a version of the JVM.&lt;/p&gt; &lt;p&gt;The &lt;i&gt;Java programming language&lt;/i&gt; is unusual because Java programs are both &lt;i&gt;compiled&lt;/i&gt; (translated into an intermediate language called Java bytecode) and &lt;i&gt;interpreted&lt;/i&gt; (bytecode parsed and run by the JVM). Compilation occurs once, and interpretation happens each time the program runs. Compiled bytecode is a form of optimized machine code for the JVM; the interpreter is an implementation of the JVM.&lt;/p&gt; &lt;p&gt;The &lt;i&gt;Java platform&lt;/i&gt; is a software-only platform that runs on top of various hardware-based platforms. It comes in three versions. It consists of the JVM and the Java Application Programming Interface (API), a large collection of ready-made software components (classes) that ease the development and deployment of applets and applications, including robust, secure, and interoperable enterprise applications. It spans everything from basic objects to networking and security and XML generation and Web services. The Java API is grouped into libraries of related classes and interfaces; the libraries are known as &lt;i&gt;packages&lt;/i&gt;.&lt;/p&gt; &lt;p&gt;Along with the Java API, every full implementation of the Java platform includes:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Development tools for compiling, running, monitoring, debugging, and documenting applications.  &lt;li&gt;Standard mechanisms for deploying applications to users.  &lt;li&gt;User interface toolkits that make it possible to create sophisticated graphical user interfaces (GUIs).  &lt;li&gt;Integration libraries that enable database access and manipulation of remote objects. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Java technology was developed by Sun Microsystems. The Java Community Process (JCP), an open organization of international Java developers and licensees, develops and revises Java technology specifications, reference implementations, and technology compatibility kits. In 2007, Sun made the bulk of its core Java technology available as open-source software under the GNU general public license version 2 (GPLv2).&lt;/p&gt; &lt;p&gt;The main benefit of the Java language is the portability of Java applications across hardware platforms and operating systems -- possible because the JVM installed on each platform understands the same bytecode. &lt;/p&gt; &lt;p&gt;The Java language and platform are impressively scalable. At the low end, existing applications can easily be adapted for devices with limited-memory resources. Scaling up, the language is an ideal framework for server-side Web programming. Because it was designed to run in a secure manner over networks, it affords this level of security when operating over the Internet. In essence, Java technology extends a user's computing power from the desktop to the resources of the Web. Web components are supported by runtime platforms called &lt;i&gt;Web containers&lt;/i&gt;, whose services include request dispatching, security, concurrency, life-cycle management, and access to APIs such as naming, transactions, and e-mail. At the high end, Java &lt;i&gt;application servers&lt;/i&gt; serve as Web containers for Java components, XML, and Web services that can interact with databases and provide dynamic Web content; they also provide an application-deployment environment for enterprise applications, with capabilities for transaction management, security, clustering, performance, availability, connectivity, and scalability.&lt;/p&gt; &lt;p&gt;The Java language was one of the first technologies to support open standards in the enterprise, opening the door to using XML and Web services to help share information and applications across business lines.  &lt;p&gt;&lt;b&gt;Multiple editions of the Java platform&lt;/b&gt; &lt;/p&gt; &lt;p&gt;Three editions of the Java platform make it easier for software developers, service providers, and device manufacturers to target specific markets:  &lt;ul&gt; &lt;li&gt;&lt;b&gt;Java SE (Java Platform, Standard Edition)&lt;/b&gt;. Formerly called J2SE, Java SE lets you develop and deploy Java applications on desktops and servers, as well as embedded and real-time environments. Java SE includes classes that support the development of Java Web services and provides the foundation for Java Platform, Enterprise Edition (Java EE). Java SE 6 ("Mustang") is the current major release of the Java SE platform. Many Java developers use Java SE 5, also known as Java 5.0 or "Tiger." &lt;br&gt; &lt;li&gt;&lt;b&gt;Java EE (Java Platform, Enterprise Edition)&lt;/b&gt;. Formerly called J2EE, the enterprise version assists in the development and deployment of portable, robust, scalable, and secure server-side Java applications. Building on the foundation of Java SE, Java EE provides Web services, component-model, management, and communications APIs for implementing enterprise class SOA and Web 2.0 applications. &lt;br&gt; &lt;li&gt;&lt;b&gt;Java ME (Java Platform, Micro Edition)&lt;/b&gt;. Formerly called J2ME, Java ME provides a robust, flexible environment for applications running on a broad range of mobile and embedded devices, such as mobile phones, PDAs, TV set-top boxes, and printers. The Java ME platform includes flexible user interfaces, a robust security model, a broad range of built-in network protocols, and extensive support for networked and offline applications that can be downloaded dynamically. Applications based on Java ME specifications are written once for a wide range of devices yet exploit each device's native capabilities. &lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-8984667726502619182?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/1T2pMoNsJhI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/1T2pMoNsJhI/what-is-java-technology.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/09/what-is-java-technology.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-6257123562542593445</guid><pubDate>Fri, 24 Aug 2007 15:11:00 +0000</pubDate><atom:updated>2007-08-24T08:11:45.807-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Testing</category><category domain="http://www.blogger.com/atom/ns#">Spring</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">JUnit</category><category domain="http://www.blogger.com/atom/ns#">Struts</category><title>Struts2 + Spring + JUnit</title><description>&lt;p&gt;Hopefully this entry serves as some search engine friendly documentation on how one might unit test Struts 2 actions configured using Spring, something I would think many, many people want to do. This used to be done using &lt;a href="http://strutstestcase.sourceforge.net/"&gt;StrutsTestCase&lt;/a&gt; in the Struts 1.x days but Webwork/Struts provides enough flexibility in its architecture to accommodate unit testing fairly easily. I’m not going to go over how the Spring configuration is setup. I’m assuming you have a struts.xml file which has actions configured like this:&lt;/p&gt;&lt;pre&gt;&amp;lt;struts&amp;gt;&lt;br /&gt; &amp;lt;package namespace="/site" extends="struts-default"&amp;gt;&lt;br /&gt;  &amp;lt;action name="deletePerson" class="personAction"&lt;br /&gt;                  method="deletePerson"&amp;gt;&lt;br /&gt;   &amp;lt;result name="success"&amp;gt;/WEB-INF/pages/person.jsp&amp;lt;/result&amp;gt;&lt;br /&gt;  &amp;lt;/action&amp;gt;&lt;br /&gt; &amp;lt;/package&amp;gt;&lt;br /&gt; ...&lt;br /&gt;&amp;lt;/struts&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;You also might have an applicationContext.xml file where you might define your Spring beans like this.&lt;/p&gt;&lt;pre&gt;&amp;lt;beans&amp;gt;&lt;br /&gt; &amp;lt;bean id="personAction"&lt;br /&gt;  class="com.arsenalist.action.PersonAction"/&amp;gt;&lt;br /&gt; ...&lt;br /&gt;&amp;lt;/beans&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Then of course you also need to have an action which you want to test which might look something like:&lt;/p&gt;&lt;pre&gt;public class PersonAction extend ActionSupport { &lt;br /&gt;&lt;br /&gt;  private int id; &lt;br /&gt;&lt;br /&gt;  public int getId() {&lt;br /&gt;    return id;&lt;br /&gt;  }&lt;br /&gt;  public void setId(int id) {&lt;br /&gt;    this.id = id;&lt;br /&gt;  }&lt;br /&gt;  public String deletePerson() {&lt;br /&gt;    ....&lt;br /&gt;    return SUCCESS;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Remember than in Struts 2, an action is usually called before and after various other interceptors are invoked. Interceptor configuration is usually specified in the struts.xml file. At this point we need to cover three different methods of how you might want to call your actions.&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Specify request parameters which are translated and mapped to the actions domain objects (id in the PersonAction class) and then execute the action while also executing all configured interceptors. &lt;br /&gt;&lt;li&gt;Instead of specifying request parameters, directly specify the values of the domain objects and then execute the action while also executing all configured interceptors. &lt;br /&gt;&lt;li&gt;Finally, you just might want to execute the action and not worry about executing the interceptors. Here you’ll specify the values of the actions domain objects and then execute the action. &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;Depending on what you’re testing and what scenario you want to reproduce, you should pick the one that suits the case. There’s an example of all three cases below. The best way I find to test all your action classes is to have one base class which sets up the Struts 2 environment and then your action test classes can extend it. Here’s a class that could be used as one of those base classes.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;See the comments for a little more detail about whats going on. One point to note is that the class being extended here is junit.framework.TestCase and not org.apache.struts2.StrutsTestCase as one might expect. The reason for this is that StrutsTestCase is not really a well written class and does not provide enough flexibility in how we want the very core Dispatcher object to be created. Also, the &lt;a href="http://struts.apache.org/2.0.8/docs/how-can-we-test-actions.html"&gt;interceptor example&lt;/a&gt; shown in the Struts documentation does not compile as there seems to have been some sort of API change. It’s been fixed in this example.&lt;/p&gt;&lt;pre&gt;public class BaseStrutsTestCase extends TestCase {&lt;br /&gt;&lt;br /&gt; private Dispatcher dispatcher;&lt;br /&gt; protected ActionProxy proxy;&lt;br /&gt; protected MockServletContext servletContext;&lt;br /&gt; protected MockHttpServletRequest request;&lt;br /&gt; protected MockHttpServletResponse response;&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * Created action class based on namespace and name&lt;br /&gt;  */&lt;br /&gt; protected T createAction(Class clazz, String namespace, String name)&lt;br /&gt;   throws Exception {&lt;br /&gt;&lt;br /&gt;  // create a proxy class which is just a wrapper around the action call.&lt;br /&gt;  // The proxy is created by checking the namespace and name against the&lt;br /&gt;  // struts.xml configuration&lt;br /&gt;  proxy = dispatcher.getContainer().getInstance(ActionProxyFactory.class).&lt;br /&gt;    createActionProxy(&lt;br /&gt;    namespace, name, null, true, false);&lt;br /&gt;&lt;br /&gt;  // set to true if you want to process Freemarker or JSP results&lt;br /&gt;  proxy.setExecuteResult(false);&lt;br /&gt;  // by default, don't pass in any request parameters&lt;br /&gt;  proxy.getInvocation().getInvocationContext().&lt;br /&gt;    setParameters(new HashMap());&lt;br /&gt;&lt;br /&gt;  // set the actions context to the one which the proxy is using&lt;br /&gt;  ServletActionContext.setContext(&lt;br /&gt;    proxy.getInvocation().getInvocationContext());&lt;br /&gt;  request = new MockHttpServletRequest();&lt;br /&gt;  response = new MockHttpServletResponse();&lt;br /&gt;  ServletActionContext.setRequest(request);&lt;br /&gt;  ServletActionContext.setResponse(response);&lt;br /&gt;  ServletActionContext.setServletContext(servletContext);&lt;br /&gt;  return (T) proxy.getAction();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; protected void setUp() throws Exception {&lt;br /&gt;  String[] config = new String[] { "META-INF/applicationContext-aws.xml" };&lt;br /&gt;&lt;br /&gt;  // Link the servlet context and the Spring context&lt;br /&gt;  servletContext = new MockServletContext();&lt;br /&gt;  XmlWebApplicationContext appContext = new XmlWebApplicationContext();&lt;br /&gt;  appContext.setServletContext(servletContext);&lt;br /&gt;  appContext.setConfigLocations(config);&lt;br /&gt;  appContext.refresh();&lt;br /&gt;  servletContext.setAttribute(WebApplicationContext.&lt;br /&gt;    ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);&lt;br /&gt;&lt;br /&gt;  // Use spring as the object factory for Struts&lt;br /&gt;  StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory(&lt;br /&gt;    null, null, servletContext);&lt;br /&gt;  ssf.setApplicationContext(appContext);&lt;br /&gt;  //ssf.setServletContext(servletContext);&lt;br /&gt;  StrutsSpringObjectFactory.setObjectFactory(ssf);&lt;br /&gt;&lt;br /&gt;  // Dispatcher is the guy that actually handles all requests.  Pass in&lt;br /&gt;  // an empty Map as the parameters but if you want to change stuff like&lt;br /&gt;  // what config files to read, you need to specify them here&lt;br /&gt;  // (see Dispatcher's source code)&lt;br /&gt;  dispatcher = new Dispatcher(servletContext,&lt;br /&gt;    new HashMap());&lt;br /&gt;  dispatcher.init();&lt;br /&gt;  Dispatcher.setInstance(dispatcher);&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;By extending the above class for our action test classes we can easily simulate any of the three scenarios listed above. I’ve added three methods to PersonActionTest which illustrate how to test the above three cases: testInterceptorsBySettingRequestParameters, testInterceptorsBySettingDomainObjects() and testActionAndSkipInterceptors(), respectively.&lt;/p&gt;&lt;pre&gt;public class PersonActionTest extends BaseStrutsTestCase { &lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * Invoke all interceptors and specify value of the action&lt;br /&gt;  * class' domain objects directly.&lt;br /&gt;  * @throws Exception Exception&lt;br /&gt;  */&lt;br /&gt; public void testInterceptorsBySettingDomainObjects()&lt;br /&gt;         throws Exception {&lt;br /&gt;  PersonAction action = createAction(PersonAction.class,&lt;br /&gt;                "/site", "deletePerson");&lt;br /&gt;  pa.setId(123);&lt;br /&gt;  String result = proxy.execute();&lt;br /&gt;  assertEquals(result, "success");&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * Invoke all interceptors and specify value of action class'&lt;br /&gt;  * domain objects through request parameters.&lt;br /&gt;  * @throws Exception Exception&lt;br /&gt;  */&lt;br /&gt; public void testInterceptorsBySettingRequestParameters()&lt;br /&gt;                     throws Exception {&lt;br /&gt;  createAction(PersonAction.class, "/site", "deletePerson");&lt;br /&gt;  Map params = new HashMap();&lt;br /&gt;  params.put("id", "123");&lt;br /&gt;  proxy.getInvocation().getInvocationContext().setParameters(params);&lt;br /&gt;  String result = proxy.execute();&lt;br /&gt;  assertEquals(result, "success");&lt;br /&gt; } &lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * Skip interceptors and specify value of action class'&lt;br /&gt;  * domain objects by setting them directly.&lt;br /&gt;  * @throws Exception Exception&lt;br /&gt;  */&lt;br /&gt; public void testActionAndSkipInterceptors() throws Exception {&lt;br /&gt;  PersonAction action = createAction(PersonAction.class,&lt;br /&gt;                  "/site", "deletePerson");&lt;br /&gt;  action.setId(123);&lt;br /&gt;  String result = action.deletePerson();&lt;br /&gt;  assertEquals(result, "success");&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The source code for Dispatcher is probably a good thing to look at if you want to configure your actions more specifically. There are options to specify zero-configuration, alternate XML files and others. Ideally the StrutsTestCaseHelper should be doing a lot more than what it does right now (creating a badly configured Dispatcher) and should allow creation of custom dispatchers and object factories. That’s the reason why I’m not using StrutsTestCase since all that does is make a couple calls using StrutsTestCaseHelper.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;If you want to test your validation, its pretty easy. Here’s a snippet of code that might do that:&lt;/p&gt;&lt;pre&gt; public void testValidation() throws Exception {&lt;br /&gt;  SomeAction action = createAction(SomeAction.class,&lt;br /&gt;                  "/site", "someAction");&lt;br /&gt;  // lets forget to set a required field: action.setId(123);&lt;br /&gt;  String result = proxy.invoke();&lt;br /&gt;  assertEquals(result, "input");&lt;br /&gt;  assertTrue("Must have one field error",&lt;br /&gt;                  action.getFieldErrors().size() == 1);&lt;br /&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This example uses Struts 2.0.8 and Spring 2.0.5.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-6257123562542593445?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/Nklj8Trng6k" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/Nklj8Trng6k/struts2-spring-junit.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>4</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/08/struts2-spring-junit.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-4386902429613500466</guid><pubDate>Wed, 22 Aug 2007 17:21:00 +0000</pubDate><atom:updated>2007-08-22T10:37:19.099-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Patterns</category><category domain="http://www.blogger.com/atom/ns#">Spring</category><title>Using DAO Design Pattern</title><description>&lt;b&gt;DAO Pattern Definition&lt;/b&gt;  &lt;p&gt;Access to data varies depending on the source of the data. Access to persistent storage, such as to a database, varies greatly depending on the type of storage (relational databases, object-oriented databases, flat files, and so forth) and the vendor implementation. &lt;br&gt;Reference: &lt;a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html"&gt;Blue Prints&lt;/a&gt; &lt;/p&gt;&lt;b&gt;Introduction&lt;/b&gt;  &lt;p&gt;When you are creating your application framework, you would like to persist your data using smart techniques, and I am not talking about Hibernate, JDO, OJB or anything else, however I can ask for you? Can your application support a storage system replacement without any problem? If your asnwer is NO, this text will be useful for you.&lt;/p&gt;&lt;b&gt;Define a Interface as foundation for DAOs&lt;/b&gt;  &lt;p&gt;You can define a simple Interface, describing "WHAT" you would like to do, and not "HOW" to do. Getting this idea, we can to think in Interfaces usage. Take a look in the following code:&lt;/p&gt;&lt;pre&gt;package framework.dao; &lt;br /&gt;&lt;br /&gt;import java.util.Collection; &lt;br /&gt;&lt;br /&gt;public interface IGenericDAO {&lt;br /&gt;    public void save(Object object) throws DAOException;&lt;br /&gt;    public void update(Object object) throws DAOException;&lt;br /&gt;    public void remove(Object object) throws DAOException;&lt;br /&gt;    public Object findByPrimaryKey(Object pk) throws DAOException;&lt;br /&gt;    public Collection findAll() throws DAOException;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;You can see that this interface can remind you the EJB EntityBeans model, if you are thinking it is correct! EntityBeans is a great idea, so We can continue using nice ideas(concepts) like that. &lt;br&gt;In fact, we are exposing that this interface says that It can save, update, remove or find results against Information storage.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;We need a simple extension from java.lang.Exception called DAOException, which can be throwed by any method, its source can be as simple as in the following code section:&lt;/p&gt;&lt;pre&gt;package framework.dao; &lt;br /&gt;&lt;br /&gt;public class DAOException extends Exception {&lt;br /&gt;   public DAOException(String message) {&lt;br /&gt;      super(message);    &lt;br /&gt;   }&lt;br /&gt; public DAOException(Throwable e) {&lt;br /&gt;      super(e);    &lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;b&gt;The Implementation &lt;/b&gt;&lt;br /&gt;&lt;p&gt;We talked previouslly about smart codes, so we need to create and use it automaticlly and easier! You can have two choices:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Create a DAOFactory class&lt;/li&gt;&lt;li&gt;Use Spring Framework&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;DAOFactory&lt;/h3&gt;This class will implement a couple of patterns,as such:&lt;br&gt;Singleton - We will use one and just one instance and &lt;br&gt;Factory Method - The method returns always an interface, but in execution it will return a concrete class as wich implements this interface, in this case IGenericDAO. &lt;br&gt;See the following code for DAOFactory: &lt;br /&gt;&lt;p&gt;&lt;pre&gt;import java.io.IOException;&lt;br /&gt;import java.util.Properties; &lt;br /&gt;&lt;br /&gt;public class DAOFactory { &lt;br /&gt;&lt;br /&gt;    private static DAOFactory me = null; &lt;br /&gt;&lt;br /&gt;    private Properties props = null; &lt;br /&gt;&lt;br /&gt;    private DAOFactory() {&lt;br /&gt;        try {&lt;br /&gt;            props = new Properties();&lt;br /&gt;            props.load(DAOFactory.class.getResourceAsStream("daos.properties"));&lt;br /&gt;        } catch (IOException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;    } &lt;br /&gt;&lt;br /&gt;    public static DAOFactory getInstance() {&lt;br /&gt;        if (null == me) {&lt;br /&gt;            me = new DAOFactory();&lt;br /&gt;        }&lt;br /&gt;        return me;&lt;br /&gt;    } &lt;br /&gt;&lt;br /&gt;    public IGenericDAO getDAO(String name) {&lt;br /&gt;        IGenericDAO retorno = null;&lt;br /&gt;        try {&lt;br /&gt;            retorno = (IGenericDAO) Class.forName(props.getProperty(name))&lt;br /&gt;                .newInstance();&lt;br /&gt;        } catch (InstantiationException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (IllegalAccessException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (ClassNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;        return retorno;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The DAOFactory is using a properties file to discover the real implementations for DAOs that will be requested by applications. &lt;br /&gt;&lt;p&gt;You can create much better resource of reading, as such to auto-detect changes and update the properties in memory and other stuff. &lt;br /&gt;&lt;h3&gt;Using Spring Framework&lt;/h3&gt;You can work with Dependency Injection, and you will use the context.xml used in all Spring Applications to describe this dependency. &lt;br&gt;Other nice Spring's feature is the ability to create DAOs implementations extends the HibernateDAOSupport class, which offer a lot of nice things to make your development easier. &lt;br /&gt;&lt;p&gt;This entry is to make you think that your applications can use dinamic configurations issues, and reduce the coupling between your layers, if you will use Spring or your own IoC framework, the most important is to use some useful DAO strategy as I this text is decribing (more information about DAO in Spring Framework - &lt;a href="http://www.springframework.org/docs/reference/orm.html"&gt;here&lt;/a&gt;). &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-4386902429613500466?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/8t1VOnlXLQQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/8t1VOnlXLQQ/using-dao-design-pattern.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>7</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/08/using-dao-design-pattern.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-7692511817833159183</guid><pubDate>Tue, 21 Aug 2007 11:17:00 +0000</pubDate><atom:updated>2007-08-21T04:17:13.807-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Research</category><category domain="http://www.blogger.com/atom/ns#">Problem-solving</category><title>Java: PermGen OutOfMemory</title><description>&lt;style&gt;&lt;br /&gt;code, pre {&lt;br /&gt;border: 1px solid #ccc;&lt;br /&gt;background-color: #eee;&lt;br /&gt;width: 90%;&lt;br /&gt;padding: 5px;&lt;br /&gt;font-family: andale mono,lucida console,monaco,fixed,monospace;&lt;br /&gt;font-size: 11px;&lt;br /&gt;line-height: 1;&lt;br /&gt;}&lt;br /&gt;&lt;/style&gt;  &lt;p&gt;This blog is in relation to &lt;strong&gt;Java PermGen OutOfMemory&lt;/strong&gt; issue as described in &lt;a title="Frank Kieviet" href="http://blogs.sun.com/fkieviet/" target="_blank"&gt;Frank Kieviet&lt;/a&gt;'s blog entries: &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://blogs.sun.com/fkieviet/entry/classloader_leaks_the_dreaded_java" target="_blank"&gt;Classloader leaks&lt;/a&gt; and &lt;a href="http://blogs.sun.com/fkieviet/entry/how_to_fix_the_dreaded" target="_blank"&gt;How to fix Classloader leaks?&lt;/a&gt;&amp;nbsp; &lt;/p&gt; &lt;p&gt;To summarize, a new instance of custom Classloader is created by Application Server whenever a new application (.ear, .jar, .war) is &lt;strong&gt;deployed &lt;/strong&gt;to the server, and this Classloader is used to load all the classes and resources contained in this application.&amp;nbsp; Benefit in this approach is that, this way applications are self-contained and isolated from each other, and there are no conflicts between different applications.&amp;nbsp; When an application is &lt;strong&gt;undeployed &lt;/strong&gt;from server, its associated Classloader is also unloaded, and it is subject to garbage-collection by JVM. &lt;/p&gt; &lt;p&gt;As described in Frank's blog, there are situations in which Classloaders cannot be garbage-collected because of dangling references to them thru most unexpected places, and this will cause memory-leak in the PermGen space (a special section of heap).&amp;nbsp; To find the cause of this problem, I used JDK 6.0's jmap and jhat utility to generate memory dump and analyze memory dump, respectively. &lt;/p&gt; &lt;h4&gt;Orphaned Classloader &lt;/h4&gt; &lt;p&gt;&lt;strong&gt;jhat &lt;/strong&gt;utility can be easily extended to include your own query on the heap snapshot, you need to download and modify the jhat source code though.&amp;nbsp; I added a new query to find all the &lt;strong&gt;Orphaned Classloaders&lt;/strong&gt; in memory and display all the reference links to these &lt;strong&gt;Orphaned Classloaders&lt;/strong&gt;.&amp;nbsp; By &lt;strong&gt;orphaned&lt;/strong&gt;, I mean these classloader instances&amp;nbsp;that have no &lt;strong&gt;strong-reference chains&lt;/strong&gt; to them from the &lt;strong&gt;root set&lt;/strong&gt;, except by these strong-references chains from rootset that goes through instance of Class loaded by the Classloader.&amp;nbsp; To illustrate this, see the diagram below (solid line = strong-reference, dash-line = weak-reference) : &lt;/p&gt; &lt;p&gt;&lt;img title="Orphaned Classloaders" src="http://lh5.google.ru/itefforts/RsrCkb4Bl0I/AAAAAAAAAB8/i7iUvJGmSx4/s800/OrphanedClassloaders.jpg" border="0" alidn="center"&gt; &lt;/p&gt;The yellow Classloader instance is &lt;strong&gt;orphaned&lt;/strong&gt;, because the only &lt;strong&gt;strong-reference chain&lt;/strong&gt; to it from root set is the chain that goes through B.class, and B.class is loaded by this Classloader (all the red lines).&amp;nbsp; All other references that do not go through classes loaded by this Classloader are weak-references.&amp;nbsp; This scenario is a possible suspect of Classloader leak, because most likely Orphaned Classloaders are not intended result of programmer, there are exceptions though.&amp;nbsp; By using this query, we can easily find all the possible suspects, and then goes through each one to determine if they are real memory leak or not.  &lt;p style="font-size: 70%" align="right"&gt;&lt;a title="blogs.sun.com" href="http://blogs.sun.com/" rel="nofollow"&gt;blogs.sun.com&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-7692511817833159183?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/nIZPOed5JL0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/nIZPOed5JL0/java-permgen-outofmemory.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>3</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/08/java-permgen-outofmemory.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-1293075626039674478</guid><pubDate>Thu, 09 Aug 2007 13:50:00 +0000</pubDate><atom:updated>2007-08-09T07:10:11.830-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">RMDB</category><category domain="http://www.blogger.com/atom/ns#">Overview</category><category domain="http://www.blogger.com/atom/ns#">Oracle</category><title>DBMS_METADATA Package in Oracle</title><description>All SQL statements are devided into two main categories:&lt;br&gt;&lt;strong&gt;DDL&lt;/strong&gt; - data definition language;&lt;br&gt;&lt;strong&gt;DML&lt;/strong&gt; - data manipulation languauge.&lt;br&gt;DML is used to change the data in the database tables. Instructions of DML are well-known for everyone: insert, update, delete. In order to save changes to database (so, the other users will see them), you need to execute commit operator. To discard all of your changes you have to execute rollback operator.&lt;br&gt;All database objects (triggers, tables, indices, etc.) have their definitions. DDL-expressions (&lt;strong&gt;metadata&lt;/strong&gt;) of these objects can be extracted from the database schema. DDL-expressions will help you during database analysis and optimization.&lt;br&gt;This article will teach you, how objects’ definitions can be extracted from the Oracle database instance.&lt;br&gt;&lt;span id="more-50"&gt;&lt;/span&gt;&lt;br&gt;Previous versions of Oracle provide no specialized ways for DDL extraction. The only way is to execute some SQL-statements or simply export database schema and parse it. These methods have both limitations and disadvantages.&lt;br&gt;Oracle 9i (and higher) brings us a powerful package - &lt;strong&gt;DBMS_METADATA&lt;/strong&gt;. Functions from DBMS_METADATA package provide an easy way to get objects’ definitions either in XML representation or in DDL one.&lt;br&gt;The main function you are going to use is &lt;strong&gt;get_ddl&lt;/strong&gt;. There are two ways of calling it:  &lt;p&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;with two parameters - object’s type and object’s name;  &lt;li&gt;with three parameters - object’s type, object’s name and schema’s name. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;For example, in order to get metadata for TRIGGER1 trigger form schema SCHEMA1 you have to use this call:&lt;/p&gt;&lt;pre&gt;select dbms_metadata.get_ddl('TRIGGER','TRIGGER1', 'SCHEMA1') from dual.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;While working with your own schema, you can ommit the third parameter. The valid objects’ types are PROCEDURE, TABLE, CONSTRAINT, INDEX, etc.&lt;br&gt;You might have noticed the &lt;strong&gt;dual&lt;/strong&gt; table in the SQL statement. This is auxiliary Oracle’s table. It consists of one column (name - “DUMMY”) and one record (value - “X”). Try to execute&lt;/p&gt;&lt;pre&gt;select * from dual&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;and you will see it.&lt;br&gt;The owner of “dual” table is SYS, but every user of database can use it. While trying to execute valid SQL statement over the “dual” table we will get no more then one record in the result set (just believe me :)). Of course, you can modify the definition of “dual” table but I strongly recommend you not to do so.&lt;br&gt;Sometimes you will not be informed about the objects’ names. In order to get objects’ names for the current schema you can execute this sort of statement:&lt;/p&gt;&lt;pre&gt;select * from USER_TABLES;&lt;br /&gt;select * from USER_TAB_COLUMNS;&lt;br /&gt;select * from USER_INDEXES;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;and so on.&lt;br&gt;So, we did it. From now you can use metadata where ever you wish.&lt;br&gt;Best regards.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-1293075626039674478?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/h5jpo1RNbyE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/h5jpo1RNbyE/dbmsmetadata-package-in-oracle.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>3</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/08/dbmsmetadata-package-in-oracle.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-2237195009140548933</guid><pubDate>Mon, 06 Aug 2007 08:17:00 +0000</pubDate><atom:updated>2007-08-06T08:45:16.389-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Research</category><title>Java research: Anonymous Inner Classes</title><description>There are a lot of articles through Internet which have mistakes regarding anonymous inner classes in Java. Anonymous inner class:  &lt;p&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;has no name;  &lt;li&gt;can’t be declared as static;  &lt;li&gt;can be instantiated only once. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Let me show you the truth.&lt;br&gt;Consider the following code:&lt;br&gt;&lt;span id="more-28"&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;public class Anonymous {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        Runnable anonym = new Runnable() {&lt;br /&gt;            public void run() {&lt;br /&gt;            }&lt;br /&gt;        };&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;In order to get the name of inner class write down the following:&lt;/p&gt;&lt;pre&gt;anonym.getClass().toString().&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;You’ll get something like that: Anonymous$1.&lt;br&gt;Anonymous class can be either static or non-static. It depends on the block in which the class have been declared. In the previous example the anonymous class was static. In this case we can create the second instance of this class in such a way:&lt;/p&gt;&lt;pre&gt;Runnable anonym2 = (Runnable) anonym&lt;br /&gt;    .getClass().newInstance().&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;There is no need in type cast in JDK 1.5.&lt;br&gt;If the anonymous class was declared in non-static block, we have to provide a reference to the outer class to the proper constructor (in reflection veritas!). In the other case we’ll get the InstantiationException.&lt;br&gt;Here we have an example (determining of proper constructor and exception handling are not shown below):&lt;/p&gt;&lt;pre&gt;public class Anonymous {&lt;br /&gt;  public void nonStaticMethod() {&lt;br /&gt;    Runnable anonym = new Runnable() {&lt;br /&gt;      public void run() {&lt;br /&gt;      }&lt;br /&gt;    };&lt;br /&gt;    Constructor[] constructors = anonym.getClass()&lt;br /&gt;        .getDeclaredConstructors();&lt;br /&gt;    Object[] params = new Object[1];&lt;br /&gt;    params[0] = this;&lt;br /&gt;&lt;br /&gt;    Runnable anonym2 = (Runnable) constructors[0]&lt;br /&gt;        .newInstance(params);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;    Anonymous example = new Anonymous();&lt;br /&gt;    example.nonStaticMethod();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;In this example we have to use getDeclaredConstructors instead of getConstructors. Method getConstructors will return only public constructors, while needed constructor is protected one.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Have a nice day.&lt;/p&gt;&lt;br /&gt;&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:e01a9e02-42f6-4496-beb7-f8f6f0f3c459" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Java" rel="tag"&gt;Java&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Programming" rel="tag"&gt;Programming&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Research" rel="tag"&gt;Research&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-2237195009140548933?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/iXW6wLUEDkM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/iXW6wLUEDkM/java-research-anonymous-inner-classes.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>6</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/08/java-research-anonymous-inner-classes.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-3639121550946307125</guid><pubDate>Thu, 02 Aug 2007 07:27:00 +0000</pubDate><atom:updated>2007-08-02T00:27:26.991-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Overview</category><category domain="http://www.blogger.com/atom/ns#">Stripes</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Struts</category><title>Familiarity with Stripes</title><description>Taken from the &lt;a href="http://stripes.mc4j.org/confluence/display/stripes/Stripes+vs.+Struts"&gt;official site Stipes&lt;/a&gt;.  &lt;hr&gt; Stripes is a presentation framework for building web applications using the latest Java technologies. The main driver behind Stripes is that web application development in Java is just too much work! It seems like every existing framework requires gobs of configuration. Struts is pretty feature-light and has some serious architectural issues. Others, like WebWork 2 and Spring-MVC are much better, but still require a lot of configuration, and seem to require you to learn a whole new language just to get started.  &lt;p&gt;Stripes was born out of ongoing frustration with the lack of a high quality, easy to use web framework. Sure, Struts has its good points, but there are a lot of small things that really add up. A lot of small things that you learn to work around, and live with, without realizing how unproductive it's making you.&lt;/p&gt; &lt;p&gt;Up until recently it would have been difficult to create a framework that was better-enough to warrant competing with Struts. And with JSF on the horizon (perpetually?), and other web frameworks in play (WebWork, Tapestry, Wicket) some might question the rationale behind yet another framework. But with Java 1.5 and Servlet 2.4 I think the time has come. The rationale is plain and simple - I wanted a web framework that made it easy, no, fun, to write web applications in Java. The best way to demonstrate is perhaps by a comparison with Struts.&lt;/p&gt;&lt;b&gt;Number of artifacts&lt;/b&gt;  &lt;p&gt;One of prime frustrations with Struts is the fact that just to implement a single page/form, I have to write or edit so many files. And I have to keep them in sync, or else things start going horribly wrong. With Struts I have to write JSP, Action, Form, a form-bean stanza in the struts-config.xml, an action stanza in the struts-config.xml, and if I'm going to do it the Struts way, a bunch of forward stanzas. And let's not go into the fact that since this is all stored in one xml file I'm continually facing merge conflicts with team mates. Yes, there are annotations for Struts, but they are just literal translations of what's in the XML file, and they don't feel natural to me.&lt;/p&gt; &lt;p&gt;Compare this with Stripes. I write JSP. I write ActionBean and annotate it with a @UrlBinding to specify the URL it should respond to, and one or more @HandlesEvent annotations to map events to methods. I'm done. All the information about the form and the action is in the same place.&lt;/p&gt;&lt;b&gt;Incremental development&lt;/b&gt;  &lt;p&gt;Write a JSP with a Struts &amp;lt;html:form&amp;gt; tag on it and try to preview it in your container before you write your form-bean. Boom! You can't. Exception! Could not find form bean! Now write your form bean. Wait - that's still not good enough. Since everything is hooked together through the action stanza in the XML you better have an action, and edit that too.&lt;/p&gt; &lt;p&gt;Maybe it's just me, but I like to be able to write JSP, see if it looks ok, then go and write the back end components to go with it. It's not brain surgery, and Stripes lets you do it.&lt;/p&gt;&lt;b&gt;Property binding&lt;/b&gt;  &lt;p&gt;Struts lets you use nested properties, and that's great. But say you have a property on your Form 'person.address.line1'. Struts will try and set it for you, but if person or address is null, you'll be very sad indeed. So you have to pre-instantiate any objects on which you want to use nested properties. This just seems like too much work.&lt;/p&gt; &lt;p&gt;Stripes will instantiate just about anything for you. Just so long as 'person' and 'address' have no-arg constructors Stripes will build them, join them together, set them on your ActionBean and then set the 'line1' property. It'll even instantiate implementations for any of the Collections interfaces, which leads us to...&lt;/p&gt;&lt;b&gt;Indexed Properties&lt;/b&gt;  &lt;p&gt;The JavaBean specification is great for the most part, but it is clearly a child of the Java GUI side of the house. Struts' implementation of indexed properties matches the JavaBean specification. But in a disconnected web model, your Action won't know (and shouldn't have to know) how many indexed properties are coming back. To make it work you end up coding "smart" indexed getter and setter methods that extend lists and insert objects just to keep Struts happy.&lt;/p&gt; &lt;p&gt;Stripes does it all for you. You provide a getter and setter that use a List or Map type, using generics to inform Stripes what type of thing should be in the List or Map. Stripes will instantiate the List or Map for you if necessary, extend it when needed, manufacture new objects and put them in the list and, you know, set properties of objects in the list.&lt;/p&gt;&lt;b&gt;&lt;/a&gt;Validation&lt;/b&gt;  &lt;p&gt;Other frameworks take shots at Struts for Validation. It's just fundamentally in the wrong place. Forget that the Struts Validator requires yet another XML file with yet more information about your Form that has to be kept in sync. Validation in Struts is divorced from Type Conversion. This is just plain wrong. Why validate that something is a well formed date, then spend a whole bunch more effort converting it to one? Well Struts almost does that. It expends a lot of effort validating it, tosses it all away and then performs some pretty weak type conversion. It's inefficient, and a pain to use. Which is why most of the Struts projects I've seen steer clear of Struts Validator.&lt;/p&gt; &lt;p&gt;In Stripes validation is tied closely to type conversion. A number of commonly used validations can be applied pre-conversion using a simple annotation. This includes things like required field checks, length checks, regex checking etc. Then type conversion happens, or tries to. If it fails, type converters produce validation errors that can be displayed to the user. So you can put your effort into creating good type converters (if the built in ones don't cover your needs) and be done.&lt;/p&gt;&lt;b&gt;Null mean Null (or does it)&lt;/b&gt;  &lt;p&gt;Ask yourself this. You have an &lt;em&gt;int&lt;/em&gt; property in your form bean and the user doesn't enter a value in a text box. What should your property be set to? Zero sounds like a sensible default right? Now, what if you have an &lt;em&gt;Integer&lt;/em&gt; property? If the user doesn't submit anything I'd say that means null wouldn't you? Apparently Struts thinks it means zero again. And if there are validation errors, the form will even repopulate with the value zero! The only way to get around this is to declare your number properties as Strings and do your own conversion (which is a lot of effort if your dealing with multiple Locales).&lt;/p&gt; &lt;p&gt;Stripes takes the position that the HTML specification is a little inconsistent, and does what it can to make it more consistent for application developers. As a result, empty strings are treated the same as if the field didn't get submitted. The user didn't enter a value, so why should your ActionBean receive one and have to figure out what it means?&lt;/p&gt;&lt;b&gt;&lt;/a&gt;Formatting&lt;/b&gt;  &lt;p&gt;The Struts FAQ says this (among other things) in answer to why the Struts tags provide so little formatting:&lt;/p&gt; &lt;p&gt;Great. JSTL doesn't have form tags, so while JSTL is great, it doesn't really help here. JSF and Struts don't mix so well even now, and that's a reason to leave people without formatting for years? And the last is just a cop-out. I want to be able to format data in the right way for each page. And it needs to be localizable etc.&lt;/p&gt; &lt;p&gt;Stripes provides high quality formatting support using the same java.text APIs that the JSTL formatting is built on. It's as similar to JSTL formatting as it can be, while being constrained to living on form tags (i.e. we can't have a separate tag for formatting a date vs. a number and so on).&lt;/p&gt;&lt;b&gt;Multi-Event Actions&lt;/b&gt;  &lt;p&gt;If you want to have a form that submits multiple different events in Struts you have to either extend the DispatchAction or write your own support for it. And since the DispatchAction requires all buttons to have the same name, and uses the value to determine the method to invoke, it's a huge pain if you're using localized or even just externalized values for your buttons.&lt;/p&gt; &lt;p&gt;Stripes uses the name of the button itself, and has built in support for multi-event Actions. You can localize to your heart's content, and Stripes will detect which button was pressed and invoke the right method for you.&lt;/p&gt;&lt;b&gt;JSP / View Helpers&lt;/b&gt;  &lt;p&gt;Struts doesn't really provide a good pattern for providing dynamic data to JSPs that are not the result of another Action. This leaves you with the options of writing a pre-action for the page or doing something outside of Struts. Then, what if another Action wants to forward to your page after it's completed processing. Do you chain the actions? Do you make the second action meet the dependencies of the page also?&lt;/p&gt; &lt;p&gt;Stripes has a neat way of handling this. A custom tag allows the use of ActionBeans as view helpers. It works similarly to the jsp:useBean tag in that if the ActionBean already exists it just gives you a reference to it. If it doesn't exist, the tag will bring it into existence, bind data out of the request on to it, and get it ready for use.&lt;/p&gt;&lt;b&gt;"HTML" Tags&lt;/b&gt;  &lt;p&gt;Maybe it's just me who could never get used to it, but why do the Struts form input tags use 'property' instead of 'name'? And why is it 'styleClass' instead of 'class'? It also makes it hard to change a tag back and forth from a plain HTML tag to a Struts tag.&lt;/p&gt; &lt;p&gt;Stripes takes pains to make all the form input tags as close to (if not identical to) their HTML counterparts as possible.&lt;/p&gt; &lt;hr&gt;  &lt;p&gt;Who had experience with Stripes? Does it make sense to use it? Your comments are welcome.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:5ba318ae-4dd4-4c95-84cc-dcb05859b71e" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Java" rel="tag"&gt;Java&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Overview" rel="tag"&gt;Overview&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Frameworks" rel="tag"&gt;Frameworks&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Stripes" rel="tag"&gt;Stripes&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Struts" rel="tag"&gt;Struts&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Spring" rel="tag"&gt;Spring&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-3639121550946307125?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/3Bklhu7l6nA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/3Bklhu7l6nA/familiarity-with-stripes.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>4</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/08/familiarity-with-stripes.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-2320238113580827020</guid><pubDate>Wed, 01 Aug 2007 07:33:00 +0000</pubDate><atom:updated>2007-08-01T00:36:03.996-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Patterns</category><title>Singleton Pattern in Java</title><description>Design patterns are descriptions of problems and possible ways of their solving during object-oriented design (OOD).&lt;br&gt;Maybe the most popular design pattern is Singleton Pattern. It is used to guarantee that there will be only one instance of particular object in the application. The realization of this pattern can be useful while creating Connection Pool, Factory, Configuration Manager, etc.&lt;br&gt;In this article you will find basic description of this pattern and the example of its practical usage (in Java).&lt;br&gt;Look through the following code:&lt;br&gt;&lt;span id="more-40"&gt;&lt;/span&gt; &lt;p&gt;&lt;/p&gt;&lt;pre&gt;public class Singleton {&lt;br /&gt;    private static Singleton _instance = null;&lt;br /&gt;&lt;br /&gt;    private Singleton() {}&lt;br /&gt;&lt;br /&gt;    public synchronized static Singleton getInstance() {&lt;br /&gt;        if (_instance == null)&lt;br /&gt;            _instance = new Singleton();&lt;br /&gt;        return _instance;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The constructor of this class has to be declared as &lt;strong&gt;private&lt;/strong&gt;. This modificator with the help of getInstance method prevents user from creating several instances of class. So, we can add the &lt;strong&gt;final&lt;/strong&gt; modificator to the class declaration.&lt;br&gt;As mentioned above, getInstance() method will create the only one instance of Singleton class. This method is &lt;strong&gt;synchronized&lt;/strong&gt; one! This limitation is used to guarantee that in multi-threaded environment there would be only one instance of Singleton class as well as in the single-threaded application.&lt;br&gt;We can get rid of &lt;strong&gt;synchronized&lt;/strong&gt; keyword. In order to do that the _instance field must be initialized like this:&lt;/p&gt;&lt;pre&gt;private static Singleton _instance = new Singleton(),&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Of course, the “if” construction is not critical in this case.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;I use implemetation of this pattern while working with project configuration. For example, the configuration file “props.txt” consists of properties set.&lt;br&gt;Consider the following code:&lt;/p&gt;&lt;pre&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class Configuration {&lt;br /&gt;    private static Configuration _instance = null;&lt;br /&gt;&lt;br /&gt;    private Properties props = null;&lt;br /&gt;&lt;br /&gt;    private Configuration() {&lt;br /&gt;         props = new Properties();&lt;br /&gt;    	try {&lt;br /&gt;	    FileInputStream fis = new FileInputStream(new File(“props.txt”));&lt;br /&gt;	    props.load(fis);&lt;br /&gt;    	}&lt;br /&gt;    	catch (Exception e) {&lt;br /&gt;    	    // catch Configuration Exception right here&lt;br /&gt;    	}&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public synchronized static Configuration getInstance() {&lt;br /&gt;        if (_instance == null)&lt;br /&gt;            _instance = new Configuration();&lt;br /&gt;        return _instance;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // get property value by name&lt;br /&gt;    public String getProperty(String key) {&lt;br /&gt;        String value = null;&lt;br /&gt;        if (props.containsKey(key))&lt;br /&gt;            value = (String) props.get(key);&lt;br /&gt;        else {&lt;br /&gt;            // the property is absent&lt;br /&gt;        }&lt;br /&gt;        return value;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Use the following code to get the value for the specified property:&lt;/p&gt;&lt;pre&gt;String propValue = Configuration.getInstance()&lt;br /&gt;    .getProperty(propKey).&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Also you can provide some useful constants for your properties:&lt;/p&gt;&lt;pre&gt;public static final String PROP_KEY = “propKey”,&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;and get their values in such a way:&lt;/p&gt;&lt;pre&gt;String propValue = Configuration.getInstance()&lt;br /&gt;    .getProperty(Configuration.PROP_KEY).&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;That’s all. Best regards. &lt;/p&gt;&lt;br /&gt;&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:dc41d487-90d0-4e42-823f-e54195e30b92" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Programming" rel="tag"&gt;Programming&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Java" rel="tag"&gt;Java&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Patterns" rel="tag"&gt;Patterns&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-2320238113580827020?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/uAVwYfpWpj0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/uAVwYfpWpj0/singleton-pattern-in-java.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>2</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/08/singleton-pattern-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-3701101299056371171</guid><pubDate>Tue, 31 Jul 2007 08:38:00 +0000</pubDate><atom:updated>2007-07-31T01:38:13.496-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Testing</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">JUnit</category><title>Some Words About JUnit Testing</title><description>&lt;div style="float: left; margin-right: 5px"&gt;&lt;a href="http://www.junit.org/"&gt;&lt;img src="http://www.junit.org/images/frogMov.gif"&gt;&lt;/a&gt; &lt;/div&gt;Testing is not a very interesting thing sometimes. Some developers use standard output or debugger in order to test their classes. But there is another way... &lt;br&gt;In this article you’ll find the introduction into JUnit library. &lt;a href="http://www.junit.org/"&gt;JUnit framework&lt;/a&gt; makes the process of test-writing much easier.&lt;br&gt;To show you the power of JUnit let me create the small class in Java and write some test cases for it. Consider the following code:&lt;br&gt;&lt;pre&gt;public class MathFunc {&lt;br /&gt;    private int variable;&lt;br /&gt;&lt;br /&gt;    public MathFunc() {&lt;br /&gt;        variable = 0;&lt;br /&gt;    }&lt;br /&gt;    public MathFunc(int var) {&lt;br /&gt;        variable = var;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int getVariable() {&lt;br /&gt;        return variable;&lt;br /&gt;    }&lt;br /&gt;    public void setVariable(int variable) {&lt;br /&gt;        this.variable = variable;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public long factorial() {&lt;br /&gt;        long result = 1;&lt;br /&gt;        if (variable &amp;gt; 1) {&lt;br /&gt;            for (int i=1; i&amp;lt;=variable; i++)&lt;br /&gt;                result = result*i;&lt;br /&gt;        }&lt;br /&gt;        return result;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public long plus(int var) {&lt;br /&gt;        long result = variable + var;&lt;br /&gt;        return result;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;At first, you have to create the class which extends junit.framework.TestCase. The proper constructor also must be defined. This constructor has to provide String parameter to the parent class’ constructor. At last, you have to write as many test methods as you want:&lt;/p&gt;&lt;pre&gt;public class TestClass extends TestCase {&lt;br /&gt;    public TestClass(String testName) {&lt;br /&gt;        super(testName);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void testFactorialNull() {&lt;br /&gt;        MathFunc math = new MathFunc();&lt;br /&gt;        assertTrue(math.factorial() == 1);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void testFactorialPositive() {&lt;br /&gt;        MathFunc math = new MathFunc(5);&lt;br /&gt;        assertTrue(math.factorial() == 120);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void testPlus() {&lt;br /&gt;        MathFunc math = new MathFunc(45);&lt;br /&gt;        assertTrue(math.plus(123) == 168);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Method assertTrue checks the parameter’s value for “true” result. So, we can compare the output value of some method to the expected value. Methods assertEquals, assertFalse, assertNull, assertNotNull, assertSame are also useful ones.&lt;br&gt;In order to combine few tests together you can use TestSuite class. Just add some tests with addTest method. Finally, you have to use TestRunner to execute tests. I prefer to use junit.textui.TestRunner (there are also graphical implementations - junit.swingui.TestRunner, junit.awtui.TestRunner). The main method of the test class looks like this:&lt;/p&gt;&lt;pre&gt;public static void main(String[] args) {&lt;br /&gt;    TestRunner runner = new TestRunner();&lt;br /&gt;    TestSuite suite = new TestSuite();&lt;br /&gt;    suite.addTest(new TestClass(“testFactorialNull”));&lt;br /&gt;    suite.addTest(new TestClass(“testFactorialPositive”));&lt;br /&gt;    suite.addTest(new TestClass(“testPlus”));&lt;br /&gt;    runner.doRun(suite);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Output after execution:&lt;/p&gt;&lt;pre&gt;Time: 0,02&lt;br /&gt;OK (3 tests)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;For the testing of more complex classes you can use methods setUp and tearDown. The first method initializes several instances of the specified class in order to use them in several test cases. The second method serves to release unused resources after tests have passed.&lt;br&gt;I hope this article will help you a little.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:48551138-afff-428b-9640-5f7467fd5e79" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Java" rel="tag"&gt;Java&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Frameworks" rel="tag"&gt;Frameworks&lt;/a&gt;, &lt;a href="http://technorati.com/tags/JUnit" rel="tag"&gt;JUnit&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Testing" rel="tag"&gt;Testing&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-3701101299056371171?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/XPQD7o1tJ7U" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/XPQD7o1tJ7U/some-words-about-junit-testing.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>3</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/07/some-words-about-junit-testing.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-7493475105281013394</guid><pubDate>Fri, 27 Jul 2007 14:56:00 +0000</pubDate><atom:updated>2007-07-27T08:30:33.595-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Spring</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><category domain="http://www.blogger.com/atom/ns#">Struts</category><title>Using OSF Layers in Your JWeb Application</title><description>&lt;p&gt;This article will discuss one strategy for combining frameworks using three popular open source frameworks. For the presentation layer we will use Struts; for our business layer we will use Spring; and for our persistence layer we will use Hibernate. You should be able to substitute any one of these frameworks in your application and get the same effect. Figure 1 shows what this looks like from a high level when the frameworks are combined.&lt;/p&gt;&lt;br&gt;&lt;br /&gt;&lt;div align='center'&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_o39cna-GY-U/RqoPEDgXj5I/AAAAAAAAABY/11MdA6fgVMs/s1600-h/OSF_Layers.jpg"&gt;&lt;img src="http://bp3.blogger.com/_o39cna-GY-U/RqoPEDgXj5I/AAAAAAAAABY/11MdA6fgVMs/s400/OSF_Layers.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5091898891030728594" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Figure 1. Overview of framework architecture with Struts, Spring, and Hibernate.&lt;br /&gt;&lt;p&gt;&lt;b&gt;Application Layer&lt;/b&gt;  &lt;p&gt;Most non-trivial web applications can be divided into at least four layers of responsibility. These layers are the presentation, persistence, business, and domain model layers. Each layer has a distinct responsibility in the application and should not mix functionality with other layers. Each application layer should be isolated from other layers but allow an interface for communication between them. Let's start by inspecting each of these layers and discuss what these layers should provide and what they should not provide.  &lt;p&gt;At one end of a typical web application is the presentation layer. Many Java developers understand what Struts provides. However, too often, coupled code such as business logic is placed into an org.apache.struts.Action. So, let's agree on what a framework like Struts should provide. Here is what Struts is responsible for:  &lt;p&gt;- Managing requests and responses for a user.  &lt;p&gt;- Providing a controller to delegate calls to business logic and other upstream processes.  &lt;p&gt;- Handling exceptions from other tiers that throw exceptions to a Struts Action.  &lt;p&gt;- Assembling a model that can be presented in a view.  &lt;p&gt;- Performing UI validation.  &lt;p&gt;Here are some items that are often coded using Struts but should not be associated with the presentation layer:  &lt;p&gt;- Direct communication with the database, such as JDBC calls.  &lt;p&gt;- Business logic and validation related to your application.  &lt;p&gt;- Transaction management.  &lt;p&gt;Introducing this type of code in the presentation layer leads to type coupling and cumbersome maintenance.  &lt;p&gt;&lt;b&gt;The Persistence Layer&lt;/b&gt;  &lt;p&gt;At the other end of a typical web application is the persistence layer. This is usually where things get out of control fast. Developers underestimate the challenges in building their own persistence frameworks. A custom, in-house persistence layer not only requires a great amount of development time, but also often lacks functionality and becomes unmanageable. There are several open source object-to-relational mapping (ORM) frameworks that solve much of this problem. In particular, the Hibernate framework allows object-to-relational persistence and query service for Java. Hibernate has a medium learning curve for Java developers who are already familiar with SQL and the JDBC API. Hibernate persistent objects are based on plain-old Java objects and Java collections. Furthermore, using Hibernate does not interfere with your IDE. The following list contains the type of code that you would write inside a persistence framework:  &lt;p&gt;- Querying relational information into objects. Hibernate does this through an OO query language called HQL, or by using an expressive criteria API. HQL is very similar to SQL except you use objects instead of tables and fields instead of columns. There are some new specific HQL language elements to learn; however, they are easy to understand and well documented. HQL is a natural language to use for querying objects that require a small learning curve.  &lt;p&gt;- Saving, updating, and deleting information stored in a database.  &lt;p&gt;- Advanced object-to-relational mapping frameworks like Hibernate have support for most major SQL databases, and they support parent/child relationships, transactions, inheritance, and polymorphism.  &lt;p&gt;Here are some items that should be avoided in the persistence layer:  &lt;p&gt;- Business logic should be in a higher layer of your application. Only data access operations should be permitted.  &lt;p&gt;- You should not have persistence logic coupled with your presentation logic. Avoid logic in presentation components such as JSPs or servlet-based classes that communicate with data access directly. By isolating persistence logic into its own layer, the application becomes flexible to change without affecting code in other layers. For example, Hibernate could be replaced with another persistence framework or API without modification to the code in any other layer.  &lt;p&gt;&lt;b&gt;The Business Layer&lt;/b&gt;  &lt;p&gt;The middle component of a typical web application is the business or service layer. This service layer is often the most ignored layer from a coding perspective. It is not uncommon to find this type of code scattered around in the UI layer or in the persistence layer. This is not the correct place because it leads to tightly coupled applications and code that can be hard to maintain over time. Fortunately, several frameworks exist that address these issues. Two of the most popular frameworks in this space are Spring and PicoContainer. These are referred to as microcontainers that have a very small footprint and determine how you wire your objects together. Both of these frameworks work on a simple concept of dependency injection (also known as inversion of control). This article will focus on Spring's use of setter injection through bean properties for named configuration parameters. Spring also allows a sophisticated form of constructor injection as an alternative to setter injection as well. The objects are wired together by a simple XML file that contains references to objects such as the transaction management handler, object factories, service objects that contain business logic, and data access objects (DAO).  &lt;p&gt;The way Spring uses these concepts will be made clearer with examples later in this article. The business layer should be responsible for the following:  &lt;p&gt;- Handling application business logic and business validation  &lt;p&gt;- Managing transactions  &lt;p&gt;- Allowing interfaces for interaction with other layers  &lt;p&gt;- Managing dependencies between business level objects  &lt;p&gt;- Adding flexibility between the presentation and the persistence layer so they do not directly communicate with each other  &lt;p&gt;- Exposing a context to the business layer from the presentation layer to obtain business services  &lt;p&gt;- Managing implementations from the business logic to the persistence layer  &lt;p&gt;&lt;b&gt;The Domain Model Layer&lt;/b&gt;  &lt;p&gt;Finally, since we are addressing non-trivial, web-based applications we need a set of objects that can move between the different layers. The domain object layer consists of objects that represent real-world business objects such as an Order, OrderLineItem, Product, and so on. This layer allows developers to stop building and maintaining unnecessary data transfer objects, or DTOs, to match their domain objects. For example, Hibernate allows you to read database information into an object graph of domain objects, so that you can present it to your UI layer in a disconnected manner. Those objects can be updated and sent back across to the persistence layer and updated within the database. Furthermore, you do not have to transform objects into DTOs, which can get lost in translation as they are moved between different application layers. This model allows Java developers to work with objects naturally in an OO fashion without additional coding.  &lt;p&gt;First, we will create our domain objects since they will interoperate with each layer. These objects will allow us to define what should be persisted, what business logic should be provided, and what type of presentation interface should be designed. Next, we will configure the persistence layer and define object-to-relational mappings with Hibernate for our domain objects. Then we will define and configure our business objects. After we have these components we can discuss wiring these layers using Spring. Finally, we will provide a presentation layer that knows how to communicate with the business service layer and knows how to handle exceptions that arise from other layers.  &lt;p&gt;&lt;b&gt;Conclusion&lt;/b&gt;  &lt;p&gt;This article covers a lot of ground in terms of technology and architecture. The main concept to take away is how to better separate your application, user interface, persistence logic, and any other application layer you require. Doing this will decouple your code, allow new code components to be added, and make your application more maintainable in the future. The technologies covered here address specific problems well. However, by using this type of architecture you can replace application layers with other technologies.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-7493475105281013394?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/cz0Gk1wpEOc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/cz0Gk1wpEOc/using-osf-layers-in-your-jweb.html</link><author>noreply@blogger.com (IT Efforts)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://bp3.blogger.com/_o39cna-GY-U/RqoPEDgXj5I/AAAAAAAAABY/11MdA6fgVMs/s72-c/OSF_Layers.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/07/using-osf-layers-in-your-jweb.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-7189161062963230621</guid><pubDate>Tue, 24 Jul 2007 12:59:00 +0000</pubDate><atom:updated>2007-07-30T09:55:19.948-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Spring</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><title>Data Validation in Hibernate</title><description>&lt;p&gt;While it's important to build data validation into as many layers of a Web application as possible, it's traditionally been very time-consuming to do so, leading many developers to just skip it - which can lead to a host of problems down the road. But with the introduction of annotations in the latest version of the Java™ platform, validation got a lot easier. In this article,&amp;nbsp;author shows you how to use the Validator component of Hibernate Annotations to build and maintain validation logic easily in your Web apps.  &lt;p&gt;Java SE 5 brought many needed enhancements to the Java language, none with more potential than annotations. With annotations, you finally have a standard, first-class metadata framework for your Java classes. Hibernate users have been manually writing *.hbm.xml files for years (or using XDoclet to automate this task). If you manually create XML files, you must update two files (the class definition and the XML mapping document) for each persistent property needed. Using HibernateDoclet simplifies this (see Listing 1 for an example) but requires you to verify that your version of HibernateDoclet supports the version of Hibernate you wish to use. The doclet information is also unavailable at run time, as it is coded into Javadoc-style comments. Hibernate Annotations, illustrated in Listing 2, improve on these alternatives by providing a standard, concise manner of mapping classes with the added benefit of run-time availability.  &lt;br /&gt;&lt;strong&gt;Listing 1. Hibernate mapping code using HibernateDoclet&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;/** &lt;br /&gt; * @hibernate.property column="NAME" length="60" not-null="true"&lt;br /&gt; */&lt;br /&gt;public String getName() {&lt;br /&gt;    return this.name;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @hibernate.many-to-one column="AGENT_ID" not-null="true" cascade="none" &lt;br /&gt; * outer-join="false" lazy="true" &lt;br /&gt; */&lt;br /&gt;public Agent getAgent() {&lt;br /&gt;    return agent;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @hibernate.set lazy="true" inverse="true" cascade="all" table="DEPARTMENT" &lt;br /&gt; * @hibernate.collection-one-to-many class="com.triview.model.Department"&lt;br /&gt; * @hibernate.collection-key column="DEPARTMENT_ID" not-null="true"&lt;br /&gt; */&lt;br /&gt;public List&lt;Department&gt; getDepartment() {&lt;br /&gt;    return department;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;If you use HibernateDoclet, you won't be able to catch mistakes until you generate the XML files or until run time. With annotations, you can detect many errors at compile time, or, if you're using a good IDE, during editing. When creating an application from scratch, you can take advantage of the hbm2ddl utility to generate the DDL for your database from the hbm.xml files. Important information -- that the name property must have a maximum length of 60 characters, say, or that the DDL should add a not null constraint -- is added to the DDL from the HibernateDoclet entries. When you use annotations, you can generate the DDL automatically in a similar manner.  &lt;p&gt;While both code mapping options are serviceable, annotations offer some clear advantages. With annotations, you can use constants to specify lengths or other values. You have a much faster build cycle without the need to generate XML files. The biggest advantage is that you can access useful information such as a not null annotation or length at run time. In addition to the annotations illustrated in Listing 2, you can specify validation constraints. Some of the included constraints available are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;@Max(value = 100)  &lt;li&gt;@Min(value = 0)  &lt;li&gt;@Past  &lt;li&gt;@Future  &lt;li&gt;@Email &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;When appropriate, these annotations will cause check constraints to be generated with the DDL. (Obviously, @Future is not an appropriate case.) You can also create custom constraint annotations as needed.  &lt;p&gt;&lt;strong&gt;Validation and application layers &lt;/strong&gt; &lt;p&gt;Writing validation code can be a tedious, time-consuming process. Often, lead developers will forgo addressing validation in a given layer to save time, but it is debatable whether or not the drawbacks of cutting corners in this area are offset by the time savings. If the time investment needed to create and maintain validation across all application layers can be greatly reduced, the debate swings toward having validation in more layers. Suppose you have an application that lets a user create an account with a username, password, and credit card number. The application components into which you would ideally like to incorporate validation are as follows:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;View: Validation through JavaScript is desirable to avoid server round trips, providing a better user experience. Users can disable JavaScript, so while this level of validation is good to have, it's not reliable. Simple validations of required fields are a must.  &lt;li&gt;Controller: Validation must be processed in the server-side logic. Code at this layer can handle validations in a manner appropriate for the specific use case. For example, when adding a new user, the controller may check to see if the specified username already exists before proceeding.  &lt;li&gt;Service: Relatively complex business logic validation is often best placed into the service layer. For example, once you have a credit card object that appears to be valid, you should verify the card information with your credit card processing service.  &lt;li&gt;DAO: By the time data reaches this layer, it really should be valid. Even so, it would be beneficial to perform a quick check to make sure that required fields are not null and that values fall into specified ranges or adhere to specified formats -- for instance, an e-mail address field should contain a valid e-mail address. It's better to catch a problem here than to cause avoidable SQLExceptions.  &lt;li&gt;DBMS: This is a common place to find validation being ignored. Even if the application you're building is the only client of the database today, other clients may be added in the future. If the application has bugs (and most do), invalid data may reach the database. In this event, if you are lucky, you will find the invalid data and need to figure out if and how it can be cleaned up.  &lt;li&gt;Model: An ideal place for validations that do not require access to outside services or knowledge of the persistent data. For example, your business logic may dictate that users provide at least one form of contact information, either a phone number or an e-mail address; you can use model layer validation to make sure that they do. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;A typical approach to validation is to use Commons Validator for simple validations and write additional validations in the controller. Commons Validator has the benefit of generating JavaScript to process validations in the view. But Commons Validator does have its drawbacks: it can only handle simple validations and it stores the validation definition in an XML file. Commons Validator was designed to be used with Struts and does not provide an easy way to reuse the validation declarations across application layers.  &lt;p&gt;When planning your validation strategy, choosing to simply handle errors as they occur is not sufficient. A good design also aims to prevent errors by generating a friendly user interface. Taking a proactive approach to validation can greatly enhance a user's perception of an application. Unfortunately, Commons Validator fails to offer support for this. Suppose you want your HTML to set the maxlength attribute of text fields to match the validation or place a percent sign (%) after text fields meant to collect percentage values. Typically, that information is hard-coded into HTML documents. If you decide to change your name property to support 75 characters instead of 60, in how many places will you need to make changes? In many applications, you will need to:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Update the DDL to increase the database column length (via HibernateDoclet, hbm.xml, or Hibernate Annotations).  &lt;li&gt;Update the Commons Validator XML file to increase the max to 75.  &lt;li&gt;Update all HTML forms related to this field to change the maxlength attribute. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;A better approach is to use Hibernate Validator. Validation definitions are added to the model layer through annotations, with support for processing the validations included. If you choose to leverage all of Hibernate, the validator helps provide validation in the DAO and DBMS layers as well. In the code samples that follow, you will take this a step further by using reflection and JSP 2.0 tag files, leveraging the annotations to dynamically generate code for the view layer. This will remove the practice of hard-coding business logic in the view.  &lt;p&gt;Hibernate DAO implementations use the validation annotations as well, if you want them to. All you need to do is specify Hibernate event-based validation in the hibernate.cfg.xml file. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-7189161062963230621?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/SJ_Adfeui3Y" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/SJ_Adfeui3Y/data-validation-in-hibernate.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>2</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/07/data-validation-in-hibernate.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-5323008016288992185</guid><pubDate>Sat, 21 Jul 2007 10:17:00 +0000</pubDate><atom:updated>2007-07-21T03:17:46.161-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><title>Introducing Hibernate</title><description>&lt;p&gt;Hibernate is a full-featured, open source &lt;a href="http://hibernate.org/"&gt;OR mapping framework&lt;/a&gt; for the Java platform. In many ways Hibernate is similar to EJB CMP CMR (container-managed-persistence/container-managed-relationships), and JDO (Java Data Objects). Unlike JDO, Hibernate focuses entirely on OR mapping for relational databases, and includes more features than most commercial products. Most EJB CMP CMR solutions use code generation to implement persistence code, while JDO uses bytecode decoration. Conversely, Hibernate uses reflection and runtime bytecode generation, making it nearly transparent to end users. (Earlier implementations of Hibernate used reflection only, which aids in debugging, and current versions retain this option.)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;p&gt;&lt;strong&gt;Porting Hibernate-based apps &lt;/strong&gt; &lt;p&gt;If your application must run on many RDBMS systems, Hibernate-based applications port almost effortlessly from IBM DB2, MySQL, PostgreSQL, Sybase, Oracle, HypersonicSQL, and many more. I even recently worked on an application port from MySQL to Firebird, which isn't all that well supported by Hibernate, and the port was effortless. See Resources for a case study of a switch between Postgres and MySQL.  &lt;p&gt;Hibernate allows you to model inheritance (several ways); association (one-to-one or one-to-many, containment, and aggregation); and composition. I'll cover several examples of each type of relationship in this article.  &lt;p&gt;Hibernate provides a query language called Hibernate Query Language (HQL), which is similar to JDO's JDOQL and EJB's EJB QL; although it is closer to the former. But Hibernate doesn't stop there: it also allows you to perform direct SQL queries and/or use object criteria to compose criteria easily at runtime. I'll use only HQL in the examples for this article.  &lt;p&gt;Unlike EJB CMP CMR and like JDO, Hibernate can work inside of or outside of a J2EE container, which is a boon for those of us doing TDD and agile development.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-5323008016288992185?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/45IpzGkUMYo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/45IpzGkUMYo/introducing-hibernate.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/07/introducing-hibernate.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-6900758365386347822</guid><pubDate>Sat, 21 Jul 2007 10:14:00 +0000</pubDate><atom:updated>2007-07-21T03:14:09.604-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Spring</category><category domain="http://www.blogger.com/atom/ns#">Software Frameworks</category><title>Introducing Spring</title><description>&lt;p&gt;The first time AOP expert Nicholas Lesiecki explained AOP to me, I didn't understand a word he was saying; and I felt much the same the first time I considered the possibility of using IOC containers. The conceptual basis of each technology alone is a lot to digest, and the myriad of new acronyms applied to each one doesn't help -- particularly given that many of them are variations on stuff we already use.  &lt;p&gt;Like many technologies, these two are much easier to understand in practice than in theory. Having done my own research on AOP and IOC container implementations (namely, XWork, PicoContainer, and Spring), I've found that these technologies help me gain functionality without adding code-based dependencies on multiple frameworks. They'll both be a part of my development projects going forward.  &lt;p&gt;In a nutshell, AOP allows developers to create non-behavioral concerns, called crosscutting concerns, and insert them in their application code. With AOP, common services like logging, persistence, transactions, and the like can be factored into aspects and applied to domain objects without complicating the object model of the domain objects.&amp;nbsp; &lt;p&gt;Developing with a new framework without unit testing is like walking on a new trapeze wire without a net: sure you could do it, but you're going to bleed. I prefer to develop with a net, and for me that net is TDD. Before DbUnit came along, testing code that was dependent on a database could be a little tough. DbUnit is an extension of JUnit that provides a framework for unit tests dependent on a database. I used DbUnit to write the test code for the example classes in this article. While not present in the article, the DbUnit code is part of the article source code (see Resources). Or for an introduction to DbUnit, see "Control your test-environment with DbUnit and Anthill" (developerWorks, April 2004) by Philippe Girolami.  &lt;p&gt;IOC allows me to create an application context where I can construct objects, and then pass to those objects their collaborating objects. As the word inversion implies, IOC is like JNDI turned inside out. Instead of using a tangle of abstract factories, service locators, singletons, and straight construction, each object is constructed with its collaborating objects. Thus, the container manages the collaborators.  &lt;p&gt;Spring is both an AOP framework and an IOC container. I believe it was Grady Booch who said the great thing about objects is that they can be replaced; and the great thing about Spring is that it helps you replace them. With Spring, you simply inject dependencies (collaborating objects) using JavaBeans properties and configuration files. Then it's easy enough to switch out collaborating objects with a similar interface when you need to.  &lt;p&gt;Spring provides an excellent on-ramp to both IOC containers and AOP. As such, you don't need to be familiar with AOP in order to follow the examples in this article. All you need to know is that you'll be using AOP to declaratively add transactional support to your example application, much the same way that you would use EJB technology. See &lt;a href="http://www.springframework.org/"&gt;Resource&lt;/a&gt; to learn more about&amp;nbsp;Spring.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-6900758365386347822?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/67DZRaIkL_Y" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/67DZRaIkL_Y/introducing-spring.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/07/introducing-spring.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-4548965644038081396</guid><pubDate>Fri, 20 Jul 2007 17:51:00 +0000</pubDate><atom:updated>2007-07-21T02:27:15.152-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Eclipse</category><title>Java Testing Tool froglogic Squish Supports New Eclipse Europa</title><description>Squish for Java is a professional functional GUI and regression testing tool enabling the creation and execution of automated GUI tests for Java SWT/RCP and AWT/Swing applications.&lt;br&gt;&lt;br&gt;Squish, and all tests created with it, are completely cross-platform and work on Windows, Linux/Unix, Mac OS X and embedded Linux.&lt;br&gt;&lt;br&gt;Support for testing Eclipse 3.3 RCP applications has now been completed and will be released to the public as of the next Squish maintenance release 3.2.2. A pre-release is available to customers upon request.&lt;br&gt;&lt;br&gt;"Following our cross-platform and cross-technology philosophy it is important for us to stay up to date with latest developments in the Java market. We decided to react quickly and implemented support for the improved version 3.3 of the Eclipse framework", said Koos Vriezen, froglogic's Java team lead.&lt;br&gt;&lt;br&gt;Squish offers a versatile testing framework for GUI applications with a choice of popular test scripting languages (Python, JavaScript, Tcl, TSL and Perl) extended by test-specific functions, open interfaces, add-ons, integrations into test management tools, a powerful IDE&lt;br&gt;aiding the creation and debugging of tests and a set of command line tools facilitating fully automated test runs.&lt;br&gt;&lt;br&gt;If you are interested in evaluating or purchasing Squish for Java or any other edition of Squish, please contact squish at froglogic dot com or visit www.froglogic.com/squish.&lt;br&gt;&lt;br&gt;Squish also supports automated testing of applications based on GUI technologies such as Trolltech's Qt and Qtopia, Web/DOM/HTML/AJAX, Tk, Four J's Genero and others.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-4548965644038081396?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/n9db97PU6zs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/n9db97PU6zs/squish-for-java-is-professional.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/07/squish-for-java-is-professional.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5741401390511285234.post-8075540239537120970</guid><pubDate>Fri, 20 Jul 2007 17:23:00 +0000</pubDate><atom:updated>2007-07-21T02:26:23.631-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Eclipse</category><category domain="http://www.blogger.com/atom/ns#">Google</category><title>Talk with GoogleTalk inside of Eclipse</title><description>ECF is a diverse collection of communication and collaboration tools. One of these is support for talking to any XMPPS (Jabber) server. Given that the popular Google Talk system uses XMPPS, we can easily configure Google Talk to run inside an Eclipse view.&lt;br&gt;&lt;br&gt;Firstly, this assumes you're using Eclipse Europa. Although ECF existed prior to Europa, the update sites weren't built in and the UIs might be slightly different.&lt;br&gt;&lt;br&gt;Secondly, it assumes that you have ECF installed. If not, go to Help -&amp;gt; Software Updates -&amp;gt; Find and Install, and then drill into the 'Search for new features to install'. The Europa Discovery Site (http://download.eclipse.org/releases/europa) should be selected, and after hitting Finish, the Eclipse Communication Framework will be shown in the Communications category. You only need the Core feature, although you can download the examples to play around with as well if you want. I suggest that you restart Eclipse once you've installed it.&lt;br&gt;&lt;br&gt;So, having got an Eclipse Europa install, how do we get it ready to use GoogleTalk? Well, there's a 'Communications' perspective which you can switch to, but very little idea of how you'd create a new account. It turns out that there's a little button in the action bar ( ) which will let you add new accounts. If you click on the arrow to the right of it, a drop-down menu will appear with IRC, MSN, XMPP, XMPPS and BitTorrent.&lt;br&gt;&lt;br&gt;Select the XMPPS one (the encrypted version of XMPP) and you'll get window asking for your username and password. This is the same one that you sign in to Google Talk; it's usually something like Joe dot Bloggs at gmail dot com. If you find you have problems, sometimes you can also sign in with Joe dot Bloggs at talk dot google dot com, but you generally won't need to do this.&lt;br&gt;&lt;br&gt;Once you click on 'Finish', you'll get a Contacts view, and from there, all of your Google contacts will be displayed. You can even set your status using the drop-down menu item at the top of the view, for example, to note that you're away or fixing a particularly vexing problem and that you'll be back soon.&lt;br&gt;&lt;br&gt;As I'm sure Scott will point out, ECF doesn't just handle Google Talk. There are a number of other supported protocols, including an IRC chat on irc://irc.freenode.net/#eclipse if your firewalls will allow it. But there's lots more to ECF; that's a subject for another day.&lt;br&gt;&lt;br&gt;Happy talking!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5741401390511285234-8075540239537120970?l=itefforts.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/TIsO/~4/CIXc1e-khWQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/TIsO/~3/CIXc1e-khWQ/talk-with-googletalk-inside-of-eclipse.html</link><author>noreply@blogger.com (IT Efforts)</author><thr:total>0</thr:total><feedburner:origLink>http://itefforts.blogspot.com/2007/07/talk-with-googletalk-inside-of-eclipse.html</feedburner:origLink></item></channel></rss>

