jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r178643 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: Path.java QName.java state/ChangeLog.java state/SharedItemStateManager.java
Date Thu, 26 May 2005 15:32:22 GMT
Author: stefan
Date: Thu May 26 08:32:20 2005
New Revision: 178643

URL: http://svn.apache.org/viewcvs?rev=178643&view=rev
Log:
Path & QName: avoid unneccessary object creation 
SharedItemStateManager: added debug output in store() method

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java?rev=178643&r1=178642&r2=178643&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java Thu May 26 08:32:20
2005
@@ -110,11 +110,11 @@
      * </ul>
      */
     private static final Pattern PATH_ELEMENT_PATTERN =
-        Pattern.compile("(\\.)|"
-                + "(\\.\\.)|"
-                + "(([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?):)?"
-                + "([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?)"
-                + "(\\[([1-9]\\d*)\\])?");
+            Pattern.compile("(\\.)|"
+            + "(\\.\\.)|"
+            + "(([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?):)?"
+            + "([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?)"
+            + "(\\[([1-9]\\d*)\\])?");
 
     /**
      * the elements of this path
@@ -386,8 +386,7 @@
                         // check if the prefix is a valid XML prefix
                         if (!XMLChar.isValidNCName(prefix)) {
                             // illegal syntax for prefix
-                            throw new MalformedPathException(
-                                    "'" + jcrPath + "' is not a valid path: '"
+                            throw new MalformedPathException("'" + jcrPath + "' is not a
valid path: '"
                                     + elem + "' specifies an illegal namespace prefix");
                         }
                     } else {
@@ -413,8 +412,7 @@
                         nsURI = resolver.getURI(prefix);
                     } catch (NamespaceException nse) {
                         // unknown prefix
-                        throw new MalformedPathException(
-                                "'" + jcrPath + "' is not a valid path: '"
+                        throw new MalformedPathException("'" + jcrPath + "' is not a valid
path: '"
                                 + elem + "' specifies an unmapped namespace prefix");
                     }
 
@@ -429,14 +427,12 @@
                 }
             } else {
                 // illegal syntax for path element
-                throw new MalformedPathException(
-                        "'" + jcrPath + "' is not a valid path: '"
+                throw new MalformedPathException("'" + jcrPath + "' is not a valid path:
'"
                         + elem + "' is not a legal path element");
             }
         }
         if (resolver != null) {
-            return new Path(
-                    (PathElement[]) list.toArray(new PathElement[list.size()]),
+            return new Path((PathElement[]) list.toArray(new PathElement[list.size()]),
                     isNormalized);
         } else {
             return null;
@@ -804,11 +800,15 @@
     }
 
     /**
-     * @param resolver
-     * @return
-     * @throws NoPrefixDeclaredException
+     * Returns a string representation of this <code>Path</code> in the
+     * JCR path format.
+     *
+     * @param resolver namespace resolver
+     * @return JCR path
+     * @throws NoPrefixDeclaredException if a namespace can not be resolved
      */
-    public String toJCRPath(NamespaceResolver resolver) throws NoPrefixDeclaredException
{
+    public String toJCRPath(NamespaceResolver resolver)
+            throws NoPrefixDeclaredException {
         if (denotesRoot()) {
             // shortcut
             return "/";
@@ -820,7 +820,7 @@
             }
             PathElement element = elements[i];
             // name
-            sb.append(element.toJCRName(resolver));
+            element.toJCRName(resolver, sb);
         }
         return sb.toString();
     }
@@ -1190,12 +1190,14 @@
      * Object representation of a single JCR path element. A PathElement
      * object contains the qualified name and optional index of a single
      * JCR path element.
-     * <p>
+     * <p/>
      * Once created, a PathElement object is immutable.
      */
     public static class PathElement {
 
-        /** Qualified name of the path element. */
+        /**
+         * Qualified name of the path element.
+         */
         private final QName name;
 
         /**
@@ -1209,7 +1211,7 @@
          * The created path element does not contain an explicit index.
          *
          * @param namespaceURI namespace URI
-         * @param localName local name
+         * @param localName    local name
          */
         private PathElement(String namespaceURI, String localName) {
             this(new QName(namespaceURI, localName));
@@ -1219,8 +1221,8 @@
          * Creates a path element with the given qualified name and index.
          *
          * @param namespaceURI namespace URI
-         * @param localName local name
-         * @param index index
+         * @param localName    local name
+         * @param index        index
          */
         private PathElement(String namespaceURI, String localName, int index) {
             this(new QName(namespaceURI, localName), index);
@@ -1244,7 +1246,7 @@
         /**
          * Creates a path element with the given qualified name and index.
          *
-         * @param name qualified name
+         * @param name  qualified name
          * @param index index
          * @throws IllegalArgumentException if the name is <code>null</code>
          */
@@ -1333,10 +1335,28 @@
          * @throws NoPrefixDeclaredException if the namespace of the path
          *                                   element name can not be resolved
          */
-        public String toJCRName(NamespaceResolver resolver) throws NoPrefixDeclaredException
{
+        public String toJCRName(NamespaceResolver resolver)
+                throws NoPrefixDeclaredException {
             StringBuffer sb = new StringBuffer();
+            toJCRName(resolver, sb);
+            return sb.toString();
+        }
+
+        /**
+         * Appends the JCR name representation of this path element to the
+         * given string buffer.
+         *
+         * @param resolver namespace resolver
+         * @param buf      string buffer where the JCR name representation
+         *                 should be appended to
+         * @throws NoPrefixDeclaredException if the namespace of the path
+         *                                   element name can not be resolved
+         * @see #toJCRName(NamespaceResolver)
+         */
+        public void toJCRName(NamespaceResolver resolver, StringBuffer buf)
+                throws NoPrefixDeclaredException {
             // name
-            sb.append(name.toJCRName(resolver));
+            name.toJCRName(resolver, buf);
             // index
             int index = getIndex();
             /**
@@ -1345,11 +1365,10 @@
              */
             //if (index > 0) {
             if (index > 1) {
-                sb.append('[');
-                sb.append(index);
-                sb.append(']');
+                buf.append('[');
+                buf.append(index);
+                buf.append(']');
             }
-            return sb.toString();
         }
 
         /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java?rev=178643&r1=178642&r2=178643&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java Thu May 26 08:32:20
2005
@@ -269,26 +269,44 @@
      *
      * @param resolver namespace resolver
      * @return prefixed name
-     * @throws NoPrefixDeclaredException if the namespace fails to resolve
+     * @throws NoPrefixDeclaredException if the namespace can not be resolved
      */
-    public String toJCRName(NamespaceResolver resolver) throws NoPrefixDeclaredException
{
+    public String toJCRName(NamespaceResolver resolver)
+            throws NoPrefixDeclaredException {
         StringBuffer sb = new StringBuffer();
+        toJCRName(resolver, sb);
+        return sb.toString();
+    }
+
+    /**
+     * Appends the qualified name in the prefixed JCR name format to the given
+     * string buffer. The namespace URI is mapped to a prefix using the given
+     * namespace resolver.
+     *
+     * @param resolver namespace resolver
+     * @param buf      string buffer where the prefixed JCR name should be
+     *                 appended to
+     * @throws NoPrefixDeclaredException if the namespace can not be resolved
+     * @see #toJCRName(NamespaceResolver)
+     */
+    public void toJCRName(NamespaceResolver resolver, StringBuffer buf)
+            throws NoPrefixDeclaredException {
         // prefix
         String prefix;
         try {
             prefix = resolver.getPrefix(namespaceURI);
         } catch (NamespaceException nse) {
-            throw new NoPrefixDeclaredException("no prefix declared for URI: " + namespaceURI);
+            throw new NoPrefixDeclaredException("no prefix declared for URI: "
+                    + namespaceURI);
         }
         if (prefix.length() == 0) {
             // default prefix (empty string)
         } else {
-            sb.append(prefix);
-            sb.append(':');
+            buf.append(prefix);
+            buf.append(':');
         }
         // name
-        sb.append(localName);
-        return sb.toString();
+        buf.append(localName);
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java?rev=178643&r1=178642&r2=178643&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java Thu
May 26 08:32:20 2005
@@ -301,4 +301,21 @@
         }
         reset();
     }
+
+    /**
+     * Returns a string representation of this change log for diagnostic
+     * purposes.
+     *
+     * @return a string representation of this change log
+     */
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append("{");
+        buf.append("#addedStates=" + addedStates.size());
+        buf.append(", #modifiedStates=" + modifiedStates.size());
+        buf.append(", #deletedStates=" + deletedStates.size());
+        buf.append(", #modifiedRefs=" + modifiedRefs.size());
+        buf.append("}");
+        return buf.toString();
+    }
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=178643&r1=178642&r2=178643&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Thu May 26 08:32:20 2005
@@ -548,8 +548,13 @@
             local.push();
 
             /* Store items in the underlying persistence manager */
+            long t0 = System.currentTimeMillis();
             persistMgr.store(shared);
             succeeded = true;
+            long t1 = System.currentTimeMillis();
+            if (log.isInfoEnabled()) {
+                log.info("persisting change log " + shared + " took " + (t1 - t0) + "ms");
+            }
 
         } finally {
 



Mime
View raw message