1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: RawStore.java,v 1.1 2008/02/07 17:12:28 mark Exp $ 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.evolve.Mutations; 17import com.sleepycat.persist.impl.Store; 18import com.sleepycat.persist.model.EntityModel; 19 20/** 21 * Provides access to the raw data in a store for use by general purpose tools. 22 * A <code>RawStore</code> provides access to stored entities without using 23 * entity classes or key classes. Keys are represented as simple type objects 24 * or, for composite keys, as {@link RawObject} instances, and entities are 25 * represented as {@link RawObject} instances. 26 * 27 * <p>{@code RawStore} objects are thread-safe. Multiple threads may safely 28 * call the methods of a shared {@code RawStore} object.</p> 29 * 30 * <p>When using a {@code RawStore}, the current persistent class definitions 31 * are not used. Instead, the previously stored metadata and class definitions 32 * are used. This has several implications:</p> 33 * <ol> 34 * <li>An {@code EntityModel} may not be specified using {@link 35 * StoreConfig#setModel}. In other words, the configured model must be 36 * null (the default).</li> 37 * <li>When storing entities, their format will not automatically be evolved 38 * to the current class definition, even if the current class definition has 39 * changed.</li> 40 * </ol> 41 * 42 * @author Mark Hayes 43 */ 44public class RawStore { 45 46 private Store store; 47 48 /** 49 * Opens an entity store for raw data access. 50 * 51 * @param env an open Berkeley DB environment. 52 * 53 * @param storeName the name of the entity store within the given 54 * environment. 55 * 56 * @param config the store configuration, or null to use default 57 * configuration properties. 58 * 59 * @throws IllegalArgumentException if the <code>Environment</code> is 60 * read-only and the <code>config ReadOnly</code> property is false. 61 */ 62 public RawStore(Environment env, String storeName, StoreConfig config) 63 throws DatabaseException { 64 65 store = new Store(env, storeName, config, true /*rawAccess*/); 66 } 67 68 /** 69 * Opens the primary index for a given entity class. 70 */ 71 public PrimaryIndex<Object,RawObject> getPrimaryIndex(String entityClass) 72 throws DatabaseException { 73 74 return store.getPrimaryIndex 75 (Object.class, null, RawObject.class, entityClass); 76 } 77 78 /** 79 * Opens the secondary index for a given entity class and secondary key 80 * name. 81 */ 82 public SecondaryIndex<Object,Object,RawObject> 83 getSecondaryIndex(String entityClass, String keyName) 84 throws DatabaseException { 85 86 return store.getSecondaryIndex 87 (getPrimaryIndex(entityClass), RawObject.class, entityClass, 88 Object.class, null, keyName); 89 } 90 91 /** 92 * Returns the environment associated with this store. 93 */ 94 public Environment getEnvironment() { 95 return store.getEnvironment(); 96 } 97 98 /** 99 * 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() 131 throws DatabaseException { 132 133 store.close(); 134 } 135} 136