001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: RawStore.java,v 1.14.2.2 2008/01/07 15:14:21 cwl Exp $
007: */
008:
009: package com.sleepycat.persist.raw;
010:
011: import com.sleepycat.je.DatabaseException;
012: import com.sleepycat.je.Environment;
013: import com.sleepycat.persist.PrimaryIndex;
014: import com.sleepycat.persist.SecondaryIndex;
015: import com.sleepycat.persist.StoreConfig;
016: import com.sleepycat.persist.evolve.Mutations;
017: import com.sleepycat.persist.impl.Store;
018: import com.sleepycat.persist.model.EntityModel;
019:
020: /**
021: * Provides access to the raw data in a store for use by general purpose tools.
022: * A <code>RawStore</code> provides access to stored entities without using
023: * entity classes or key classes. Keys are represented as simple type objects
024: * or, for composite keys, as {@link RawObject} instances, and entities are
025: * represented as {@link RawObject} instances.
026: *
027: * <p>{@code RawStore} objects are thread-safe. Multiple threads may safely
028: * call the methods of a shared {@code RawStore} object.</p>
029: *
030: * <p>When using a {@code RawStore}, the current persistent class definitions
031: * are not used. Instead, the previously stored metadata and class definitions
032: * are used. This has several implications:</p>
033: * <ol>
034: * <li>An {@code EntityModel} may not be specified using {@link
035: * StoreConfig#setModel}. In other words, the configured model must be
036: * null (the default).</li>
037: * <li>When storing entities, their format will not automatically be evolved
038: * to the current class definition, even if the current class definition has
039: * changed.</li>
040: * </ol>
041: *
042: * @author Mark Hayes
043: */
044: public class RawStore {
045:
046: private Store store;
047:
048: /**
049: * Opens an entity store for raw data access.
050: *
051: * @param env an open Berkeley DB environment.
052: *
053: * @param storeName the name of the entity store within the given
054: * environment.
055: *
056: * @param config the store configuration, or null to use default
057: * configuration properties.
058: *
059: * @throws IllegalArgumentException if the <code>Environment</code> is
060: * read-only and the <code>config ReadOnly</code> property is false.
061: */
062: public RawStore(Environment env, String storeName,
063: StoreConfig config) throws DatabaseException {
064:
065: store = new Store(env, storeName, config, true /*rawAccess*/);
066: }
067:
068: /**
069: * Opens the primary index for a given entity class.
070: */
071: public PrimaryIndex<Object, RawObject> getPrimaryIndex(
072: String entityClass) throws DatabaseException {
073:
074: return store.getPrimaryIndex(Object.class, null,
075: RawObject.class, entityClass);
076: }
077:
078: /**
079: * Opens the secondary index for a given entity class and secondary key
080: * name.
081: */
082: public SecondaryIndex<Object, Object, RawObject> getSecondaryIndex(
083: String entityClass, String keyName)
084: throws DatabaseException {
085:
086: return store.getSecondaryIndex(getPrimaryIndex(entityClass),
087: RawObject.class, entityClass, Object.class, null,
088: keyName);
089: }
090:
091: /**
092: * Returns the environment associated with this store.
093: */
094: public Environment getEnvironment() {
095: return store.getEnvironment();
096: }
097:
098: /**
099: * Returns a copy of the entity store configuration.
100: */
101: public StoreConfig getConfig() {
102: return store.getConfig();
103: }
104:
105: /**
106: * Returns the name of this store.
107: */
108: public String getStoreName() {
109: return store.getStoreName();
110: }
111:
112: /**
113: * Returns the last configured and stored entity model for this store.
114: */
115: public EntityModel getModel() {
116: return store.getModel();
117: }
118:
119: /**
120: * Returns the set of mutations that were configured and stored previously.
121: */
122: public Mutations getMutations() {
123: return store.getMutations();
124: }
125:
126: /**
127: * Closes all databases and sequences that were opened by this model. No
128: * databases opened via this store may be in use.
129: */
130: public void close() throws DatabaseException {
131:
132: store.close();
133: }
134: }
|