KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > ObjectNotStorable


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test;
22
23 import java.io.*;
24
25 import com.db4o.*;
26 import com.db4o.tools.*;
27
28 public class ObjectNotStorable implements Runnable JavaDoc{
29     
30     private static final String JavaDoc FILE = "notStorable.yap";
31     private static boolean throwException = false;
32     
33     private String JavaDoc name;
34     
35     private ObjectNotStorable(String JavaDoc name){
36         if(throwException){
37             throw new RuntimeException JavaDoc();
38         }
39         this.name = name;
40     }
41
42     public static void main(String JavaDoc[] args) {
43         throwException = false;
44         new ObjectNotStorable(null).run();
45     }
46     
47     public void run(){
48         new File(FILE).delete();
49         Db4o.configure().exceptionsOnNotStorable(true);
50         run1();
51     }
52     
53     private void run1(){
54         try{
55             setExc();
56         }catch(Exception JavaDoc e){
57             e.printStackTrace();
58         }
59         try{
60             getExc();
61         }catch(Exception JavaDoc e){
62             e.printStackTrace();
63         }
64     }
65     
66     private static void setOK(){
67         throwException = false;
68         ObjectContainer con = Db4o.openFile(FILE);
69         ObjectNotStorable ons = new ObjectNotStorable("setOK");
70         con.set(ons);
71         con.close();
72     }
73     
74     private static void setExc(){
75         ObjectContainer con = Db4o.openFile(FILE);
76         throwException = false;
77         ObjectNotStorable ons = new ObjectNotStorable("setExc");
78         throwException = true;
79         con.set(ons);
80         con.close();
81     }
82     
83     private static void getOK(){
84         throwException = false;
85         ObjectContainer con = Db4o.openFile(FILE);
86         ObjectSet set = con.get(new ObjectNotStorable(null));
87         while(set.hasNext()){
88             Logger.log(con, set.next());
89         }
90         con.close();
91     }
92     
93     private static void getExc(){
94         throwException = true;
95         ObjectContainer con = Db4o.openFile(FILE);
96         ObjectSet set = con.get(null);
97         while(set.hasNext()){
98             Logger.log(con, set.next());
99         }
100         con.close();
101         
102     }
103 }
104
Popular Tags