[exo-jcr-commits] exo-jcr SVN: r500 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr: impl/dataflow and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Nov 9 04:19:01 EST 2009


Author: areshetnyak
Date: 2009-11-09 04:19:00 -0500 (Mon, 09 Nov 2009)
New Revision: 500

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
Log:
EXOJCR-201 :Add serialization mechanism to PersistentItemData, PersistentNodeData, etc.

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java	2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java	2009-11-09 09:19:00 UTC (rev 500)
@@ -18,8 +18,15 @@
  */
 package org.exoplatform.services.jcr.dataflow.persistent;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.exoplatform.services.jcr.datamodel.IllegalPathException;
 import org.exoplatform.services.jcr.datamodel.ItemData;
 import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
 
 /**
  * Created by The eXo Platform SAS. </br>
@@ -30,17 +37,34 @@
  * @version $Id$
  */
 
-public abstract class PersistedItemData implements ItemData
+public abstract class PersistedItemData implements ItemData, Externalizable
 {
 
-   protected final String id;
+   /**
+    * SerialVersionUID to serialization.
+    */
+   private static final long serialVersionUID = -3845740801904303663L;
 
-   protected final QPath qpath;
+   protected String id;
 
-   protected final String parentId;
+   protected QPath qpath;
 
-   protected final int version;
+   protected String parentId;
 
+   protected int version;
+   
+   private final int NOT_NULL_VALUE = 1;
+
+   private final int NULL_VALUE = -1;
+
+   
+   /**
+    *  Empty constructor to serialization.
+    */
+   public PersistedItemData()
+   {
+   }
+   
    public PersistedItemData(String id, QPath qpath, String parentId, int version)
    {
       this.id = id;
@@ -104,4 +128,67 @@
 
       return false;
    }
+   
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      byte[] buf;
+
+      try
+      {
+         buf = new byte[in.readInt()];
+         in.readFully(buf);
+         String sQPath = new String(buf, Constants.DEFAULT_ENCODING);
+         qpath = QPath.parse(sQPath);
+      }
+      catch (final IllegalPathException e)
+      {
+         throw new IOException("Deserialization error. " + e)
+         {
+
+            /**
+             * {@inheritDoc}
+             */
+            @Override
+            public Throwable getCause()
+            {
+               return e;
+            }
+         };
+      }
+
+      buf = new byte[in.readInt()];
+      in.readFully(buf);
+      id = new String(buf);
+
+      int isNull = in.readInt();
+      if (isNull == NOT_NULL_VALUE)
+      {
+         buf = new byte[in.readInt()];
+         in.readFully(buf);
+         parentId = new String(buf);
+      }
+
+      version = in.readInt();
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      byte[] buf = qpath.getAsString().getBytes(Constants.DEFAULT_ENCODING);
+      out.writeInt(buf.length);
+      out.write(buf);
+
+      out.writeInt(id.getBytes().length);
+      out.write(id.getBytes());
+
+      if (parentId != null)
+      {
+         out.writeInt(NOT_NULL_VALUE);
+         out.writeInt(parentId.getBytes().length);
+         out.write(parentId.getBytes());
+      }
+      else
+         out.writeInt(NULL_VALUE);
+
+      out.writeInt(version);
+   }
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java	2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java	2009-11-09 09:19:00 UTC (rev 500)
@@ -18,14 +18,21 @@
  */
 package org.exoplatform.services.jcr.dataflow.persistent;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.jcr.RepositoryException;
+
 import org.exoplatform.services.jcr.access.AccessControlList;
 import org.exoplatform.services.jcr.dataflow.ItemDataVisitor;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
 import org.exoplatform.services.jcr.datamodel.InternalQName;
 import org.exoplatform.services.jcr.datamodel.NodeData;
 import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
 
-import javax.jcr.RepositoryException;
-
 /**
  * Created by The eXo Platform SAS.</br>
  * 
@@ -35,15 +42,23 @@
  * @version $Id$
  */
 
-public class PersistedNodeData extends PersistedItemData implements NodeData
+public class PersistedNodeData extends PersistedItemData implements NodeData, Externalizable
 {
 
-   protected final int orderNumber;
+   /**
+    * serialVersionUID to serialization. 
+    */
+   private static final long serialVersionUID = 3033563403958948338L;
 
-   protected final InternalQName primaryTypeName;
+   //TODO remove final
+   protected int orderNumber;
 
-   protected final InternalQName[] mixinTypeNames;
+   //TODO remove final
+   protected InternalQName primaryTypeName;
 
+   //TODO remove final
+   protected InternalQName[] mixinTypeNames;
+
    protected AccessControlList acl;
 
    public PersistedNodeData(String id, QPath qpath, String parentId, int version, int orderNumber,
@@ -123,4 +138,94 @@
       return true;
    }
 
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      super.readExternal(in);
+      
+      orderNumber = in.readInt();
+
+      // primary type
+      byte[] buf;
+      try
+      {
+         buf = new byte[in.readInt()];
+         in.readFully(buf);
+         primaryTypeName = InternalQName.parse(new String(buf, Constants.DEFAULT_ENCODING));
+      }
+      catch (final IllegalNameException e)
+      {
+         throw new IOException(e.getMessage())
+         {
+            private static final long serialVersionUID = 3489809179234435267L;
+
+            /**
+             * {@inheritDoc}
+             */
+            @Override
+            public Throwable getCause()
+            {
+               return e;
+            }
+         };
+      }
+
+      // mixins
+      int count = in.readInt();
+      mixinTypeNames = new InternalQName[count];
+      for (int i = 0; i < count; i++)
+      {
+         try
+         {
+            buf = new byte[in.readInt()];
+            in.readFully(buf);
+            mixinTypeNames[i] = InternalQName.parse(new String(buf, Constants.DEFAULT_ENCODING));
+         }
+         catch (final IllegalNameException e)
+         {
+            throw new IOException(e.getMessage())
+            {
+               private static final long serialVersionUID = 3489809179234435268L; // eclipse
+
+               // gen
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public Throwable getCause()
+               {
+                  return e;
+               }
+            };
+         }
+      }
+
+      // acl
+      acl.readExternal(in);
+      
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      super.writeExternal(out);
+      
+      out.writeInt(orderNumber);
+
+      // primary type
+      byte[] ptbuf = primaryTypeName.getAsString().getBytes(Constants.DEFAULT_ENCODING);
+      out.writeInt(ptbuf.length);
+      out.write(ptbuf);
+
+      // mixins
+      out.writeInt(mixinTypeNames.length);
+      for (int i = 0; i < mixinTypeNames.length; i++)
+      {
+         byte[] buf = mixinTypeNames[i].getAsString().getBytes(Constants.DEFAULT_ENCODING);
+         out.writeInt(buf.length);
+         out.write(buf);
+      }
+
+      acl.writeExternal(out);
+   }
+
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java	2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java	2009-11-09 09:19:00 UTC (rev 500)
@@ -23,6 +23,11 @@
 import org.exoplatform.services.jcr.datamodel.QPath;
 import org.exoplatform.services.jcr.datamodel.ValueData;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.jcr.RepositoryException;
@@ -36,15 +41,30 @@
  * @version $Id$
  */
 
-public class PersistedPropertyData extends PersistedItemData implements PropertyData
+public class PersistedPropertyData extends PersistedItemData implements PropertyData, Externalizable
 {
 
+   /**
+    * serialVersionUID to serialization. 
+    */
+   private static final long serialVersionUID = 2035566403758848232L;
+   
+   protected final static int NULL_VALUES = -1;
+   
    protected List<ValueData> values;
 
-   protected final int type;
+   protected int type;
 
-   protected final boolean multiValued;
+   protected boolean multiValued;
 
+   /**
+    * Empty constructor to serialization.
+    */
+   public PersistedPropertyData()
+   {
+      super();
+   }
+   
    public PersistedPropertyData(String id, QPath qpath, String parentId, int version, int type, boolean multiValued)
    {
       super(id, qpath, parentId, version);
@@ -119,5 +139,42 @@
       else
          throw new RuntimeException("The values can not be changed ");
    }
+   
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      super.writeExternal(out);
 
+      out.writeInt(type);
+      out.writeBoolean(multiValued);
+
+      if (values != null)
+      {
+         int listSize = values.size();
+         out.writeInt(listSize);
+         for (int i = 0; i < listSize; i++)
+            out.writeObject(values.get(i));
+      }
+      else
+      {
+         out.writeInt(NULL_VALUES);
+      }
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      super.readExternal(in);
+
+      type = in.readInt();
+
+      multiValued = in.readBoolean();
+
+      int listSize = in.readInt();
+      if (listSize != NULL_VALUES)
+      {
+         values = new ArrayList<ValueData>();
+         for (int i = 0; i < listSize; i++)
+            values.add((ValueData)in.readObject());
+      }
+   }
+
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java	2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java	2009-11-09 09:19:00 UTC (rev 500)
@@ -18,13 +18,14 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow;
 
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-
 import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.nio.MappedByteBuffer;
@@ -34,11 +35,28 @@
 
 import javax.jcr.RepositoryException;
 
-public class EditableValueData extends TransientValueData
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+public class EditableValueData extends TransientValueData implements Externalizable
 {
 
-   protected final int maxIOBuffSize;
+   /**
+    *  SerialVersionUID to serialization.
+    */
+   private static final long serialVersionUID = -5280857006905550884L;
+   
+   protected int maxIOBuffSize;
 
+   /**
+    * Empty constructor to serialization.
+    */
+   public EditableValueData() 
+   {
+      super();
+      maxIOBuffSize = 0;
+   }
+   
+   
    public EditableValueData(byte[] bytes, int orderNumber, FileCleaner fileCleaner, int maxBufferSize,
       File tempDirectory) throws IOException
    {
@@ -437,4 +455,14 @@
          }
       }
    }
+   
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      maxIOBuffSize = in.readInt();
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeInt(maxIOBuffSize);
+   }
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java	2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java	2009-11-09 09:19:00 UTC (rev 500)
@@ -27,6 +27,7 @@
 import java.io.InputStream;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.Serializable;
 
 import javax.jcr.RepositoryException;
 
@@ -39,6 +40,10 @@
 public class ByteArrayPersistedValueData extends AbstractValueData implements Externalizable
 {
 
+   /**
+    * The serialVersionUID.
+    */
+   private static final long serialVersionUID = -9131328056670315388L;
    protected byte[] data;
    
    /**

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java	2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java	2009-11-09 09:19:00 UTC (rev 500)
@@ -18,15 +18,16 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow.persistent;
 
-import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-import org.exoplatform.services.jcr.impl.util.io.SwapFile;
-
+import java.io.Externalizable;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import javax.jcr.RepositoryException;
 
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.SwapFile;
+
 /**
  * Created by The eXo Platform SAS. Implementation of FileStream ValueData secures deleting file in
  * object finalization
@@ -35,10 +36,23 @@
  * @version $Id$
  */
 
-public class CleanableFileStreamValueData extends FileStreamPersistedValueData
+public class CleanableFileStreamValueData extends FileStreamPersistedValueData implements Externalizable
 {
 
    protected final FileCleaner cleaner;
+   
+   
+   /**
+    *  Empty constructor to serialization.
+    * 
+    * @throws FileNotFoundException
+    */
+   public CleanableFileStreamValueData() throws FileNotFoundException
+   {
+      super();
+      //TODO
+      cleaner = null;
+   }
 
    /**
     * CleanableFileStreamValueData constructor.
@@ -76,7 +90,7 @@
 
             if (log.isDebugEnabled())
             {
-               log.debug("Ñould not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
+               log.debug("�ould not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
                   + file.getAbsolutePath());
             }
          }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java	2009-11-09 07:13:07 UTC (rev 499)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java	2009-11-09 09:19:00 UTC (rev 500)
@@ -21,10 +21,14 @@
 import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
 import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 
+import java.io.Externalizable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
 
 import javax.jcr.RepositoryException;
 
@@ -35,10 +39,24 @@
  * @version $Id$
  */
 
-public class FileStreamPersistedValueData extends AbstractValueData
+public class FileStreamPersistedValueData extends AbstractValueData implements Externalizable
 {
 
+   /**
+    * The serialVersionUID 
+    */
+   private static final long serialVersionUID = -2668587716865690994L;
+   
    protected final File file;
+   
+   /**
+    *  Empty constructor to serialization.
+    */
+   public FileStreamPersistedValueData() 
+   {
+      super(0); 
+      file = null;
+   }
 
    /**
     * FileStreamPersistedValueData  constructor.
@@ -109,6 +127,18 @@
       return false;
    }
 
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
    // TODO cleanup
    //  protected void finalize() throws Throwable {
    //    try {



More information about the exo-jcr-commits mailing list