root/trunk/LogicMail/src/org/logicprobe/LogicMail/util/DataStore.java

Revision 275, 4.1 kB (checked in by octorian, 5 months ago)
Line 
1/*-
2 * Copyright (c) 2007, Derek Konigsberg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the project nor the names of its
15 *    contributors may be used to endorse or promote products derived
16 *    from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32package org.logicprobe.LogicMail.util;
33
34/**
35 * Provides a common interface for persistent data storage implementations.
36 * The interface provides the ability to store objects by name or unique id.
37 * Since all serializable objects provide a unique id, everything should
38 * actually be stored by unique id.  A mapping table should be internally
39 * maintained to allow name lookups.  Named storage allows retrieval of
40 * top-level objects for which the unique id is unknown.
41 */
42public interface DataStore {
43    /**
44     * Gets an object by name lookup.
45     * @param name Name for the object
46     * @return Matching object
47     */
48    public abstract Serializable getNamedObject(String name);
49   
50    /**
51     * Gets an array of all the named objects available.
52     * @return Array of available named objects
53     */
54    public abstract String[] getNamedObjects();
55   
56    /**
57     * Gets an object by unique id lookup.
58     * @param id Unique id for the object
59     * @return Matching object
60     */
61    public abstract Serializable getObject(long id);
62   
63    /**
64     * Puts an object into the store with a name mapping.
65     * This should also create the necessary unique id mapping.
66     * If the object matching the name already exists in the store,
67     * it will be overwritten.
68     * @param name Name for the object
69     * @param object Object to store
70     */
71    public abstract void putNamedObject(String name, Serializable object);
72   
73    /**
74     * Puts an object into the store.
75     * If the object matching the same unique id already exists in the store,
76     * it will be overwritten.
77     * @param object Object to store
78     */
79    public abstract void putObject(Serializable object);
80   
81    /**
82     * Removes an object with a name mapping from the store.
83     * This will also remove the unique id mapping.
84     * @param name Name of object to remove
85     */
86    public abstract void removeNamedObject(String name);
87   
88    /**
89     * Removes an object from the store.
90     * @param object Object to remove
91     */
92    public abstract void removeObject(Serializable object);
93   
94    /**
95     * Save the contents of the store to persistent memory.
96     */
97    public abstract void save();
98   
99    /**
100     * Load the contents of the store from persistent memory.
101     */
102    public abstract void load();
103   
104    /**
105     * Delete this store from the device.
106     * Calling save() or load() after this method may result
107     * in the store being recreated.
108     */
109    public abstract void delete();
110}
Note: See TracBrowser for help on using the browser.