Beruflich Dokumente
Kultur Dokumente
A Guide to Document
Locking in Notes/Domino 6
James Ray
Native Notes/Domino
Document Locking
Bonus Information
As a bonus, the Document Locking Demo database
(doclockd.nsf at www.eVIEW.com) includes these
useful libraries not mentioned in the article:
GetQueryStringArgument Parses the
query string argument from the query_string
CGI variable.
libAgentLoggingClassV2 A LotusScript
library that contains a user-defined class to perform logging of agent execution. Used in the
LockDecay agent.
libDocLocking LotusScript library where the
bulk of document locking code is kept.
www.eVIEW.com
Note!
Users with Manager access must be careful when
exercising their authority to unlock a database
document. If they edit the document, they could
cause a conflict condition.
http://www-10.lotus.com/ldd/notesua.nsf/find/inside-notes
www.eVIEW.com
Scenario 2 Demonstrating
Persistent-Temporary Locks
Scenario 2 is very similar to scenario 1 in that the
target database is either on or can communicate
readily with the master lock server. In this case,
the user is attempting to edit a document without
manually requesting to lock the document first.
As soon as the user attempts to open the document
in edit mode through the UI, Domino communicates
with the master lock server and determines
whether the user is allowed to lock the document.
If the user is allowed to lock the document and if
the document is available for locking, the master
lock server places a persistent lock on the document.
However, this persistent lock is only temporary;
it will be removed after the user closes the
document in the UI.
A persistent-temporary lock is considered safe, as
it ensures no one else has the document locked while
Tip!
It is a good idea to design UIs (forms and views)
so that end users know the status of a document.
A simple computed text label on the form suffices
to indicate the current lock status of the document being edited.
Scenario 3 Demonstrating
Provisional Locks
Best Practices
Figure 1
www.eVIEW.com
Figure 2
Scenario 4 Demonstrating
Provisional-Temporary Locks
Figure 3
Figure 4
Figure 5
10
Figure 6
www.eVIEW.com
Lock Promotion
As youve seen, the persistent lock is the only type
of lock that is safe for allowing users to begin editing
documents. Provisional and provisional-temporary
locks are not intrinsically safe for allowing users to
make edits, because these lock types allow race
conditions to occur and could result in data loss.
The whole idea behind provisional and provisionaltemporary locks is that, when the master lock server
becomes available, they may or may not be promoted
to persistent locks.
If a user creates a provisional or provisionaltemporary lock on a document, the database replica
must communicate with the master lock server and
Figure 7
Lock Types
Scenario
Lock Type
Persistent
Available
Manual/Menu
Yes
Persistent-Temporary
Available
Provisional
Unavailable
Manual/Menu
Provisional-Temporary
Unavailable
5a
Provisional
Note: An argument
may be passed to
allow/disallow locks
Unavailable
Programmatic LotusScript
or Java code
No
5b
None
Unavailable
No
Figure 8
No
A provisional lock in database <YourDatabaseHere> has NOT been promoted to a hard lock. There was a
conflict detected. Your changes may be found in the body of this message. A document link to the original
document is attached to the end of the message.
11
Figure 9
Changes made to the database <YourDatabaseHere> have NOT been incorporated into the database. There
was a conflict detected. Your changes may be found in body of this message. A document link to the original
document is attached to the end of the message.
12
www.eVIEW.com
Note!
You can use replication to trigger and synchronize
document locking, but you should not expect Notes
replication to always report that changes were
replicated.
Into Practice
Now that youve seen what the Notes/Domino
document-locking implementation is all about, its
time to get practical. Next, we turn to setup and administration and then to programming document locking.
13
Figure 10
Figure 11
14
www.eVIEW.com
Important!
Make sure that the defined master lock server
has a replica of the database. As you saw, if
there is no replica on the master lock server,
only provisional locks will be created and users
will never be able to unlock documents regardless of whether the master lock server is available to the client.
15
Programming Notes/Domino 6
Document Locking in the
Notes Client
Since Lotus Notes/Domino version 6.0, programmers
have been able to use the Notes formula and
LotusScript languages to code solutions with document
locking. Java coding for document locking came with
the release of Notes/Domino 6.5. In the demonstration
database that accompanies this article, I provide
examples written in all three languages.
One of the most important aspects of programming
document locking is to provide an interface to allow
users to know the status of locked and unlocked
documents. Figure 12 shows you the view called
1. Main , which is one of the views in the demonstration database. This view displays the lock status
of documents. The first column of the view contains
a red or green icon to indicate document lock statuses
(red for locked, green for unlocked). In fact, users
can click on this status icon to trigger the document to
attempt document locking or unlocking. Documents
highlighted in red (dark gray) are persistently locked;
documents highlighted in yellow (light gray) are
provisionally locked.
To create this view, I used two view features
that are new in Notes/Domino 6: row custom color
Figure 12
16
www.eVIEW.com
Figure 13
red := 255:0:0;
white := 255:255:255;
yellow := 255:255:0;
black := 1:1:1;
plain:= 0:0:0;
@If(@IsAvailable($Writers); red:white;
@IsAvailable($PWriters) | @IsAvailable($PTWriters); yellow:black;
white:plain)
Figure 14
17
Figure 14 (continued)
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
REM Reserved - do not use for release 6.0
Case VALIDATE_REQUEST
REM Not used for icon columns
Case SAVE_REQUEST
REM Toggle document locks
Call toggleLock(doc)
Case NEWENTRY_REQUEST
End Select
End Sub
18
www.eVIEW.com
Figure 15
19
Figure 16
20
www.eVIEW.com
Figure 17
Figure 18
Sub Initialize
On Error Goto ErrorHandler
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim strUNID As String, strWebDbName As String
Dim varRet As Variant
Dim nnn As NotesName
varRet = Evaluate("@WebDBName")
strWebDbName = Cstr(varRet(0))
Set db = s.CurrentDatabase
Set doc = s.DocumentContext
strUNID = Left(GetQueryStringArgument(doc),32)
Set view = db.GetView("allbyunid")
Set doc = view.GetDocumentByKey(strUNID,True)
Call doc.unlock
If doc.LockHolders(0) = "" Then
Print |
<script>
//alert("Check-in failed, you do not have permission to unlock the document.");
top.location = "/| & strWebDbName & |";
</script>
(continues on next page)
21
Figure 18 (continued)
|
Else
End If
ExitGracefully:
Exit Sub
ErrorHandler:
If Error$ = "Notes error: The document is not locked by you" Then
Set nnn = New NotesName(doc.LockHolders(0))
Print |
<script>
alert("Check-in failed, The document is currently locked by | & nnn.Abbreviated & |. You do not have permission to unlock the document.");
top.location = "/| & strWebDbName & |";
</script>
|
Else
Print "***Error: " & Str(Err) & " : " & Error$
End If
Resume ExitGracefully
End Sub
22
Lock Decay
Document locking raises the possibility of forgotten
locked documents. If a document is locked by an end
user and he or she neglects to act on it or unlock it in
a timely manner, then other users continue to be
restricted from editing the locked document and the
document is considered to be stagnant. This situation
can lead to database managers receiving late-night
requests to manually unlock stranded locked documents.
www.eVIEW.com
Figure 19
It may also be worthwhile to monitor the lastmodified property of the document to help determine
when a document entered a stagnant state.
23
Figure 20
Setting
Definition
Indicates the time that must pass after a document is locked before it can
be decayed
Last Modified Decay (#, Unit) Indicates the time that must pass after a document is modified before the lock
can be decayed
Send Message
Message Text
Include DocLink
Decay Users
Roles
Indicates what roles this profile should apply to (if roles have been selected)
Weight
Indicates the weighted value for this document (used to determine the configuration
document whose settings should be used when there are multiple Lock Decay
Config documents)
24
www.eVIEW.com
Figure 21
Figure 22
25
Figure 23
26
www.eVIEW.com
Figure 24
Figure 25
27
Figure 25 (continued)
strMsg = cfgdoc.txtMsg(0)
Set memo = db.CreateDocument
memo.SendTo = strWho
memo.Subject = "Your document has been decayed."
Set rti = New NotesRichTextItem(memo, "Body" )
Call rti.AppendText(strMsg)
Call rti.AddNewline(1, True)
If cfgdoc.radLink(0) = "1" Then
Call rti.AppendDocLink(lockdoc, "Previous Locked Document")
End If
Call memo.send (False)
End If
End Function
28
www.eVIEW.com
Figure 26
Figure 27 Dialog for Editing a Design Note When the Master Lock Server Is Unavailable
29
Figure 28
Figure 29
Figure 30
Scenario
Outcome
R5 client trying
to edit a locked
document
Notes/Domino 6
client trying to
edit a document
on an R5 server
Best Practices
In this section, I gather up the recommendations and
best practices for document locking that were provided
30
See http://www-1.ibm.com/support/
docview.wss?rs=0&q=7003259&uid=swg27003259
www.eVIEW.com
Notes/Domino 6 Document
Locking and Design Locking
in a Nutshell
Document locking comes built-in with Lotus
Notes/Domino version 6.0 and above. Out-of-the-box
functionality requires no additional development and
provides a clean solution for record locking in a Lotus
Notes client environment provided that the master
lock server is readily available for replication and
NRPC communication with clients and other servers.
To use document or design locking, the master lock
server must have a replica of the database.
Lotus provides programmability of document
locking using the Notes formula and LotusScript
31
32
www.eVIEW.com