UrSQL: Data Storage for JavaUrSQL is a persistent storage API for Java Desktop Applications. Unlike other SQL variants, UrSQL doesn't require any kind of server or driver. It's usage is as simple as storing data should be.
Loading a database file is as easy as
UrSQLController controller = new UrSQLController("database.udb");Writing Data to the DatabaseUrSQL stores entries as key value pairs. Groups of entries are called entities, each with a unique numerical ID.
To create a new entity, which will store key-value entries:
UrSQLEntity entity = controller.createEntity();Now, we can create a new entry:
UrSQLEntry entry = new UrSQLEntry("key", "value");This entry now has the key/value pair "key: value". However, we have not specified what entity it belongs to yet. To do so:
entity.addEntry(entry);Now, we can write our entry to the database:
controller.writeEntry(entry);We could also write the entire entity to the database:
controller.writeEntity(entity);Reading Data From the DatabaseUrSQL can search its database for particular entities and entries based on queries containing key/value pairs. For example, the following finds the entity where "key1" has a value of "value1" and "key2" has a value of "value2":
UrSQLEntity entity = controller.getEntity("key1: value1; key2: value2");Notice that the colon (:) is used to separate keys and values, and the semi-colon (;) is used to separate key/value pairs. The spaces after the colon and semicolon are not necessary, but make the code a bit easier to read. Now, you can access individual entries from the entity with their key names:
UrSQLEntry entry = entity.getEntry("key1");The entry object contains the entry's key and value, which can be accessed with:
String key = entry.getKey();
String value = entry.getValue();Or, if you don't want to access an entire entity, you can also access a single entry using a query. This query uses known values in the same entity to search out the correct entry within the correct entity. For example, if we know that an entry with the key "key1" is contained in the same entity as an entry with the key "key2" and value "value2", then we can use the following:
UrSQLEntry entry = controller.getEntry("key1", "key2: value2");Or, the second argument can be the actual UrSQLEntity that houses the desired entry. The entry can then be accessed and changed accordingly. Remember no data is actually written to the database until writeEntry or writeEntity is called by the controller object.