Subversion Repositories SmartDukaan

Rev

Rev 17 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 18
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.metamodel.util;
4
package in.shop2020.metamodel.util;
5
 
5
 
-
 
6
import in.shop2020.util.Utils;
-
 
7
 
6
import java.io.File;
8
import java.io.File;
7
import java.io.FileInputStream;
9
import java.io.FileInputStream;
8
import java.io.FileOutputStream;
10
import java.io.FileOutputStream;
9
import java.io.ObjectInputStream;
11
import java.io.ObjectInputStream;
10
import java.io.ObjectOutputStream;
12
import java.io.ObjectOutputStream;
Line 12... Line 14...
12
/**
14
/**
13
 * @author naveen
15
 * @author naveen
14
 *
16
 *
15
 */
17
 */
16
public class DBUtils {
18
public class DBUtils {
17
	
19
 
18
	/**
20
	/**
19
	 * 
21
	 * 
20
	 * @param objectToStore
22
	 * @param objectToStore
-
 
23
	 * @param dbFile
-
 
24
	 * @throws Exception
21
	 */
25
	 */
22
	public static void store(Object objectToStore, String dbFile) throws Exception {
26
	public static void store(Object objectToStore, String dbFile) 
23
		System.out.println("store()");
27
		throws Exception {		
24
		
-
 
25
		FileOutputStream fos = new FileOutputStream(new File(dbFile));
28
		FileOutputStream fos = new FileOutputStream(new File(dbFile));
26
		ObjectOutputStream out = new ObjectOutputStream(fos);
29
		ObjectOutputStream out = new ObjectOutputStream(fos);
27
		
30
		
28
		out.writeObject(objectToStore);
31
		out.writeObject(objectToStore);
29
		out.close();
32
		out.close();
30
		System.out.println("Serialization complete");
33
		Utils.logger.info("Serialization complete");
31
	}
34
	}
32
	
35
	
33
	/**
36
	/**
34
	 * 
37
	 * 
-
 
38
	 * @param dbFile
-
 
39
	 * @return
-
 
40
	 * @throws Exception
35
	 */
41
	 */
36
	public static Object read(String dbFile) throws Exception {
42
	public static Object read(String dbFile) throws Exception {
37
		System.out.println("read()");
-
 
38
 
-
 
39
		FileInputStream fis = new FileInputStream(new File(dbFile));
43
		FileInputStream fis = new FileInputStream(new File(dbFile));
40
		ObjectInputStream in = new ObjectInputStream(fis);
44
		ObjectInputStream in = new ObjectInputStream(fis);
41
		Object obj = in.readObject();
45
		Object obj = in.readObject();
42
		in.close();
46
		in.close();
43
		
47
		
44
		System.out.println("De-serialization complete");
48
		Utils.logger.info("De-serialization complete");
45
		return obj;
49
		return obj;
46
	}
50
	}
47
}
51
}