Debian Codegraph @

lang/java/src/com/sleepycat/persist/impl/ReadOnlyCatalog.java

raw
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.List;
11 import java.util.Map;
12 import java.util.NoSuchElementException;
13
14 import com.sleepycat.compat.DbCompat;
15 import com.sleepycat.persist.raw.RawObject;
16 import java.util.IdentityHashMap;
17
18 /**
19 * Read-only catalog operations used when initializing new formats. This
20 * catalog is used temprarily when the main catalog has not been updated yet,
21 * but the new formats need to do catalog lookups.
22 *
23 * @see PersistCatalog#addNewFormat
24 *
25 * @author Mark Hayes
26 */
27 class ReadOnlyCatalog implements Catalog {
28
29 private final ClassLoader classLoader;
30 private List<Format> formatList;
31 private Map<String, Format> formatMap;
32
33 ReadOnlyCatalog(ClassLoader classLoader,
34 List<Format> formatList,
35 Map<String, Format> formatMap) {
36 this.classLoader = classLoader;
37 this.formatList = formatList;
38 this.formatMap = formatMap;
39 }
40
41 public int getInitVersion(Format format, boolean forReader) {
42 return Catalog.CURRENT_VERSION;
43 }
44
45 public Format getFormat(int formatId, boolean expectStored) {
46 try {
47 Format format = formatList.get(formatId);
48 if (format == null) {
49 throw DbCompat.unexpectedState
50 ("Format does not exist: " + formatId);
51 }
52 return format;
53 } catch (NoSuchElementException e) {
54 throw DbCompat.unexpectedState
55 ("Format does not exist: " + formatId);
56 }
57 }
58
59 public Format getFormat(Class cls, boolean checkEntitySubclassIndexes) {
60 Format format = formatMap.get(cls.getName());
61 if (format == null) {
62 throw new IllegalArgumentException
63 ("Class is not persistent: " + cls.getName());
64 }
65 return format;
66 }
67
68 public Format getFormat(String className) {
69 return formatMap.get(className);
70 }
71
72 public Format createFormat(String clsName,
73 Map<String, Format> newFormats) {
74 throw DbCompat.unexpectedState();
75 }
76
77 public Format createFormat(Class type, Map<String, Format> newFormats) {
78 throw DbCompat.unexpectedState();
79 }
80
81 public boolean isRawAccess() {
82 return false;
83 }
84
85 public Object convertRawObject(RawObject o, IdentityHashMap converted) {
86 throw DbCompat.unexpectedState();
87 }
88
89 public Class resolveClass(String clsName)
90 throws ClassNotFoundException {
91
92 return SimpleCatalog.resolveClass(clsName, classLoader);
93 }
94
95 public Class resolveKeyClass(String clsName) {
96 return SimpleCatalog.resolveKeyClass(clsName, classLoader);
97 }
98 }