public void destroy() { try { session.close(); } finally { session = null; } } }
private Object readResolve() throws ObjectStreamException { // we need a transaction for this boolean started = false; if (!TransactionHelper.isTransactionActiveOrMarkedRollback()) { started = TransactionHelper.startTransaction(); } try { try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) { referent = session.getDocument(ref); referent.detach(true); return referent; } } catch (RuntimeException cause) { InvalidObjectException error = new InvalidObjectException( "Cannot refetch " + ref + " from " + repositoryName); error.initCause(cause); throw error; } finally { if (started) { TransactionHelper.commitOrRollbackTransaction(); } } }
public CoreSessionRegistrationInfo(CloseableCoreSession session) { super("DEBUG: opening stacktrace, sessionId=" + session.getSessionId() + ", thread=" + Thread.currentThread().getName()); this.session = session; }
IterableQueryResult results = session.queryAndFetch(query, "NXQL"); List<String> routeIds = new ArrayList<>(); for (Map<String, Serializable> result : results) { for (String routeId : routeIds) { try { DocumentModel docRoute = session.getDocument(new IdRef(routeId)); DocumentRoute route = docRoute.getAdapter(DocumentRoute.class); List<String> relatedDocIds = route.getAttachedDocuments(); session.removeDocument(route.getDocument().getRef()); session.close(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); session.close();
@Override public DocumentModel createComment(DocumentModel docModel, DocumentModel parent, DocumentModel child) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentModel parentDocModel = session.getDocument(parent.getRef()); String containerPath = parent.getPath().removeLastSegments(1).toString(); DocumentModel newComment = internalCreateComment(session, parentDocModel, child, containerPath); session.save(); return newComment; } }
@Override public Blob resolveBlobFromDownloadUrl(String downloadURL) { Pair<String, Action> pair = getDownloadPathAndAction(downloadURL); if (pair == null) { return null; } String downloadPath = pair.getLeft(); try { DownloadBlobInfo downloadBlobInfo = new DownloadBlobInfo(downloadPath); try (CloseableCoreSession session = CoreInstance.openCoreSession(downloadBlobInfo.repository)) { DocumentRef docRef = new IdRef(downloadBlobInfo.docId); if (!session.exists(docRef)) { return null; } DocumentModel doc = session.getDocument(docRef); Blob blob = resolveBlob(doc, downloadBlobInfo.xpath); if (!checkPermission(doc, downloadBlobInfo.xpath, blob, null, null)) { return null; } return blob; } } catch (IllegalArgumentException e) { return null; } }
for (DocumentRef source : sources) { DocumentTranslationMap map = new DocumentTranslationMapImpl(repo, repo); DocumentModel sourceDoc = session.getDocument(source); DocumentModel destDoc = session.copy(source, targetLocation.getDocRef(), null); roots.add(destDoc.getRef()); session.save();
@Override public void deleteComment(DocumentModel docModel, DocumentModel comment) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentRef ref = comment.getRef(); if (!session.exists(ref)) { throw new NuxeoException("Comment Document does not exist: " + comment.getId()); } session.removeDocument(ref); notifyEvent(session, CommentEvents.COMMENT_REMOVED, docModel, comment); session.save(); } }
@Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) throws CommentSecurityException { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentModel createdComment = internalCreateComment(session, docModel, comment, path); session.save(); return createdComment; } }
@Override public DocumentModel createComment(DocumentModel docModel, String comment, String author) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentModel commentDM = session.createDocumentModel(COMMENT_DOC_TYPE); commentDM.setPropertyValue(CommentsConstants.COMMENT_TEXT, comment); commentDM.setPropertyValue(CommentsConstants.COMMENT_AUTHOR, author); commentDM.setPropertyValue(CommentsConstants.COMMENT_CREATION_DATE, Calendar.getInstance()); commentDM = internalCreateComment(session, docModel, commentDM, null); session.save(); return commentDM; } }
@Override public void releaseCoreSession(CloseableCoreSession session) { String sessionId = session.getSessionId(); CoreSessionRegistrationInfo info = sessions.remove(sessionId); String debug = "closing stacktrace, sessionId=" + sessionId + ", thread=" + Thread.currentThread().getName(); if (info == null) { CoreSessionRegistrationInfo closed = recentlyClosedSessions.getIfPresent(sessionId); if (closed == null) { // no knowledge of this sessionId, log the current stacktrace Exception e = new Exception("DEBUG: " + debug); log.warn("Closing unknown CoreSession", e); } else { // this sessionId was recently closed and we kept info about it // log the current stacktrace with the original opening and closing as suppressed exceptions Exception e = new Exception("DEBUG: spurious " + debug); e.addSuppressed(closed); log.warn("Closing already closed CoreSession", e); } } else { // regular closing, record a stacktrace info.addSuppressed(new Exception("DEBUG: " + debug)); recentlyClosedSessions.put(sessionId, info); // don't keep the session around, all we want is the stacktrace objects info.session = null; } session.destroy(); }
@Override public DocumentTranslationMap importDocuments(InputStream in, String repo, DocumentRef root) { DocumentReader reader = null; DocumentModelWriter writer = null; try (CloseableCoreSession coreSession = CoreInstance.openCoreSessionSystem(repo)) { final DocumentModel dst = coreSession.getDocument(root); reader = new NuxeoArchiveReader(in); writer = new DocumentModelWriter(coreSession, dst.getPathAsString()); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); DocumentTranslationMap map = pipe.run(); coreSession.save(); return map; } catch (IOException e) { throw new NuxeoException(e); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } }
try (CloseableCoreSession session = CoreInstance.openCoreSession(downloadBlobInfo.repository)) { DocumentRef docRef = new IdRef(downloadBlobInfo.docId); if (!session.exists(docRef)) { return; DocumentModel doc = session.getDocument(docRef); if (info) { Blob blob = resolveBlob(doc, xpath);
@Override public DocumentModel createComment(DocumentModel docModel, DocumentModel comment) throws CommentSecurityException { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { comment.setPropertyValue(COMMENT_ANCESTOR_IDS, (Serializable) computeAncestorIds(session, docModel.getId())); DocumentModel doc = internalCreateComment(session, docModel, comment, null); session.save(); doc.detach(true); return doc; } }
/** * Closes the session that was opened by {@link #openSystemSession()} or {@link #openUserSession()}. * * @since 5.8 */ public void closeSession() { if (session != null) { ((CloseableCoreSession) session).close(); session = null; } }
uuid = docRef.toString(); } else { DocumentModel doc = session.getDocument(docRef); uuid = doc.getId();
@Override public void close() throws IOException { if (shouldBeClosed) { ((CloseableCoreSession) session).close(); } }
Set<Resource> allResources = new HashSet<Resource>(); for (DocumentRef docRef : sources) { DocumentModel doc = session.getDocument(docRef); Map<String, Object> context = Collections.<String, Object> singletonMap( ResourceAdapter.CORE_SESSION_CONTEXT_KEY, session);
public void releaseCoreSession() { ((CloseableCoreSession) session).close(); session = null; }