• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/db-4.8.30/java/src/com/sleepycat/persist/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
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     * @deprecated As of JE 4.0.13, replaced by {@link
58     * StoreConfig#clone()}.</p>
59     */
60    public StoreConfig cloneConfig() {
61        try {
62            return (StoreConfig) super.clone();
63        } catch (CloneNotSupportedException cannotHappen) {
64            return null;
65        }
66    }
67
68    /**
69     * Returns a shallow copy of the configuration.
70     */
71    @Override
72    public StoreConfig clone() {
73        try {
74            return (StoreConfig) super.clone();
75        } catch (CloneNotSupportedException cannotHappen) {
76            return null;
77        }
78    }
79
80    /**
81     * Specifies whether creation of a new store is allowed.  By default this
82     * property is false.
83     *
84     * <p>If this property is false and the internal store metadata database
85     * does not exist, {@link DatabaseException} will be thrown when the store
86     * is opened.</p>
87     */
88    public void setAllowCreate(boolean allowCreate) {
89        this.allowCreate = allowCreate;
90    }
91
92    /**
93     * Returns whether creation of a new store is allowed.
94     */
95    public boolean getAllowCreate() {
96        return allowCreate;
97    }
98
99    /**
100     * Specifies whether opening an existing store is prohibited.  By default
101     * this property is false.
102     *
103     * <p>If this property is true and the internal store metadata database
104     * already exists, {@link DatabaseException} will be thrown when the store
105     * is opened.</p>
106     */
107    public void setExclusiveCreate(boolean exclusiveCreate) {
108        this.exclusiveCreate = exclusiveCreate;
109    }
110
111    /**
112     * Returns whether opening an existing store is prohibited.
113     */
114    public boolean getExclusiveCreate() {
115        return exclusiveCreate;
116    }
117
118    /**
119     * Sets the transactional configuration property.  By default this property
120     * is false.
121     *
122     * <p>This property is true to open all store indices for transactional
123     * access.  True may not be specified if the environment is not also
124     * transactional.</p>
125     */
126    public void setTransactional(boolean transactional) {
127        this.transactional = transactional;
128    }
129
130    /**
131     * Returns the transactional configuration property.
132     */
133    public boolean getTransactional() {
134        return transactional;
135    }
136
137    /**
138     * Sets the read-only configuration property.  By default this property is
139     * false.
140     *
141     * <p>This property is true to open all store indices for read-only access,
142     * or false to open them for read-write access.  False may not be specified
143     * if the environment is read-only.</p>
144     */
145    public void setReadOnly(boolean readOnly) {
146        this.readOnly = readOnly;
147    }
148
149    /**
150     * Returns the read-only configuration property.
151     */
152    public boolean getReadOnly() {
153        return readOnly;
154    }
155
156
157    /**
158     * Sets the bulk-load-secondaries configuration property.  By default this
159     * property is false.
160     *
161     * <p>This property is true to cause the initial creation of secondary
162     * indices to be performed as a bulk load.  If this property is true and
163     * {@link EntityStore#getSecondaryIndex EntityStore.getSecondaryIndex} has
164     * never been called for a secondary index, that secondary index will not
165     * be created or written as records are written to the primary index.  In
166     * addition, if that secondary index defines a foreign key constraint, the
167     * constraint will not be enforced.</p>
168     *
169     * <p>The secondary index will be populated later when the {code
170     * getSecondaryIndex} method is called for the first time for that index,
171     * or when the store is closed and re-opened with this property set to
172     * false and the primary index is obtained.  In either case, the secondary
173     * index is populated by reading through the entire primary index and
174     * adding records to the secondary index as needed.  While populating the
175     * secondary, foreign key constraints will be enforced and an exception is
176     * thrown if a constraint is violated.</p>
177     *
178     * <p>When loading a primary index along with secondary indexes from a
179     * large input data set, configuring a bulk load of the secondary indexes
180     * is sometimes more performant than updating the secondary indexes each
181     * time the primary index is updated.  The absence of foreign key
182     * constraints during the load also provides more flexibility.</p>
183     */
184    public void setSecondaryBulkLoad(boolean secondaryBulkLoad) {
185        this.secondaryBulkLoad = secondaryBulkLoad;
186    }
187
188    /**
189     * Returns the bulk-load-secondaries configuration property.
190     */
191    public boolean getSecondaryBulkLoad() {
192        return secondaryBulkLoad;
193    }
194
195    /**
196     * Sets the entity model that defines entity classes and index keys.
197     *
198     * <p>If null is specified or this method is not called, an {@link
199     * AnnotationModel} instance is used by default.</p>
200     */
201    public void setModel(EntityModel model) {
202        this.model = model;
203    }
204
205    /**
206     * Returns the entity model that defines entity classes and index keys.
207     */
208    public EntityModel getModel() {
209        return model;
210    }
211
212    /**
213     * Configures mutations for performing lazy evolution of stored instances.
214     * Existing mutations for this store are not cleared, so the mutations
215     * required are only those changes that have been made since the store was
216     * last opened.  Some new mutations may override existing specifications,
217     * and some may be supplemental.
218     *
219     * <p>If null is specified and the store already exists, the previously
220     * specified mutations are used.  The mutations are stored persistently in
221     * serialized form.</p>
222     *
223     * <p>Mutations must be available to handle all changes to classes that are
224     * incompatible with the class definitions known to this store.  See {@link
225     * Mutations} and {@link com.sleepycat.persist.evolve Class Evolution} for
226     * more information.</p>
227     *
228     * <p>If an incompatible class change has been made and mutations are not
229     * available for handling the change, {@link IncompatibleClassException}
230     * will be thrown when creating an {@link EntityStore}.</p>
231     */
232    public void setMutations(Mutations mutations) {
233        this.mutations = mutations;
234    }
235
236    /**
237     * Returns the configured mutations for performing lazy evolution of stored
238     * instances.
239     */
240    public Mutations getMutations() {
241        return mutations;
242    }
243
244    /**
245     * Specifies the object reponsible for naming of files and databases.
246     *
247     * By default this property is {@link DatabaseNamer#DEFAULT}.
248     *
249     * @throws NullPointerException if a null parameter value is passed.
250     */
251    public void setDatabaseNamer(DatabaseNamer databaseNamer) {
252        if (databaseNamer == null) {
253            throw new NullPointerException();
254        }
255        this.databaseNamer = databaseNamer;
256    }
257
258    /**
259     * Returns the object reponsible for naming of files and databases.
260     */
261    public DatabaseNamer getDatabaseNamer() {
262        return databaseNamer;
263    }
264}
265