TechnoBuzz

A Techno Blog, mainly about Java

Transactions methodoloy

A transaction that is isolated means that the transaction in progress is invisible to other transactions until the transaction has been committed. SQL92 supports four different isolation levels. Hopwever the measning of the different isolation levels differ between databases.

I am working on an web application that uses DB2 and sets a transaction isolation level as follows: transactionIsolationLevel of READ_UNCOMMITTED
– the data is visible as soon as it is written to the table. Basically, data is visible by other transactions even if commit() has not been invoked. This mode provides basic transaction support, but dirty reads , nonrepeatable reads, and phantom reads are all possible. Note that the Oracle database does not support this mode.

  • Dirty reads: A transaction reads a row in a database table containing uncommitted changes from another transaction.
  • Nonrepeatable reads: A transaction reads a row in a database table, a second transaction changes the same row and the first transaction rereads the row and gets a different value.
  • Phantom reads: A transaction re-executes a query, returning a set of rows that satisfies a search condition and finds that another committed transaction has inserted additional rows that satisfy the condition.
  • Locking – we do optimistic.This allows concurrent access to the data, but must implement a stratgey for competing updates (an update must be rejected if the data to be updated has changed since the prospective updater last read it).

    for updates: for the row you plan to update, save the data asoociated with the primary key as ‘the original’  , then when you enter the update method, you check to see if the row has been updated by checking ‘the original’ bean data for the entry, and doing a lookup on the data in the database using the primary key from ‘the original’ data. if its finds data based on the originals primary key, the data is the one you stored away as original, and has not been updated. However, if it does not find the entry based on ‘the original’ primary key, means it no longer exists. Next, we continue on with other update checks by seeing if any of the data for the current entry has been changed by someone else since we saved out ‘the original’. If any of the data has changed, we don’t allow the update. Furthermore, you might check if the changes you are making don’t duplicate an existing entry in the table.

    for inserts: you might check if the entry you are adding don’t duplicate an existing entry in the table.

    for deletes: it pretty much similar to updates except you dont have to check field by field on the entry to see if it has been changed by someone else. All you are checking here is if the entry still exists. You might have a check to disallow certain entries from being deleted.

    Link: programmer to programmer

    Advertisements

    May 31, 2005 Posted by | J2EE | Leave a comment

    Newsletter

    I found this newsletter on Java [RSS feed] : "a newsletter for people who are highly proficient in Java. This newsletter is not for the uninitiated".

    I think I have decided to do the certification thing after about five years in the java world. Not sure where I will start, but some sites I will check out are:

    Or, I could try this free Sun JAVA test

    May 26, 2005 Posted by | J2EE | Leave a comment

    Jakarta Commons

    The current application I am working on makes use of the Jakarta Commons. This includes things like Bean  Utilities , and Digester :

    • org.apache.commons.beanutils.BeanUtils
    • org.apache.commons.digester.Digester

    May 25, 2005 Posted by | Open Source | Leave a comment

    Bad Art

    Create your own drawing here

    May 24, 2005 Posted by | Art | Leave a comment

    Business Delegate

    At the JavaCamp site, they have a Design Patterns section. On the left hand side menu under J2EE Patterns, click on the Business Delegate pattern for an overview:

    An intermediate class decouples between presentation-tier clients and business services.

    On the where to use for the Business Delegate pattern, I think it says it best by indicating :

    Hide the underlying implementation details of business service.

    From Brett McLaughlin’s article on Business Delegate pattern, he says that its builds on the builds on the Business Interface pattern. It mentions to read up on this here as it is part of the EJB best practices series.

    Other related links :

    May 24, 2005 Posted by | Patterns & UML | Leave a comment

    Blogebrity

    I while back Baseball Blogger/Poet Humbug came up with the Periodic List of Bloggers.

    Now comes word of the Blogebrity list. The A list, B list, and C List.

    May 23, 2005 Posted by | Blogging | Leave a comment

    Star Wars

    I saw the ROTS as this web site refers to it. Sitting in the theater I am thinking I have almost 30 years invested in watching this sci fi saga. The fight scenes light saver style were great. Seeing Anakin just turn on the evil switch just did not do it for me. But, overall I liked the film and how it tied up the loose ends.

    I am not sure what to make of this web site http://darthside.blogspot.com/

    May 22, 2005 Posted by | Movies | Leave a comment

    J2SE : Harmony

    The Apache Harmony project sets out to create an open-source version of J2SE under the Apache license. Read all about it here  . Mr Gosling seems against it and open source all together.

    May 19, 2005 Posted by | Open Source | Leave a comment

    View

    View – renders the content of the model – access data from model and decide how to present it – forward user input to controller.

    Tiles provides a framework for defining and dynamically populating page layouts.

    The JSP file will define a template with placeholders where the content should go.

    When the JSP file is invoked, it replaces the place holders with content creating a page
    which is an instance of the layout.

    Enabling the Tiles plugin:
    Administrator\webApplication\WEB-INF\struts-config.xml:
    <plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property value="/WEB-INF/tiles-defs.xml" property="definitions-config" />
         <set-property value="0" property="definitions-debug" />
         <set-property value="0" property="definitions-parser-details" />
         <set-property value="false" property="definitions-parser-validate" />
    </plug-in>

    Administrator\webApplication\WEB-INF\web.xml:
    <taglib>
    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
    </taglib>

    A Tiles definition specifies the layout for a piece of content.

    Tiles can insert into a JSP using the definition name which consists of:

    • name or identifier
    • set of attributes associated with the definition
    • a layout JSP name (instance file name of the given definition and attributes)

    Using the Tiles Tag libray in JSP file:

    <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

    <tiles:insert> –  Inserts a tiles definition or attribute into a JSP page.
       Note: the attribute ‘template’ is deprecated (1.2)
             It is replaced by the attribute ‘page’ .
                     <tiles:insert template="/templates/Header.jsp" >

    <tiles:put>    –  Defines an attribute (or parameter) for a definition.
       Note: the attribute ‘name’ specifies the name of the attribute
              <tiles:put name="page_title" direct="true">
              <bean:message key="head.title.prefix"/>
              <bean:message key="title.profile.create1"/>
                </tiles:put>

    Using the Bean Tag libray in JSP file:

    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

    <bean:define>    –  Defines a variable to be associated with a bean property
     
              <bean:define  id="codeText" name="securityListForm"
                                  type="java.lang.String" property="code"
                                  scope="request"></bean:define>
    <bean:message>    –  Display a text replacement string associated with an identifier (prop file)
     
              <bean:message key="head.title.prefix"/>
                                
    <bean:write>    –  Display a bean properties value (name can be bean name or bean variable defined for jsp)

               <bean:write name="CodeListForm" property="code" />

    Using the logic Tag libray in JSP file:

    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

    <logic:iterate>    –  Iterate over a list

    <logic:iterate id="codes"              indexId="index"
                      name="securityListForm" property="list"
                      scope="request"
                      type="org.CodeBean"
       >

    </logic:iterate:>

     

    <logic:greaterThan>    –  execute logic if condition met

                     <bean:size id="listSize" name="listForm" property="list"/>
                     <logic:greaterThan name="listSize" value="0">
                     </logic:greaterThan>

     

    <logic:equal>    –  execute logic if condition met

                  <logic:equal name="securityListForm" property="tabNumber" value="20">
                     </logic:equal>

    Using the HTML Tag libray in JSP file:

    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

    <html:form>    –  form definition

    <html:text >

    <html:submit>

    <html:select>

    <html:option>

    <html:multibox>

    <html:cancel>

    <html:options>

    Not Empty Tag

    May 18, 2005 Posted by | Struts | Leave a comment

    TriJug Meeting with Gavin King

    I attended the TriJug meeting with Gavin King of JBoss.  Gavin is one of the founders of the Hibernate (Object/Relational Technology). He is also co-author of the book Hibernate in Action which covers version 2.0. 

    Just a few notes from the meeting:

    Hibernate 3 is the recent version. Supports annotation to document O/R mapping, allthough you can still use XML to indicate this.

    There was a question from audience asking about a situation where they had their database in production in one schema, and the same database for design in another schema. Gavin was like I don’t see why you would want to do that.

    He indicated that hibernate would still be a good fit for applications that did alot of joins, but as always you are limited by the speed of the database.

    I asked him if Hibernate would be enhanced to support JDO. He indicated NO. He basically said that they are against the JDO spec. That was the main thing I wanted to get answered at this meeting as JDO and Hibernate seem similar. But, Hibernate is strictly a O/R implementation where as the JDO implemntations follow Sun’s specification.

    As far as JBoss, Mark Fleury has had a busy week, and he talks about Gluecode here.  His point in the blog entry about Open Source model being validated now that IBM has bought this technology is true. But, this was already the case as IBM’s Portal product is built ontop of the Jetspeed  open source product. 

    May 17, 2005 Posted by | Hibernate & ORM, Open Source | Leave a comment

    Blogging, Firefox

    Blogging at IBM. There is a policy even. Last week at Big Blue it was Firefox news.

    May 17, 2005 Posted by | Blogging | Leave a comment

    Gluecode

    When I heard about the GlueCode purchase by IBM yesterday I did not think about the ramifications to other Open Source Application Servers. With IBM adding to their portfolio of Enterprise solutions, this does put more pressure on other lower end application servers.

    I wonder what this means to Tomcat in particular. Stay tuned…

    Nice writeup on this by Bobby.

    Reaction from JBOSS

    May 11, 2005 Posted by | Open Source | Leave a comment

    A Hibernate Experience

    Reflections on Hibernate:

    "with hql and its other mechanisms of querying a database (e.g. the criteria api), hibernate has successfully taken root and i believe is on its way to supplanting sql"

    May 6, 2005 Posted by | Hibernate & ORM | Leave a comment

    Validation

    Should we do the validation on client or on the server.

    Anything web or browser specific should be done on the client.

    Otherwise, we should do it on the server side.

    Typically, Business Objects can be called from non-web entities. Therefore, having validation there is a good idea.

    May 3, 2005 Posted by | J2EE | Leave a comment

    Forward versus redirect

    link

    Forward

    • forward is performed internally by the servlet
    • the browser is completely unaware that it has taken place, so its original URL remains intact
    • any browser reload will simple repeat the original request, with the original URL

    Redirect

    • redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
    • a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
    • redirect is always slower than a forward, since it requires a second browser request
    • beans placed in the original request scope are not available to the second request

    May 3, 2005 Posted by | J2EE | Leave a comment