chemistry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Mertins (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (CMIS-78) Load Node Types only once
Date Tue, 15 Dec 2009 13:59:18 GMT

    [ https://issues.apache.org/jira/browse/CMIS-78?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790746#action_12790746
] 

Michael Mertins edited comment on CMIS-78 at 12/15/09 1:58 PM:
---------------------------------------------------------------

This is my patch:

Index: JcrRepository.java
===================================================================
--- JcrRepository.java	(revision 890780)
+++ JcrRepository.java	(working copy)
@@ -67,7 +67,9 @@
     private final String workspace;
 
     private final SimpleCredentials creds;
-
+    
+    private NodeTypeIterator nodeTypes = null;
+    
     public JcrRepository(javax.jcr.Repository repository, String workspace,
             SimpleCredentials creds) {
         this.repository = repository;
@@ -115,9 +117,23 @@
         try {
             Session session = repository.login(creds, workspace);
 
-            // TODO fetch the types only once, include other types
-            NodeTypeManager ntmgr = session.getWorkspace().getNodeTypeManager();
-            NodeType nt = ntmgr.getNodeType(typeId);
+            
+			// get matching NodeType either from session or from nodeTypes
+			// iterator
+			NodeType nt = null;
+			if (nodeTypes == null) {
+				NodeTypeManager ntmgr = session.getWorkspace()
+						.getNodeTypeManager();
+				nt = ntmgr.getNodeType(typeId);
+			} else {
+				while (nodeTypes.hasNext()) {
+					// can .getName() ever match typeId?
+					if (nodeTypes.nextNodeType().getName().equals(typeId)) {
+						nt = nodeTypes.nextNodeType();
+						break;
+					}
+				}
+			}
 
             BaseType baseType = BaseType.FOLDER;
             if (JcrCmisMap.isBaseTypeDocument(nt.getName())) {
@@ -142,10 +158,13 @@
 
         try {
             List<Type> result = new ArrayList<Type>();
-
-            Session session = repository.login(creds, workspace);
-
-            NodeTypeIterator nodeTypes = session.getWorkspace().getNodeTypeManager().getAllNodeTypes();
+			// fetch types only once
+			if (this.nodeTypes == null) {
+				Session session = repository.login(creds, workspace);
+				this.nodeTypes = session.getWorkspace().getNodeTypeManager()
+						.getAllNodeTypes();
+			}
+          
             while (nodeTypes.hasNext()) {
                 NodeType nodeType = nodeTypes.nextNodeType();
                 if (nodeType.isMixin()) {


      was (Author: mmertins):
    This is my patch:
  
> Load Node Types only once
> -------------------------
>
>                 Key: CMIS-78
>                 URL: https://issues.apache.org/jira/browse/CMIS-78
>             Project: Chemistry
>          Issue Type: Improvement
>          Components: jcr
>            Reporter: Michael Mertins
>         Attachments: JcrRepository.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Implementation of ToDo in getType() and getTypes(). Please look at my implementation
of getType() carefully as I'm not sure if the typeId can equal the .getName()

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message