diff --git a/java/lc-esp-eo-engine/src/main/java/lc/esp/eo/EOTransaction.java b/java/lc-esp-eo-engine/src/main/java/lc/esp/eo/EOTransaction.java index 253f3df7eeb101fbe2a2ba6a79ee91055efa3b17..762d0d0bc2cd3bd3edc71b364c34119fd617405a 100644 --- a/java/lc-esp-eo-engine/src/main/java/lc/esp/eo/EOTransaction.java +++ b/java/lc-esp-eo-engine/src/main/java/lc/esp/eo/EOTransaction.java @@ -77,19 +77,29 @@ public class EOTransaction implements AutoCloseable { shardByKey(COLLECTION_CHUNKS, KEY_ID); } + /** + * Shard the given collection to the given key using a hashed strategy. This call is asynchronous and may return + * before all of the shards have been updated. + */ private void shardByKey(String collectionName, String keyName) { String path = databaseName + "." + collectionName; MongoDatabase adminDb = client.getDatabase("admin"); Document cmd = new Document("shardCollection", path).append("key", new Document(keyName, "hashed")); Document response = adminDb.runCommand(cmd); logger.info("shardBykey: {}", response); - // TODO: Wait for `db.collection.getShardDistribution()` + // TODO: Wait for `db.collection.getShardDistribution()`? } + /** + * Create an object of the given type and return the newly created id. + */ public EOId objCreate(String type) { return objCreate(type, null); } + /** + * Create a new object of the given type, with the given user-defined data. + */ public EOId objCreate(String type, Map values) { // FIXME: Returning ObjectId here is a leaky abstraction assert (type != null); @@ -102,6 +112,9 @@ public class EOTransaction implements AutoCloseable { return id == null ? null : new EOBsonId(id); } + /** + * Create an association between the source and destination objects of the given type. + */ public String assocCreate(EOId srcObjectId, EOId dstObjectId, String type) { return assocCreate(srcObjectId, dstObjectId, type, null); } @@ -128,7 +141,7 @@ public class EOTransaction implements AutoCloseable { } /** - * Return a count of the associations originationg from the given source object of the given type. + * Return a count of the associations originating from the given source object of the given type. */ public long assocCount(EOId srcObjectId, String type) { MongoCollection col = db.getCollection(COLLECTION_ASSOC); @@ -137,6 +150,10 @@ public class EOTransaction implements AutoCloseable { .append(KEY_TYPE, type)); } + /** + * Read a given object and return it to the caller in the form of an {@link EO}. Reading the object will not + * query the underlying associations, so only the id, type, and any user-defined data is returned. + */ public EO objRead(EOId id) { MongoCollection col = db.getCollection(COLLECTION_OBJ); BasicDBObject query = new BasicDBObject(); @@ -154,7 +171,11 @@ public class EOTransaction implements AutoCloseable { return eo; } + /** + * Delete the given object. + */ public void objDelete(EOId id) { + // TODO: Implement association delete MongoCollection col = db.getCollection(COLLECTION_OBJ); col.deleteOne(session, new Document().append("_id", ((EOBsonId) id).getObjectId())); } @@ -201,6 +222,9 @@ public class EOTransaction implements AutoCloseable { assocCreate(newId, parentId, TYPE_FS_LINK, Map.of(KEY_FS_FILENAME, "..")); } + /** + * Commit the current transaction, and begin a new one. + */ public void commit() { session.commitTransaction(); pendingFiles = null; @@ -229,6 +253,10 @@ public class EOTransaction implements AutoCloseable { session.startTransaction(); } + /** + * Close the given transaction and free any associated resources. If the transaction had pending changes, it will + * be rolled back. + */ @Override public void close() { rollback();