Controling multiuser environment

X-Application Version: 4.1.1, 3.1.3
Tamino Version : 4.1.1, 3.1
Platform : Win2k,
WebContainer : Tomcat 4.1.18
JDK Version : 1.4.1

Hi everybody…

I have a xapplication development with multiuser environment that I have a problem with the ensure the consistency of documents.

T1 : User A get the Document1 with timestamp 2003-09-22T09:01:29
T1+1 :User B get the same document1 with timestamp 2003-09-22T09:01:29

In the view.jsp I display this timestamp with the follow scriplet code :

<%
SessionContext sessionContext = ServletSessionContext.getSessionContext(pageContext);
BusinessDocument document = sessionContext.getDocument(“documentoDocument”);
NodeLocation documentnodeloc = document.getNodeLocation();
out.print(getLastUpdateTime(documento,documentnodeloc));
%>

T3 : User B modify the document1. In the view.jsp page display 2003-09-22T09:05:18
T3 : User A refresh the view.jsp and display the timestamp 2003-09-22T09:01:29

T4 : User A try to modify the document1 and receive a error of document’s consistency because He gets the document timestamp 2003-09-22T09:01:29 and this one is distint that the lastmodified timestamp of the document1 : 2003-09-22T09:05:18

NOTE : I will try controle this one comparing the both timestamp when the user will try to modify the document (when he click the modify buttom I will validate the timestamps, if are distint the user must refresh the document with the new information of TAMINO store)


My questions are :
1.- How I controling the best way of consistency with a multiuser environment…? and
2.- How I get the lastmodified timestamp from TAMINO with Xapp-API?

NOTE 2 : With the NodeLocation Object I can get the store object asociate to this one… In the TaminoStoreV4 has a method for get the lastmodified timestamps but … I don’t know how generate the TXMLObject of the root document… (Please I need any example for this one…)


I could get the lastmodified timestamp with the follow xquery statement (but I want to make this with Xapp_API):

declare namespace tf = “http://namespaces.softwareag.com/tamino/TaminoFunction
declare namespace itf = “http://namespaces.softwareag.com/tamino/InternalTaminoFunction
declare namespace xapp = “404
for $wrapper in input()/documento
where tf:getInoId($wrapper)=3
return element xapp:Result { element xapp:NodeLocation {attribute id {tf:getInoId($wrapper)}, attribute nodeId {itf:getNodeId($wrapper)}, element doctype{itf:getDoctype($wrapper)}, element collection{tf:getCollection($wrapper)}, element timestamp{tf:getLastModified(root($wrapper))}} , element xapp:Body {$wrapper}}

Thanks in advance … and I will be welcome any help and suggestions…


MTP

Hello,

X-Application uses the timestamp as meta-information for implementing the optimistic locking mechanism for XML documents. If you sent a query by an xapp:action tag with type=query, your XQuery expression will be wrapped by X-Application. The reason for the wrapping is to get meta-information as timestamp, ino-id, doctype, etc.

For you request to control when a document has to be refreshed. I would propose a plug-in. With the plug-in you could overwrite the standard method that is invoked by the ‘modify’ action. Before invoking the standard behavior (setting the document state to the ‘modify’ mode) you could check the timestamp with the current timestamp of the document.

How to get the timestamp?

(1) Your plug-in requires the ‘workspace’
(2) Your plug-in requires the current document

The code could look like this:

public static void myModify(BusinessDocumentWorksapce ws, BusinessDocument doc) {
    TaminoStore store = (TaminoStore)ws.getStore();
    String timestamp = store.getLastUpdateTime(document.getDomTree(), document.getNodeLocation());
    if (!timestamp.equals(document.getNodeLocation().getTimestamp())) {
        // your code
    } else if (doc.getState() != BusinessDocument.MODIFIABLE) {
        doc.modify();    
    }
}



Before starting with the plug-in you should read the chapter ‘Plug-ins’ of the X-Application documentation.

Bye,
Christian.