jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r650301 - in /jackrabbit/branches/1.4/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
Date Mon, 21 Apr 2008 22:28:30 GMT
Author: jukka
Date: Mon Apr 21 15:28:23 2008
New Revision: 650301

URL: http://svn.apache.org/viewvc?rev=650301&view=rev
Log:
1.4: Merged revisions 640838 and 641319 (JCR-1463)

Added:
    jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
      - copied, changed from r640838, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
Modified:
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=650301&r1=650300&r2=650301&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
Mon Apr 21 15:28:23 2008
@@ -52,6 +52,11 @@
     private static Logger log = LoggerFactory.getLogger(InternalVersionHistory.class);
 
     /**
+     * The last current time that was returned by {@link #getCurrentTime()}.
+     */
+    private static final Calendar CURRENT_TIME = Calendar.getInstance();
+
+    /**
      * the cache of the version labels
      * key = version label (String)
      * value = version name
@@ -162,8 +167,8 @@
         if (rootVersion.getSuccessors().length==0) {		
             Iterator iter = nameCache.keySet().iterator();
             while (iter.hasNext()) {
-                Name versionName = (Name)iter.next();
-                InternalVersionImpl v = (InternalVersionImpl)createVersionInstance(versionName);
+                Name versionName = (Name) iter.next();
+                InternalVersionImpl v = createVersionInstance(versionName);
                 v.legacyResolveSuccessors();
             }
         }
@@ -480,7 +485,7 @@
         NodeStateEx vNode = node.addNode(name, NameConstants.NT_VERSION, versionId, true);
 
         // initialize 'created', 'predecessors' and 'successors'
-        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(Calendar.getInstance()));
+        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
         vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, predecessors);
         vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
 
@@ -533,7 +538,7 @@
         NodeStateEx vNode = pNode.addNode(NameConstants.JCR_ROOTVERSION, NameConstants.NT_VERSION,
versionId, true);
 
         // initialize 'created' and 'predecessors'
-        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(Calendar.getInstance()));
+        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
         vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
         vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
 
@@ -557,5 +562,25 @@
 
         parent.store();
         return new InternalVersionHistoryImpl(vMgr, pNode);
+    }
+
+    /**
+     * Returns the current time as a calendar instance and makes sure that no
+     * two Calendar instances represent the exact same time. If this method is
+     * called quickly in succession each Calendar instance returned is at least
+     * one millisecond later than the previous one.
+     *
+     * @return the current time.
+     */
+    static Calendar getCurrentTime() {
+        long time = System.currentTimeMillis();
+        synchronized (CURRENT_TIME) {
+            if (time > CURRENT_TIME.getTimeInMillis()) {
+                CURRENT_TIME.setTimeInMillis(time);
+            } else {
+                CURRENT_TIME.add(Calendar.MILLISECOND, 1);
+            }
+            return (Calendar) CURRENT_TIME.clone();
+        }
     }
 }

Copied: jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
(from r640838, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java?p2=jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java&p1=jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java&r1=640838&r2=650301&rev=650301&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImplTest.java
Mon Apr 21 15:28:23 2008
@@ -35,7 +35,7 @@
         for (int i = 0; i < 100; i++) {
             Calendar next = InternalVersionHistoryImpl.getCurrentTime();
             assertTrue("InternalVersionHistoryImpl.getCurrentTime() not monotonically increasing",
-                    last.compareTo(next) < 0);
+                    last.getTimeInMillis() < next.getTimeInMillis());
             last = next;
         }
     }



Mime
View raw message