Skip to content

Commit

Permalink
Merge pull request #173 from gchq/169-improve-the-magmacoreservice
Browse files Browse the repository at this point in the history
169 Improve the MagmaCoreService API
  • Loading branch information
GCHQDeveloper42 authored Jan 25, 2024
2 parents 5de974d + 4b2c7e8 commit 979f6e9
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@

/**
* Service for interacting with a {@link MagmaCoreDatabase}.
*
* <p>
* Note that Transaction control is manual unless using any of the following:
* </p>
* <ol>
* <li>getInTransaction()</li>
* <li>runInReadTransaction()</li>
* <li>runInWriteTransaction()</li>
* <li>exportTtl()</li>
* <li>importTtl()</li>
* <li>verifyModel()</li>
* </ol>
* <p>
* Nested transactions are not supported so ensure that no transaction is in progress before
* using any of the above methods.
* </p>
*/
public class MagmaCoreService {

Expand Down Expand Up @@ -675,6 +691,24 @@ public void create(final Thing thing) {
database.create(thing);
}

/**
* Delete an entity from the collection.
*
* @param object Entity to delete.
*/
void delete(final Thing object) {
database.delete(object);
}

/**
* Apply a set of deletes to the database.
*
* @param deletes a {@link List} of {@link DbDeleteOperation}
*/
void delete(final List<DbDeleteOperation> deletes) {
database.delete(deletes);
}

/**
* Convert a {@link Collection} of {@link Thing} objects to a {@link DbTransformation} that can be
* used to persist them. Typically this should be followed by a call to `runInTransaction`.
Expand Down Expand Up @@ -843,6 +877,35 @@ public List<Thing> verifyModel() {
return DataIntegrityReport.verify(database);
}

/**
* Start a transaction in READ mode.
*/
void beginRead() {
database.beginRead();
}

/**
* Start a transaction in Write mode.
*/
void beginWrite() {
database.beginWrite();
}

/**
* Commit a transaction - Finish the current transaction and make any changes permanent (if a
* "write" transaction).
*/
void commit() {
database.commit();
}

/**
* Abort a transaction - Finish the transaction and undo any changes (if a "write" transaction).
*/
void abort() {
database.abort();
}

/**
* Execute a SELECT query.
*
Expand Down

0 comments on commit 979f6e9

Please sign in to comment.