Subversion Repositories SmartDukaan

Rev

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