KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > StorageManagerTestImpl


1 /**
2  * Copyright (C) 2003-2004
3  * - France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Release: 1.0
20  *
21  * Authors: Olivier Lobry (olivier.lobry@rd.francetelecom.com)
22  *
23  */

24
25 package org.objectweb.perseus;
26
27 import org.objectweb.perseus.persistence.api.StorageManager;
28 import org.objectweb.perseus.persistence.api.ConnectionHolder;
29 import org.objectweb.perseus.persistence.api.PersistenceException;
30 import org.objectweb.perseus.persistence.api.WorkingSet;
31 import org.objectweb.perseus.persistence.api.State;
32
33 import java.util.HashSet JavaDoc;
34
35 public class StorageManagerTestImpl implements StorageManager {
36
37
38     HashSet JavaDoc persObjs;
39
40     public StorageManagerTestImpl() {
41         persObjs = new HashSet JavaDoc();
42     }
43
44     public Object JavaDoc export(ConnectionHolder context, Object JavaDoc obj) throws PersistenceException {
45         Object JavaDoc id;
46         if (obj instanceof PString) {
47             id = new PString((PString) obj);
48         } else if (obj instanceof PInteger) {
49             id = new PInteger((PInteger) obj);
50         } else
51             throw new PersistenceException("Illegal persistent type");
52         persObjs.add(id);
53         return id;
54     }
55
56     public Object JavaDoc export(ConnectionHolder context, Object JavaDoc obj, Object JavaDoc hints) throws PersistenceException {
57         return export(context, obj);
58     }
59
60     public void unexport(ConnectionHolder context, Object JavaDoc oid) throws PersistenceException {
61         if (!persObjs.remove(oid))
62             throw new PersistenceException("Not a persistent object");
63     }
64
65     public void unexport(ConnectionHolder context, Object JavaDoc oid, Object JavaDoc hints) throws PersistenceException {
66         unexport(context, oid);
67     }
68
69     public void read(ConnectionHolder context, Object JavaDoc oid, State state) throws PersistenceException {
70         if (state instanceof PStringState) {
71             ((PStringState) state).set((PString) oid);
72         } else if (state instanceof PIntegerState) {
73             ((PIntegerState) state).set((PInteger) oid);
74         } else
75             throw new PersistenceException("Illegal persistent type");
76     }
77
78     public void read(WorkingSet context, Object JavaDoc oid, State state) throws PersistenceException {
79         if (state instanceof PStringState) {
80             ((PStringState) state).set((PString) oid);
81         } else if (state instanceof PIntegerState) {
82             ((PIntegerState) state).set((PInteger) oid);
83         } else
84             throw new PersistenceException("Illegal persistent type");
85     }
86
87     public void write(ConnectionHolder context, Object JavaDoc oid, State state) throws PersistenceException {
88         if (state instanceof PStringState) {
89             ((PString) oid).set((PString) state);
90         } else if (state instanceof PIntegerState) {
91             ((PInteger) oid).set((PInteger) state);
92         } else
93             throw new PersistenceException("Illegal persistent type");
94     }
95
96     public void beginWS(WorkingSet ws) {
97     }
98
99     public void endWS(WorkingSet ws) {
100     }
101 }
102
Popular Tags