001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: StoreConfig.java,v 1.13.2.3 2008/01/07 15:14:18 cwl Exp $
007: */
008:
009: package com.sleepycat.persist;
010:
011: import com.sleepycat.je.DatabaseException;
012: import com.sleepycat.je.DatabaseNotFoundException;
013: import com.sleepycat.je.Environment; // for javadoc
014: import com.sleepycat.persist.evolve.IncompatibleClassException;
015: import com.sleepycat.persist.evolve.Mutations;
016: import com.sleepycat.persist.model.AnnotationModel;
017: import com.sleepycat.persist.model.EntityModel;
018: import com.sleepycat.persist.raw.RawStore;
019:
020: /**
021: * Configuration properties used with an {@link EntityStore} or {@link
022: * RawStore}.
023: *
024: * <p>{@code StoreConfig} objects are thread-safe. Multiple threads may safely
025: * call the methods of a shared {@code StoreConfig} object.</p>
026: *
027: * <p>See the {@link <a href="package-summary.html#example">package
028: * summary example</a>} for an example of using a {@code StoreConfig}.</p>
029: *
030: * @author Mark Hayes
031: */
032: public class StoreConfig implements Cloneable {
033:
034: /**
035: * The default store configuration containing properties as if the
036: * configuration were constructed and not modified.
037: */
038: public static final StoreConfig DEFAULT = new StoreConfig();
039:
040: private boolean allowCreate;
041: private boolean exclusiveCreate;
042: private boolean transactional;
043: private boolean readOnly;
044: private boolean deferredWrite;
045: private boolean secondaryBulkLoad;
046: private EntityModel model;
047: private Mutations mutations;
048:
049: /**
050: * Creates an entity store configuration object with default properties.
051: */
052: public StoreConfig() {
053: }
054:
055: /**
056: * Returns a shallow copy of the configuration.
057: */
058: public StoreConfig cloneConfig() {
059: try {
060: return (StoreConfig) clone();
061: } catch (CloneNotSupportedException cannotHappen) {
062: return null;
063: }
064: }
065:
066: /**
067: * Specifies whether creation of a new store is allowed. By default this
068: * property is false.
069: *
070: * <p>If this property is false and the internal store metadata database
071: * does not exist, {@link DatabaseNotFoundException} will be thrown when
072: * the store is opened.</p>
073: */
074: public void setAllowCreate(boolean allowCreate) {
075: this .allowCreate = allowCreate;
076: }
077:
078: /**
079: * Returns whether creation of a new store is allowed.
080: */
081: public boolean getAllowCreate() {
082: return allowCreate;
083: }
084:
085: /**
086: * Specifies whether opening an existing store is prohibited. By default
087: * this property is false.
088: *
089: * <p>If this property is true and the internal store metadata database
090: * already exists, {@link DatabaseException} will be thrown when the store
091: * is opened.</p>
092: */
093: public void setExclusiveCreate(boolean exclusiveCreate) {
094: this .exclusiveCreate = exclusiveCreate;
095: }
096:
097: /**
098: * Returns whether opening an existing store is prohibited.
099: */
100: public boolean getExclusiveCreate() {
101: return exclusiveCreate;
102: }
103:
104: /**
105: * Sets the transactional configuration property. By default this property
106: * is false.
107: *
108: * <p>This property is true to open all store indices for transactional
109: * access. True may not be specified if the environment is not also
110: * transactional.</p>
111: */
112: public void setTransactional(boolean transactional) {
113: this .transactional = transactional;
114: }
115:
116: /**
117: * Returns the transactional configuration property.
118: */
119: public boolean getTransactional() {
120: return transactional;
121: }
122:
123: /**
124: * Sets the read-only configuration property. By default this property is
125: * false.
126: *
127: * <p>This property is true to open all store indices for read-only access,
128: * or false to open them for read-write access. False may not be specified
129: * if the environment is read-only.</p>
130: */
131: public void setReadOnly(boolean readOnly) {
132: this .readOnly = readOnly;
133: }
134:
135: /**
136: * Returns the read-only configuration property.
137: */
138: public boolean getReadOnly() {
139: return readOnly;
140: }
141:
142: /**
143: * Sets the deferred-write configuration property. By default this
144: * property is false.
145: *
146: * <p>This property is true to open all store index databases for
147: * deferred-write access. True may not be specified if the store is
148: * transactional.</p>
149: *
150: * <p>Deferred write stores avoid disk I/O and are not guaranteed to be
151: * persistent until {@link EntityStore#sync} or {@link Environment#sync} is
152: * called. This mode is particularly geared toward temporary stores, or
153: * stores that frequently modify and delete data records. See the Getting
154: * Started Guide, Database chapter for a full description of the mode.</p>
155: *
156: * @see #setTransactional
157: */
158: public void setDeferredWrite(boolean deferredWrite) {
159: this .deferredWrite = deferredWrite;
160: }
161:
162: /**
163: * Returns the deferred-write configuration property.
164: */
165: public boolean getDeferredWrite() {
166: return deferredWrite;
167: }
168:
169: /**
170: * Sets the bulk-load-secondaries configuration property. By default this
171: * property is false.
172: *
173: * <p>This property is true to cause the initial creation of secondary
174: * indices to be performed as a bulk load. If this property is true and
175: * {@link EntityStore#getSecondaryIndex EntityStore.getSecondaryIndex} has
176: * never been called for a secondary index, that secondary index will not
177: * be created or written as records are written to the primary index. In
178: * addition, if that secondary index defines a foreign key constraint, the
179: * constraint will not be enforced.</p>
180: *
181: * <p>The secondary index will be populated later when the {code
182: * getSecondaryIndex} method is called for the first time for that index,
183: * or when the store is closed and re-opened with this property set to
184: * false and the primary index is obtained. In either case, the secondary
185: * index is populated by reading through the entire primary index and
186: * adding records to the secondary index as needed. While populating the
187: * secondary, foreign key constraints will be enforced and an exception is
188: * thrown if a constraint is violated.</p>
189: *
190: * <p>When loading a primary index along with secondary indexes from a
191: * large input data set, configuring a bulk load of the secondary indexes
192: * is sometimes more performant than updating the secondary indexes each
193: * time the primary index is updated. The absence of foreign key
194: * constraints during the load also provides more flexibility.</p>
195: */
196: public void setSecondaryBulkLoad(boolean secondaryBulkLoad) {
197: this .secondaryBulkLoad = secondaryBulkLoad;
198: }
199:
200: /**
201: * Returns the bulk-load-secondaries configuration property.
202: */
203: public boolean getSecondaryBulkLoad() {
204: return secondaryBulkLoad;
205: }
206:
207: /**
208: * Sets the entity model that defines entity classes and index keys.
209: *
210: * <p>If null is specified or this method is not called, an {@link
211: * AnnotationModel} instance is used by default.</p>
212: */
213: public void setModel(EntityModel model) {
214: this .model = model;
215: }
216:
217: /**
218: * Returns the entity model that defines entity classes and index keys.
219: */
220: public EntityModel getModel() {
221: return model;
222: }
223:
224: /**
225: * Configures mutations for performing lazy evolution of stored instances.
226: * Existing mutations for this store are not cleared, so the mutations
227: * required are only those changes that have been made since the store was
228: * last opened. Some new mutations may override existing specifications,
229: * and some may be supplemental.
230: *
231: * <p>If null is specified and the store already exists, the previously
232: * specified mutations are used. The mutations are stored persistently in
233: * serialized form.</p>
234: *
235: * <p>Mutations must be available to handle all changes to classes that are
236: * incompatible with the class definitions known to this store. See {@link
237: * Mutations} and {@link com.sleepycat.persist.evolve Class Evolution} for
238: * more information.</p>
239: *
240: * <p>If an incompatible class change has been made and mutations are not
241: * available for handling the change, {@link IncompatibleClassException}
242: * will be thrown when creating an {@link EntityStore}.</p>
243: */
244: public void setMutations(Mutations mutations) {
245: this .mutations = mutations;
246: }
247:
248: /**
249: * Returns the configured mutations for performing lazy evolution of stored
250: * instances.
251: */
252: public Mutations getMutations() {
253: return mutations;
254: }
255: }
|