• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/db-4.7.25.NC/java/src/com/sleepycat/persist/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: StoreConfig.java,v 1.1 2008/02/07 17:12:26 mark Exp $
7 */
8
9package com.sleepycat.persist;
10
11import com.sleepycat.db.DatabaseException;
12import com.sleepycat.db.Environment; // for javadoc
13import com.sleepycat.persist.evolve.IncompatibleClassException;
14import com.sleepycat.persist.evolve.Mutations;
15import com.sleepycat.persist.model.AnnotationModel;
16import com.sleepycat.persist.model.EntityModel;
17import com.sleepycat.persist.raw.RawStore; // for javadoc
18
19/**
20 * Configuration properties used with an {@link EntityStore} or {@link
21 * RawStore}.
22 *
23 * <p>{@code StoreConfig} objects are thread-safe.  Multiple threads may safely
24 * call the methods of a shared {@code StoreConfig} object.</p>
25 *
26 * <p>See the {@link <a href="package-summary.html#example">package
27 * summary example</a>} for an example of using a {@code StoreConfig}.</p>
28 *
29 * @author Mark Hayes
30 */
31public class StoreConfig implements Cloneable {
32
33    /**
34     * The default store configuration containing properties as if the
35     * configuration were constructed and not modified.
36     */
37    public static final StoreConfig DEFAULT = new StoreConfig();
38
39    private boolean allowCreate;
40    private boolean exclusiveCreate;
41    private boolean transactional;
42    private boolean readOnly;
43    private boolean secondaryBulkLoad;
44    private EntityModel model;
45    private Mutations mutations;
46    private DatabaseNamer databaseNamer = DatabaseNamer.DEFAULT;
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 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 DatabaseException} will be thrown when the store
71     * 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
143    /**
144     * Sets the bulk-load-secondaries configuration property.  By default this
145     * property is false.
146     *
147     * <p>This property is true to cause the initial creation of secondary
148     * indices to be performed as a bulk load.  If this property is true and
149     * {@link EntityStore#getSecondaryIndex EntityStore.getSecondaryIndex} has
150     * never been called for a secondary index, that secondary index will not
151     * be created or written as records are written to the primary index.  In
152     * addition, if that secondary index defines a foreign key constraint, the
153     * constraint will not be enforced.</p>
154     *
155     * <p>The secondary index will be populated later when the {code
156     * getSecondaryIndex} method is called for the first time for that index,
157     * or when the store is closed and re-opened with this property set to
158     * false and the primary index is obtained.  In either case, the secondary
159     * index is populated by reading through the entire primary index and
160     * adding records to the secondary index as needed.  While populating the
161     * secondary, foreign key constraints will be enforced and an exception is
162     * thrown if a constraint is violated.</p>
163     *
164     * <p>When loading a primary index along with secondary indexes from a
165     * large input data set, configuring a bulk load of the secondary indexes
166     * is sometimes more performant than updating the secondary indexes each
167     * time the primary index is updated.  The absence of foreign key
168     * constraints during the load also provides more flexibility.</p>
169     */
170    public void setSecondaryBulkLoad(boolean secondaryBulkLoad) {
171        this.secondaryBulkLoad = secondaryBulkLoad;
172    }
173
174    /**
175     * Returns the bulk-load-secondaries configuration property.
176     */
177    public boolean getSecondaryBulkLoad() {
178        return secondaryBulkLoad;
179    }
180
181    /**
182     * Sets the entity model that defines entity classes and index keys.
183     *
184     * <p>If null is specified or this method is not called, an {@link
185     * AnnotationModel} instance is used by default.</p>
186     */
187    public void setModel(EntityModel model) {
188        this.model = model;
189    }
190
191    /**
192     * Returns the entity model that defines entity classes and index keys.
193     */
194    public EntityModel getModel() {
195        return model;
196    }
197
198    /**
199     * Configures mutations for performing lazy evolution of stored instances.
200     * Existing mutations for this store are not cleared, so the mutations
201     * required are only those changes that have been made since the store was
202     * last opened.  Some new mutations may override existing specifications,
203     * and some may be supplemental.
204     *
205     * <p>If null is specified and the store already exists, the previously
206     * specified mutations are used.  The mutations are stored persistently in
207     * serialized form.</p>
208     *
209     * <p>Mutations must be available to handle all changes to classes that are
210     * incompatible with the class definitions known to this store.  See {@link
211     * Mutations} and {@link com.sleepycat.persist.evolve Class Evolution} for
212     * more information.</p>
213     *
214     * <p>If an incompatible class change has been made and mutations are not
215     * available for handling the change, {@link IncompatibleClassException}
216     * will be thrown when creating an {@link EntityStore}.</p>
217     */
218    public void setMutations(Mutations mutations) {
219        this.mutations = mutations;
220    }
221
222    /**
223     * Returns the configured mutations for performing lazy evolution of stored
224     * instances.
225     */
226    public Mutations getMutations() {
227        return mutations;
228    }
229
230    /**
231     * Specifies the object reponsible for naming of files and databases.
232     *
233     * By default this property is {@link DatabaseNamer#DEFAULT}.
234     *
235     * @throws NullPointerException if a null parameter value is passed.
236     */
237    public void setDatabaseNamer(DatabaseNamer databaseNamer) {
238        if (databaseNamer == null) {
239            throw new NullPointerException();
240        }
241        this.databaseNamer = databaseNamer;
242    }
243
244    /**
245     * Returns the object reponsible for naming of files and databases.
246     */
247    public DatabaseNamer getDatabaseNamer() {
248        return databaseNamer;
249    }
250}
251