KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > StoreConfig


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: StoreConfig.java,v 1.13 2006/11/29 21:23:27 mark Exp $
7  */

8
9 package com.sleepycat.persist;
10
11 import com.sleepycat.je.DatabaseException;
12 import com.sleepycat.je.DatabaseNotFoundException;
13 import com.sleepycat.je.Environment; // for javadoc
14
import com.sleepycat.persist.evolve.IncompatibleClassException;
15 import com.sleepycat.persist.evolve.Mutations;
16 import com.sleepycat.persist.model.AnnotationModel;
17 import com.sleepycat.persist.model.EntityModel;
18 import com.sleepycat.persist.raw.RawStore;
19
20 /**
21  * Configuration properties used with an {@link EntityStore} or {@link
22  * RawStore}.
23  *
24  * <p>{@code StoreConfig} objects are thread-safe. Multiple threads may safely
25  * call the methods of a shared {@code StoreConfig} object.</p>
26  *
27  * <p>See the {@link <a HREF="package-summary.html#example">package
28  * summary example</a>} for an example of using a {@code StoreConfig}.</p>
29  *
30  * @author Mark Hayes
31  */

32 public class StoreConfig implements Cloneable JavaDoc {
33
34     /**
35      * The default store configuration containing properties as if the
36      * configuration were constructed and not modified.
37      */

38     public static final StoreConfig DEFAULT = new StoreConfig();
39
40     private boolean allowCreate;
41     private boolean exclusiveCreate;
42     private boolean transactional;
43     private boolean readOnly;
44     private boolean deferredWrite;
45     private EntityModel model;
46     private Mutations mutations;
47
48     /**
49      * Creates an entity store configuration object with default properties.
50      */

51     public StoreConfig() {
52     }
53
54     /**
55      * Returns a shallow copy of the configuration.
56      */

57     public StoreConfig cloneConfig() {
58         try {
59             return (StoreConfig) clone();
60         } catch (CloneNotSupportedException JavaDoc cannotHappen) {
61             return null;
62         }
63     }
64
65     /**
66      * Specifies whether creation of a new store is allowed. By default this
67      * property is false.
68      *
69      * <p>If this property is false and the internal store metadata database
70      * does not exist, {@link DatabaseNotFoundException} will be thrown when
71      * the store is opened.</p>
72      */

73     public void setAllowCreate(boolean allowCreate) {
74         this.allowCreate = allowCreate;
75     }
76
77     /**
78      * Returns whether creation of a new store is allowed.
79      */

80     public boolean getAllowCreate() {
81         return allowCreate;
82     }
83
84     /**
85      * Specifies whether opening an existing store is prohibited. By default
86      * this property is false.
87      *
88      * <p>If this property is true and the internal store metadata database
89      * already exists, {@link DatabaseException} will be thrown when the store
90      * is opened.</p>
91      */

92     public void setExclusiveCreate(boolean exclusiveCreate) {
93         this.exclusiveCreate = exclusiveCreate;
94     }
95
96     /**
97      * Returns whether opening an existing store is prohibited.
98      */

99     public boolean getExclusiveCreate() {
100         return exclusiveCreate;
101     }
102
103     /**
104      * Sets the transactional configuration property. By default this property
105      * is false.
106      *
107      * <p>This property is true to open all store indices for transactional
108      * access. True may not be specified if the environment is not also
109      * transactional.</p>
110      */

111     public void setTransactional(boolean transactional) {
112         this.transactional = transactional;
113     }
114
115     /**
116      * Returns the transactional configuration property.
117      */

118     public boolean getTransactional() {
119         return transactional;
120     }
121
122     /**
123      * Sets the read-only configuration property. By default this property is
124      * false.
125      *
126      * <p>This property is true to open all store indices for read-only access,
127      * or false to open them for read-write access. False may not be specified
128      * if the environment is read-only.</p>
129      */

130     public void setReadOnly(boolean readOnly) {
131         this.readOnly = readOnly;
132     }
133
134     /**
135      * Returns the read-only configuration property.
136      */

137     public boolean getReadOnly() {
138         return readOnly;
139     }
140
141     /**
142      * Sets the deferred-write configuration property. By default this
143      * property is false.
144      *
145      * <p>This property is true to open all store index databases for
146      * deferred-write access. True may not be specified if the store is
147      * transactional.</p>
148      *
149      * <p>Deferred write stores avoid disk I/O and are not guaranteed to be
150      * persistent until {@link EntityStore#sync} or {@link Environment#sync} is
151      * called. This mode is particularly geared toward temporary stores, or
152      * stores that frequently modify and delete data records. See the Getting
153      * Started Guide, Database chapter for a full description of the mode.</p>
154      *
155      * @see #setTransactional
156      */

157     public void setDeferredWrite(boolean deferredWrite) {
158         this.deferredWrite = deferredWrite;
159     }
160
161     /**
162      * Returns the deferred-write configuration property.
163      */

164     public boolean getDeferredWrite() {
165         return deferredWrite;
166     }
167
168     /**
169      * Sets the entity model that defines entity classes and index keys.
170      *
171      * <p>If null is specified or this method is not called, an {@link
172      * AnnotationModel} instance is used by default.</p>
173      */

174     public void setModel(EntityModel model) {
175         this.model = model;
176     }
177
178     /**
179      * Returns the entity model that defines entity classes and index keys.
180      */

181     public EntityModel getModel() {
182         return model;
183     }
184
185     /**
186      * Configures mutations for performing lazy evolution of stored instances.
187      * Existing mutations for this store are not cleared, so the mutations
188      * required are only those changes that have been made since the store was
189      * last opened. Some new mutations may override existing specifications,
190      * and some may be supplemental.
191      *
192      * <p>If null is specified and the store already exists, the previously
193      * specified mutations are used. The mutations are stored persistently in
194      * serialized form.</p>
195      *
196      * <p>Mutations must be available to handle all changes to classes that are
197      * incompatible with the class definitions known to this store. See {@link
198      * Mutations} and {@link com.sleepycat.persist.evolve Class Evolution} for
199      * more information.</p>
200      *
201      * <p>If an incompatible class change has been made and mutations are not
202      * available for handling the change, {@link IncompatibleClassException}
203      * will be thrown when creating an {@link EntityStore}.</p>
204      */

205     public void setMutations(Mutations mutations) {
206         this.mutations = mutations;
207     }
208
209     /**
210      * Returns the configured mutations for performing lazy evolution of stored
211      * instances.
212      */

213     public Mutations getMutations() {
214         return mutations;
215     }
216 }
217
Popular Tags