1 8 9 package com.sleepycat.persist.model; 10 11 import java.util.ArrayList ; 12 import java.util.Collections ; 13 import java.util.List ; 14 import java.util.Set ; 15 16 import com.sleepycat.persist.EntityStore; 17 import com.sleepycat.persist.PrimaryIndex; 18 import com.sleepycat.persist.SecondaryIndex; 19 import com.sleepycat.persist.impl.Format; 20 import com.sleepycat.persist.impl.PersistCatalog; 21 import com.sleepycat.persist.raw.RawObject; 22 import com.sleepycat.persist.raw.RawType; 23 24 53 public abstract class EntityModel { 54 55 private PersistCatalog catalog; 56 57 60 protected EntityModel() { 61 } 62 63 76 public final boolean isOpen() { 77 return catalog != null; 78 } 79 80 93 public final void registerClass(Class persistentClass) { 94 if (catalog != null) { 95 throw new IllegalStateException ("Store is already open"); 96 } else { 97 String className = persistentClass.getName(); 98 ClassMetadata meta = getClassMetadata(className); 99 if (meta == null) { 100 throw new IllegalArgumentException 101 ("Class is not persistent: " + className); 102 } 103 } 104 } 105 106 110 void setCatalog(PersistCatalog catalog) { 111 this.catalog = catalog; 112 } 113 114 121 public abstract ClassMetadata getClassMetadata(String className); 122 123 129 public abstract EntityMetadata getEntityMetadata(String className); 130 131 141 public abstract Set <String > getKnownClasses(); 142 143 152 public final RawType getRawType(String className) { 153 if (catalog != null) { 154 return catalog.getFormat(className); 155 } else { 156 throw new IllegalStateException ("Store is not open"); 157 } 158 } 159 160 174 public final RawType getRawTypeVersion(String className, int version) { 175 if (catalog != null) { 176 Format format = catalog.getLatestVersion(className); 177 while (format != null) { 178 if (version == format.getVersion()) { 179 return format; 180 } 181 } 182 return null; 183 } else { 184 throw new IllegalStateException ("Store is not open"); 185 } 186 } 187 188 200 public final List <RawType> getAllRawTypeVersions(String className) { 201 if (catalog != null) { 202 Format format = catalog.getLatestVersion(className); 203 if (format != null) { 204 List <RawType> list = new ArrayList <RawType>(); 205 while (format != null) { 206 list.add(format); 207 format = format.getPreviousVersion(); 208 } 209 return Collections.unmodifiableList(list); 210 } else { 211 return null; 212 } 213 } else { 214 throw new IllegalStateException ("Store is not open"); 215 } 216 } 217 218 228 public final Object convertRawObject(RawObject raw) { 229 return catalog.convertRawObject(raw, null); 230 } 231 } 232 | Popular Tags |