org.nuxeo.ecm.core.api.Lock类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(281)

本文整理了Java中org.nuxeo.ecm.core.api.Lock类的一些代码示例,展示了Lock类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lock类的具体详情如下:
包路径:org.nuxeo.ecm.core.api.Lock
类名称:Lock

Lock介绍

[英]Information about a lock set on a document.

The lock information holds the owner, which is a user id, and the lock creation time.
[中]有关文档上的锁集的信息。
锁信息保存所有者(即用户id)和锁创建时间。

代码示例

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

  1. protected String stringFromLock(Lock lock) {
  2. if (lock == null) {
  3. throw new NullPointerException("null lock");
  4. }
  5. return lock.getOwner() + ":" + lock.getCreated().getTimeInMillis();
  6. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-mem

  1. @Override
  2. public synchronized Lock setLock(String id, Lock lock) {
  3. State state = states.get(id);
  4. if (state == null) {
  5. // document not found
  6. throw new DocumentNotFoundException(id);
  7. }
  8. String owner = (String) state.get(KEY_LOCK_OWNER);
  9. if (owner != null) {
  10. // return old lock
  11. Calendar created = (Calendar) state.get(KEY_LOCK_CREATED);
  12. return new Lock(owner, created);
  13. }
  14. state.put(KEY_LOCK_OWNER, lock.getOwner());
  15. state.put(KEY_LOCK_CREATED, lock.getCreated());
  16. return null;
  17. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

  1. @Override
  2. public Lock removeLock(final String id, final String owner) {
  3. RedisExecutor redisExecutor = Framework.getService(RedisExecutor.class);
  4. List<String> keys = Collections.singletonList(redisNamespace + id);
  5. List<String> args = Collections.singletonList(owner == null ? "" : owner);
  6. String lockString = (String) redisExecutor.evalsha(scriptRemoveSha, keys, args);
  7. Lock lock = lockFromString(lockString);
  8. if (lock != null && owner != null && !owner.equals(lock.getOwner())) {
  9. lock = new Lock(lock, true); // failed removal
  10. }
  11. return lock;
  12. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

  1. protected static String getDocumentLocker(DocumentModel doc) {
  2. Lock lock = doc.getLockInfo();
  3. return lock == null ? null : lock.getOwner();
  4. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

  1. return null;
  2. if (oldLock != null && !LockManager.canLockBeRemoved(oldLock.getOwner(), owner)) {
  3. oldLock = new Lock(oldLock, true);
  4. } else {
  5. if (oldLock == null) {
  6. if (oldLock != null && oldLock.getFailed()) {
  7. lockCache.put(id, new Lock(oldLock, false));
  8. } else {
  9. lockCache.put(id, NULL_LOCK);

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

  1. @Override
  2. public Lock removeLock(DocumentRef docRef) throws LockException {
  3. Document doc = resolveReference(docRef);
  4. String owner;
  5. if (hasPermission(docRef, UNLOCK)) {
  6. // always unlock
  7. owner = null;
  8. } else {
  9. owner = getPrincipal().getName();
  10. }
  11. Lock lock = doc.removeLock(owner);
  12. if (lock == null) {
  13. // there was no lock, we're done
  14. return null;
  15. }
  16. if (lock.getFailed()) {
  17. // lock removal failed due to owner check
  18. throw new LockException("Document already locked by " + lock.getOwner() + ": " + docRef);
  19. }
  20. DocumentModel docModel = readModel(doc);
  21. Map<String, Serializable> options = new HashMap<>();
  22. options.put("lock", lock);
  23. notifyEvent(DocumentEventTypes.DOCUMENT_UNLOCKED, docModel, options, null, null, true, false);
  24. return lock;
  25. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

  1. protected Lock lockFromString(String lockString) {
  2. if (lockString == null) {
  3. return null;
  4. }
  5. String[] split = lockString.split(":");
  6. if (split.length != 2 || !StringUtils.isNumeric(split[1])) {
  7. throw new IllegalArgumentException(
  8. "Invalid Redis lock : " + lockString + ", should be " + redisNamespace + "<id>");
  9. }
  10. Calendar created = Calendar.getInstance();
  11. created.setTimeInMillis(Long.parseLong(split[1]));
  12. return new Lock(split[0], created);
  13. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

  1. @Override
  2. public Lock removeLock(final Serializable id, final String owner, final boolean force) {
  3. if (log.isDebugEnabled()) {
  4. log.debug("removeLock " + id + " owner=" + owner + " force=" + force);
  5. }
  6. Lock oldLock = force ? null : getLock(id);
  7. if (!force && owner != null) {
  8. if (oldLock == null) {
  9. // not locked, nothing to do
  10. return null;
  11. }
  12. if (!LockManager.canLockBeRemoved(oldLock.getOwner(), owner)) {
  13. // existing mismatched lock, flag failure
  14. return new Lock(oldLock, true);
  15. }
  16. }
  17. if (force || oldLock != null) {
  18. deleteRows(Model.LOCK_TABLE_NAME, Collections.singleton(id));
  19. }
  20. return oldLock;
  21. }

代码示例来源:origin: toutatice-services.listeemargement/toutatice-listeemargement-ecm

  1. private boolean isNotLockedOrIsLockOwner(DocumentModel document) throws ClientException {
  2. Lock lockInfo = document.getLockInfo();
  3. return (null != lockInfo) ? lockInfo.getOwner().equals(currentUser.getName()) : true;
  4. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage

  1. @Override
  2. public void updateImport(CoreSession session, DocumentModel docModel, ExportedDocument xdoc) throws Exception {
  3. Element lockInfo = xdoc.getDocument().getRootElement().element("lockInfo");
  4. if (lockInfo != null) {
  5. String createdMS = lockInfo.element("created").getText();
  6. String owner = lockInfo.element("owner").getText();
  7. Calendar created = Calendar.getInstance();
  8. created.setTimeInMillis(Long.parseLong(createdMS));
  9. Lock lock = new Lock(owner, created);
  10. getLockManager(session).setLock(docModel.getId(), lock);
  11. }
  12. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

  1. @Override
  2. public Lock setLock(final Serializable id, final Lock lock) {
  3. if (log.isDebugEnabled()) {
  4. log.debug("setLock " + id + " owner=" + lock.getOwner());
  5. }
  6. Lock oldLock = getLock(id);
  7. if (oldLock == null) {
  8. Row row = new Row(Model.LOCK_TABLE_NAME, id);
  9. row.put(Model.LOCK_OWNER_KEY, lock.getOwner());
  10. row.put(Model.LOCK_CREATED_KEY, lock.getCreated());
  11. insertSimpleRows(Model.LOCK_TABLE_NAME, Collections.singletonList(row));
  12. }
  13. return oldLock;
  14. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-mongodb

  1. );
  2. Updates.set(KEY_LOCK_OWNER, lock.getOwner()), //
  3. Updates.set(KEY_LOCK_CREATED, converter.serializableToBson(lock.getCreated())) //
  4. );
  5. if (log.isTraceEnabled()) {
  6. Calendar oldCreated = (Calendar) converter.scalarToSerializable(old.get(KEY_LOCK_CREATED));
  7. if (oldOwner != null) {
  8. return new Lock(oldOwner, oldCreated);

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

  1. @Override
  2. public Lock setLock(DocumentRef docRef) throws LockException {
  3. Document doc = resolveReference(docRef);
  4. // TODO: add a new permission named LOCK and use it instead of
  5. // WRITE_PROPERTIES
  6. checkPermission(doc, WRITE_PROPERTIES);
  7. Lock lock = new Lock(getPrincipal().getName(), new GregorianCalendar());
  8. Lock oldLock = doc.setLock(lock);
  9. if (oldLock != null) {
  10. throw new LockException("Document already locked by " + oldLock.getOwner() + ": " + docRef);
  11. }
  12. DocumentModel docModel = readModel(doc);
  13. Map<String, Serializable> options = new HashMap<>();
  14. options.put("lock", lock);
  15. notifyEvent(DocumentEventTypes.DOCUMENT_LOCKED, docModel, options, null, null, true, false);
  16. return lock;
  17. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

  1. @Override
  2. public Access checkPermission(Document doc, ACP mergedAcp, NuxeoPrincipal principal, String permission,
  3. String[] resolvedPermissions, String[] additionalPrincipals) {
  4. Access access = Access.UNKNOWN;
  5. // policy only applies on WRITE
  6. if (resolvedPermissions == null || !Arrays.asList(resolvedPermissions).contains(SecurityConstants.WRITE)) {
  7. return access;
  8. }
  9. // check the lock
  10. String username = principal.getName();
  11. Lock lock = doc.getLock();
  12. if (lock != null && !username.equals(lock.getOwner())) {
  13. // locked by another user => deny
  14. access = Access.DENY;
  15. }
  16. return access;
  17. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

  1. @Override
  2. public Lock getLock(Serializable id) {
  3. if (log.isDebugEnabled()) {
  4. try {
  5. log.debug("getLock " + id + " while autoCommit=" + connection.getAutoCommit());
  6. } catch (SQLException e) {
  7. throw new RuntimeException(e);
  8. }
  9. }
  10. RowId rowId = new RowId(Model.LOCK_TABLE_NAME, id);
  11. Row row = readSimpleRow(rowId);
  12. return row == null ? null
  13. : new Lock((String) row.get(Model.LOCK_OWNER_KEY), (Calendar) row.get(Model.LOCK_CREATED_KEY));
  14. }

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-webapp-core

  1. @Override
  2. public Map<String, Serializable> getLockDetails(DocumentModel document) {
  3. if (lockDetails == null || !StringUtils.equals(documentId, document.getId())) {
  4. lockDetails = new HashMap<String, Serializable>();
  5. documentId = document.getId();
  6. Lock lock = documentManager.getLockInfo(document.getRef());
  7. if (lock == null) {
  8. return lockDetails;
  9. }
  10. lockDetails.put(LOCKER, lock.getOwner());
  11. lockDetails.put(LOCK_CREATED, lock.getCreated());
  12. }
  13. return lockDetails;
  14. }

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-webdav

  1. @Override
  2. public String getCheckoutUser(DocumentRef ref) {
  3. Lock lock = getSession().getLockInfo(ref);
  4. if (lock != null) {
  5. return lock.getOwner();
  6. }
  7. return null;
  8. }

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-mem

  1. @Override
  2. public synchronized Lock getLock(String id) {
  3. State state = states.get(id);
  4. if (state == null) {
  5. // document not found
  6. throw new DocumentNotFoundException(id);
  7. }
  8. String owner = (String) state.get(KEY_LOCK_OWNER);
  9. if (owner == null) {
  10. return null;
  11. }
  12. Calendar created = (Calendar) state.get(KEY_LOCK_CREATED);
  13. return new Lock(owner, created);
  14. }

代码示例来源:origin: opentoutatice-ecm.elasticsearch-customizer/opentoutatice-addon-elasticsearch-customizer-ecm

  1. /**
  2. * Write lock informations of document.
  3. *
  4. * @param jg
  5. * @param doc
  6. * @throws JsonGenerationException
  7. * @throws IOException
  8. */
  9. // FIXME: create a lock index?
  10. protected void writeLockInfos(JsonGenerator jg, DocumentModel doc) throws JsonGenerationException, IOException {
  11. Lock lock = doc.getLockInfo();
  12. if (lock != null) {
  13. jg.writeStringField("ttc:lockOwner", lock.getOwner());
  14. jg.writeStringField("ttc:lockCreated", ISODateTimeFormat.dateTime().print(new DateTime(lock.getCreated())));
  15. }
  16. }

代码示例来源:origin: org.nuxeo.ecm.routing/nuxeo-routing-core

  1. @Override
  2. public boolean isLockedByCurrentUser(CoreSession session) {
  3. Lock lockInfo = session.getLockInfo(doc.getRef());
  4. if (lockInfo == null) {
  5. return false;
  6. }
  7. String lockOwner = lockInfo.getOwner();
  8. NuxeoPrincipal userName = session.getPrincipal();
  9. return userName.getName().equals(lockOwner);
  10. }

相关文章