gpt4 book ai didi

xpages - 在 xPages 中处理文档锁定的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-01 14:45:35 26 4
gpt4 key购买 nike

在 xPages 中处理文档锁定的最佳方法是什么?目前我们使用标准的软锁定,它似乎在 Notes 客户端中运行良好。

在 xPages 中,我考虑使用“允许文档锁定”功能,但我担心人们会在不使用关闭或保存按钮的情况下关闭浏览器,然后锁定将永远不会被清除。

当用户关闭 session 时,有没有办法清除锁定?我没有看到这样的事件。

或者有没有更简单的方法来锁定文档?

我意识到我可以使用代理清除锁,但是什么时候运行呢?我会想某个晚上的某个时候,我相当肯定锁应该不再真正处于事件状态。

最佳答案

这是我正在使用的代码:

/* DOCUMENT LOCKING */
/*

use the global object "documentLocking" with:
.lock(doc) -> locks a document
.unlock(doc) -> unlocks a document
.isLocked(doc) -> returns true/false
.lockedBy(doc) -> returns name of lock holder
.lockedDT(doc) -> returns datetime stamp of lock

*/
function ynDocumentLocking() {

/*

a lock is an entry in the application scope

with key = "$ynlock_"+UNID

containing an array with
(0) = username of lock holder
(1) = timestamp of lock


*/

var lockMaxAge = 60 * 120; // in seconds, default 120 min

this.getUNID = function(v) {
if (!v) return null;
if (typeof v == "NotesXspDocument") return v.getDocument().getUniversalID();
if (typeof v == "string") return v;
return v.getUniversalID();
}

/* puts a lock into application scope */
this.lock = function(doc:NotesDocument) {
var a = new Array(1);
a[0] = @UserName();
a[1] = @Now();
applicationScope.put("$ynlock_"+this.getUNID(doc), a);
// print("SET LOCK "+"$ynlock_"+doc.getUniversalID()+" / "+a[0]+" / "+a[1]);
}

/* removes a lock from the application scope */
this.unlock = function(doc:NotesDocument) {
applicationScope.put("$ynlock_"+this.getUNID(doc), null);
//print("REMOVED LOCK for "+"$ynlock_"+doc.getUniversalID());
}

this.isLocked = function(doc:NotesDocument) {
try {
//print("ISLOCKED for "+"$ynlock_"+doc.getUniversalID());

// check how old the lock is
var v = applicationScope.get("$ynlock_"+this.getUNID(doc));
if (!v) {
//print("no lock found -> return false");
return false;
}

// if lock holder is the current user, treat as not locked
if (v[0] == @UserName()) {
//print("lock holder = user -> not locked");
return false;
}


var dLock:NotesDateTime = session.createDateTime(v[1]);
var dNow:NotesDateTime = session.createDateTime(@Now());
// diff is in seconds
//print("time diff="+dNow.timeDifference(dLock)+" dLock="+v[1]+" now="+@Now());
// if diff > x seconds then remove lock, it not locked
if (dNow.timeDifference(dLock) > lockMaxAge) {
// print("LOCK is older than maxAge "+lockMaxAge+" -> returning false");
return false;
}
//print("return true");
return true;
// TODO: check how old the lock is
} catch (e) {
print("ynDocumentLocking.isLocked: "+e);
}

}

this.lockedBy = function(doc:NotesDocument) {
try {
var v = applicationScope.get("$ynlock_"+this.getUNID(doc));
if (!v) return "";
//print("ISLOCKEDBY "+"$ynlock_"+doc.getUniversalID()+" = "+v[0]);
return v[0];

} catch (e) {
print("ynDocumentLocking.isLockedBy: "+e);
}
}

this.lockedDT = function(doc:NotesDocument) {
try {
var v = applicationScope.get("$ynlock_"+this.getUNID(doc));
if (!v) return "";
return v[1];

} catch (e) {
print("ynDocumentLocking.isLockedBy: "+e);
}
}

}

var documentLocking = new ynDocumentLocking();

关于xpages - 在 xPages 中处理文档锁定的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10882925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com