blob: b8a1be8a68d358e11c2bada6540e4311b983ec61 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package net.floodlightcontroller.storage;
19
20import java.util.List;
21import java.util.Map;
22import java.util.Set;
23import java.util.concurrent.Future;
24
25import net.floodlightcontroller.core.module.IFloodlightService;
26
27public interface IStorageSourceService extends IFloodlightService {
28
29 /** Set the column to be used as the primary key for a table. This should
30 * be guaranteed to be unique for all of the rows in the table, although the
31 * storage API does not necessarily enforce this requirement. If no primary
32 * key name is specified for a table then the storage API assumes there is
33 * a column named "id" that is used as the primary key. In this case when
34 * a new row is inserted using the storage API and no id is specified
35 * explictly in the row data, the storage API automatically generates a
36 * unique ID (typically a UUID) for the id column. To work across all
37 * possible implementations of the storage API it is safest, though, to
38 * specify the primary key column explicitly.
39 * FIXME: It's sort of a kludge to have to specify the primary key column
40 * here. Ideally there would be some sort of metadata -- perhaps stored
41 * directly in the table, at least in the NoSQL case -- that the
42 * storage API could query to obtain the primary key info.
43 * @param tableName The name of the table for which we're setting the key
44 * @param primaryKeyName The name of column to be used as the primary key
45 */
46 public void setTablePrimaryKeyName(String tableName, String primaryKeyName);
47
48 /** Create a new table if one does not already exist with the given name.
49 *
50 * @param tableName The name of the table to create.
51 * @param indexedColumns Which columns should be indexed
52 */
53 void createTable(String tableName, Set<String> indexedColumns);
54
55 /**
56 * @return the set of all tables that have been created via createTable
57 */
58 Set<String> getAllTableNames();
59
60 /** Create a query object representing the given query parameters. The query
61 * object can be passed to executeQuery to actually perform the query and obtain
62 * a result set.
63 *
64 * @param tableName The name of the table to query.
65 * @param columnNames The list of columns to return in the result set.
66 * @param predicate The predicate that specifies which rows to return in the result set.
67 * @param ordering Specification of order that rows are returned from the result set
68 * returned from executing the query. If the ordering is null, then rows are returned
69 * in an implementation-specific order.
70 * @return Query object to be passed to executeQuery.
71 */
72 IQuery createQuery(String tableName, String[] columnNames, IPredicate predicate, RowOrdering ordering);
73
74 /** Execute a query created with createQuery.
75 *
76 * @param query The query to execute
77 * @return The result set containing the rows/columns specified in the query.
78 */
79 IResultSet executeQuery(IQuery query);
80
81 /** Execute a query created with the given query parameters.
82 *
83 * @param tableName The name of the table to query.
84 * @param columnNames The list of columns to return in the result set.
85 * @param predicate The predicate that specifies which rows to return in the result set.
86 * @param ordering Specification of order that rows are returned from the result set
87 * returned from executing the query. If the ordering is null, then rows are returned
88 * in an implementation-specific order.
89 * @return The result set containing the rows/columns specified in the query.
90 */
91 IResultSet executeQuery(String tableName, String[] columnNames, IPredicate predicate,
92 RowOrdering ordering);
93
94 /** Execute a query and call the row mapper to map the results to Java objects.
95 *
96 * @param tableName The name of the table to query.
97 * @param columnNames The list of columns to return in the result set.
98 * @param predicate The predicate that specifies which rows to return in the result set.
99 * @param ordering Specification of order that rows are returned from the result set
100 * returned from executing the query. If the ordering is null, then rows are returned
101 * in an implementation-specific order.
102 * @param rowMapper The client-supplied object that maps the data in a row in the result
103 * set to a client object.
104 * @return The result set containing the rows/columns specified in the query.
105 */
106 Object[] executeQuery(String tableName, String[] columnNames, IPredicate predicate,
107 RowOrdering ordering, IRowMapper rowMapper);
108
109 /** Insert a new row in the table with the given column data.
110 * If the primary key is the default value of "id" and is not specified in the
111 * then a unique id will be automatically assigned to the row.
112 * @param tableName The name of the table to which to add the row
113 * @param values The map of column names/values to add to the table.
114 */
115 void insertRow(String tableName, Map<String,Object> values);
116
117 /** Update or insert a list of rows in the table.
118 * The primary key must be included in the map of values for each row.
119 * @param tableName The table to update or insert into
120 * @param values The map of column names/values to update the rows
121 */
122 void updateRows(String tableName, List<Map<String,Object>> rows);
123
124 /** Update the rows in the given table. Any rows matching the predicate
125 * are updated with the column names/values specified in the values map.
126 * (The values map should not contain the special column "id".)
127 * @param tableName The table to update
128 * @param predicate The predicate to use to select which rows to update
129 * @param values The map of column names/values to update the rows.
130 */
131 void updateMatchingRows(String tableName, IPredicate predicate, Map<String,Object> values);
132
133 /** Update or insert a row in the table with the given row key (primary
134 * key) and column names/values. (If the values map contains the special
135 * column "id", its value must match rowId.)
136 * @param tableName The table to update or insert into
137 * @param rowKey The ID (primary key) of the row to update
138 * @param values The map of column names/values to update the rows
139 */
140 void updateRow(String tableName, Object rowKey, Map<String,Object> values);
141
142 /** Update or insert a row in the table with the given column data.
143 * The primary key must be included in the map of values.
144 * @param tableName The table to update or insert into
145 * @param values The map of column names/values to update the rows
146 */
147 void updateRow(String tableName, Map<String,Object> values);
148
149 /** Delete the row with the given primary key.
150 *
151 * @param tableName The table from which to delete the row
152 * @param rowKey The primary key of the row to delete.
153 */
154 void deleteRow(String tableName, Object rowKey);
155
156 /** Delete the rows with the given keys.
157 *
158 * @param tableName The table from which to delete the rows
159 * @param rowKeys The set of primary keys of the rows to delete.
160 */
161 void deleteRows(String tableName, Set<Object> rowKeys);
162
163 /**
164 * Delete the rows that match the predicate
165 * @param tableName
166 * @param predicate
167 */
168 void deleteMatchingRows(String tableName, IPredicate predicate);
169
170 /** Query for a row with the given ID (primary key).
171 *
172 * @param tableName The name of the table to query
173 * @param rowKey The primary key of the row
174 * @return The result set containing the row with the given ID
175 */
176 IResultSet getRow(String tableName, Object rowKey);
177
178 /**
179 * Set exception handler to use for asynchronous operations.
180 * @param exceptionHandler
181 */
182 void setExceptionHandler(IStorageExceptionHandler exceptionHandler);
183
184 /**
185 * Asynchronous variant of executeQuery.
186 *
187 * @param query
188 * @return
189 */
190 public Future<IResultSet> executeQueryAsync(final IQuery query);
191
192 /**
193 * Asynchronous variant of executeQuery.
194 *
195 * @param tableName
196 * @param columnNames
197 * @param predicate
198 * @param ordering
199 * @return
200 */
201 public Future<IResultSet> executeQueryAsync(final String tableName,
202 final String[] columnNames, final IPredicate predicate,
203 final RowOrdering ordering);
204
205 /**
206 * Asynchronous variant of executeQuery
207 *
208 * @param tableName
209 * @param columnNames
210 * @param predicate
211 * @param ordering
212 * @param rowMapper
213 * @return
214 */
215 public Future<Object[]> executeQueryAsync(final String tableName,
216 final String[] columnNames, final IPredicate predicate,
217 final RowOrdering ordering, final IRowMapper rowMapper);
218
219 /**
220 * Asynchronous variant of insertRow.
221 *
222 * @param tableName
223 * @param values
224 * @return
225 */
226 public Future<?> insertRowAsync(final String tableName, final Map<String,Object> values);
227
228 /**
229 * Asynchronous variant of updateRows
230 * @param tableName
231 * @param rows
232 */
233 public Future<?> updateRowsAsync(final String tableName, final List<Map<String,Object>> rows);
234
235 /**
236 * Asynchronous variant of updateMatchingRows
237 *
238 * @param tableName
239 * @param predicate
240 * @param values
241 * @return
242 */
243 public Future<?> updateMatchingRowsAsync(final String tableName, final IPredicate predicate,
244 final Map<String,Object> values);
245
246 /**
247 * Asynchronous variant of updateRow
248 *
249 * @param tableName
250 * @param rowKey
251 * @param values
252 * @return
253 */
254 public Future<?> updateRowAsync(final String tableName, final Object rowKey,
255 final Map<String,Object> values);
256
257 /**
258 * Asynchronous version of updateRow
259 *
260 * @param tableName
261 * @param values
262 * @return
263 */
264 public Future<?> updateRowAsync(final String tableName, final Map<String,Object> values);
265
266 /**
267 * Asynchronous version of deleteRow
268 *
269 * @param tableName
270 * @param rowKey
271 * @return
272 */
273 public Future<?> deleteRowAsync(final String tableName, final Object rowKey);
274
275 /**
276 * Asynchronous version of deleteRows
277 *
278 * @param tableName
279 * @param rowKeys
280 * @return
281 */
282 public Future<?> deleteRowsAsync(final String tableName, final Set<Object> rowKeys);
283
284 /**
285 * Asynchronous version of deleteRows
286 *
287 * @param tableName
288 * @param predicate
289 * @return
290 */
291 public Future<?> deleteMatchingRowsAsync(final String tableName, final IPredicate predicate);
292
293 /**
294 * Asynchronous version of getRow
295 *
296 * @param tableName
297 * @param rowKey
298 * @return
299 */
300 public Future<?> getRowAsync(final String tableName, final Object rowKey);
301
302 /**
303 * Asynchronous version of save
304 *
305 * @param resultSet
306 * @return
307 */
308 public Future<?> saveAsync(final IResultSet resultSet);
309
310 /** Add a listener to the specified table. The listener is called
311 * when any modifications are made to the table. You can add the same
312 * listener instance to multiple tables, since the table name is
313 * included as a parameter in the listener methods.
314 * @param tableName The name of the table to listen for modifications
315 * @param listener The listener instance to call
316 */
317 public void addListener(String tableName, IStorageSourceListener listener);
318
319 /** Remove a listener from the specified table. The listener should
320 * have been previously added to the table with addListener.
321 * @param tableName The name of the table with the listener
322 * @param listener The previously installed listener instance
323 */
324 public void removeListener(String tableName, IStorageSourceListener listener);
325
326 /** This is logically a private method and should not be called by
327 * clients of this interface.
328 * @param notifications the notifications to dispatch
329 */
330 public void notifyListeners(List<StorageSourceNotification> notifications);
331}