com.sleepycat.persist.StoreConfig Maven / Gradle / Ivy
/*-
* Copyright (C) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
*
* This file was distributed by Oracle as part of a version of Oracle Berkeley
* DB Java Edition made available at:
*
* http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html
*
* Please see the LICENSE file included in the top-level directory of the
* appropriate version of Oracle Berkeley DB Java Edition for a copy of the
* license and additional information.
*/
package com.sleepycat.persist;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment; // for javadoc
import com.sleepycat.persist.evolve.IncompatibleClassException;
import com.sleepycat.persist.evolve.Mutations;
import com.sleepycat.persist.model.AnnotationModel;
import com.sleepycat.persist.model.EntityModel;
import com.sleepycat.persist.raw.RawStore; // for javadoc
/**
* Configuration properties used with an {@link EntityStore} or {@link
* RawStore}.
*
* {@code StoreConfig} objects are thread-safe. Multiple threads may safely
* call the methods of a shared {@code StoreConfig} object.
*
* See the package
* summary example for an example of using a {@code StoreConfig}.
*
* @author Mark Hayes
*/
public class StoreConfig implements Cloneable {
/**
* The default store configuration containing properties as if the
* configuration were constructed and not modified.
*/
public static final StoreConfig DEFAULT = new StoreConfig();
private boolean allowCreate;
private boolean exclusiveCreate;
private boolean transactional;
private boolean readOnly;
/* */
private boolean replicated = true;
private boolean deferredWrite;
private boolean temporary;
/* */
private boolean secondaryBulkLoad;
private EntityModel model;
private Mutations mutations;
private DatabaseNamer databaseNamer = DatabaseNamer.DEFAULT;
/**
* Creates an entity store configuration object with default properties.
*/
public StoreConfig() {
}
/**
* Returns a shallow copy of the configuration.
*
* @return the clone.
*
* @deprecated As of JE 4.0.13, replaced by {@link StoreConfig#clone()}.
*/
public StoreConfig cloneConfig() {
try {
return (StoreConfig) super.clone();
} catch (CloneNotSupportedException cannotHappen) {
return null;
}
}
/**
* Returns a shallow copy of the configuration.
*/
@Override
public StoreConfig clone() {
try {
return (StoreConfig) super.clone();
} catch (CloneNotSupportedException cannotHappen) {
return null;
}
}
/**
* Specifies whether creation of a new store is allowed. By default this
* property is false.
*
* If this property is false and the internal store metadata database
* does not exist, {@link DatabaseException} will be thrown when the store
* is opened.
*
* @param allowCreate whether creation of a new store is allowed.
*
* @return 'this'.
*/
public StoreConfig setAllowCreate(boolean allowCreate) {
setAllowCreateVoid(allowCreate);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param allowCreate whether creation of a new store is allowed.
*/
public void setAllowCreateVoid(boolean allowCreate) {
this.allowCreate = allowCreate;
}
/**
* Returns whether creation of a new store is allowed.
*
* @return whether creation of a new store is allowed.
*/
public boolean getAllowCreate() {
return allowCreate;
}
/**
* Specifies whether opening an existing store is prohibited. By default
* this property is false.
*
* If this property is true and the internal store metadata database
* already exists, {@link DatabaseException} will be thrown when the store
* is opened.
*
* @param exclusiveCreate whether opening an existing store is prohibited.
*
* @return 'this'.
*/
public StoreConfig setExclusiveCreate(boolean exclusiveCreate) {
setExclusiveCreateVoid(exclusiveCreate);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param exclusiveCreate whether opening an existing store is prohibited.
*/
public void setExclusiveCreateVoid(boolean exclusiveCreate) {
this.exclusiveCreate = exclusiveCreate;
}
/**
* Returns whether opening an existing store is prohibited.
*
* @return whether opening an existing store is prohibited.
*/
public boolean getExclusiveCreate() {
return exclusiveCreate;
}
/**
* Sets the transactional configuration property. By default this property
* is false.
*
* This property is true to open all store indices for transactional
* access. True may not be specified if the environment is not also
* transactional.
*
* @param transactional whether the store is transactional.
*
* @return 'this'.
*/
public StoreConfig setTransactional(boolean transactional) {
setTransactionalVoid(transactional);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param transactional whether the store is transactional.
*/
public void setTransactionalVoid(boolean transactional) {
this.transactional = transactional;
}
/**
* Returns the transactional configuration property.
*
* @return whether the store is transactional.
*/
public boolean getTransactional() {
return transactional;
}
/**
* Sets the read-only configuration property. By default this property is
* false.
*
* This property is true to open all store indices for read-only access,
* or false to open them for read-write access. False may not be specified
* if the environment is read-only.
*
* @param readOnly whether the store is read-only.
*
* @return 'this'.
*/
public StoreConfig setReadOnly(boolean readOnly) {
setReadOnlyVoid(readOnly);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param readOnly whether the store is read-only.
*/
public void setReadOnlyVoid(boolean readOnly) {
this.readOnly = readOnly;
}
/**
* Returns the read-only configuration property.
*
* @return whether the store is read-only.
*/
public boolean getReadOnly() {
return readOnly;
}
/* */
/**
* Configures a store to be replicated or non-replicated, in a replicated
* Environment. By default this property is true, meaning that by default
* a store is replicated in a replicated Environment.
*
* In a non-replicated Environment, this property is ignored. All stores
* are non-replicated in a non-replicated Environment.
*
* @param replicated whether the store is replicated.
*
* @return 'this'.
*
* @see
* Non-replicated
* Databases in a Replicated Environment
*/
public StoreConfig setReplicated(boolean replicated) {
setReplicatedVoid(replicated);
return this;
}
/**
* @hidden
* The void return setter for use by Bean editors.
*
* @param replicated whether the store is replicated.
*/
public void setReplicatedVoid(boolean replicated) {
this.replicated = replicated;
}
/**
* Returns the replicated property for the store.
*
* This method returns true by default. However, in a non-replicated
* Environment, this property is ignored. All stores are non-replicated
* in a non-replicated Environment.
*
* @return whether the store is replicated.
*
* @see #setReplicated
*/
public boolean getReplicated() {
return replicated;
}
/**
* Sets the deferred-write configuration property. By default this
* property is false.
*
*
This property is true to open all store index databases for
* deferred-write access. True may not be specified if the store is
* transactional.
*
* Deferred write stores avoid disk I/O and are not guaranteed to be
* persistent until {@link EntityStore#sync} or {@link Environment#sync} is
* called or the store is closed normally. This mode is particularly geared
* toward stores that frequently modify and delete data records. See the
* Getting Started Guide, Database chapter for a full description of the
* mode.
*
* @param deferredWrite whether the store is deferred-write.
*
* @return 'this'.
*
* @see #setTransactional
*/
public StoreConfig setDeferredWrite(boolean deferredWrite) {
setDeferredWriteVoid(deferredWrite);
return this;
}
/**
* @hidden
* The void return setter for use by Bean editors.
*
* @param deferredWrite whether the store is deferred-write.
*/
public void setDeferredWriteVoid(boolean deferredWrite) {
this.deferredWrite = deferredWrite;
}
/**
* Returns the deferred-write configuration property.
*
* @return whether the store is deferred-write.
*/
public boolean getDeferredWrite() {
return deferredWrite;
}
/**
* Sets the temporary configuration property. By default this property is
* false.
*
* This property is true to open all store databases as temporary
* databases. True may not be specified if the store is transactional.
*
* Temporary stores avoid disk I/O and are not persistent -- they are
* deleted when the store is closed or after a crash. This mode is
* particularly geared toward in-memory stores. See the Getting Started
* Guide, Database chapter for a full description of the mode.
*
* @param temporary whether the store is temporary.
*
* @return 'this'.
*
* @see #setTransactional
*/
public StoreConfig setTemporary(boolean temporary) {
setTemporaryVoid(temporary);
return this;
}
/**
* @hidden
* The void return setter for use by Bean editors.
*
* @param temporary whether the store is temporary.
*/
public void setTemporaryVoid(boolean temporary) {
this.temporary = temporary;
}
/**
* Returns the temporary configuration property.
*
* @return whether the store is temporary.
*/
public boolean getTemporary() {
return temporary;
}
/* */
/**
* Sets the bulk-load-secondaries configuration property. By default this
* property is false.
*
* This property is true to cause the initial creation of secondary
* indices to be performed as a bulk load. If this property is true and
* {@link EntityStore#getSecondaryIndex EntityStore.getSecondaryIndex} has
* never been called for a secondary index, that secondary index will not
* be created or written as records are written to the primary index. In
* addition, if that secondary index defines a foreign key constraint, the
* constraint will not be enforced.
*
* The secondary index will be populated later when the {@code
* getSecondaryIndex} method is called for the first time for that index,
* or when the store is closed and re-opened with this property set to
* false and the primary index is obtained. In either case, the secondary
* index is populated by reading through the entire primary index and
* adding records to the secondary index as needed. While populating the
* secondary, foreign key constraints will be enforced and an exception is
* thrown if a constraint is violated.
*
* When loading a primary index along with secondary indexes from a
* large input data set, configuring a bulk load of the secondary indexes
* is sometimes more performant than updating the secondary indexes each
* time the primary index is updated. The absence of foreign key
* constraints during the load also provides more flexibility.
*
* @param secondaryBulkLoad whether bulk-load-secondaries is used.
*
* @return 'this'.
*/
public StoreConfig setSecondaryBulkLoad(boolean secondaryBulkLoad) {
setSecondaryBulkLoadVoid(secondaryBulkLoad);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param secondaryBulkLoad whether bulk-load-secondaries is used.
*/
public void setSecondaryBulkLoadVoid(boolean secondaryBulkLoad) {
this.secondaryBulkLoad = secondaryBulkLoad;
}
/**
* Returns the bulk-load-secondaries configuration property.
*
* @return whether bulk-load-secondaries is used.
*/
public boolean getSecondaryBulkLoad() {
return secondaryBulkLoad;
}
/**
* Sets the entity model that defines entity classes and index keys.
*
* If null is specified or this method is not called, an {@link
* AnnotationModel} instance is used by default.
*
* @param model the EntityModel.
*
* @return 'this'.
*/
public StoreConfig setModel(EntityModel model) {
setModelVoid(model);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param model the EntityModel.
*/
public void setModelVoid(EntityModel model) {
this.model = model;
}
/**
* Returns the entity model that defines entity classes and index keys.
*
* @return the EntityModel.
*/
public EntityModel getModel() {
return model;
}
/**
* Configures mutations for performing lazy evolution of stored instances.
* Existing mutations for this store are not cleared, so the mutations
* required are only those changes that have been made since the store was
* last opened. Some new mutations may override existing specifications,
* and some may be supplemental.
*
* If null is specified and the store already exists, the previously
* specified mutations are used. The mutations are stored persistently in
* serialized form.
*
* Mutations must be available to handle all changes to classes that are
* incompatible with the class definitions known to this store. See {@link
* Mutations} and {@link com.sleepycat.persist.evolve Class Evolution} for
* more information.
*
* If an incompatible class change has been made and mutations are not
* available for handling the change, {@link IncompatibleClassException}
* will be thrown when creating an {@link EntityStore}.
*
* @param mutations the Mutations.
*
* @return 'this'.
*/
public StoreConfig setMutations(Mutations mutations) {
setMutationsVoid(mutations);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param mutations the Mutations.
*/
public void setMutationsVoid(Mutations mutations) {
this.mutations = mutations;
}
/**
* Returns the configured mutations for performing lazy evolution of stored
* instances.
*
* @return the Mutations.
*/
public Mutations getMutations() {
return mutations;
}
/**
*
* @hidden
*
* Specifies the object reponsible for naming of files and databases.
*
* By default this property is {@link DatabaseNamer#DEFAULT}.
*
* @param databaseNamer the DatabaseNamer.
*
* @return 'this'.
*
* @throws NullPointerException if a null parameter value is passed.
*/
public StoreConfig setDatabaseNamer(DatabaseNamer databaseNamer) {
setDatabaseNamerVoid(databaseNamer);
return this;
}
/**
*
* @hidden
*
* The void return setter for use by Bean editors.
*
* @param databaseNamer the DatabaseNamer.
*/
public void setDatabaseNamerVoid(DatabaseNamer databaseNamer) {
if (databaseNamer == null) {
throw new NullPointerException();
}
this.databaseNamer = databaseNamer;
}
/**
*
* @hidden
*
* Returns the object reponsible for naming of files and databases.
*
* @return the DatabaseNamer.
*/
public DatabaseNamer getDatabaseNamer() {
return databaseNamer;
}
}