Subversion Repositories SmartDukaan

Rev

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