commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bali...@apache.org
Subject cvs commit: jakarta-commons-sandbox/simplestore/docs users-guide.html
Date Sun, 31 Mar 2002 10:46:35 GMT
baliuka     02/03/31 02:46:35

  Added:       simplestore/docs users-guide.html
  Log:
  Added docs
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/simplestore/docs/users-guide.html
  
  Index: users-guide.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  
  <HTML>
    <HEAD>
    <STYLE>
      h3{ color:navy };
      code{ color:navy };
    </STYLE>
      <TITLE>SimpleStore Usere Guide</TITLE>
    </HEAD>
    <BODY alink='navy' vlink='navy' >
       <center> <h3>SimpleStore Users Guide</h3></center>
   <h3>What is SimpleStore ?</h3>
    <p> 
  
      SimpleStore is customizable persistence framework. It defines
      interfaces for Transparent Persistence and provides reference implementation.
      It designed to store objects in Transactionl resource like RDMS, but
      can be used with any kind of storage. It is two storage types
      in reference implementation: RDMS and <a href='http://jdbm.sourceforge.net'>BTree
file from JDBM</a>.
      
  
    </p>
   <h3 > What can SimpleStore do for me? </h3>
   <p>
  
     You can use it to implement persitence aspect in your web application, or
     object model, you can use it as  service for you server like  
       <a href='http://eob.sourceforge.net'>EOB</a> or EJB (CMP,BMP). 
     You can extend it and implement your  persitence framework. 
     
   </p>
  
   <h3> PersitenceManagerFactory </h3>
  
    <p>
      This interface is used to implement well known Factory design pattern it
      used to setup singleton PersitenceManager instanse. PersitenceManager is
      the most specific interface in your code:
     <p>
     <code>
       <pre >
       DBPersistenceManagerFactory factory = new DBPersistenceManagerFactory();
          factory.setDriver(<span style='color:red'>"org.hsqldb.jdbcDriver"</span>);
          factory.setUrl(<span style='color:red'>"jdbc:hsqldb:sample"</span>);
          factory.setUser(<span style='color:red'>"sa"</span>);
          factory.setPassword(<span style='color:red'>""</span>);
          factory.setMaxConnections(<b style='color:blue'>1</b>);
          factory.setMetaResource(<span style='color:red'>"org/apache/commons/simplestore/storage.xml"</span>);
        PersitenceManager  pm = factory.<b>getPersistenceManager</b>();
      </pre>
     </code> 
     this example setups PersitenceManager to use RDMS as storage.
    </content>
     <h3 >PersitenceManager</h3>
     <p>
      PersitenceManager is factory for you beans and transactions, Transaction is
      the last interface you need to know from SimpleStore if you not going to extend
      SimpleStore. You dont need to exdend any specific Class or implement internal
      persitence interfaces, you dont need any code generator. Just design your
      object model, use interfaces and classes, SimpleStore will implement persitence
      aspect for you, but you still need some "Metadata" it very trivial xml file, but 
      it can be writen usin opional tags or generated later. Start to desin beans:
     </p>
       <code>
     <pre >
   <b>public abstract class</b> Message 
     
    {
          public MessageImpl(){}
  
          public void addReply(Message m) {
            m.setSubmitted(new java.util.Date());
            m.setParent(this);
      }
          public int numberOfReplies() {
            return getReplies().size();
      }
       <b>public abstract</b> java.util.Collection <b>getReplies</b>();
  
       <b>public abstract</b> Date <b>getSubmitted</b>(); 
  
       <b>public abstract</b> void <b>setSubmitted</b>(Date v);
  
       <b>public abstract</b> String <b>getContents</b>();
  
       <b>public abstract</b> void <b>setContents</b>(String v); 
  
       <b>public abstract</b> String <b>getEmail</b>(); 
  
       <b>public abstract</b> void <b>setEmail</b>(String v); 
  
       <b>public abstract</b> String <b>getName</b>(); 
  
       <b>public abstract</b> void <b>setName</b>(String v);
  
       <b>public abstract</b> String <b>getSubject</b>(); 
  
       <b>public abstract</b> void <b>setSubject</b>(String v);
      
       <b>public abstract</b> void <b>setParent</b>( Message parent
) ;
  
      
     }
      </pre> 
       </code>
     <p>
      This is persistent bean from Jakarta Velocity demo. All abstract methods are implemented

      by SimpleStore, PersitenceManager returns this implementation :
     </p>
      <code>
       <pre >
         PersitenceManager  pm = factory.<b>getPersistenceManager</b>();
         Transaction transaction = pm.<b>getTransaction</b>(); 
         
         transaction.<b>begin</b>();   
  
            Message parent = pm.<b>findInstance</b>(Message.class,parentOid);
            Message msg    = pm.<b>createInstance</b>(Message.class);        
  
                    msg.setSubject(subject);
                    msg.setEmail(email);
                    msg.setName(name);
                    msg.setContents(contents);
                    parent.addReplay(msg);
  
         transaction.<b>commit</b>();
      </pre> 
      </code>
    Last you will need some metadata it helps simplestore to implement your beans:
   <code>
    <pre>
       
     &lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
      &lt;!DOCTYPE storage&gt; 
        &lt;storage&gt;
          &lt;mclass  id="<b>Message</b>" name="MESSAGE"&gt;
            &lt;field id="<b>parent</b>" name="parent"&gt;
                &lt;reference mclass="<b>Message</b>"/&gt; 
            &lt;/field&gt;
            &lt;field id="<b>replies</b>"&gt;
            &lt;reference mclass="<b>Message</b>" field="parent"/&gt;

            &lt;/field&gt;
          &lt;/mclass&gt;
       &lt;/storage&gt;
    
  </pre>
   </code>
   <h3 >Transaction</h3>
      <p>
      SimpleStore supports only atomic persistence operations,
      All operations must be in transaction context:
     <code>
     <pre> 
      Transaction transaction = pm.<b>getTransaction</b>(); 
          transaction.<b>begin</b>();   
             
          //..........................
          //    <i> operations </i>
          //..........................
      
          transaction.<b>commit</b>();// or transaction.<b>rollback</b>();
      
      
      </pre>
      </code>
      </p>  
        
    
    </BODY>
  </HTML>
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message