You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2005/07/25 17:50:52 UTC
svn commit: r225142 [2/2] - in
/incubator/jackrabbit/trunk/contrib/bdb-persistence: ./ applications/
applications/test/ src/ src/java/ src/java/org/ src/java/org/apache/
src/java/org/apache/jackrabbit/ src/java/org/apache/jackrabbit/core/
src/java/org/...
Added: incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/NodeStateTupleBinding.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/NodeStateTupleBinding.java?rev=225142&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/NodeStateTupleBinding.java (added)
+++ incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/NodeStateTupleBinding.java Mon Jul 25 08:50:40 2005
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.state.bdb;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.nodetype.NodeDefId;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.name.QName;
+
+import com.sleepycat.bind.tuple.TupleBinding;
+import com.sleepycat.bind.tuple.TupleInput;
+import com.sleepycat.bind.tuple.TupleOutput;
+
+public class NodeStateTupleBinding extends TupleBinding {
+
+ private Log log = LogFactory.getLog(NodeStateTupleBinding.class);
+
+ private NodeId id;
+
+ public NodeStateTupleBinding(NodeId nodeId) {
+ this.id = nodeId;
+ }
+
+ public NodeStateTupleBinding() {
+ }
+
+ public Object entryToObject(TupleInput in) {
+
+ NodeState state = new NodeState(id.getUUID(), null, null, NodeState.STATUS_NEW, false);
+
+ // check uuid
+ String s = in.readString();
+ if (!state.getUUID().equals(s)) {
+ String msg = "invalid serialized state: uuid mismatch";
+ log.debug(msg);
+ throw new RuntimeException(msg);
+ }
+
+ // deserialize node state
+
+ // primaryType
+ s = in.readString();
+ state.setNodeTypeName(QName.valueOf(s));
+ // parentUUID
+ s = in.readString();
+ if (s.length() > 0) {
+ state.setParentUUID(s);
+ }
+ // definitionId
+ s = in.readString();
+ state.setDefinitionId(NodeDefId.valueOf(s));
+ // mixin types
+ int count = in.readInt(); // count
+ Set set = new HashSet(count);
+ for (int i = 0; i < count; i++) {
+ set.add(QName.valueOf(in.readString())); // name
+ }
+ if (set.size() > 0) {
+ state.setMixinTypeNames(set);
+ }
+ // properties (names)
+ count = in.readInt(); // count
+ for (int i = 0; i < count; i++) {
+ state.addPropertyName(QName.valueOf(in.readString())); // name
+ }
+ // child nodes (list of name/uuid pairs)
+ count = in.readInt(); // count
+ for (int i = 0; i < count; i++) {
+ QName name = QName.valueOf(in.readString()); // name
+ String s1 = in.readString(); // uuid
+ state.addChildNodeEntry(name, s1);
+ }
+
+ return state;
+ }
+
+ public void objectToEntry(Object o, TupleOutput out) {
+
+ NodeState state = (NodeState) o;
+
+ // uuid
+ out.writeString(state.getUUID());
+ // primaryType
+ out.writeString(state.getNodeTypeName().toString());
+ // parentUUID
+ out.writeString(state.getParentUUID() == null ? "" : state.getParentUUID());
+ // definitionId
+ out.writeString(state.getDefinitionId().toString());
+ // mixin types
+ Collection c = state.getMixinTypeNames();
+ out.writeInt(c.size()); // count
+ for (Iterator iter = c.iterator(); iter.hasNext();) {
+ out.writeString(iter.next().toString()); // name
+ }
+ // properties (names)
+ c = state.getPropertyNames();
+ out.writeInt(c.size()); // count
+ for (Iterator iter = c.iterator(); iter.hasNext();) {
+ QName propName = (QName) iter.next();
+ out.writeString(propName.toString()); // name
+ }
+ // child nodes (list of name/uuid pairs)
+ c = state.getChildNodeEntries();
+ out.writeInt(c.size()); // count
+ for (Iterator iter = c.iterator(); iter.hasNext();) {
+ NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
+ out.writeString(entry.getName().toString()); // name
+ out.writeString(entry.getUUID()); // uuid
+ }
+
+ }
+
+}
Propchange: incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/NodeStateTupleBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/PropertyStateTupleBinding.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/PropertyStateTupleBinding.java?rev=225142&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/PropertyStateTupleBinding.java (added)
+++ incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/PropertyStateTupleBinding.java Mon Jul 25 08:50:40 2005
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.state.bdb;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.nodetype.PropDefId;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.value.BLOBFileValue;
+import org.apache.jackrabbit.core.value.InternalValue;
+
+import com.sleepycat.bind.tuple.TupleBinding;
+import com.sleepycat.bind.tuple.TupleInput;
+import com.sleepycat.bind.tuple.TupleOutput;
+
+public class PropertyStateTupleBinding extends TupleBinding {
+
+ private BLOBStore blobStore;
+ private PropertyId id;
+
+ public PropertyStateTupleBinding(BLOBStore blobStore) {
+ this.blobStore = blobStore;
+ }
+
+ public PropertyStateTupleBinding(PropertyId propertyId, BLOBStore blobStore) {
+ this.blobStore = blobStore;
+ this.id = propertyId;
+ }
+
+ public Object entryToObject(TupleInput in) {
+ try {
+ PropertyState state = new PropertyState(id.getName(), id.getParentUUID(), PropertyState.STATUS_NEW, false);
+
+ // type
+ int type = in.readInt();
+ state.setType(type);
+ // multiValued
+ boolean multiValued = in.readBoolean();
+ state.setMultiValued(multiValued);
+ // definitionId
+ String s = in.readString();
+ state.setDefinitionId(PropDefId.valueOf(s));
+ // values
+ int count = in.readInt(); // count
+ InternalValue[] values = new InternalValue[count];
+ for (int i = 0; i < count; i++) {
+ InternalValue val;
+ if (type == PropertyType.BINARY) {
+ s = in.readString(); // value (i.e. blobId)
+ // special handling required for binary value:
+ // the value stores the id of the blob resource in the blob store
+ val = InternalValue.create(blobStore.get(s));
+ } else {
+ int len = in.readInt(); // lenght of byte[]
+ byte[] bytes = new byte[len];
+ in.read(bytes); // byte[]
+ s = new String(bytes, BerkeleyDBPersistenceManager.ENCODING);
+ val = InternalValue.valueOf(s, type);
+ }
+ values[i] = val;
+ }
+ state.setValues(values);
+
+ return state;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void objectToEntry(Object o, TupleOutput out) {
+ try {
+ PropertyState state = (PropertyState) o;
+
+ // type
+ out.writeInt(state.getType());
+ // multiValued
+ out.writeBoolean(state.isMultiValued());
+ // definitionId
+ out.writeString(state.getDefinitionId().toString());
+ // values
+ InternalValue[] values = state.getValues();
+ out.writeInt(values.length); // count
+ for (int i = 0; i < values.length; i++) {
+ InternalValue val = values[i];
+ if (state.getType() == PropertyType.BINARY) {
+ // special handling required for binary value:
+ // spool binary value to file in blob store
+ BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
+ InputStream in = blobVal.getStream();
+ String blobId;
+ try {
+ blobId = blobStore.put((PropertyId) state.getId(), i, in, blobVal.getLength());
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ // store id of blob as property value
+ out.writeString(blobId); // value
+ // replace value instance with value
+ // backed by resource in blob store and delete temp file
+ values[i] = InternalValue.create(blobStore.get(blobId));
+ blobVal.discard();
+ blobVal = null; // gc hint
+ } else {
+ byte[] bytes = val.toString().getBytes(BerkeleyDBPersistenceManager.ENCODING);
+ out.writeInt(bytes.length); // lenght of byte[]
+ out.write(bytes); // byte[]
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Propchange: incubator/jackrabbit/trunk/contrib/bdb-persistence/src/java/org/apache/jackrabbit/core/state/bdb/PropertyStateTupleBinding.java
------------------------------------------------------------------------------
svn:eol-style = native