[exo-jcr-commits] exo-jcr SVN: r1086 - in jcr/branches/1.12.0-OPT/exo.jcr.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
Wed Dec 16 04:18:07 EST 2009
Author: tolusha
Date: 2009-12-16 04:18:06 -0500 (Wed, 16 Dec 2009)
New Revision: 1086
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeItemData.java
Removed:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeTransientItemData.java
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientItemData.java
Log:
EXOJCR-300: Externalize test fix
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-12-16 09:05:19 UTC (rev 1085)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-12-16 09:18:06 UTC (rev 1086)
@@ -18,10 +18,18 @@
*/
package org.exoplatform.services.jcr.dataflow.persistent;
+import org.exoplatform.services.jcr.access.AccessControlList;
+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;
import org.exoplatform.services.jcr.impl.dataflow.TransientItemData;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
import javax.jcr.RepositoryException;
/**
@@ -33,17 +41,21 @@
* @version $Id$
*/
-public abstract class PersistedItemData implements ItemData
+public abstract class PersistedItemData implements ItemData, Externalizable
{
- protected final String id;
+ protected String id;
- protected final QPath qpath;
+ protected QPath qpath;
- protected final String parentId;
+ protected String parentId;
- protected final int version;
+ protected int version;
+ private int NOT_NULL_VALUE = 1;
+
+ private int NULL_VALUE = -1;
+
public PersistedItemData(String id, QPath qpath, String parentId, int version)
{
this.id = id;
@@ -83,7 +95,7 @@
{
return parentId;
}
-
+
/**
* Creates transient copy of this persistent ItemData.
*
@@ -110,4 +122,78 @@
return false;
}
+
+ // ----------------- Externalizable
+ public PersistedItemData()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ 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();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ 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-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-16 09:05:19 UTC (rev 1085)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-16 09:18:06 UTC (rev 1086)
@@ -20,12 +20,19 @@
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 org.exoplatform.services.jcr.impl.dataflow.TransientItemData;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
import javax.jcr.RepositoryException;
/**
@@ -37,14 +44,14 @@
* @version $Id$
*/
-public class PersistedNodeData extends PersistedItemData implements NodeData
+public class PersistedNodeData extends PersistedItemData implements NodeData, Externalizable
{
- protected final int orderNumber;
+ protected int orderNumber;
- protected final InternalQName primaryTypeName;
+ protected InternalQName primaryTypeName;
- protected final InternalQName[] mixinTypeNames;
+ protected InternalQName[] mixinTypeNames;
protected AccessControlList acl;
@@ -112,12 +119,114 @@
@Override
public TransientItemData createTransientCopy()
{
-// TransientNodeData dataCopy =
-// new TransientNodeData(getQPath(), getIdentifier(), getPersistedVersion(), getPrimaryTypeName(),
-// getMixinTypeNames(), getOrderNumber(), getParentIdentifier() != null ? getParentIdentifier() : null,
-// getACL());
-//
-// return dataCopy;
+ // TransientNodeData dataCopy =
+ // new TransientNodeData(getQPath(), getIdentifier(), getPersistedVersion(), getPrimaryTypeName(),
+ // getMixinTypeNames(), getOrderNumber(), getParentIdentifier() != null ? getParentIdentifier() : null,
+ // getACL());
+ //
+ // return dataCopy;
throw new IllegalStateException("createTransientCopy deprecated");
}
+
+ // ----------------- Externalizable
+ public PersistedNodeData()
+ {
+ super();
+ acl = new AccessControlList();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ 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);
+ }
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-12-16 09:05:19 UTC (rev 1085)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-12-16 09:18:06 UTC (rev 1086)
@@ -26,6 +26,10 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientItemData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.List;
@@ -40,15 +44,17 @@
* @version $Id$
*/
-public class PersistedPropertyData extends PersistedItemData implements PropertyData
+public class PersistedPropertyData extends PersistedItemData implements PropertyData, Externalizable
{
protected List<ValueData> values;
- protected final int type;
+ protected int type;
- protected final boolean multiValued;
+ protected boolean multiValued;
+ protected final static int NULL_VALUES = -1;
+
public PersistedPropertyData(String id, QPath qpath, String parentId, int version, int type, boolean multiValued,
List<ValueData> values)
{
@@ -105,18 +111,67 @@
@Deprecated
public TransientItemData createTransientCopy() throws RepositoryException
{
-// List<ValueData> copyValues = new ArrayList<ValueData>();
-// for (ValueData vdata : getValues())
-// {
-// copyValues.add(((PersistedValueData)vdata).createTransientCopy());
-// }
-//
-// TransientPropertyData dataCopy =
-// new TransientPropertyData(getQPath(), getIdentifier(), getPersistedVersion(), getType(),
-// getParentIdentifier(), isMultiValued(), copyValues);
-//
-// return dataCopy;
-
+ // List<ValueData> copyValues = new ArrayList<ValueData>();
+ // for (ValueData vdata : getValues())
+ // {
+ // copyValues.add(((PersistedValueData)vdata).createTransientCopy());
+ // }
+ //
+ // TransientPropertyData dataCopy =
+ // new TransientPropertyData(getQPath(), getIdentifier(), getPersistedVersion(), getType(),
+ // getParentIdentifier(), isMultiValued(), copyValues);
+ //
+ // return dataCopy;
+
throw new IllegalStateException("createTransientCopy deprecated");
}
+
+ // ----------------- Externalizable
+ public PersistedPropertyData()
+ {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ 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);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ 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-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientItemData.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientItemData.java 2009-12-16 09:05:19 UTC (rev 1085)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientItemData.java 2009-12-16 09:18:06 UTC (rev 1086)
@@ -155,6 +155,9 @@
this.persistedVersion++;
}
+ /**
+ * {@inheritDoc}
+ */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
byte[] buf;
@@ -197,6 +200,9 @@
persistedVersion = in.readInt();
}
+ /**
+ * {@inheritDoc}
+ */
public void writeExternal(ObjectOutput out) throws IOException
{
byte[] buf = qpath.getAsString().getBytes(Constants.DEFAULT_ENCODING);
Added: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeItemData.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeItemData.java (rev 0)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeItemData.java 2009-12-16 09:18:06 UTC (rev 1086)
@@ -0,0 +1,80 @@
+/*
+ * 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 org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.dataflow.persistent.PersistedItemData;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 21.01.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestExternalizabeItemData extends JcrImplBaseTest
+{
+
+ public void testPersistedItemData() throws Exception
+ {
+ ItemData idSrc = ((NodeImpl)root).getData();
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(os);
+
+ assertTrue(idSrc instanceof PersistedItemData);
+
+ oos.writeObject(idSrc);
+
+ ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(is);
+
+ ItemData idDest = (ItemData)ois.readObject();
+
+ assertNotNull(idDest);
+ }
+
+ public void testTransientItemData() throws Exception
+ {
+ ItemData idSrc = ((NodeImpl)root.addNode("test")).getData();
+
+ assertTrue(idSrc instanceof TransientItemData);
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(os);
+
+ oos.writeObject(idSrc);
+
+ ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(is);
+
+ ItemData idDest = (ItemData)ois.readObject();
+
+ assertNotNull(idDest);
+ }
+
+}
Property changes on: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeItemData.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeTransientItemData.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeTransientItemData.java 2009-12-16 09:05:19 UTC (rev 1085)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestExternalizabeTransientItemData.java 2009-12-16 09:18:06 UTC (rev 1086)
@@ -1,58 +0,0 @@
-/*
- * 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 org.exoplatform.services.jcr.JcrImplBaseTest;
-import org.exoplatform.services.jcr.datamodel.ItemData;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date: 21.01.2009
- *
- * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
- * @version $Id: TestExternalizabeTransientItemData.java 111 2008-11-11 11:11:11Z rainf0x $
- */
-public class TestExternalizabeTransientItemData extends JcrImplBaseTest
-{
-
- public void testRootNode() throws Exception
- {
- ItemData idSrc = ((NodeImpl)root).getData();
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(os);
-
- oos.writeObject(idSrc);
-
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- ObjectInputStream ois = new ObjectInputStream(is);
-
- ItemData idDest = (ItemData)ois.readObject();
-
- assertNotNull(idDest);
- }
-
-}
More information about the exo-jcr-commits
mailing list