| 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.Set; |
| 11 |
|
| 12 |
import com.sleepycat.persist.model.ClassMetadata; |
| 13 |
import com.sleepycat.persist.model.EntityMetadata; |
| 14 |
import com.sleepycat.persist.model.EntityModel; |
| 15 |
|
| 16 |
/** |
| 17 |
* The EntityModel used when a RawStore is opened. The metadata and raw type |
| 18 |
* information comes from the catalog directly, without using the current |
| 19 |
* class definitions. |
| 20 |
* |
| 21 |
* @author Mark Hayes |
| 22 |
*/ |
| 23 |
class StoredModel extends EntityModel { |
| 24 |
|
| 25 |
private volatile PersistCatalog catalog; |
| 26 |
private volatile Set<String> knownClasses; |
| 27 |
|
| 28 |
StoredModel(final PersistCatalog catalog) { |
| 29 |
this.catalog = catalog; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* This method is used to initialize the model when catalog creation is |
| 34 |
* complete, and reinitialize it when a Replica refresh occurs. |
| 35 |
*/ |
| 36 |
@Override |
| 37 |
protected void setCatalog(final PersistCatalog newCatalog) { |
| 38 |
super.setCatalog(newCatalog); |
| 39 |
this.catalog = newCatalog; |
| 40 |
knownClasses = newCatalog.getModelClasses(); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public ClassMetadata getClassMetadata(String className) { |
| 45 |
ClassMetadata metadata = null; |
| 46 |
Format format = catalog.getFormat(className); |
| 47 |
if (format != null && format.isCurrentVersion()) { |
| 48 |
metadata = format.getClassMetadata(); |
| 49 |
} |
| 50 |
return metadata; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public EntityMetadata getEntityMetadata(String className) { |
| 55 |
EntityMetadata metadata = null; |
| 56 |
Format format = catalog.getFormat(className); |
| 57 |
if (format != null && format.isCurrentVersion()) { |
| 58 |
metadata = format.getEntityMetadata(); |
| 59 |
} |
| 60 |
return metadata; |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public Set<String> getKnownClasses() { |
| 65 |
return knownClasses; |
| 66 |
} |
| 67 |
} |