Skip to content

Commit 56f1d39

Browse files
committed
Documentation
1 parent a6ced45 commit 56f1d39

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

src/org/labkey/remoteapi/query/SaveRowsApiCommand.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,55 @@
77
import java.util.List;
88
import java.util.Map;
99

10+
/**
11+
* Command for executing multiple data modification operations (insert, update, delete) in a single request
12+
* to a LabKey Server. This command allows batching multiple operations together, optionally in a transaction.
13+
* <p>
14+
* All data exposed from a LabKey Server is organized into schemas containing queries. Each command in a batch
15+
* specifies the schema name (e.g., 'lists' or 'study') and query name (e.g., 'People' or 'Samples') to operate on.
16+
* <p>
17+
* The command supports several features:
18+
* <ul>
19+
* <li>Multiple operations (insert, update, delete) in a single request</li>
20+
* <li>Optional transaction support to ensure all-or-nothing execution</li>
21+
* <li>Validation-only mode to check operations without making changes</li>
22+
* <li>Audit trail support with configurable detail levels</li>
23+
* <li>Custom audit comments for tracking changes</li>
24+
* </ul>
25+
* <p>
26+
* Example usage:
27+
* <pre><code>
28+
* ApiKeyCredentialsProvider credentials = new ApiKeyCredentialsProvider("xxx");
29+
* Connection conn = new Connection("http://localhost:8080", credentials);
30+
* SaveRowsApiCommand saveCmd = new SaveRowsApiCommand();
31+
*
32+
* // Add new gene annotations
33+
* saveCmd.addCommand(new Command(CommandType.Insert, "genome", "GeneAnnotations",
34+
* List.of(
35+
* Map.of("name", "p53 binding site", "geneName", "TP53", "start", 1000, "end", 1020),
36+
* Map.of("name", "TATA box", "geneName", "BRCA1", "start", 2500, "end", 2506)
37+
* )));
38+
*
39+
* // Update annotation positions
40+
* Command updateCmd = new Command(CommandType.Update, "genome", "GeneAnnotations",
41+
* List.of(Map.of(
42+
* "name", "Promoter region",
43+
* "geneName", "EGFR",
44+
* "start", 5000,
45+
* "end", 5500
46+
* )));
47+
* updateCmd.setAuditBehavior(SaveRowsCommand.AuditBehavior.DETAILED);
48+
* updateCmd.setAuditUserComment("Updated promoter region coordinates based on new assembly");
49+
* saveCmd.addCommand(updateCmd);
50+
*
51+
* // Delete obsolete annotation
52+
* saveCmd.addCommand(new Command(CommandType.Delete, "genome", "GeneAnnotations",
53+
* List.of(Map.of("name", "Putative enhancer", "geneName", "MYC"))));
54+
*
55+
* // Execute all commands in a transaction
56+
* SaveRowsApiResponse response = saveCmd.execute(conn, "GenomeProject");
57+
* </code></pre>
58+
*/
1059
public class SaveRowsApiCommand extends PostCommand<SaveRowsApiResponse>
1160
{
1261
private final List<Command> _commands = new ArrayList<>();

src/org/labkey/remoteapi/query/SaveRowsApiResponse.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,59 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12+
/**
13+
* Response object for the {@link SaveRowsApiCommand}, containing results of batch operations executed on the server.
14+
* This response provides details about the success or failure of each command in the batch, including:
15+
* <ul>
16+
* <li>Whether the transaction was committed</li>
17+
* <li>Number of errors encountered</li>
18+
* <li>Detailed results for each command executed</li>
19+
* </ul>
20+
* <p>
21+
* Example usage:
22+
* <pre><code>
23+
* SaveRowsApiCommand cmd = new SaveRowsApiCommand();
24+
* // Add commands to insert/update/delete gene annotations...
25+
* SaveRowsApiResponse response = cmd.execute(connection, "GenomeProject");
26+
*
27+
* if (response.isCommitted())
28+
* {
29+
* for (SaveRowsApiResponse.Result result : response.getResults())
30+
* {
31+
* System.out.println(String.format(
32+
* "%s operation affected %d rows in %s.%s",
33+
* result.getCommand(),
34+
* result.getRowsAffected(),
35+
* result.getSchemaName(),
36+
* result.getQueryName()
37+
* ));
38+
*
39+
* // For detailed examination of affected rows
40+
* for (Map<String, Object> row : result.getRows())
41+
* {
42+
* System.out.println(String.format(
43+
* "Gene %s annotation at position %d-%d",
44+
* row.get("geneName"),
45+
* row.get("start"),
46+
* row.get("end")
47+
* ));
48+
* }
49+
*
50+
* // Check if operation was audited
51+
* if (result.getTransactionAuditId() > 0)
52+
* {
53+
* System.out.println("Audit record created with ID: " +
54+
* result.getTransactionAuditId());
55+
* }
56+
* }
57+
* }
58+
* else
59+
* {
60+
* System.out.println("Transaction failed with " +
61+
* response.getErrorCount() + " errors");
62+
* }
63+
* </code></pre>
64+
*/
1265
public class SaveRowsApiResponse extends CommandResponse
1366
{
1467
private final boolean _committed;

src/org/labkey/remoteapi/test/SaveRowsApiDemo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ public class SaveRowsApiDemo
2222
{
2323
public static void main(String[] args) throws Exception
2424
{
25-
String folderPath = "SaveRowsCommandDemo";
25+
String folderPath = "SaveRowsApiDemo";
2626
String schemaName = "lists";
2727
String queryName = "Players";
2828

29+
// Furnish your own API key
2930
ApiKeyCredentialsProvider credentials = new ApiKeyCredentialsProvider("xxx");
3031
Connection conn = new Connection("http://localhost:8080", credentials);
3132

0 commit comments

Comments
 (0)