[exo-jcr-commits] exo-jcr SVN: r1157 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Dec 23 11:49:35 EST 2009
Author: nzamosenchuk
Date: 2009-12-23 11:49:34 -0500 (Wed, 23 Dec 2009)
New Revision: 1157
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
Log:
EXOJCR-325: Merged Serialization from JBC branch. (Commits were used: 492, 496, 500)
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -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: PersistedItemData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-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-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -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: PersistedNodeData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-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-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -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: PersistedPropertyData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-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-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -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-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -928,8 +928,26 @@
}
else
{
+ // write streams
out.writeInt(2);
+ //TODO Need optimization in backup service.
+ byte[] buf = new byte[4*1024];
+
+ if (!spooled)
+ spoolInputStream();
+ InputStream in = (spoolFile == null ? new ByteArrayInputStream(data) : new FileInputStream(spoolFile));
+ long dataLength = (spoolFile == null ? data.length : spoolFile.length());
+ int len;
+
+ //write length of spoolFile
+ out.writeLong(dataLength);
+
+ while ((len = in.read(buf)) > 0)
+ out.write(buf, 0, len);
+
+ in.close();
}
+
out.writeInt(orderNumber);
out.writeInt(maxBufferSize);
}
@@ -946,6 +964,37 @@
data = new byte[in.readInt()];
in.readFully(data);
}
+ else
+ {
+ //read file form stream
+ long lengthSpoolFile = in.readLong();
+
+ //TODO May be optimization.
+ SpoolFile sf = SpoolFile.createTempFile("jcrvd", null, tempDirectory);
+ sf.acquire(this);
+ OutputStream outStream = new FileOutputStream(sf);
+
+ byte[] buf = new byte[4*1024];
+
+ while (lengthSpoolFile > 0) {
+ if (lengthSpoolFile - buf.length > 0)
+ {
+ in.readFully(buf);
+ outStream.write(buf);
+ }
+ else
+ {
+ in.readFully(buf, 0, (int) lengthSpoolFile);
+ outStream.write(buf, 0, (int) lengthSpoolFile);
+ }
+ lengthSpoolFile-=buf.length;
+ }
+ outStream.flush();
+ outStream.close();
+ spoolFile = sf;
+ spooled = true;
+ }
+
orderNumber = in.readInt();
maxBufferSize = in.readInt();
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -22,8 +22,12 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
import javax.jcr.RepositoryException;
@@ -33,10 +37,22 @@
* @author Gennady Azarenkov
* @version $Id: ByteArrayPersistedValueData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class ByteArrayPersistedValueData extends AbstractValueData
+public class ByteArrayPersistedValueData extends AbstractValueData implements Externalizable
{
+ /**
+ * The serialVersionUID.
+ */
+ private static final long serialVersionUID = -9131328056670315388L;
protected byte[] data;
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public ByteArrayPersistedValueData()
+ {
+ super(0);
+ }
/**
* ByteArrayPersistedValueData constructor.
@@ -108,4 +124,20 @@
return false;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ orderNumber = in.readInt();
+
+ data = new byte[in.readInt()];
+ in.readFully(data);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeInt(orderNumber);
+
+ out.writeInt(data.length);
+ out.write(data);
+ }
+
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -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: CleanableFileStreamValueData.java 35209 2009-08-07 15:32:27Z pnedonosko $
*/
-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-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -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: FileStreamPersistedValueData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-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 {
Copied: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java (from rev 492, jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java)
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.dataflow;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 06.11.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestTransientValueDataSerialization
+ extends JcrImplBaseTest
+{
+
+ public void testTVDSerialization() throws Exception
+ {
+ File f = createBLOBTempFile(145);
+ f.deleteOnExit();
+
+ // Create TransientValueData instants
+ TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+ tvd.setMaxBufferSize(200*1024);
+ tvd.setFileCleaner(new FileCleaner());
+
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(tvd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedTransientValueData);
+ assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+ assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+ compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+ }
+
+ public void testTVDSerialization2M() throws Exception
+ {
+ File f = createBLOBTempFile(2145);
+ f.deleteOnExit();
+
+ // Create TransientValueData instants
+ TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+ tvd.setMaxBufferSize(200*1024);
+ tvd.setFileCleaner(new FileCleaner());
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(tvd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedTransientValueData);
+ assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+ assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+ compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+ }
+}
Copied: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java (from rev 496, jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java)
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 06.11.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestByteArrayPersistedValueDataSerialization
+ extends JcrImplBaseTest
+{
+ public void testBAPVDSerialization() throws Exception
+ {
+
+ byte []buf = new byte[124578];
+
+ for (int i = 0; i< buf.length; i++)
+ buf[i] = (byte) (Math.random()*256);
+
+ // Create ValueData instants
+ ByteArrayPersistedValueData vd = new ByteArrayPersistedValueData(buf, 11);
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(vd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ ByteArrayPersistedValueData deserializedValueData = (ByteArrayPersistedValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedValueData);
+ assertEquals(vd.getLength(), deserializedValueData.getLength());
+ assertEquals(vd.getOrderNumber(), deserializedValueData.getOrderNumber());
+
+ for (int j = 0; j < vd.getAsByteArray().length; j++)
+ assertEquals(vd.getAsByteArray()[j], deserializedValueData.getAsByteArray()[j]);
+ }
+}
More information about the exo-jcr-commits
mailing list