|
From: <tho...@us...> - 2010-07-26 18:15:16
|
Revision: 3295
http://bigdata.svn.sourceforge.net/bigdata/?rev=3295&view=rev
Author: thompsonbry
Date: 2010-07-26 18:15:10 +0000 (Mon, 26 Jul 2010)
Log Message:
-----------
Added / simplified explicit versioning.
Modified Paths:
--------------
branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java 2010-07-26 18:14:42 UTC (rev 3294)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java 2010-07-26 18:15:10 UTC (rev 3295)
@@ -308,20 +308,42 @@
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ /**
+ * The initial version.
+ * <p>
+ * Note: Explicit versioning for the {@link DefaultTupleSerializer} was
+ * introduced with inlining of datatype literals for the RDF database.
+ */
+ private final static transient int VERSION0 = 0;
- delegateKeyBuilderFactory = (IKeyBuilderFactory)in.readObject();
-
- threadLocalKeyBuilderFactory = new ThreadLocalKeyBuilderFactory(delegateKeyBuilderFactory);
-
- leafKeysCoder = (IRabaCoder) in.readObject();
+ /**
+ * The current version.
+ */
+ private final static transient int VERSION = VERSION0;
- leafValsCoder = (IRabaCoder) in.readObject();
+ public void readExternal(final ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ final short version = in.readShort();
+ switch (version) {
+ case VERSION0:
+ delegateKeyBuilderFactory = (IKeyBuilderFactory) in.readObject();
+ threadLocalKeyBuilderFactory = new ThreadLocalKeyBuilderFactory(
+ delegateKeyBuilderFactory);
+ leafKeysCoder = (IRabaCoder) in.readObject();
+ leafValsCoder = (IRabaCoder) in.readObject();
+ break;
+ default:
+ throw new UnsupportedOperationException("Unknown version: "
+ + version);
+ }
+
}
- public void writeExternal(ObjectOutput out) throws IOException {
+ public void writeExternal(final bjectOutput out) throws IOException {
+ out.writeShort(VERSION);
+
out.writeObject(delegateKeyBuilderFactory);
out.writeObject(leafKeysCoder);
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java 2010-07-26 18:14:42 UTC (rev 3294)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java 2010-07-26 18:15:10 UTC (rev 3295)
@@ -32,7 +32,9 @@
import java.io.ObjectOutput;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+
import org.openrdf.model.Value;
+
import com.bigdata.btree.DefaultTupleSerializer;
import com.bigdata.btree.ITuple;
import com.bigdata.btree.keys.ASCIIKeyBuilderFactory;
@@ -202,55 +204,30 @@
return tmp;
}
-
+
/**
- * Included only the UTF serialization of the namespace field without
- * explicit version support.
- *
* <pre>
+ * valueFactoryClass:UTF
* namespace:UTF
* </pre>
*/
static final transient short VERSION0 = 0;
- /**
- * Added the UTF serialization of the class name of the value factory
- * and an explicit version number in the serialization format. This
- * version is detected by a read of an empty string from the original
- * UTF field.
- *
- * <pre>
- * "":UTF
- * valueFactoryClass:UTF
- * namespace:UTF
- * </pre>
- *
- * Note: THere are unit tests for this backward compatible serialization
- * change in TestId2TermTupleSerializer.
- */
- static final transient short VERSION1 = 1;
+ private static final transient short VERSION = VERSION0;
- private static final transient short VERSION = VERSION1;
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
- short version = VERSION0;
- String s1 = in.readUTF();
- String s2 = BigdataValueFactoryImpl.class.getName();
- if (s1.length() == 0) {
- version = in.readShort();
- s1 = in.readUTF();
- s2 = in.readUTF();
- }
+ final short version = in.readShort();
+ final String namespace;
+ final String valueFactoryClass;
switch (version) {
case VERSION0:
- case VERSION1:
+ namespace = in.readUTF();
+ valueFactoryClass = in.readUTF();
break;
default:
throw new IOException("unknown version=" + version);
}
- final String namespace = s1;
- final String valueFactoryClass = s2;
// set the namespace field.
this.namespace = namespace;
// resolve the valueSerializer from the value factory class.
@@ -275,18 +252,14 @@
valueSer = this.valueFactory.getValueSerializer();
}
- public void writeExternal(ObjectOutput out) throws IOException {
+ public void writeExternal(final ObjectOutput out) throws IOException {
super.writeExternal(out);
final short version = VERSION;
final String valueFactoryClass = valueFactory.getClass().getName();
+ out.writeShort(version);
switch (version) {
case VERSION0:
out.writeUTF(namespace);
- break;
- case VERSION1:
- out.writeUTF("");
- out.writeShort(version);
- out.writeUTF(namespace);
out.writeUTF(valueFactoryClass);
break;
default:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|