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
39 virtual ~StorageService() {}
\r
42 * A "context" for accessing a StorageService instance.
\r
43 * Handles are created and freed using the StorageService interface,
\r
44 * and can be kept for the life of the service, and shared by multiple
\r
47 class XMLTOOL_API StorageHandle {
\r
48 MAKE_NONCOPYABLE(StorageHandle);
\r
49 friend class XMLTOOL_API StorageService;
\r
51 virtual ~StorageHandle() {}
\r
53 StorageHandle(StorageService* storage) : m_storage(storage) {}
\r
54 StorageService* m_storage;
\r
59 * Returns a new handle for the storage service.
\r
60 * The caller <strong>MUST</strong> delete the handle
\r
61 * before freeing the StorageService itself.
\r
63 * @return a new handle
\r
65 virtual StorageHandle* createHandle()=0;
\r
68 * Creates a new "short" record in the storage service.
\r
70 * @param handle a valid storage handle
\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
\r
73 * @param expiration an expiration timestamp, after which the record can be purged
\r
75 * @throws IOException raised if errors occur in the insertion process
\r
77 virtual void createString(StorageHandle* handle, const char* key, const char* value, time_t expiration)=0;
\r
80 * Returns an existing "short" record from the storage service.
\r
82 * @param handle a valid storage handle
\r
83 * @param key null-terminated unique key of up to 255 bytes
\r
84 * @param value location in which to return the record value
\r
85 * @param modifiedSince the record should not be returned if unmodified since this time,
\r
86 * or 0 to always return
\r
87 * @return true iff the record exists and was returned (based on the modifiedSince value)
\r
89 * @throws IOException raised if errors occur in the read process
\r
91 virtual bool readString(StorageHandle* handle, const char* key, std::string& value, time_t modifiedSince=0)=0;
\r
94 * Updates an existing "short" record in the storage service.
\r
96 * @param handle a valid storage handle
\r
97 * @param key null-terminated unique key of up to 255 bytes
\r
98 * @param value null-terminated value of up to 255 bytes to store, or NULL to leave alone
\r
99 * @param expiration a new expiration timestamp, or 0 to leave alone
\r
100 * @return true iff the record exists and was updated
\r
102 * @throws IOException raised if errors occur in the update process
\r
104 virtual bool updateString(StorageHandle* handle, const char* key, const char* value=NULL, time_t expiration=0)=0;
\r
107 * Deletes an existing "short" record from the storage service.
\r
109 * @param handle a valid storage handle
\r
110 * @param key null-terminated unique key of up to 255 bytes
\r
111 * @return true iff the record existed and was deleted
\r
113 * @throws IOException raised if errors occur in the deletion process
\r
115 virtual bool deleteString(StorageHandle* handle, const char* key)=0;
\r
118 * Creates a new "long" record in the storage service.
\r
120 * @param handle a valid storage handle
\r
121 * @param key null-terminated unique key of up to 255 bytes
\r
122 * @param value null-terminated value of arbitrary length
\r
123 * @param expiration an expiration timestamp, after which the record can be purged
\r
125 * @throws IOException raised if errors occur in the insertion process
\r
127 virtual void createText(StorageHandle* handle, const char* key, const char* value, time_t expiration)=0;
\r
130 * Returns an existing "long" record from the storage service.
\r
132 * @param handle a valid storage handle
\r
133 * @param key null-terminated unique key of up to 255 bytes
\r
134 * @param value location in which to return the record value
\r
135 * @param modifiedSince the record should not be returned if unmodified since this time,
\r
136 * or 0 to always return
\r
137 * @return true iff the record exists and was returned (based on the modifiedSince value)
\r
139 * @throws IOException raised if errors occur in the read process
\r
141 virtual bool readText(StorageHandle* handle, const char* key, std::string& value, time_t modifiedSince=0)=0;
\r
144 * Updates an existing "long" record in the storage service.
\r
146 * @param handle a valid storage handle
\r
147 * @param key null-terminated unique key of up to 255 bytes
\r
148 * @param value null-terminated value of arbitrary length to store, or NULL to leave alone
\r
149 * @param expiration a new expiration timestamp, or 0 to leave alone
\r
150 * @return true iff the record exists and was updated
\r
152 * @throws IOException raised if errors occur in the update process
\r
154 virtual bool updateText(StorageHandle* handle, const char* key, const char* value=NULL, time_t expiration=0)=0;
\r
157 * Deletes an existing "long" record from the storage service.
\r
159 * @param handle a valid storage handle
\r
160 * @param key null-terminated unique key of up to 255 bytes
\r
161 * @return true iff the record existed and was deleted
\r
163 * @throws IOException raised if errors occur in the deletion process
\r
165 virtual bool deleteText(StorageHandle* handle, const char* key)=0;
\r
168 * Manually trigger a cleanup of expired records.
\r
169 * The method <strong>MAY</strong> return without guaranteeing that
\r
170 * cleanup has already occurred.
\r
172 * @param handle a valid storage handle
\r
174 virtual void reap(StorageHandle* handle)=0;
\r
177 StorageService() {}
\r
179 virtual bool isValid(StorageHandle* handle) {
\r
180 return this == (handle ? handle->m_storage : NULL);
\r
185 * Registers StorageService classes into the runtime.
\r
187 void XMLTOOL_API registerStorageServices();
\r
189 /** StorageService based on in-memory caching. */
\r
190 #define MEMORY_STORAGE_SERVICE "org.opensaml.xmlooling.MemoryStorageService"
\r
193 #endif /* __xmltooling_storage_h__ */
\r