Subversion Repositories SmartDukaan

Rev

Rev 1050 | Rev 1153 | 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
import in.shop2020.metamodel.core.Media;
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
import com.sleepycat.persist.model.EntityMetadata;
13
 
14
public class ContentViews {
15
 
16
    private StoredMap entityMap;
17
    private StoredMap entityMetadataMap;
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
 
39
        EntryBinding commonKeyBinding =   new SerialBinding(catalog, String.class);
40
        EntryBinding commonDataBinding =   new SerialBinding(catalog, Object.class);
41
 
42
        EntryBinding definitionKeyBinding =   new SerialBinding(catalog, String.class);
43
        EntryBinding definitionDataBinding =   new SerialBinding(catalog, Object.class);
44
 
45
        EntryBinding entityByCategoryKeyBinding =   new SerialBinding(catalog, Long.class);
46
 
47
 
48
        // Create map views for all stores and indices.
49
        // StoredSortedMap is not used since the stores and indices are
50
        // ordered by serialized key objects, which do not provide a very
51
        // useful ordering.
52
        //
53
        entityMap = new StoredMap(db.getEntityDatabase(),entityKeyBinding, entityDataBinding, true);
54
 
55
        entityMetadataMap = new StoredMap(db.getEntityMetadataDatabase(),entityMetadataKeyBinding, entityMetadataDataBinding, true);
56
 
57
        dataObjectMap = new StoredMap(db.getDataObjectDatabase(), commonKeyBinding, commonDataBinding, true);
58
 
59
        definitionMap = new StoredMap(db.getDefinitionDatabase(), definitionKeyBinding, definitionDataBinding, true);
60
 
61
        entityByCategoryMap = new StoredMap(db.getCategoryByCategoryDatabase(), entityByCategoryKeyBinding, entityDataBinding, true);
62
    }
63
 
64
    // The views returned below can be accessed using the java.util.Map or
65
    // java.util.Set interfaces, or using the StoredMap and StoredEntrySet
66
    // classes, which provide additional methods.  The entry sets could be
67
    // obtained directly from the Map.entrySet() method, but convenience
68
    // methods are provided here to return them in order to avoid down-casting
69
    // elsewhere.
70
 
71
    /**
72
     * Return a map view of the part storage container.
73
     */
74
    public final StoredMap getEntityMap() {
75
 
76
        return entityMap;
77
    }
78
 
79
    public final StoredMap getEntityByCategoryMap() {
80
 
81
        return entityByCategoryMap;
82
    }
83
 
84
 
85
    /**
86
     * Return a map view of the part storage container.
87
     */
88
    public final StoredMap getEntityMetadataMap() {
89
 
90
        return entityMetadataMap;
91
    }
92
 
93
    /**
94
     * Return a map view of the part storage container.
95
     */
96
    public final StoredMap getDefinitionMap() {
97
 
98
        return definitionMap;
99
    }
100
 
101
    /**
102
     * Return a map view of the supplier storage container.
103
     */
104
    public final StoredMap getDataObjectMap() {
105
 
106
        return dataObjectMap;
107
    }
108
 
109
    /**
110
     * Return an entry set view of the part storage container.
111
     */
112
    public final StoredEntrySet getEntityEntrySet() {
113
 
114
        return (StoredEntrySet) entityMap.entrySet();
115
    }
116
 
117
    /**
118
     * Return an entry set view of the part storage container.
119
     */
120
    public final StoredEntrySet getEntityMetaDataEntrySet() {
121
 
122
        return (StoredEntrySet) entityMetadataMap.entrySet();
123
    }
124
 
125
    /**
126
     * Return an entry set view of the part storage container.
127
     */
128
    public final StoredEntrySet getDefinitionEntrySet() {
129
 
130
        return (StoredEntrySet) definitionMap.entrySet();
131
    }
132
 
133
 
134
    /**
135
     * Return an entry set view of the supplier storage container.
136
     */
137
    public final StoredEntrySet getDataObjectEntrySet() {
138
 
139
        return (StoredEntrySet) dataObjectMap.entrySet();
140
    }
141
 
142
}