Configuration Management in Java EE Applications Using Subversion

Configuration Management in Java EE Applications Using Subversion

Initializing JavaSVN

The class SVNManager is our gateway to Subversion. It uses the low-level JavaSVN APIs to directly interact with the repository since we do not deal with working copies. We initialize the JavaSVN library to either interact with the repository over HTTP(S) or SVN(S). We have chosen to interact with the repository using HTTP (WebDAV), since this will lead to fewer deployment/firewall issues.



The library is initialized using the call DAVRepositoryFactory.setup(). The class SVNRepository has all the required methods to directly interact with the Subversion repository. This class is initialized using the SVNRepositoryFactory class by providing the root of the tree hierarchy in the repository. The class ISVNAuthenticationManager is used to provide the authentication information required for SVNRepository to interact with the repository.

public void initRepository() {

        //initialize the system to work over http

        DAVRepositoryFactory.setup();

        ............

        //point to the root folder of repository

        SVNURL svnUrl = SVNURL.parseURIEncoded

                        ("http://localhost/repos/");

        //initialize the SVNRepository

        theRepository = SVNRepositoryFactory.

                        create(svnUrl);

        //Creates the Auth manager with our user

        //and password credentials

        ISVNAuthenticationManager authManager =

                new BasicAuthenticationManager

                (name, password);

        //provides the credentials to the

        //SVNRepository

        theManager.setAuthenticationManager

                (authManager);

        ........

}

Storing Data in Subversion

Subversion stores data in a hierarchical format, meaning we have to come up with a standard for storing our domain entities. For the sake of this example, we will store all the domain objects under the folder DomainObjects. The class of the domain object will determine the sub-directory under which all the domain objects of that type will be stored. The individual domain objects are stored as XML files with the name of their primary keys.

To store the LoanData domain object, we will invoke the checkInObject method of our SVNManager object. An implementation of the ISVNEditor obtained through the SVNRepository object is used to create or update revisions of our domain object in the repository. All the operations performed on the editor will be committed only when the closeEdit method is called. The SVNDeltaGenerator class is used to obtain differences between the version currently in the repository with one that is being updated. Subversion receives updates for new versions in the form of such deltas rather than the entire object to improve network performance.

public SVNResult checkInObject(

                BaseTrackingObject obj){

        .....

        //Obtain the editor handle from the

        //repository

        ISVNEditor editor = theRepository.

                getCommitEditor(obj.

                getModificationReason(), null);

        ....

        //create the file at the specified path

                editor.addFile(path, null, -1);

        }

        else {

                //file is already present, so open

                //the file in the repository

                editor.openFile(path, -1);

        }

        ....

        String checksum = deltaGenerator.

                        sendDelta(path,

                        new ByteArrayInputStream(

                        obj.getXmlRepresentation().

                        getBytes()),

                        editor, true);

        .....

        editor.closeEdit();

        ...

}

Retrieving Change History

To retrieve the history of versions for a particular domain object, we will call SVNManager's getRevisionLog method. The latest revision number of the repository can be obtained using SVNRepository's getLatestRevision() method. The SVNManager.log method helps obtain the log entries associated with each revision. The log entries contain information such as when was the revision created, who created the revision, what was the revision number, etc. A call to the SVNManager.getFile method helps retrieve a particular revision from the repository.

public List getRevisionLog(BaseTrackingObject

        obj, long startRevision,

        long endRevision) {

        .....

        if(endRevision==-1) {

                //obtain the latest revision from

                //the repository

                endRevision =

                        theRepository.getLatestRevision();

        }

        //retrieve the various log entries for

        //the particular object path

        Collection revisionLogs = theRepository.

                log(new String[] {path}, null,

                        startRevision, endRevision,

                        false, true);

        ....

        //Obtain the contents of the object at

        //the specified revision

        theRepository.getFile(path, revisionInfo.

                getRevisionNumber(),

                new Properties(),

                xmlFileContentsStream);

        ....

}

Prev  [1] [2] [3] Next

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > Java EE > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction