| 1 |
/*- |
| 2 |
* See the file LICENSE for redistribution information. |
| 3 |
* |
| 4 |
* Copyright (c) 2002, 2013 Oracle and/or its affiliates. All rights reserved. |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
package com.sleepycat.persist.impl; |
| 9 |
|
| 10 |
import java.util.Map; |
| 11 |
|
| 12 |
import com.sleepycat.persist.raw.RawObject; |
| 13 |
import java.util.IdentityHashMap; |
| 14 |
|
| 15 |
/** |
| 16 |
* Catalog operation interface used by format classes. |
| 17 |
* |
| 18 |
* @see PersistCatalog |
| 19 |
* @see SimpleCatalog |
| 20 |
* @see ReadOnlyCatalog |
| 21 |
* |
| 22 |
* @author Mark Hayes |
| 23 |
*/ |
| 24 |
interface Catalog { |
| 25 |
|
| 26 |
/* |
| 27 |
* The catalog version is returned by getInitVersion and is the version of |
| 28 |
* the serialized format classes loaded from the stored catalog. When a |
| 29 |
* field is added, for example, the version can be checked to determine how |
| 30 |
* to initialize the field in Format.initialize. |
| 31 |
* |
| 32 |
* -1: The version is considered to be -1 when reading the beta version of |
| 33 |
* the catalog data. At this point no version field was stored, but we can |
| 34 |
* distinguish the beta stored format. See PersistCatalog. |
| 35 |
* |
| 36 |
* 0: The first released version of the catalog data, after beta. At this |
| 37 |
* point no version field was stored, but it is initialized to zero when |
| 38 |
* the PersistCatalog.Data object is de-serialized. |
| 39 |
* |
| 40 |
* 1: Add the ComplexFormat.ConvertFieldReader.oldFieldNum field. [#15797] |
| 41 |
*/ |
| 42 |
static final int BETA_VERSION = -1; |
| 43 |
static final int CURRENT_VERSION = 1; |
| 44 |
|
| 45 |
/** |
| 46 |
* See above. |
| 47 |
*/ |
| 48 |
int getInitVersion(Format format, boolean forReader); |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns a format for a given ID, or throws an exception. This method is |
| 52 |
* used when reading an object from the byte array format. |
| 53 |
* |
| 54 |
* @param expectStored is true if reading a record from a database, and |
| 55 |
* therefore the format ID is expected to be stored also. If the format ID |
| 56 |
* is not stored, a RefreshException is thrown. |
| 57 |
* |
| 58 |
* @throws IllegalStateException if the formatId does not correspond to a |
| 59 |
* persistent class. This is an internal consistency error. |
| 60 |
*/ |
| 61 |
Format getFormat(int formatId, boolean expectStored) |
| 62 |
throws RefreshException; |
| 63 |
|
| 64 |
/** |
| 65 |
* Returns a format for a given class, or throws an exception. This method |
| 66 |
* is used when writing an object that was passed in by the user. |
| 67 |
* |
| 68 |
* @param checkEntitySubclassIndexes is true if we're expecting this format |
| 69 |
* to be an entity subclass and therefore subclass secondary indexes should |
| 70 |
* be opened. |
| 71 |
* |
| 72 |
* @throws IllegalArgumentException if the class is not persistent. This |
| 73 |
* is a user error. |
| 74 |
*/ |
| 75 |
Format getFormat(Class cls, boolean checkEntitySubclassIndexes) |
| 76 |
throws RefreshException; |
| 77 |
|
| 78 |
/** |
| 79 |
* Returns a format by class name. Unlike {@link #getFormat(Class)}, the |
| 80 |
* format will not be created if it is not already known. |
| 81 |
*/ |
| 82 |
Format getFormat(String className); |
| 83 |
|
| 84 |
/** |
| 85 |
* @see PersistCatalog#createFormat |
| 86 |
*/ |
| 87 |
Format createFormat(String clsName, Map<String, Format> newFormats); |
| 88 |
|
| 89 |
/** |
| 90 |
* @see PersistCatalog#createFormat |
| 91 |
*/ |
| 92 |
Format createFormat(Class type, Map<String, Format> newFormats); |
| 93 |
|
| 94 |
/** |
| 95 |
* @see PersistCatalog#isRawAccess |
| 96 |
*/ |
| 97 |
boolean isRawAccess(); |
| 98 |
|
| 99 |
/** |
| 100 |
* @see PersistCatalog#convertRawObject |
| 101 |
*/ |
| 102 |
Object convertRawObject(RawObject o, IdentityHashMap converted) |
| 103 |
throws RefreshException; |
| 104 |
|
| 105 |
/** |
| 106 |
* @see PersistCatalog#resolveClass |
| 107 |
*/ |
| 108 |
Class resolveClass(String clsName) |
| 109 |
throws ClassNotFoundException; |
| 110 |
|
| 111 |
/** |
| 112 |
* @see PersistCatalog#resolveKeyClass |
| 113 |
*/ |
| 114 |
Class resolveKeyClass(String clsName); |
| 115 |
} |