Subversion Repositories SmartDukaan

Rev

Rev 1061 | Rev 2275 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1050 rajveer 1
package in.shop2020.storage.bdb;
2
 
3
import in.shop2020.metamodel.core.Entity;
4
import in.shop2020.metamodel.core.EntityState;
5
 
6
import com.sleepycat.bind.EntryBinding;
7
import com.sleepycat.bind.serial.ClassCatalog;
8
import com.sleepycat.bind.serial.SerialBinding;
9
import com.sleepycat.collections.StoredEntrySet;
10
import com.sleepycat.collections.StoredMap;
11
 
12
public class ContentViews {
13
 
14
    private StoredMap entityMap;
15
    private StoredMap entityMetadataMap;
16
    private StoredMap dataObjectMap;
17
    private StoredMap definitionMap;
18
 
19
    private StoredMap entityByCategoryMap;
20
 
21
    /**
22
     * Create the data bindings and collection views.
23
     */
24
    public ContentViews(ContentDatabase db) {
25
 
26
        // In this sample, the stored key and data entries are used directly
27
        // rather than mapping them to separate objects. Therefore, no binding
28
        // classes are defined here and the SerialBinding class is used.
29
        //
30
        ClassCatalog catalog = db.getClassCatalog();
31
        EntryBinding entityKeyBinding = new SerialBinding(catalog, Long.class);
32
        EntryBinding entityDataBinding =  new SerialBinding(catalog, Entity.class);
33
 
34
        EntryBinding entityMetadataKeyBinding = new SerialBinding(catalog, Long.class);
35
        EntryBinding entityMetadataDataBinding =  new SerialBinding(catalog, EntityState.class);
36
 
37
        EntryBinding commonKeyBinding =   new SerialBinding(catalog, String.class);
38
        EntryBinding commonDataBinding =   new SerialBinding(catalog, Object.class);
39
 
40
        EntryBinding definitionKeyBinding =   new SerialBinding(catalog, String.class);
41
        EntryBinding definitionDataBinding =   new SerialBinding(catalog, Object.class);
42
 
43
        EntryBinding entityByCategoryKeyBinding =   new SerialBinding(catalog, Long.class);
44
 
45
 
46
        // Create map views for all stores and indices.
47
        // StoredSortedMap is not used since the stores and indices are
48
        // ordered by serialized key objects, which do not provide a very
49
        // useful ordering.
50
        //
51
        entityMap = new StoredMap(db.getEntityDatabase(),entityKeyBinding, entityDataBinding, true);
52
 
53
        entityMetadataMap = new StoredMap(db.getEntityMetadataDatabase(),entityMetadataKeyBinding, entityMetadataDataBinding, true);
54
 
55
        dataObjectMap = new StoredMap(db.getDataObjectDatabase(), commonKeyBinding, commonDataBinding, true);
56
 
57
        definitionMap = new StoredMap(db.getDefinitionDatabase(), definitionKeyBinding, definitionDataBinding, true);
58
 
59
        entityByCategoryMap = new StoredMap(db.getCategoryByCategoryDatabase(), entityByCategoryKeyBinding, entityDataBinding, true);
60
    }
61
 
62
    // The views returned below can be accessed using the java.util.Map or
63
    // java.util.Set interfaces, or using the StoredMap and StoredEntrySet
64
    // classes, which provide additional methods.  The entry sets could be
65
    // obtained directly from the Map.entrySet() method, but convenience
66
    // methods are provided here to return them in order to avoid down-casting
67
    // elsewhere.
68
 
69
    /**
1153 rajveer 70
     * Return a map view of the entity storage container.
1050 rajveer 71
     */
72
    public final StoredMap getEntityMap() {
73
 
74
        return entityMap;
75
    }
76
 
1153 rajveer 77
    /**
78
     * 
79
     * @return a map view of the entities by category storage container.
80
     */
1050 rajveer 81
    public final StoredMap getEntityByCategoryMap() {
82
 
83
        return entityByCategoryMap;
84
    }
85
 
86
 
87
    /**
1153 rajveer 88
     * Return a map view of the entity metadata storage container.
1050 rajveer 89
     */
90
    public final StoredMap getEntityMetadataMap() {
91
 
92
        return entityMetadataMap;
93
    }
94
 
95
    /**
1153 rajveer 96
     * Return a map view of the definition storage container.
1050 rajveer 97
     */
98
    public final StoredMap getDefinitionMap() {
99
 
100
        return definitionMap;
101
    }
102
 
103
    /**
1153 rajveer 104
     * Return a map view of the object storage container.
1050 rajveer 105
     */
106
    public final StoredMap getDataObjectMap() {
107
 
108
        return dataObjectMap;
109
    }
110
 
111
    /**
1153 rajveer 112
     * Return an entry set view of the entity storage container.
1050 rajveer 113
     */
114
    public final StoredEntrySet getEntityEntrySet() {
115
 
116
        return (StoredEntrySet) entityMap.entrySet();
117
    }
118
 
119
    /**
1153 rajveer 120
     * Return an entry set view of the entity metadata storage container.
1050 rajveer 121
     */
122
    public final StoredEntrySet getEntityMetaDataEntrySet() {
123
 
124
        return (StoredEntrySet) entityMetadataMap.entrySet();
125
    }
126
 
127
    /**
1153 rajveer 128
     * Return an entry set view of the definitions storage container.
1050 rajveer 129
     */
130
    public final StoredEntrySet getDefinitionEntrySet() {
131
 
132
        return (StoredEntrySet) definitionMap.entrySet();
133
    }
134
 
135
 
136
    /**
1153 rajveer 137
     * Return an entry set view of the object storage container.
1050 rajveer 138
     */
139
    public final StoredEntrySet getDataObjectEntrySet() {
140
        return (StoredEntrySet) dataObjectMap.entrySet();
141
    }
142
 
143
}