• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/java/src/com/sleepycat/persist/raw/
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.raw;
10
11import com.sleepycat.db.DatabaseException;
12import com.sleepycat.db.Environment;
13import com.sleepycat.persist.PrimaryIndex;
14import com.sleepycat.persist.SecondaryIndex;
15import com.sleepycat.persist.StoreConfig;
16import com.sleepycat.persist.StoreExistsException;
17import com.sleepycat.persist.StoreNotFoundException;
18import com.sleepycat.persist.evolve.IncompatibleClassException;
19import com.sleepycat.persist.evolve.Mutations;
20import com.sleepycat.persist.impl.Store;
21import com.sleepycat.persist.model.EntityModel;
22
23/**
24 * Provides access to the raw data in a store for use by general purpose tools.
25 * A <code>RawStore</code> provides access to stored entities without using
26 * entity classes or key classes.  Keys are represented as simple type objects
27 * or, for composite keys, as {@link RawObject} instances, and entities are
28 * represented as {@link RawObject} instances.
29 *
30 * <p>{@code RawStore} objects are thread-safe.  Multiple threads may safely
31 * call the methods of a shared {@code RawStore} object.</p>
32 *
33 * <p>When using a {@code RawStore}, the current persistent class definitions
34 * are not used.  Instead, the previously stored metadata and class definitions
35 * are used.  This has several implications:</p>
36 * <ol>
37 * <li>An {@code EntityModel} may not be specified using {@link
38 * StoreConfig#setModel}.  In other words, the configured model must be
39 * null (the default).</li>
40 * <li>When storing entities, their format will not automatically be evolved
41 * to the current class definition, even if the current class definition has
42 * changed.</li>
43 * </ol>
44 *
45 * @author Mark Hayes
46 */
47public class RawStore {
48
49    private Store store;
50
51    /**
52     * Opens an entity store for raw data access.
53     *
54     * @param env an open Berkeley DB environment.
55     *
56     * @param storeName the name of the entity store within the given
57     * environment.
58     *
59     * @param config the store configuration, or null to use default
60     * configuration properties.
61     *
62     * @throws IllegalArgumentException if the <code>Environment</code> is
63     * read-only and the <code>config ReadOnly</code> property is false.
64     */
65    public RawStore(Environment env, String storeName, StoreConfig config)
66        throws StoreNotFoundException, DatabaseException {
67
68        try {
69            store = new Store(env, storeName, config, true /*rawAccess*/);
70        } catch (StoreExistsException e) {
71            /* Should never happen, ExclusiveCreate not used. */
72            throw new RuntimeException(e);
73        } catch (IncompatibleClassException e) {
74            /* Should never happen, evolution is not performed. */
75            throw new RuntimeException(e);
76        }
77    }
78
79    /**
80     * Opens the primary index for a given entity class.
81     */
82    public PrimaryIndex<Object,RawObject> getPrimaryIndex(String entityClass)
83        throws DatabaseException {
84
85        return store.getPrimaryIndex
86            (Object.class, null, RawObject.class, entityClass);
87    }
88
89    /**
90     * Opens the secondary index for a given entity class and secondary key
91     * name.
92     */
93    public SecondaryIndex<Object,Object,RawObject>
94        getSecondaryIndex(String entityClass, String keyName)
95        throws DatabaseException {
96
97        return store.getSecondaryIndex
98            (getPrimaryIndex(entityClass), RawObject.class, entityClass,
99             Object.class, null, keyName);
100    }
101
102    /**
103     * Returns the environment associated with this store.
104     */
105    public Environment getEnvironment() {
106        return store.getEnvironment();
107    }
108
109    /**
110     * Returns a copy of the entity store configuration.
111     */
112    public StoreConfig getConfig() {
113        return store.getConfig();
114    }
115
116    /**
117     * Returns the name of this store.
118     */
119    public String getStoreName() {
120        return store.getStoreName();
121    }
122
123    /**
124     * Returns the last configured and stored entity model for this store.
125     */
126    public EntityModel getModel() {
127        return store.getModel();
128    }
129
130    /**
131     * Returns the set of mutations that were configured and stored previously.
132     */
133    public Mutations getMutations() {
134        return store.getMutations();
135    }
136
137    /**
138     * Closes all databases and sequences that were opened by this model.  No
139     * databases opened via this store may be in use.
140     */
141    public void close()
142        throws DatabaseException {
143
144        store.close();
145    }
146}
147