Author: brane
Date: Wed Jun 19 06:45:08 2013
New Revision: 1494471

URL: http://svn.apache.org/r1494471
Log:
On the javahl-ra branch:
Implement commit editor creation and disposal.

[in subversion/bindings/javahl/src/org/apache/subversion/javahl]
* ISVNEditor.java (ISVNEditor.dispose): New method.
* remote/CommitEditor.java (ISVNEditor.dispose): New (boilerplate).
  (CommitEditor.createInstance): New factory method (boilerplate).
* remote/RemoteSession.java (RemoteSession.editors): New member.
  (RemoteSession.nativeDispose): New native method, replaces dispose().
  (dispose): Remove 'native' qualified and implement here.

[in subversion/bindings/javahl/native]
* org_apache_subversion_javahl_remote_RemoteSession.cpp
  (Java_org_apache_subversion_javahl_remote_RemoteSession_nativeDispose):
   Renamed from Java_org_apache_subversion_javahl_remote_RemoteSession_dispose.

Modified:
    
subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_remote_RemoteSession.cpp
    
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java
    
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/CommitEditor.java
    
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/RemoteSession.java

Modified: 
subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_remote_RemoteSession.cpp
URL: 
http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_remote_RemoteSession.cpp?rev=1494471&r1=1494470&r2=1494471&view=diff
==============================================================================
--- 
subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_remote_RemoteSession.cpp
 (original)
+++ 
subversion/branches/javahl-ra/subversion/bindings/javahl/native/org_apache_subversion_javahl_remote_RemoteSession.cpp
 Wed Jun 19 06:45:08 2013
@@ -46,7 +46,7 @@ Java_org_apache_subversion_javahl_remote
 }
 
 JNIEXPORT void JNICALL
-Java_org_apache_subversion_javahl_remote_RemoteSession_dispose(
+Java_org_apache_subversion_javahl_remote_RemoteSession_nativeDispose(
     JNIEnv *env, jobject jthis)
 {
   JNIEntry(RemoteSession, dispose);

Modified: 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java
URL: 
http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java?rev=1494471&r1=1494470&r2=1494471&view=diff
==============================================================================
--- 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java
 (original)
+++ 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java
 Wed Jun 19 06:45:08 2013
@@ -39,6 +39,12 @@ import java.util.Map;
 public interface ISVNEditor
 {
     /**
+     * Release the native peer (should not depend on finalize),
+     * and abort the edit if it has not been completed yet.
+     */
+    void dispose();
+
+    /**
      * Create a new directory at <code>relativePath</code>.
      * The immediate parent of <code>relativePath</code> is expected to exist.
      *

Modified: 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/CommitEditor.java
URL: 
http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/CommitEditor.java?rev=1494471&r1=1494470&r2=1494471&view=diff
==============================================================================
--- 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/CommitEditor.java
 (original)
+++ 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/CommitEditor.java
 Wed Jun 19 06:45:08 2013
@@ -40,6 +40,8 @@ import java.util.Map;
  */
 public class CommitEditor extends JNIObject implements ISVNEditor
 {
+    public void dispose() {/* TODO */}
+
     public void addDirectory(String relativePath,
                              Iterable<String> children,
                              Map<String, byte[]> properties,
@@ -145,6 +147,16 @@ public class CommitEditor extends JNIObj
     }
 
     /**
+     * This factory method called from RemoteSession.getCommitEditor.
+     */
+    static final CommitEditor createInstance(RemoteSession owner)
+            throws ClientException
+    {
+        // FIXME: temporary implementation
+        return new CommitEditor(0L);
+    }
+
+    /**
      * This constructor is called from JNI to get an instance.
      */
     protected CommitEditor(long cppAddr)

Modified: 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/RemoteSession.java
URL: 
http://svn.apache.org/viewvc/subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/RemoteSession.java?rev=1494471&r1=1494470&r2=1494471&view=diff
==============================================================================
--- 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/RemoteSession.java
 (original)
+++ 
subversion/branches/javahl-ra/subversion/bindings/javahl/src/org/apache/subversion/javahl/remote/RemoteSession.java
 Wed Jun 19 06:45:08 2013
@@ -32,6 +32,8 @@ import org.apache.subversion.javahl.JNIO
 import org.apache.subversion.javahl.OperationContext;
 import org.apache.subversion.javahl.ClientException;
 
+import java.lang.ref.WeakReference;
+import java.util.HashSet;
 import java.util.Date;
 import java.util.Map;
 
@@ -40,7 +42,22 @@ import static java.util.concurrent.TimeU
 
 public class RemoteSession extends JNIObject implements ISVNRemote
 {
-    public native void dispose();
+    public void dispose()
+    {
+        if (editors != null)
+        {
+            // Deactivate all open editors
+            for (WeakReference<ISVNEditor> ref : editors)
+            {
+                ISVNEditor ed = ref.get();
+                if (ed == null)
+                    continue;
+                ed.dispose();
+                ref.clear();
+            }
+        }
+        nativeDispose();
+    }
 
     public native void cancelOperation() throws ClientException;
 
@@ -75,7 +92,11 @@ public class RemoteSession extends JNIOb
 
     public ISVNEditor getCommitEditor() throws ClientException
     {
-        throw new RuntimeException("Not implemented: getCommitEditor");
+        ISVNEditor ed = CommitEditor.createInstance(this);
+        if (editors == null)
+            editors = new HashSet<WeakReference<ISVNEditor>>();
+        editors.add(new WeakReference<ISVNEditor>(ed));
+        return ed;
     }
 
     @Override
@@ -89,9 +110,17 @@ public class RemoteSession extends JNIOb
         super(cppAddr);
     }
 
+    private native void nativeDispose();
+
     /*
      * NOTE: This field is accessed from native code for callbacks.
      */
     private RemoteSessionContext sessionContext = new RemoteSessionContext();
     private class RemoteSessionContext extends OperationContext {}
+
+    /*
+     * The set of open editors. We need this in order to dispose/abort
+     * the editors when the session is disposed.
+     */
+    private HashSet<WeakReference<ISVNEditor>> editors;
 }


Reply via email to