Subversion Repositories SmartDukaan

Rev

Rev 299 | Blame | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.util;

import java.io.File;
import java.util.Map;

import in.shop2020.metamodel.core.Entity;
import in.shop2020.metamodel.definitions.Catalog;
import in.shop2020.metamodel.definitions.EntityContainer;

/**
 * @author naveen
 *
 */
public class MISC {

        /**
         * @param args
         * @throws Exception 
         */
        public static void main(String[] args) throws Exception {
                MISC m = new MISC();
                
                m.serializeIndivisually();
        }
        
        /**
         * @throws Exception 
         * 
         */
        public void serializeIndivisually() throws Exception {
                EntityContainer ents = Catalog.getInstance().getEntityContainer();
                Map<Long, Entity> entities = ents.getEntities();
                
                for(Long entityID : entities.keySet()) {
                        Entity entity = entities.get(entityID);
                        System.out.println("ID:" + entity.getID());
                        
                        String dir = Utils.ENTITIES_DB_PATH + "/" + entityID;
                        File dirFile = new File(dir);
                        
                        if(!dirFile.exists()) {
                                dirFile.mkdir();
                        }
                        
                        String fileName = Utils.ENTITIES_DB_PATH + "/" + entityID + 
                                "/entity.ser";
                        File fileNameFile = new File(fileName);
                        if(fileNameFile.exists()) {
                                fileNameFile.delete();
                        }
                        
                        fileNameFile.createNewFile();
                        
                        DBUtils.store(entity, fileName);
                }
        }
}