001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test;
022:
023: import java.io.*;
024:
025: import com.db4o.*;
026: import com.db4o.tools.*;
027:
028: public class ObjectNotStorable implements Runnable {
029:
030: private static final String FILE = "notStorable.yap";
031: private static boolean throwException = false;
032:
033: private String name;
034:
035: private ObjectNotStorable(String name) {
036: if (throwException) {
037: throw new RuntimeException();
038: }
039: this .name = name;
040: }
041:
042: public static void main(String[] args) {
043: throwException = false;
044: new ObjectNotStorable(null).run();
045: }
046:
047: public void run() {
048: new File(FILE).delete();
049: Db4o.configure().exceptionsOnNotStorable(true);
050: run1();
051: }
052:
053: private void run1() {
054: try {
055: setExc();
056: } catch (Exception e) {
057: e.printStackTrace();
058: }
059: try {
060: getExc();
061: } catch (Exception e) {
062: e.printStackTrace();
063: }
064: }
065:
066: private static void setOK() {
067: throwException = false;
068: ObjectContainer con = Db4o.openFile(FILE);
069: ObjectNotStorable ons = new ObjectNotStorable("setOK");
070: con.set(ons);
071: con.close();
072: }
073:
074: private static void setExc() {
075: ObjectContainer con = Db4o.openFile(FILE);
076: throwException = false;
077: ObjectNotStorable ons = new ObjectNotStorable("setExc");
078: throwException = true;
079: con.set(ons);
080: con.close();
081: }
082:
083: private static void getOK() {
084: throwException = false;
085: ObjectContainer con = Db4o.openFile(FILE);
086: ObjectSet set = con.get(new ObjectNotStorable(null));
087: while (set.hasNext()) {
088: Logger.log(con, set.next());
089: }
090: con.close();
091: }
092:
093: private static void getExc() {
094: throwException = true;
095: ObjectContainer con = Db4o.openFile(FILE);
096: ObjectSet set = con.get(null);
097: while (set.hasNext()) {
098: Logger.log(con, set.next());
099: }
100: con.close();
101:
102: }
103: }
|