|
| 1 | +package net.b07z.sepia.server.core.database; |
| 2 | + |
| 3 | +import org.json.simple.JSONObject; |
| 4 | + |
| 5 | +/** |
| 6 | + * Interface for classes that supply database access. First and foremost this is meant to be an interface for Elasticsearch (and not DynamoDB, but feel free ...). |
| 7 | + * |
| 8 | + * @author Florian Quirin |
| 9 | + * |
| 10 | + */ |
| 11 | +public interface DatabaseInterface { |
| 12 | + |
| 13 | + /** |
| 14 | + * Set the data/properties/values of an item of "type" at "index". |
| 15 | + * @param index - index or table name like e.g. "account" or "knowledge" |
| 16 | + * @param type - subclass name, e.g. "user", "lists", "banking" (for account) or "geodata" and "dictionary" (for knowledge) |
| 17 | + * @param item_id - unique item/id name, e.g. user email address, dictionary word or geodata location name |
| 18 | + * @param data - JSON string with data objects that should be stored for index/type/item, e.g. {"name":"john"} |
| 19 | + * @return error code indicating success (0) or different errors (1 - database not reached) etc. ... |
| 20 | + */ |
| 21 | + public int setItemData(String index, String type, String item_id, JSONObject data); |
| 22 | + |
| 23 | + /** |
| 24 | + * Set the data/properties/values of an arbitrary item of "type" at "index". Use this if you don't care about the unique id like |
| 25 | + * when you store blog posts. The item id will be generated automatically. |
| 26 | + * @param index - index or table name like e.g. "homepage" |
| 27 | + * @param type - subclass name, e.g. "blogpost" |
| 28 | + * @param data - JSON string with data objects that should be stored for index/type/any_id, e.g. {"title":"Hot News", "body":"bla bla...", "author":"john james"} |
| 29 | + * @return JSON with "_id" of created doc and error "code" indicating success (0) or different errors (1 - database not reached) etc. ... |
| 30 | + */ |
| 31 | + public JSONObject setAnyItemData(String index, String type, JSONObject data); |
| 32 | + |
| 33 | + /** |
| 34 | + * Get item at path "index/type/item_id" |
| 35 | + * @param index - index or table name like e.g. "account" or "knowledge" |
| 36 | + * @param type - subclass name, e.g. "user", "lists", "banking" (for account) or "geodata" and "dictionary" (for knowledge) |
| 37 | + * @param item_id - unique item/id name, e.g. user email address, dictionary word or geodata location name |
| 38 | + * @return JSONObject with result or error description |
| 39 | + */ |
| 40 | + public JSONObject getItem(String index, String type, String item_id); |
| 41 | + |
| 42 | + /** |
| 43 | + * Get filtered entries of the item at path "index/type/item_id". Use this if you want for example only a user name or something. |
| 44 | + * @param index - index or table name like e.g. "account" or "knowledge" |
| 45 | + * @param type - subclass name, e.g. "user", "lists", "banking" (for account) or "geodata" and "dictionary" (for knowledge) |
| 46 | + * @param item_id - unique item/id name, e.g. user email address, dictionary word or geodata location name |
| 47 | + * @param filters - String array with filters like ["name", "address", "language", "age"] |
| 48 | + * @return JSONObject with result or error description |
| 49 | + */ |
| 50 | + public JSONObject getItemFiltered(String index, String type, String item_id, String[] filters); |
| 51 | + |
| 52 | + /** |
| 53 | + * Update or create the data/properties/values of an item of "type" at "index". |
| 54 | + * @param index - index or table name like e.g. "account" or "knowledge" |
| 55 | + * @param type - subclass name, e.g. "user", "lists", "banking" (for account) or "geodata" and "dictionary" (for knowledge) |
| 56 | + * @param item_id - unique item/id name, e.g. user email address, dictionary word or geodata location name |
| 57 | + * @param data - JSON string with data objects that should be stored for index/type/item, e.g. {"name":"john"} |
| 58 | + * @return error code indicating success (0) or different errors (1 - database not reached) etc. ... |
| 59 | + */ |
| 60 | + public int updateItemData(String index, String type, String item_id, JSONObject data); |
| 61 | + |
| 62 | + /** |
| 63 | + * Search at "path" for a keyword. |
| 64 | + * @param path - can be index, type or item, e.g. "index/type/item_id" or only "index/" |
| 65 | + * @param search_term - something to search like "name:John" or simply "John" or "*" for all. |
| 66 | + * @return JSONObject with search result or error description |
| 67 | + */ |
| 68 | + public JSONObject searchSimple(String path, String search_term); |
| 69 | + |
| 70 | + /** |
| 71 | + * Search at "path" for something via a query in JSON format |
| 72 | + * @param path - can be index, type or item, e.g. "index/type/item_id" or only "index/" |
| 73 | + * @param jsonQuery - query as JSON string |
| 74 | + * @return JSONObject with search result or error description |
| 75 | + */ |
| 76 | + public JSONObject searchByJson(String path, String jsonQuery); |
| 77 | + |
| 78 | + /** |
| 79 | + * Delete item of "type" at "index". |
| 80 | + * @param index - index or table name like e.g. "account" |
| 81 | + * @param type - subclass name, e.g. "user" |
| 82 | + * @param item_id - item to delete, e.g. a user_id (email) |
| 83 | + * @return error code indicating success (0) or different errors (1 - database not reached) etc. ... |
| 84 | + */ |
| 85 | + public int deleteItem(String index, String type, String item_id); |
| 86 | + |
| 87 | + /** |
| 88 | + * Delete any object like "index" (with all entries), "type" or "item" |
| 89 | + * @param path - path of what you want to delete like "account/" or "account/banking/" |
| 90 | + * @return error code indicating success (0) or different errors (1 - database not reached) etc. ... |
| 91 | + */ |
| 92 | + public int deleteAnything(String path); |
| 93 | + |
| 94 | + /** |
| 95 | + * Search at "path" for something via a query in JSON format and if it exists delete it. |
| 96 | + * @param path - can be index, type or item, e.g. "index/type/item_id" or only "index/" |
| 97 | + * @param jsonQuery - query as JSON string |
| 98 | + * @return JSONObject with delete result or error description |
| 99 | + */ |
| 100 | + public JSONObject deleteByJson(String path, String jsonQuery); |
| 101 | + |
| 102 | +} |
0 commit comments