jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r293078 - in /incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server: ServerAdapterFactory.java ServerObject.java ServerQueryResult.java
Date Sun, 02 Oct 2005 06:55:11 GMT
Author: jukka
Date: Sat Oct  1 23:55:01 2005
New Revision: 293078

URL: http://svn.apache.org/viewcvs?rev=293078&view=rev
Log:
JCR-231: Avoid using the RangedIterator.getSize() method that might return -1.
Made some small cleanups in the getRemoteXxxArray methods.
Moved a part of the code from ServerQueryResult.getRows() up to ServerObject.getRemotRowArray()
for consistency.

Modified:
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerObject.java
    incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerQueryResult.java

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java?rev=293078&r1=293077&r2=293078&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java
Sat Oct  1 23:55:01 2005
@@ -265,17 +265,17 @@
         RemoteEventCollection.RemoteEvent[] remoteEvents;
         if (events != null) {
             List eventList = new ArrayList();
-            for (int i = 0; events.hasNext(); i++) {
-                Event event = events.nextEvent();
+            while (events.hasNext()) {
                 try {
-                    eventList.add(new ServerEventCollection.ServerEvent(event.getType(),
-                        event.getPath(), event.getUserID()));
+                    Event event = events.nextEvent();
+                    eventList.add(new ServerEventCollection.ServerEvent(
+                            event.getType(), event.getPath(), event.getUserID()));
                 } catch (RepositoryException re) {
                     throw new RemoteException(re.getMessage(), re);
                 }
             }
-            remoteEvents = new RemoteEventCollection.RemoteEvent[eventList.size()];
-            eventList.toArray(remoteEvents);
+            remoteEvents = (RemoteEventCollection.RemoteEvent[])
+                eventList.toArray(new RemoteEventCollection.RemoteEvent[eventList.size()]);
         } else {
             remoteEvents = new RemoteEventCollection.RemoteEvent[0]; // for safety
         }

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerObject.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerObject.java?rev=293078&r1=293077&r2=293078&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerObject.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerObject.java
Sat Oct  1 23:55:01 2005
@@ -18,6 +18,7 @@
 
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.util.ArrayList;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.InvalidItemStateException;
@@ -46,6 +47,7 @@
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.RowIterator;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
@@ -57,6 +59,7 @@
 import org.apache.jackrabbit.rmi.remote.RemoteNodeType;
 import org.apache.jackrabbit.rmi.remote.RemoteProperty;
 import org.apache.jackrabbit.rmi.remote.RemotePropertyDefinition;
+import org.apache.jackrabbit.rmi.remote.RemoteRow;
 import org.apache.jackrabbit.rmi.remote.RemoteVersion;
 
 /**
@@ -207,15 +210,15 @@
      */
     protected RemoteProperty[] getRemotePropertyArray(PropertyIterator iterator)
             throws RemoteException {
-        if (iterator == null) {
+        if (iterator != null) {
+            ArrayList remotes = new ArrayList();
+            while (iterator.hasNext()) {
+                remotes.add(factory.getRemoteProperty(iterator.nextProperty()));
+            }
+            return (RemoteProperty[]) remotes.toArray(new RemoteProperty[remotes.size()]);
+        } else {
             return new RemoteProperty[0]; // for safety
         }
-
-        RemoteProperty[] remotes = new RemoteProperty[(int) iterator.getSize()];
-        for (int i = 0; iterator.hasNext(); i++) {
-            remotes[i] = factory.getRemoteProperty(iterator.nextProperty());
-        }
-        return remotes;
     }
 
     /**
@@ -232,11 +235,11 @@
     protected RemoteNode[] getRemoteNodeArray(NodeIterator iterator)
             throws RemoteException {
         if (iterator != null) {
-            RemoteNode[] remotes = new RemoteNode[(int) iterator.getSize()];
-            for (int i = 0; iterator.hasNext(); i++) {
-                remotes[i] = getRemoteNode(iterator.nextNode());
+            ArrayList remotes = new ArrayList();
+            while (iterator.hasNext()) {
+                remotes.add(getRemoteNode(iterator.nextNode()));
             }
-            return remotes;
+            return (RemoteNode[]) remotes.toArray(new RemoteNode[remotes.size()]);
         } else {
             return new RemoteNode[0]; // for safety
         }
@@ -280,11 +283,11 @@
     protected RemoteVersion[] getRemoteVersionArray(VersionIterator iterator)
             throws RemoteException {
         if (iterator != null) {
-            RemoteVersion[] remotes = new RemoteVersion[(int) iterator.getSize()];
-            for (int i = 0; iterator.hasNext(); i++) {
-                remotes[i] = factory.getRemoteVersion(iterator.nextVersion());
+            ArrayList remotes = new ArrayList();
+            while (iterator.hasNext()) {
+                remotes.add(factory.getRemoteVersion(iterator.nextVersion()));
             }
-            return remotes;
+            return (RemoteVersion[]) remotes.toArray(new RemoteVersion[remotes.size()]);
         } else {
             return new RemoteVersion[0]; // for safety
         }
@@ -328,12 +331,11 @@
     protected RemoteNodeType[] getRemoteNodeTypeArray(NodeTypeIterator iterator)
             throws RemoteException {
         if (iterator != null) {
-            RemoteNodeType[] remotes =
-                new RemoteNodeType[(int) iterator.getSize()];
-            for (int i = 0; iterator.hasNext(); i++) {
-                remotes[i] = factory.getRemoteNodeType(iterator.nextNodeType());
+            ArrayList remotes = new ArrayList();
+            while (iterator.hasNext()) {
+                remotes.add(factory.getRemoteNodeType(iterator.nextNodeType()));
             }
-            return remotes;
+            return (RemoteNodeType[]) remotes.toArray(new RemoteNodeType[remotes.size()]);
         } else {
             return new RemoteNodeType[0]; // for safety
         }
@@ -384,6 +386,30 @@
             return remotes;
         } else {
             return new RemotePropertyDefinition[0]; // for safety
+        }
+    }
+
+    /**
+     * Utility method for creating an array of remote references for
+     * local query result rows. The remote references are created using the
+     * remote adapter factory.
+     * <p>
+     * A <code>null</code> input is treated as an empty iterator.
+     *
+     * @param iterator local query result row iterator
+     * @return remote query result row array
+     * @throws RemoteException on RMI errors
+     */
+    protected RemoteRow[] getRemoteRowArray(RowIterator iterator)
+            throws RemoteException {
+        if (iterator != null) {
+            ArrayList remotes = new ArrayList();
+            while (iterator.hasNext()) {
+                remotes.add(getFactory().getRemoteRow(iterator.nextRow()));
+            }
+            return (RemoteRow[]) remotes.toArray(new RemoteRow[remotes.size()]);
+        } else {
+            return new RemoteRow[0]; // for safety
         }
     }
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerQueryResult.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerQueryResult.java?rev=293078&r1=293077&r2=293078&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerQueryResult.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-rmi/src/java/org/apache/jackrabbit/rmi/server/ServerQueryResult.java
Sat Oct  1 23:55:01 2005
@@ -18,10 +18,8 @@
 
 import java.rmi.RemoteException;
 
-import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.query.QueryResult;
-import javax.jcr.query.RowIterator;
 
 import org.apache.jackrabbit.rmi.remote.RemoteNode;
 import org.apache.jackrabbit.rmi.remote.RemoteQueryResult;
@@ -64,30 +62,12 @@
 
     /** {@inheritDoc} */
     public RemoteRow[] getRows() throws RepositoryException, RemoteException {
-        RowIterator iterator = result.getRows();
-        if (iterator != null) {
-            RemoteRow[] remotes = new RemoteRow[(int) iterator.getSize()];
-            for (int i = 0; iterator.hasNext(); i++) {
-                remotes[i] = getFactory().getRemoteRow(iterator.nextRow());
-            }
-            return remotes;
-        } else {
-            return new RemoteRow[0]; // for safety
-        }
+        return getRemoteRowArray(result.getRows());
     }
 
     /** {@inheritDoc} */
     public RemoteNode[] getNodes() throws RepositoryException, RemoteException {
-        NodeIterator iterator = result.getNodes();
-        if (iterator != null) {
-            RemoteNode[] remotes = new RemoteNode[(int) iterator.getSize()];
-            for (int i = 0; iterator.hasNext(); i++) {
-                remotes[i] = getRemoteNode(iterator.nextNode());
-            }
-            return remotes;
-        } else {
-            return new RemoteNode[0]; // for safety
-        }
+        return getRemoteNodeArray(result.getNodes());
     }
 
 }



Mime
View raw message