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

Revision 321, 3.6 kB (checked in by octorian, 2 months ago)

Converted data store to use the RIM Persistent Object Store instead of the J2ME RecordStore. This is the first code change to LogicMail that will impose a code signing requirement on binaries, and isn't expected to be the last.

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 * Factory for creating DataStore instances.
36 * The DataStore instances are intended to be used by classes that
37 * provide a less general interface to the types of data being
38 * stored.
39 */
40public final class DataStoreFactory {
41    private static DataStore configurationStore;
42    private static DataStore metadataStore;
43    private static DataStore connectionCacheStore;
44   
45    /** Creates a new instance of DataStoreFactory */
46    private DataStoreFactory() {
47    }
48   
49    /**
50     * Gets the data store for configuration objects.
51     *
52     * @return Configuration store
53     */
54    public static synchronized DataStore getConfigurationStore() {
55        if(configurationStore == null) {
56                // "org.logicprobe.LogicMail.store.configuration"
57                configurationStore = new PersistentObjectDataStore(0xbb981925fd9130abL);
58        }
59        return configurationStore;
60    }
61   
62    /**
63     * Gets the data store for metadata objects, such as runtime
64     * state information that should be saved for ease of use.
65     *
66     * @return Metadata store
67     */
68    public static synchronized DataStore getMetadataStore() {
69        if(metadataStore == null) {
70                // "org.logicprobe.LogicMail.store.metadata"
71            metadataStore = new PersistentObjectDataStore(0xf630df16ea30eb49L);
72        }
73        return metadataStore;
74    }
75   
76    /**
77     * Gets the cache store for connections.  This is one global store
78     * shared by all connections, and used to maintain lightweight
79     * data like folder tree structures.  All users are expected to
80     * use unique names to store their data.
81     *
82     * @return Cache store
83     */
84    public static synchronized DataStore getConnectionCacheStore() {
85        if(connectionCacheStore == null) {
86                // "org.logicprobe.LogicMail.store.connection"
87            connectionCacheStore = new PersistentObjectDataStore(0xe53945d6e054c98cL);
88            connectionCacheStore.load();
89        }
90        return connectionCacheStore;
91    }
92}
Note: See TracBrowser for help on using the browser.