Armed with information about the VCR and its versions and how they relate together, we can discuss how to modify them. 11.3.1 CHECKOUT and CHECKINIn existing versioning systems, clients frequently check out files before they start editing them, and they check them in again when finished. DeltaV supports a checkin/checkout model because it's common and solves a number of subtle problems. "Check out" and "check in" are widely used phrases that often have different meanings in different software systems. In some versioning systems, when a file is checked out by one user, it cannot be checked out by another user, but in other systems a file can be checked out twice. In some systems, checking out downloads the resource content to the client machine, but in other systems the content is downloaded in a separate operation. At least the order of operations is consistent across versioning systems using this terminology: The client checks out the file, edits it, and then checks it in again. Usually, the checkin operation creates the new version. DeltaV introduces the CHECKOUT and CHECKIN methods. CHECKOUT sets the state of the VCR to checked out, and CHECKIN returns it to the checked-in state and creates a new version. A VCR can only be changed while it is checked out. If the user checks out a resource and then decides not to make changes after all, there must be a way to make the resource checked-in again without creating a new version. This operation is called UNCHECKOUT. If any changes were made while the resource was checked out, these are thrown away as the UNCHECKOUT restores the VCR to the same contents and dead properties of the previous target version. The server returns the VCR to the checked-in state. DeltaV is built on WebDAV, so DeltaV can use the GET, PUT, LOCK, and UNLOCK methods. There's no need to reinvent the functions those methods provide. Thus, CHECKOUT does not download the content of the resource, GET does. CHECKIN does not upload the content of the resource, PUT does. CHECKOUT does not prevent other users from changing a resource because locks already provide that functionality. So what do CHECKOUT and CHECKIN do on their own? There are several functions.
CHECKOUT and CHECKIN are explicit methods that cause the server to perform the requested operation. There are also occasions when the server must perform the same operation automatically. Although we haven't yet discussed what causes an automatic CHECKOUT or CHECKIN operation, the behavior of the operation is identical.
The next sections fill in the details of checking out a resource, editing a checked-out resource, checking it in, and cancelling a checkout. 11.3.2 CHECKOUT and Checked-Out VCRsA CHECKOUT operation changes the state of the VCR from checked-in to checked-out (see Listing 11-3). No new versions are created. When a resource is checked out, it is not locked or downloaded to the client. Those operations are already covered by LOCK and GET methods, and there's no need to overload checkout to include those operations. With this separation of concerns, the client has more flexibility to perform exactly the desired set of operations. When a VCR is checked out, its target version gets a new live property: The checkout-set property of the target version must contain the URL of the VCR that was just checked out. Listing 11-3 CHECKOUT example.CHECKOUT /docs/index.html HTTP/1.1 Host: www.example.com HTTP/1.1 200 OK While a VCR is checked out, the resource may be edited. The contents of the VCR are now independent of any version already created. The changes made on a checked-out VCR do not create a new version; instead, changes are applied to the content and dead properties of the VCR as it currently appears. The VCR content and dead properties were initialized to those of the target version when it was checked out, but they diverge from that version as changes are made and saved. Compare Figure 11-3 with Figure 11-2; when the VCR is checked out, its body can be different from the body of any historical version. Figure 11-3. Checked-out VCR has independent contents from any version.Note that all clients, including other users, can view and modify a checked-out resource normally.
The client that does the CHECKOUT must separately issue a LOCK request to prevent other clients from using PUT, PROPPATCH, or CHECKIN. In the checked-out state, the VCR has different values for some live properties. For example, the getlastmodified property value changes every time a write operation is used. The checked-out property only exists in this state. Its value is an <href> element containing a link to the target version.
11.3.3 Editing a Checked-Out ResourceAfter a successful CHECKOUT operation on a VCR, the client software may issue write requests like PUT and PROPPATCH. The client software may also COPY content from somewhere else, in which case the checked-out VCR's URL is the destination of the COPY method. Listing 11-4 is an example of using PUT to update a checked-out VCR. This request does not create a new version, because the resource isn't checked in yet, but it does modify the VCR's contents and live properties, as if the VCR were a regular resource. Listing 11-4 PUT request to a checked-out VCR and success response.PUT /docs/index.html HTTP/1.1 Host: www.example.com Content-type: text/html Content-length: 11 Hello world HTTP/1.1 204 No Content ETag: "12345-09876"
Client application software can save a temporary copy of the content on the local file system while it is being edited. Every time the user chooses to save the work, the local copy is changed. Only when the user decides to check in does the client issue one PUT request with all the new content, one PROPPATCH request to set the comment property and any other new property values, and finally CHECKIN. In an alternative model, the client may issue a number of PUT operations throughout the editing session. This alternative model can be used in a number of situations:
One way of looking at the DeltaV model is that CHECKOUT and CHECKIN reflect user decisions to start and finish editing the file, whereas GET and PUT are performed whenever the software needs to. When the client sends the CHECKIN request, the server will respond with the URL of the newly created version. 11.3.4 CHECKIN and Checked-In VCRsWhen a checked-out VCR gets a CHECKIN request, it is returned to the checked-in state, and one new version is created (even if no changes were made). The server assigns a new URL for the new version. The body and dead properties of the new version are copied from the VCR at the instant of the CHECKIN, as shown by the large arrows in Figure 11-4. Figure 11-4. State of a resource through checkout, write operation, and checkin.At CHECKIN, the server must remove the checked-out property of the VCR and restore the checked-in property. It must also set the value of the checked-in property on the VCR to point to the newly created version, which makes it the new target version. When the new version is created, the value of the predecessor-set property must be the URL of the version from which it was derived. With the functionality defined so far, the predecessor must be the previous target version. The successor-set property for a new version is empty (but the property should exist). The server assigns a value to the version-name property which is distinct from all other version names in the same version history. CHECKIN also causes some changes to live properties on the previous target version. The URL of the VCR is removed from the checkout-set property, and the successor-set property has a new value added, which is the URL of the new version (Figure 11-5). Figure 11-5. Version relationships.In the response to a CHECKIN request, the server tells the client the location of the newly created version. A successful response status is 201 Created rather than 200 OK, because of the new version created (see Listing 11-5). Listing 11-5 CHECKIN example.CHECKIN /docs/index.html HTTP/1.1 Host: www.example.com HTTP/1.1 201 Created Location: http://www.example.com/his/vers1/32.html Now that the VCR is checked in again, the server must not allow it to be altered. It has the same contents and dead properties as its target version. 11.3.5 UNCHECKOUTUNCHECKOUT takes the VCR from checked-out to checked-in state without creating a new version. The checked-in property is restored to the value it had before, and the checked-out property is removed. Any live properties that were altered on any version (like checkout-set) are restored to the way they were before. The resource content and dead properties are restored to those of the target version. The resource's URL is not affected by UNCHECKOUT. That means if a MOVE operation is applied to a resource while it is checked out, the MOVE operation is not undone when the UNCHECKOUT operation is applied. The UNCHECKOUT operation still restores the original content and dead properties in the new location. |