Subversion Repositories SmartDukaan

Rev

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

Rev 2275 Rev 2768
Line 1... Line -...
1
 
-
 
2
package in.shop2020.storage.bdb;
1
package in.shop2020.storage.bdb;
3
 
2
 
-
 
3
import in.shop2020.metamodel.core.Brand;
4
import in.shop2020.metamodel.core.Entity;
4
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.EntityState;
5
import in.shop2020.metamodel.core.EntityState;
6
import in.shop2020.metamodel.core.Helpdoc;
6
import in.shop2020.metamodel.core.Helpdoc;
7
import in.shop2020.util.Utils;
7
import in.shop2020.util.Utils;
8
 
8
 
9
 
-
 
10
import java.util.Collection;
9
import java.util.Collection;
11
import java.util.Map;
10
import java.util.Map;
12
 
11
 
13
import com.sleepycat.collections.TransactionRunner;
12
import com.sleepycat.collections.TransactionRunner;
14
import com.sleepycat.collections.TransactionWorker;
13
import com.sleepycat.collections.TransactionWorker;
Line 18... Line 17...
18
 * Entry point for storing everything in berkley database. Singleton class which initialises the berkley database.
17
 * Entry point for storing everything in berkley database. Singleton class which initialises the berkley database.
19
 * @author rajveer
18
 * @author rajveer
20
 *
19
 *
21
 */
20
 */
22
public class StorageManager {
21
public class StorageManager {
23
 
-
 
24
    private final ContentDatabase db;
22
    private final ContentDatabase db;
25
    private final ContentViews views;
23
    private final ContentViews views;
26
    private final TransactionRunner txnRunner;
24
    private final TransactionRunner txnRunner;
27
    private static StorageManager storageUtils;
25
    private static StorageManager storageUtils;
28
    private static final String homeDir =  Utils.BERKELEY_DB_PATH;
26
    private static final String homeDir =  Utils.BERKELEY_DB_PATH;
Line 35... Line 33...
35
    
33
    
36
    /**
34
    /**
37
     * Run the sample program.
35
     * Run the sample program.
38
     */
36
     */
39
    public static void main(String[] args) {
37
    public static void main(String[] args) {
40
 
-
 
41
        System.out.println("\nRunning sample: " + StorageManager.class);
38
        System.out.println("\nRunning sample: " + StorageManager.class);
42
 
39
 
43
        
-
 
44
        try {
40
        try {
45
        	Collection<Entity> entities=  StorageManager.getStorageManager().getEntitisByCategory(10002);
41
        	Collection<Entity> entities=  StorageManager.getStorageManager().getEntitisByCategory(10002);
46
        	for(Entity entity: entities){
42
        	for(Entity entity: entities) {
47
        		System.out.println(entity.getID());
43
        		System.out.println(entity.getID());
48
        	}
44
        	}
49
        	//StorageManager.getStorageManager().printEntitis(10002);
45
        	//StorageManager.getStorageManager().printEntitis(10002);
50
        } catch (Exception e) {
46
        } catch (Exception e) {
51
            // If an exception reaches this point, the last transaction did not
47
            // If an exception reaches this point, the last transaction did not
Line 273... Line 269...
273
	    	Map states = views.getEntityMetadataMap();
269
	    	Map states = views.getEntityMetadataMap();
274
        	states.put(new Long(entityMetadata.getID()), entityMetadata);
270
        	states.put(new Long(entityMetadata.getID()), entityMetadata);
275
		}
271
		}
276
    }
272
    }
277
 
273
 
-
 
274
    /**
-
 
275
     * Returns all brands from the database.
-
 
276
     */
-
 
277
    public Map<Long, Brand> getBrands() {
-
 
278
        return views.getBrandMap();
-
 
279
    }
-
 
280
 
-
 
281
    /**
-
 
282
     * Updates a given brand in the database.
-
 
283
     */
-
 
284
    public void updateBrand(Brand brand) {
-
 
285
        Map<Long, Brand> states = views.getBrandMap();
-
 
286
        states.put(new Long(brand.getID()), brand);
-
 
287
    }
-
 
288
 
-
 
289
    /**
-
 
290
     * Returns a brand object given a id after looking it up from map
-
 
291
     * of values loaded from database.
-
 
292
     */
-
 
293
    public Brand getBrand(long brandId) {
-
 
294
        return views.getBrandMap().get(brandId);
-
 
295
    }
-
 
296
 
278
}
297
}