2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * @file xmltooling/util/StorageService.h
\r
20 * Generic data storage facility for use by services that require persistence.
\r
23 #ifndef __xmltooling_storage_h__
\r
24 #define __xmltooling_storage_h__
\r
26 #include <xmltooling/XMLObject.h>
\r
30 namespace xmltooling {
\r
33 * Generic data storage facility for use by services that require persistence.
\r
35 class XMLTOOL_API StorageService
\r
37 MAKE_NONCOPYABLE(StorageService);
\r
42 virtual ~StorageService() {}
\r
45 * Creates a new "short" record in the storage service.
\r
47 * @param key null-terminated unique key of up to 255 bytes
\r
48 * @param value null-terminated value of up to 255 bytes to store
\r
49 * @param expiration an expiration timestamp, after which the record can be purged
\r
51 * @throws IOException raised if errors occur in the insertion process
\r
53 virtual void createString(const char* key, const char* value, time_t expiration)=0;
\r
56 * Returns an existing "short" record from the storage service.
\r
58 * @param key null-terminated unique key of up to 255 bytes
\r
59 * @param value location in which to return the record value
\r
60 * @param modifiedSince the record should not be returned if unmodified since this time,
\r
61 * or 0 to always return
\r
62 * @return true iff the record exists and was returned (based on the modifiedSince value)
\r
64 * @throws IOException raised if errors occur in the read process
\r
66 virtual bool readString(const char* key, std::string& value, time_t modifiedSince=0)=0;
\r
69 * Updates an existing "short" record in the storage service.
\r
71 * @param key null-terminated unique key of up to 255 bytes
\r
72 * @param value null-terminated value of up to 255 bytes to store, or NULL to leave alone
\r
73 * @param expiration a new expiration timestamp, or 0 to leave alone
\r
74 * @return true iff the record exists and was updated
\r
76 * @throws IOException raised if errors occur in the update process
\r
78 virtual bool updateString(const char* key, const char* value=NULL, time_t expiration=0)=0;
\r
81 * Deletes an existing "short" record from the storage service.
\r
83 * @param key null-terminated unique key of up to 255 bytes
\r
84 * @return true iff the record existed and was deleted
\r
86 * @throws IOException raised if errors occur in the deletion process
\r
88 virtual bool deleteString(const char* key)=0;
\r
91 * Creates a new "long" record in the storage service.
\r
93 * @param key null-terminated unique key of up to 255 bytes
\r
94 * @param value null-terminated value of arbitrary length
\r
95 * @param expiration an expiration timestamp, after which the record can be purged
\r
97 * @throws IOException raised if errors occur in the insertion process
\r
99 virtual void createText(const char* key, const char* value, time_t expiration)=0;
\r
102 * Returns an existing "long" record from the storage service.
\r
104 * @param key null-terminated unique key of up to 255 bytes
\r
105 * @param value location in which to return the record value
\r
106 * @param modifiedSince the record should not be returned if unmodified since this time,
\r
107 * or 0 to always return
\r
108 * @return true iff the record exists and was returned (based on the modifiedSince value)
\r
110 * @throws IOException raised if errors occur in the read process
\r
112 virtual bool readText(const char* key, std::string& value, time_t modifiedSince=0)=0;
\r
115 * Updates an existing "long" record in the storage service.
\r
117 * @param key null-terminated unique key of up to 255 bytes
\r
118 * @param value null-terminated value of arbitrary length to store, or NULL to leave alone
\r
119 * @param expiration a new expiration timestamp, or 0 to leave alone
\r
120 * @return true iff the record exists and was updated
\r
122 * @throws IOException raised if errors occur in the update process
\r
124 virtual bool updateText(const char* key, const char* value=NULL, time_t expiration=0)=0;
\r
127 * Deletes an existing "long" record from the storage service.
\r
129 * @param key null-terminated unique key of up to 255 bytes
\r
130 * @return true iff the record existed and was deleted
\r
132 * @throws IOException raised if errors occur in the deletion process
\r
134 virtual bool deleteText(const char* key)=0;
\r
137 * Manually trigger a cleanup of expired records.
\r
138 * The method <strong>MAY</strong> return without guaranteeing that
\r
139 * cleanup has already occurred.
\r
141 virtual void reap()=0;
\r
145 * Registers StorageService classes into the runtime.
\r
147 void XMLTOOL_API registerStorageServices();
\r
149 /** StorageService based on in-memory caching. */
\r
150 #define MEMORY_STORAGE_SERVICE "org.opensaml.xmlooling.MemoryStorageService"
\r
153 #endif /* __xmltooling_storage_h__ */
\r