Class DbPostAction

java.lang.Object
io.inversion.Rule<A>
io.inversion.Action<DbPostAction>
io.inversion.action.db.DbPostAction
All Implemented Interfaces:
Comparable<DbPostAction>
Direct Known Subclasses:
DbPatchAction, DbPutAction

public class DbPostAction extends Action<DbPostAction>
  • Field Details

    • collapseAll

      protected boolean collapseAll
    • strictRest

      protected boolean strictRest
      When true, forces PUTs to have an resourceKey in the URL
    • getResponse

      protected boolean getResponse
  • Constructor Details

    • DbPostAction

      public DbPostAction()
  • Method Details

    • nextPath

      public static String nextPath(String path, String next)
    • run

      public void run(Request req, Response res) throws ApiException
      Description copied from class: Action
      Override this method with your custom business logic or override one of the http method "doMETHOD" specific handlers.
      Overrides:
      run in class Action<DbPostAction>
      Parameters:
      req - the Request being serviced
      res - the Reponse being generated
      Throws:
      ApiException
    • patch

      public void patch(Request req, Response res) throws ApiException
      Unlike upsert for POST/PUT, this method is specifically NOT recursive for patching nested documents. It will only patch the parent collection/table.

      TODO: add support for JSON Patch format...maybe

      Parameters:
      req - the request to run
      res - the response to populate
      Throws:
      ApiException
    • upsert

      public void upsert(Request req, Response res) throws ApiException
      Throws:
      ApiException
    • upsert

      protected List<String> upsert(Request req, Collection collection, JSArray nodes)
      README README README README

      Algorithm:

      Step 1: Upsert all nodes in this generation...meaning not recursively including key values for all many-to-one foreign keys but excluding all one-to-many and many-to-many key changes...non many-to-one relationships involve modifying other tables that have foreign keys back to this collection's table, not the direct modification of the single table underlying this collection.

      Step 2: For each relationship POST back through the "front door". This is the primary recursion that enables nested documents to submitted all at once by client. Putting this step first ensure that all new objects are POSTed, with their newly created hrefs placed back in the JSON prior to any PUTs that depend on relationship keys to exist.

      Step 3: PKs generated for child documents which are actually relationship parents, are set as foreign keys back on the parent json (which is actually the one-to-many child)

      Step 4: Find the key values for all new/kept one-to-many and many-to-many relationships

      Step 5.1 Upsert all of those new/kept relationships and create the RQL queries needed find all relationships NOT in the upserts.

      Step 5.2 Null out all now invalid many-to-one foreign keys back and delete all now invalid many-to-many relationships rows.

      Parameters:
      req - the request being serviced
      collection - the collection be modified
      nodes - the records to update
      Returns:
      the entity keys of all upserted records
    • isCollapseAll

      public boolean isCollapseAll()
    • withCollapseAll

      public DbPostAction withCollapseAll(boolean collapseAll)
    • isStrictRest

      public boolean isStrictRest()
    • withStrictRest

      public DbPostAction withStrictRest(boolean strictRest)
    • isGetResponse

      public boolean isGetResponse()
    • withGetResponse

      public DbPostAction withGetResponse(boolean expandResponse)
    • collapse

      public static void collapse(JSNode parent, boolean collapseAll, Set collapses, String path)