View Javadoc

1   // 
2   //Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. 
3   //All rights reserved. 
4   //   
5   //Redistribution and use in source and binary forms, with or without modification,  
6   //are permitted provided that the following conditions are met: 
7   //   
8   //* Redistributions of source code must retain the above copyright notice,  
9   //this list of conditions and the following disclaimer. 
10  //* Redistributions in binary form must reproduce the above copyright notice,  
11  //this list of conditions and the following disclaimer in the documentation  
12  //and/or other materials provided with the distribution. 
13  //* Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.  
14  //nor the names of its contributors may be used to endorse or promote products  
15  //derived from this software without specific prior written permission. 
16  // 
17  //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
18  //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  
19  //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
20  //IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  
21  //INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  
22  //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
23  //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
24  //WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  
25  //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  
26  //POSSIBILITY OF SUCH DAMAGE. 
27  //
28  
29  package org.objectledge.naming.db;
30  
31  import org.objectledge.database.persistence.InputRecord;
32  import org.objectledge.database.persistence.OutputRecord;
33  import org.objectledge.database.persistence.PersistenceException;
34  import org.objectledge.database.persistence.Persistent;
35  import org.objectledge.database.persistence.PersistentFactory;
36  
37  /**
38   * Persistent representation of java.naming.Context.
39   * 
40   * @author <a href="mailto:pablo@caltha.pl">Pawel Potempski</a>
41   */
42  public class PersistentContext implements Persistent
43  {
44      // constants /////////////////////////////////////////////////////////////
45  
46      /*** The table name. */
47      public static final String TABLE_NAME = "ledge_naming_context";
48  
49      /*** The key columns. */
50      public static final String[] KEY_COLUMNS = new String[] { "context_id" };
51  
52      /*** the object factory. */
53      public static final PersistentFactory FACTORY = new PersistentFactory()
54      {
55          public Persistent newInstance()
56          {
57              return new PersistentContext(null, -1);
58          }
59      };
60      
61      // instance variables ////////////////////////////////////////////////////
62  
63      /*** The context id. */
64      private long contextId = -1;
65      
66      /*** The dn */
67      private String dn;
68      
69      /*** The parent context id */
70      private long parentId = -1;
71  
72      /***
73       * Persistent context constructor.
74       * 
75       * @param dn the dn of the context.
76       * @param parentId the id of the parent context.
77       */
78      public PersistentContext(String dn, long parentId)
79      {
80          this.dn = dn;
81          this.parentId = parentId;
82      }
83  
84      /***
85       * {@inheritDoc}
86       */
87      public String getTable()
88      {
89          return TABLE_NAME;
90      }
91  
92      /***
93       * {@inheritDoc}
94       */
95      public String[] getKeyColumns()
96      {
97          return KEY_COLUMNS;
98      }
99  
100     /***
101      * {@inheritDoc}
102      */
103     public void getData(OutputRecord record) throws PersistenceException
104     {
105         record.setLong("context_id", contextId);
106         record.setString("dn", getDN());
107         record.setLong("parent", parentId);
108     }
109 
110     /***
111      * {@inheritDoc}
112      */
113     public void setData(InputRecord record) throws PersistenceException
114     {
115         contextId = record.getLong("context_id");
116         dn = record.getString("dn");
117         parentId = record.getLong("parent");
118     }
119 
120     /***
121      * {@inheritDoc}
122      */
123     public boolean getSaved()
124     {
125         return contextId != -1L;
126     }
127 
128     /***
129      * {@inheritDoc}
130      */
131     public void setSaved(long id)
132     {
133         this.contextId = id;
134     }
135     
136     /***
137      * Get the context id.
138      * 
139      * @return the context id.
140      */
141     public long getContextId()
142     {
143         return contextId;
144     }
145         
146     /***
147      * Return the dn.
148      * 
149      * @return the dn.
150      */
151     public String getDN()
152     {
153         return dn;
154     }
155     
156     /***
157      * Set the dn.
158      * 
159      * @param dn the dn.
160      */
161     public void setDN(String dn)
162     {
163         this.dn = dn;
164     }
165     
166     /***
167      * Get the parent id.
168      * 
169      * @return the parent context id.
170      */
171     public long getParent()
172     {
173         return parentId;
174     }
175 }