Subversion Repositories SmartDukaan

Rev

Rev 1061 | Rev 2275 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1061 Rev 1153
Line 7... Line 7...
7
import com.sleepycat.bind.serial.ClassCatalog;
7
import com.sleepycat.bind.serial.ClassCatalog;
8
import com.sleepycat.bind.serial.SerialSerialKeyCreator;
8
import com.sleepycat.bind.serial.SerialSerialKeyCreator;
9
import com.sleepycat.bind.serial.StoredClassCatalog;
9
import com.sleepycat.bind.serial.StoredClassCatalog;
10
import com.sleepycat.je.Database;
10
import com.sleepycat.je.Database;
11
import com.sleepycat.je.DatabaseConfig;
11
import com.sleepycat.je.DatabaseConfig;
12
import com.sleepycat.je.DatabaseEntry;
-
 
13
import com.sleepycat.je.DatabaseException;
12
import com.sleepycat.je.DatabaseException;
14
import com.sleepycat.je.Environment;
13
import com.sleepycat.je.Environment;
15
import com.sleepycat.je.EnvironmentConfig;
14
import com.sleepycat.je.EnvironmentConfig;
16
import com.sleepycat.je.SecondaryConfig;
15
import com.sleepycat.je.SecondaryConfig;
17
import com.sleepycat.je.SecondaryDatabase;
16
import com.sleepycat.je.SecondaryDatabase;
18
import com.sleepycat.je.SecondaryKeyCreator;
-
 
19
 
17
 
-
 
18
 
-
 
19
/**
-
 
20
 * database for storing various objects of Content Management System
-
 
21
 * @author rajveer
-
 
22
 *
-
 
23
 */
20
public class ContentDatabase {
24
public class ContentDatabase {
21
 
25
 
22
    private static final String CLASS_CATALOG = "java_class_catalog";
26
    private static final String CLASS_CATALOG = "java_class_catalog";
23
    private static final String ENTITY_STORE = "entity_store";
27
    private static final String ENTITY_STORE = "entity_store";
24
    private static final String DATA_OBJECT_STORE = "data_object_store";
28
    private static final String DATA_OBJECT_STORE = "data_object_store";
Line 39... Line 43...
39
    /**
43
    /**
40
     * Open all storage containers, indices, and catalogs.
44
     * Open all storage containers, indices, and catalogs.
41
     */
45
     */
42
    public ContentDatabase(String homeDirectory)
46
    public ContentDatabase(String homeDirectory)
43
        throws DatabaseException {
47
        throws DatabaseException {
44
 
48
    	
45
        // Open the Berkeley DB environment in transactional mode.
49
        // Open the Berkeley DB environment in transactional mode.
46
        //
50
        //
47
        System.out.println("Opening environment in: " + homeDirectory);
51
        System.out.println("Opening environment in: " + homeDirectory);
48
        EnvironmentConfig envConfig = new EnvironmentConfig();
52
        EnvironmentConfig envConfig = new EnvironmentConfig();
49
        envConfig.setTransactional(true);
53
        envConfig.setTransactional(true);
Line 80... Line 84...
80
        secConfig.setSortedDuplicates(true);
84
        secConfig.setSortedDuplicates(true);
81
        secConfig.setKeyCreator(new EntityByCategory(javaCatalog, Long.class, Entity.class, Long.class));
85
        secConfig.setKeyCreator(new EntityByCategory(javaCatalog, Long.class, Entity.class, Long.class));
82
        entityByCategoryDb = env.openSecondaryDatabase(null, ENTITY_CATEGORY_INDEX, entityDb, secConfig);
86
        entityByCategoryDb = env.openSecondaryDatabase(null, ENTITY_CATEGORY_INDEX, entityDb, secConfig);
83
    }
87
    }
84
 
88
 
-
 
89
    /**
-
 
90
     * Private class for making Category ad an index to entity database, which extends SerialSerialKeyCreator.
-
 
91
     * Will create the secondary key once some new entity is added. 
-
 
92
     * @author rajveer
-
 
93
     *
-
 
94
     */
85
    private static class EntityByCategory extends SerialSerialKeyCreator<Object, Object, Object>{
95
    private static class EntityByCategory extends SerialSerialKeyCreator<Object, Object, Object>{
86
 
96
 
87
    	public EntityByCategory(ClassCatalog classCatalog, Class primaryKeyClass, Class dataClass, Class indexKeyClass) {
97
    	public EntityByCategory(ClassCatalog classCatalog, Class primaryKeyClass, Class dataClass, Class indexKeyClass) {
88
			super(classCatalog, primaryKeyClass, dataClass, indexKeyClass);
98
			super(classCatalog, primaryKeyClass, dataClass, indexKeyClass);
89
		}
99
		}
Line 98... Line 108...
98
    
108
    
99
    /**
109
    /**
100
     * Return the storage environment for the database.
110
     * Return the storage environment for the database.
101
     */
111
     */
102
    public final Environment getEnvironment() {
112
    public final Environment getEnvironment() {
103
 
-
 
104
        return env;
113
        return env;
105
    }
114
    }
106
 
115
 
107
    /**
116
    /**
108
     * Return the class catalog.
117
     * Return the class catalog.
Line 111... Line 120...
111
 
120
 
112
        return javaCatalog;
121
        return javaCatalog;
113
    }
122
    }
114
 
123
 
115
    /**
124
    /**
116
     * Return the entity storage container.
125
     * Return the definition storage container.
117
     */
126
     */
118
    public final Database getDefinitionDatabase() {
127
    public final Database getDefinitionDatabase() {
119
 
128
 
120
        return definitionDb;
129
        return definitionDb;
121
    }
130
    }
122
    
131
    
123
    /**
132
    /**
124
     * Return the entity storage container.
133
     * @return Return the entity storage container.
125
     */
134
     */
126
    public final Database getEntityDatabase() {
135
    public final Database getEntityDatabase() {
127
 
136
 
128
        return entityDb;
137
        return entityDb;
129
    }
138
    }
130
 
139
 
-
 
140
    /**
-
 
141
     * 
-
 
142
     * @return
-
 
143
     */
131
    public final SecondaryDatabase getCategoryByCategoryDatabase() {
144
    public final SecondaryDatabase getCategoryByCategoryDatabase() {
132
 
145
 
133
        return entityByCategoryDb;
146
        return entityByCategoryDb;
134
    }
147
    }
135
 
148
 
136
    
149
    
137
    /**
150
    /**
138
     * Return the entity storage container.
151
     * @return Return the entity metadata storage container.
139
     */
152
     */
140
    public final Database getEntityMetadataDatabase() {
153
    public final Database getEntityMetadataDatabase() {
141
 
154
 
142
        return entityMetadataDb;
155
        return entityMetadataDb;
143
    }
156
    }
144
    
157
    
145
    /**
158
    /**
146
     * Return the supplier storage container.
159
     * @return Return the objects storage container.
147
     */
160
     */
148
    public final Database getDataObjectDatabase() {
161
    public final Database getDataObjectDatabase() {
149
 
162
 
150
        return dataObjectDb;
163
        return dataObjectDb;
151
    }
164
    }