You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gora.apache.org by le...@apache.org on 2014/06/04 18:36:26 UTC
[09/50] [abbrv] GORA-321. Merge GORA_94 into Gora trunk
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/examples/java/org/apache/gora/examples/generated/WebPage.java
----------------------------------------------------------------------
diff --git a/gora-core/src/examples/java/org/apache/gora/examples/generated/WebPage.java b/gora-core/src/examples/java/org/apache/gora/examples/generated/WebPage.java
index 9827aec..44b3e0a 100644
--- a/gora-core/src/examples/java/org/apache/gora/examples/generated/WebPage.java
+++ b/gora-core/src/examples/java/org/apache/gora/examples/generated/WebPage.java
@@ -1,277 +1,667 @@
/**
- *Licensed to the Apache Software Foundation (ASF) under one
- *or more contributor license agreements. See the NOTICE file
- *distributed with this work for additional information
- *regarding copyright ownership. The ASF licenses this file
- *to you 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
+ * Autogenerated by Avro
*
- *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.
+ * DO NOT EDIT DIRECTLY
*/
-
-package org.apache.gora.examples.generated;
-
-import java.nio.ByteBuffer;
-import java.util.Map;
-import java.util.HashMap;
-import org.apache.avro.Protocol;
-import org.apache.avro.Schema;
-import org.apache.avro.AvroRuntimeException;
-import org.apache.avro.Protocol;
-import org.apache.avro.util.Utf8;
-import org.apache.avro.ipc.AvroRemoteException;
-import org.apache.avro.generic.GenericArray;
-import org.apache.avro.specific.FixedSize;
-import org.apache.avro.specific.SpecificExceptionBase;
-import org.apache.avro.specific.SpecificRecordBase;
-import org.apache.avro.specific.SpecificRecord;
-import org.apache.avro.specific.SpecificFixed;
-import org.apache.gora.persistency.StateManager;
-import org.apache.gora.persistency.impl.PersistentBase;
-import org.apache.gora.persistency.impl.StateManagerImpl;
-import org.apache.gora.persistency.StatefulHashMap;
-import org.apache.gora.persistency.ListGenericArray;
+package org.apache.gora.examples.generated;
@SuppressWarnings("all")
-public class WebPage extends PersistentBase {
-
- /**
- * Variable holding the data bean schema.
- */
- public static final Schema _SCHEMA = Schema.parse("{\"type\":\"record\",\"name\":\"WebPage\",\"namespace\":\"org.apache.gora.examples.generated\",\"fields\":[{\"name\":\"url\",\"type\":\"string\"},{\"name\":\"content\",\"type\":[\"null\",\"bytes\"]},{\"name\":\"parsedContent\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"outlinks\",\"type\":{\"type\":\"map\",\"values\":\"string\"}},{\"name\":\"metadata\",\"type\":{\"type\":\"record\",\"name\":\"Metadata\",\"fields\":[{\"name\":\"version\",\"type\":\"int\"},{\"name\":\"data\",\"type\":{\"type\":\"map\",\"values\":\"string\"}}]}}]}");
-
- /**
- * Enum containing all data bean's fields.
- */
+public class WebPage extends org.apache.gora.persistency.impl.PersistentBase implements org.apache.avro.specific.SpecificRecord, org.apache.gora.persistency.Persistent {
+ public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"WebPage\",\"namespace\":\"org.apache.gora.examples.generated\",\"fields\":[{\"name\":\"__g__dirty\",\"type\":\"bytes\",\"doc\":\"Bytes used to represent weather or not a field is dirty.\",\"default\":\"AA==\"},{\"name\":\"url\",\"type\":[\"null\",\"string\"],\"default\":null},{\"name\":\"content\",\"type\":[\"null\",\"bytes\"],\"default\":null},{\"name\":\"parsedContent\",\"type\":{\"type\":\"array\",\"items\":\"string\"},\"default\":{}},{\"name\":\"outlinks\",\"type\":{\"type\":\"map\",\"values\":[\"null\",\"string\"]},\"default\":{}},{\"name\":\"headers\",\"type\":[\"null\",{\"type\":\"map\",\"values\":[\"null\",\"string\"]}],\"default\":null},{\"name\":\"metadata\",\"type\":{\"type\":\"record\",\"name\":\"Metadata\",\"fields\":[{\"name\":\"__g__dirty\",\"type\":\"bytes\",\"doc\":\"Bytes used to represent weather or not a field is dirty.\",\"default\":\
"AA==\"},{\"name\":\"version\",\"type\":\"int\",\"default\":0},{\"name\":\"data\",\"type\":{\"type\":\"map\",\"values\":\"string\"},\"default\":{}}]},\"default\":null}]}");
+
+ /** Enum containing all data bean's fields. */
public static enum Field {
- URL(0,"url"),
- CONTENT(1,"content"),
- PARSED_CONTENT(2,"parsedContent"),
- OUTLINKS(3,"outlinks"),
- METADATA(4,"metadata"),
+ __G__DIRTY(0, "__g__dirty"),
+ URL(1, "url"),
+ CONTENT(2, "content"),
+ PARSED_CONTENT(3, "parsedContent"),
+ OUTLINKS(4, "outlinks"),
+ HEADERS(5, "headers"),
+ METADATA(6, "metadata"),
;
-
/**
* Field's index.
*/
private int index;
-
+
/**
* Field's name.
*/
private String name;
-
+
/**
* Field's constructor
* @param index field's index.
* @param name field's name.
*/
Field(int index, String name) {this.index=index;this.name=name;}
-
+
/**
* Gets field's index.
* @return int field's index.
*/
public int getIndex() {return index;}
-
+
/**
* Gets field's name.
* @return String field's name.
*/
public String getName() {return name;}
-
+
/**
* Gets field's attributes to string.
* @return String field's attributes to string.
*/
public String toString() {return name;}
};
-
- /**
- * Contains all field's names.
- */
- public static final String[] _ALL_FIELDS = {"url","content","parsedContent","outlinks","metadata",};
- static {
- PersistentBase.registerFields(WebPage.class, _ALL_FIELDS);
+
+ public static final String[] _ALL_FIELDS = {
+ "__g__dirty",
+ "url",
+ "content",
+ "parsedContent",
+ "outlinks",
+ "headers",
+ "metadata",
+ };
+
+ /** Bytes used to represent weather or not a field is dirty. */
+ private java.nio.ByteBuffer __g__dirty = java.nio.ByteBuffer.wrap(new byte[1]);
+ private java.lang.CharSequence url;
+ private java.nio.ByteBuffer content;
+ private java.util.List<java.lang.CharSequence> parsedContent;
+ private java.util.Map<java.lang.CharSequence,java.lang.CharSequence> outlinks;
+ private java.util.Map<java.lang.CharSequence,java.lang.CharSequence> headers;
+ private org.apache.gora.examples.generated.Metadata metadata;
+ public org.apache.avro.Schema getSchema() { return SCHEMA$; }
+ // Used by DatumWriter. Applications should not call.
+ public java.lang.Object get(int field$) {
+ switch (field$) {
+ case 0: return __g__dirty;
+ case 1: return url;
+ case 2: return content;
+ case 3: return parsedContent;
+ case 4: return outlinks;
+ case 5: return headers;
+ case 6: return metadata;
+ default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ }
}
- private Utf8 url;
- private ByteBuffer content;
- private GenericArray<Utf8> parsedContent;
- private Map<Utf8,Utf8> outlinks;
- private Metadata metadata;
+ // Used by DatumReader. Applications should not call.
+ @SuppressWarnings(value="unchecked")
+ public void put(int field$, java.lang.Object value) {
+ switch (field$) {
+ case 0: __g__dirty = (java.nio.ByteBuffer)(value); break;
+ case 1: url = (java.lang.CharSequence)(value); break;
+ case 2: content = (java.nio.ByteBuffer)(value); break;
+ case 3: parsedContent = (java.util.List<java.lang.CharSequence>)((value instanceof org.apache.gora.persistency.Dirtyable) ? value : new org.apache.gora.persistency.impl.DirtyListWrapper((java.util.List)value)); break;
+ case 4: outlinks = (java.util.Map<java.lang.CharSequence,java.lang.CharSequence>)((value instanceof org.apache.gora.persistency.Dirtyable) ? value : new org.apache.gora.persistency.impl.DirtyMapWrapper((java.util.Map)value)); break;
+ case 5: headers = (java.util.Map<java.lang.CharSequence,java.lang.CharSequence>)(value); break;
+ case 6: metadata = (org.apache.gora.examples.generated.Metadata)(value); break;
+ default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ }
+ }
+
/**
- * Default Constructor
+ * Gets the value of the 'url' field.
*/
- public WebPage() {
- this(new StateManagerImpl());
+ public java.lang.CharSequence getUrl() {
+ return url;
}
-
+
/**
- * Constructor
- * @param stateManager for the data bean.
+ * Sets the value of the 'url' field.
+ * @param value the value to set.
*/
- public WebPage(StateManager stateManager) {
- super(stateManager);
- parsedContent = new ListGenericArray<Utf8>(getSchema().getField("parsedContent").schema());
- outlinks = new StatefulHashMap<Utf8,Utf8>();
+ public void setUrl(java.lang.CharSequence value) {
+ this.url = value;
+ setDirty(1);
}
/**
- * Returns a new instance by using a state manager.
- * @param stateManager for the data bean.
- * @return WebPage created.
+ * Checks the dirty status of the 'url' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
*/
- public WebPage newInstance(StateManager stateManager) {
- return new WebPage(stateManager);
+ public boolean isUrlDirty(java.lang.CharSequence value) {
+ return isDirty(1);
}
-
+
/**
- * Returns the schema of the data bean.
- * @return Schema for the data bean.
+ * Gets the value of the 'content' field.
*/
- public Schema getSchema() { return _SCHEMA; }
-
+ public java.nio.ByteBuffer getContent() {
+ return content;
+ }
+
/**
- * Gets a specific field.
- * @param field index of a field for the data bean.
- * @return Object representing a data bean's field.
+ * Sets the value of the 'content' field.
+ * @param value the value to set.
*/
- public Object get(int _field) {
- switch (_field) {
- case 0: return url;
- case 1: return content;
- case 2: return parsedContent;
- case 3: return outlinks;
- case 4: return metadata;
- default: throw new AvroRuntimeException("Bad index");
- }
+ public void setContent(java.nio.ByteBuffer value) {
+ this.content = value;
+ setDirty(2);
}
/**
- * Puts a value for a specific field.
- * @param field index of a field for the data bean.
- * @param value value of a field for the data bean.
+ * Checks the dirty status of the 'content' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
*/
- @SuppressWarnings(value="unchecked")
- public void put(int _field, Object _value) {
- if(isFieldEqual(_field, _value)) return;
- getStateManager().setDirty(this, _field);
- switch (_field) {
- case 0:url = (Utf8)_value; break;
- case 1:content = (ByteBuffer)_value; break;
- case 2:parsedContent = (GenericArray<Utf8>)_value; break;
- case 3:outlinks = (Map<Utf8,Utf8>)_value; break;
- case 4:metadata = (Metadata)_value; break;
- default: throw new AvroRuntimeException("Bad index");
- }
+ public boolean isContentDirty(java.nio.ByteBuffer value) {
+ return isDirty(2);
}
-
+
/**
- * Gets the Url.
- * @return Utf8 representing WebPage Url.
+ * Gets the value of the 'parsedContent' field.
*/
- public Utf8 getUrl() {
- return (Utf8) get(0);
+ public java.util.List<java.lang.CharSequence> getParsedContent() {
+ return parsedContent;
}
-
+
/**
- * Sets the Url.
- * @param value containing WebPage Url.
+ * Sets the value of the 'parsedContent' field.
+ * @param value the value to set.
*/
- public void setUrl(Utf8 value) {
- put(0, value);
+ public void setParsedContent(java.util.List<java.lang.CharSequence> value) {
+ this.parsedContent = (value instanceof org.apache.gora.persistency.Dirtyable) ? value : new org.apache.gora.persistency.impl.DirtyListWrapper(value);
+ setDirty(3);
}
/**
- * Gets Content.
- * @return the ByteBuffer value.
+ * Checks the dirty status of the 'parsedContent' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
*/
- public ByteBuffer getContent() {
- return (ByteBuffer) get(1);
+ public boolean isParsedContentDirty(java.util.List<java.lang.CharSequence> value) {
+ return isDirty(3);
}
-
+
/**
- * Sets the Content.
- * @param the Content value to be set.
+ * Gets the value of the 'outlinks' field.
*/
- public void setContent(ByteBuffer value) {
- put(1, value);
+ public java.util.Map<java.lang.CharSequence,java.lang.CharSequence> getOutlinks() {
+ return outlinks;
}
-
+
/**
- * Gets the ParsedContent array.
- * @return GenericArray<Utf8> containing Utf8 elements.
+ * Sets the value of the 'outlinks' field.
+ * @param value the value to set.
*/
- public GenericArray<Utf8> getParsedContent() {
- return (GenericArray<Utf8>) get(2);
+ public void setOutlinks(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ this.outlinks = (value instanceof org.apache.gora.persistency.Dirtyable) ? value : new org.apache.gora.persistency.impl.DirtyMapWrapper(value);
+ setDirty(4);
}
/**
- * Adds a Utf8 element into the array.
- * @param the Utf8 element to be added.
+ * Checks the dirty status of the 'outlinks' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
*/
- public void addToParsedContent(Utf8 element) {
- getStateManager().setDirty(this, 2);
- parsedContent.add(element);
+ public boolean isOutlinksDirty(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ return isDirty(4);
}
-
+
/**
- * Gets Outlinks.
- * @return Map containing Outlinks value.
+ * Gets the value of the 'headers' field.
*/
- public Map<Utf8, Utf8> getOutlinks() {
- return (Map<Utf8, Utf8>) get(3);
+ public java.util.Map<java.lang.CharSequence,java.lang.CharSequence> getHeaders() {
+ return headers;
}
-
+
/**
- * Gets the Outlinks's value using a key.
- * @param key gets a specific Outlinks using a WebPageID.
- * @return Utf8 containing Outlinks value.
+ * Sets the value of the 'headers' field.
+ * @param value the value to set.
*/
- public Utf8 getFromOutlinks(Utf8 key) {
- if (outlinks == null) { return null; }
- return outlinks.get(key);
+ public void setHeaders(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ this.headers = value;
+ setDirty(5);
}
/**
- * Adds a Outlinks into a WebPage.
- * @param Map containing Outlinks value.
+ * Checks the dirty status of the 'headers' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
*/
- public void putToOutlinks(Utf8 key, Utf8 value) {
- getStateManager().setDirty(this, 3);
- outlinks.put(key, value);
+ public boolean isHeadersDirty(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ return isDirty(5);
}
-
+
+ /**
+ * Gets the value of the 'metadata' field.
+ */
+ public org.apache.gora.examples.generated.Metadata getMetadata() {
+ return metadata;
+ }
+
/**
- * Removes Outlinks from a WebPage.
- * @return key WebPage ID to be removed.
+ * Sets the value of the 'metadata' field.
+ * @param value the value to set.
*/
- public Utf8 removeFromOutlinks(Utf8 key) {
- if (outlinks == null) { return null; }
- getStateManager().setDirty(this, 3);
- return outlinks.remove(key);
+ public void setMetadata(org.apache.gora.examples.generated.Metadata value) {
+ this.metadata = value;
+ setDirty(6);
}
/**
- * Gets the Metadata.
- * @return Metadata representing WebPage Metadata.
+ * Checks the dirty status of the 'metadata' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
*/
- public Metadata getMetadata() {
- return (Metadata) get(4);
+ public boolean isMetadataDirty(org.apache.gora.examples.generated.Metadata value) {
+ return isDirty(6);
+ }
+
+ /** Creates a new WebPage RecordBuilder */
+ public static org.apache.gora.examples.generated.WebPage.Builder newBuilder() {
+ return new org.apache.gora.examples.generated.WebPage.Builder();
+ }
+
+ /** Creates a new WebPage RecordBuilder by copying an existing Builder */
+ public static org.apache.gora.examples.generated.WebPage.Builder newBuilder(org.apache.gora.examples.generated.WebPage.Builder other) {
+ return new org.apache.gora.examples.generated.WebPage.Builder(other);
+ }
+
+ /** Creates a new WebPage RecordBuilder by copying an existing WebPage instance */
+ public static org.apache.gora.examples.generated.WebPage.Builder newBuilder(org.apache.gora.examples.generated.WebPage other) {
+ return new org.apache.gora.examples.generated.WebPage.Builder(other);
+ }
+
+ private static java.nio.ByteBuffer deepCopyToWriteOnlyBuffer(
+ java.nio.ByteBuffer input) {
+ java.nio.ByteBuffer copy = java.nio.ByteBuffer.allocate(input.capacity());
+ int position = input.position();
+ input.reset();
+ int mark = input.position();
+ int limit = input.limit();
+ input.rewind();
+ input.limit(input.capacity());
+ copy.put(input);
+ input.rewind();
+ copy.rewind();
+ input.position(mark);
+ input.mark();
+ copy.position(mark);
+ copy.mark();
+ input.position(position);
+ copy.position(position);
+ input.limit(limit);
+ copy.limit(limit);
+ return copy.asReadOnlyBuffer();
}
/**
- * Sets the Metadata.
- * @param value containing WebPage Metadata.
+ * RecordBuilder for WebPage instances.
*/
- public void setMetadata(Metadata value) {
- put(4, value);
+ public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<WebPage>
+ implements org.apache.avro.data.RecordBuilder<WebPage> {
+
+ private java.nio.ByteBuffer __g__dirty;
+ private java.lang.CharSequence url;
+ private java.nio.ByteBuffer content;
+ private java.util.List<java.lang.CharSequence> parsedContent;
+ private java.util.Map<java.lang.CharSequence,java.lang.CharSequence> outlinks;
+ private java.util.Map<java.lang.CharSequence,java.lang.CharSequence> headers;
+ private org.apache.gora.examples.generated.Metadata metadata;
+
+ /** Creates a new Builder */
+ private Builder() {
+ super(org.apache.gora.examples.generated.WebPage.SCHEMA$);
+ }
+
+ /** Creates a Builder by copying an existing Builder */
+ private Builder(org.apache.gora.examples.generated.WebPage.Builder other) {
+ super(other);
+ }
+
+ /** Creates a Builder by copying an existing WebPage instance */
+ private Builder(org.apache.gora.examples.generated.WebPage other) {
+ super(org.apache.gora.examples.generated.WebPage.SCHEMA$);
+ if (isValidValue(fields()[0], other.__g__dirty)) {
+ this.__g__dirty = (java.nio.ByteBuffer) data().deepCopy(fields()[0].schema(), other.__g__dirty);
+ fieldSetFlags()[0] = true;
+ }
+ if (isValidValue(fields()[1], other.url)) {
+ this.url = (java.lang.CharSequence) data().deepCopy(fields()[1].schema(), other.url);
+ fieldSetFlags()[1] = true;
+ }
+ if (isValidValue(fields()[2], other.content)) {
+ this.content = (java.nio.ByteBuffer) data().deepCopy(fields()[2].schema(), other.content);
+ fieldSetFlags()[2] = true;
+ }
+ if (isValidValue(fields()[3], other.parsedContent)) {
+ this.parsedContent = (java.util.List<java.lang.CharSequence>) data().deepCopy(fields()[3].schema(), other.parsedContent);
+ fieldSetFlags()[3] = true;
+ }
+ if (isValidValue(fields()[4], other.outlinks)) {
+ this.outlinks = (java.util.Map<java.lang.CharSequence,java.lang.CharSequence>) data().deepCopy(fields()[4].schema(), other.outlinks);
+ fieldSetFlags()[4] = true;
+ }
+ if (isValidValue(fields()[5], other.headers)) {
+ this.headers = (java.util.Map<java.lang.CharSequence,java.lang.CharSequence>) data().deepCopy(fields()[5].schema(), other.headers);
+ fieldSetFlags()[5] = true;
+ }
+ if (isValidValue(fields()[6], other.metadata)) {
+ this.metadata = (org.apache.gora.examples.generated.Metadata) data().deepCopy(fields()[6].schema(), other.metadata);
+ fieldSetFlags()[6] = true;
+ }
+ }
+
+ /** Gets the value of the 'url' field */
+ public java.lang.CharSequence getUrl() {
+ return url;
+ }
+
+ /** Sets the value of the 'url' field */
+ public org.apache.gora.examples.generated.WebPage.Builder setUrl(java.lang.CharSequence value) {
+ validate(fields()[1], value);
+ this.url = value;
+ fieldSetFlags()[1] = true;
+ return this;
+ }
+
+ /** Checks whether the 'url' field has been set */
+ public boolean hasUrl() {
+ return fieldSetFlags()[1];
+ }
+
+ /** Clears the value of the 'url' field */
+ public org.apache.gora.examples.generated.WebPage.Builder clearUrl() {
+ url = null;
+ fieldSetFlags()[1] = false;
+ return this;
+ }
+
+ /** Gets the value of the 'content' field */
+ public java.nio.ByteBuffer getContent() {
+ return content;
+ }
+
+ /** Sets the value of the 'content' field */
+ public org.apache.gora.examples.generated.WebPage.Builder setContent(java.nio.ByteBuffer value) {
+ validate(fields()[2], value);
+ this.content = value;
+ fieldSetFlags()[2] = true;
+ return this;
+ }
+
+ /** Checks whether the 'content' field has been set */
+ public boolean hasContent() {
+ return fieldSetFlags()[2];
+ }
+
+ /** Clears the value of the 'content' field */
+ public org.apache.gora.examples.generated.WebPage.Builder clearContent() {
+ content = null;
+ fieldSetFlags()[2] = false;
+ return this;
+ }
+
+ /** Gets the value of the 'parsedContent' field */
+ public java.util.List<java.lang.CharSequence> getParsedContent() {
+ return parsedContent;
+ }
+
+ /** Sets the value of the 'parsedContent' field */
+ public org.apache.gora.examples.generated.WebPage.Builder setParsedContent(java.util.List<java.lang.CharSequence> value) {
+ validate(fields()[3], value);
+ this.parsedContent = value;
+ fieldSetFlags()[3] = true;
+ return this;
+ }
+
+ /** Checks whether the 'parsedContent' field has been set */
+ public boolean hasParsedContent() {
+ return fieldSetFlags()[3];
+ }
+
+ /** Clears the value of the 'parsedContent' field */
+ public org.apache.gora.examples.generated.WebPage.Builder clearParsedContent() {
+ parsedContent = null;
+ fieldSetFlags()[3] = false;
+ return this;
+ }
+
+ /** Gets the value of the 'outlinks' field */
+ public java.util.Map<java.lang.CharSequence,java.lang.CharSequence> getOutlinks() {
+ return outlinks;
+ }
+
+ /** Sets the value of the 'outlinks' field */
+ public org.apache.gora.examples.generated.WebPage.Builder setOutlinks(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ validate(fields()[4], value);
+ this.outlinks = value;
+ fieldSetFlags()[4] = true;
+ return this;
+ }
+
+ /** Checks whether the 'outlinks' field has been set */
+ public boolean hasOutlinks() {
+ return fieldSetFlags()[4];
+ }
+
+ /** Clears the value of the 'outlinks' field */
+ public org.apache.gora.examples.generated.WebPage.Builder clearOutlinks() {
+ outlinks = null;
+ fieldSetFlags()[4] = false;
+ return this;
+ }
+
+ /** Gets the value of the 'headers' field */
+ public java.util.Map<java.lang.CharSequence,java.lang.CharSequence> getHeaders() {
+ return headers;
+ }
+
+ /** Sets the value of the 'headers' field */
+ public org.apache.gora.examples.generated.WebPage.Builder setHeaders(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ validate(fields()[5], value);
+ this.headers = value;
+ fieldSetFlags()[5] = true;
+ return this;
+ }
+
+ /** Checks whether the 'headers' field has been set */
+ public boolean hasHeaders() {
+ return fieldSetFlags()[5];
+ }
+
+ /** Clears the value of the 'headers' field */
+ public org.apache.gora.examples.generated.WebPage.Builder clearHeaders() {
+ headers = null;
+ fieldSetFlags()[5] = false;
+ return this;
+ }
+
+ /** Gets the value of the 'metadata' field */
+ public org.apache.gora.examples.generated.Metadata getMetadata() {
+ return metadata;
+ }
+
+ /** Sets the value of the 'metadata' field */
+ public org.apache.gora.examples.generated.WebPage.Builder setMetadata(org.apache.gora.examples.generated.Metadata value) {
+ validate(fields()[6], value);
+ this.metadata = value;
+ fieldSetFlags()[6] = true;
+ return this;
+ }
+
+ /** Checks whether the 'metadata' field has been set */
+ public boolean hasMetadata() {
+ return fieldSetFlags()[6];
+ }
+
+ /** Clears the value of the 'metadata' field */
+ public org.apache.gora.examples.generated.WebPage.Builder clearMetadata() {
+ metadata = null;
+ fieldSetFlags()[6] = false;
+ return this;
+ }
+
+ @Override
+ public WebPage build() {
+ try {
+ WebPage record = new WebPage();
+ record.__g__dirty = fieldSetFlags()[0] ? this.__g__dirty : (java.nio.ByteBuffer) java.nio.ByteBuffer.wrap(new byte[1]);
+ record.url = fieldSetFlags()[1] ? this.url : (java.lang.CharSequence) defaultValue(fields()[1]);
+ record.content = fieldSetFlags()[2] ? this.content : (java.nio.ByteBuffer) defaultValue(fields()[2]);
+ record.parsedContent = fieldSetFlags()[3] ? this.parsedContent : (java.util.List<java.lang.CharSequence>) new org.apache.gora.persistency.impl.DirtyListWrapper((java.util.List)defaultValue(fields()[3]));
+ record.outlinks = fieldSetFlags()[4] ? this.outlinks : (java.util.Map<java.lang.CharSequence,java.lang.CharSequence>) new org.apache.gora.persistency.impl.DirtyMapWrapper((java.util.Map)defaultValue(fields()[4]));
+ record.headers = fieldSetFlags()[5] ? this.headers : (java.util.Map<java.lang.CharSequence,java.lang.CharSequence>) defaultValue(fields()[5]);
+ record.metadata = fieldSetFlags()[6] ? this.metadata : (org.apache.gora.examples.generated.Metadata) Metadata.newBuilder().build();
+ return record;
+ } catch (Exception e) {
+ throw new org.apache.avro.AvroRuntimeException(e);
+ }
+ }
+ }
+
+ public WebPage.Tombstone getTombstone(){
+ return TOMBSTONE;
}
-}
+
+ public WebPage newInstance(){
+ return newBuilder().build();
+ }
+
+ private static final Tombstone TOMBSTONE = new Tombstone();
+
+ public static final class Tombstone extends WebPage implements org.apache.gora.persistency.Tombstone {
+
+ private Tombstone() { }
+
+ /**
+ * Gets the value of the 'url' field.
+ */
+ public java.lang.CharSequence getUrl() {
+ throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
+ }
+
+ /**
+ * Sets the value of the 'url' field.
+ * @param value the value to set.
+ */
+ public void setUrl(java.lang.CharSequence value) {
+ throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
+ }
+
+ /**
+ * Checks the dirty status of the 'url' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
+ */
+ public boolean isUrlDirty(java.lang.CharSequence value) {
+ throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
+ }
+
+ /**
+ * Gets the value of the 'content' field.
+ */
+ public java.nio.ByteBuffer getContent() {
+ throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
+ }
+
+ /**
+ * Sets the value of the 'content' field.
+ * @param value the value to set.
+ */
+ public void setContent(java.nio.ByteBuffer value) {
+ throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
+ }
+
+ /**
+ * Checks the dirty status of the 'content' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
+ */
+ public boolean isContentDirty(java.nio.ByteBuffer value) {
+ throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
+ }
+
+ /**
+ * Gets the value of the 'parsedContent' field.
+ */
+ public java.util.List<java.lang.CharSequence> getParsedContent() {
+ throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
+ }
+
+ /**
+ * Sets the value of the 'parsedContent' field.
+ * @param value the value to set.
+ */
+ public void setParsedContent(java.util.List<java.lang.CharSequence> value) {
+ throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
+ }
+
+ /**
+ * Checks the dirty status of the 'parsedContent' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
+ */
+ public boolean isParsedContentDirty(java.util.List<java.lang.CharSequence> value) {
+ throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
+ }
+
+ /**
+ * Gets the value of the 'outlinks' field.
+ */
+ public java.util.Map<java.lang.CharSequence,java.lang.CharSequence> getOutlinks() {
+ throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
+ }
+
+ /**
+ * Sets the value of the 'outlinks' field.
+ * @param value the value to set.
+ */
+ public void setOutlinks(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
+ }
+
+ /**
+ * Checks the dirty status of the 'outlinks' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
+ */
+ public boolean isOutlinksDirty(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
+ }
+
+ /**
+ * Gets the value of the 'headers' field.
+ */
+ public java.util.Map<java.lang.CharSequence,java.lang.CharSequence> getHeaders() {
+ throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
+ }
+
+ /**
+ * Sets the value of the 'headers' field.
+ * @param value the value to set.
+ */
+ public void setHeaders(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
+ }
+
+ /**
+ * Checks the dirty status of the 'headers' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
+ */
+ public boolean isHeadersDirty(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> value) {
+ throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
+ }
+
+ /**
+ * Gets the value of the 'metadata' field.
+ */
+ public org.apache.gora.examples.generated.Metadata getMetadata() {
+ throw new java.lang.UnsupportedOperationException("Get is not supported on tombstones");
+ }
+
+ /**
+ * Sets the value of the 'metadata' field.
+ * @param value the value to set.
+ */
+ public void setMetadata(org.apache.gora.examples.generated.Metadata value) {
+ throw new java.lang.UnsupportedOperationException("Set is not supported on tombstones");
+ }
+
+ /**
+ * Checks the dirty status of the 'metadata' field. A field is dirty if it represents a change that has not yet been written to the database.
+ * @param value the value to set.
+ */
+ public boolean isMetadataDirty(org.apache.gora.examples.generated.Metadata value) {
+ throw new java.lang.UnsupportedOperationException("IsDirty is not supported on tombstones");
+ }
+
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumReader.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumReader.java b/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumReader.java
index 40b844d..e69de29 100644
--- a/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumReader.java
+++ b/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumReader.java
@@ -1,260 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.gora.avro;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.WeakHashMap;
-
-import org.apache.avro.Schema;
-import org.apache.avro.Schema.Field;
-import org.apache.avro.generic.GenericArray;
-import org.apache.avro.io.Decoder;
-import org.apache.avro.io.ResolvingDecoder;
-import org.apache.avro.specific.SpecificDatumReader;
-import org.apache.avro.util.Utf8;
-import org.apache.gora.mapreduce.FakeResolvingDecoder;
-import org.apache.gora.persistency.ListGenericArray;
-import org.apache.gora.persistency.Persistent;
-import org.apache.gora.persistency.State;
-import org.apache.gora.persistency.StatefulHashMap;
-import org.apache.gora.persistency.StatefulMap;
-import org.apache.gora.persistency.impl.PersistentBase;
-import org.apache.gora.persistency.impl.StateManagerImpl;
-import org.apache.gora.util.IOUtils;
-
-/**
- * PersistentDatumReader reads, fields' dirty and readable information.
- */
-public class PersistentDatumReader<T extends PersistentBase>
- extends SpecificDatumReader<T> {
-
- private Schema rootSchema;
- private T cachedPersistent; // for creating objects
-
- private WeakHashMap<Decoder, ResolvingDecoder> decoderCache
- = new WeakHashMap<Decoder, ResolvingDecoder>();
-
- private boolean readDirtyBits = true;
-
- public PersistentDatumReader() {
- }
-
- public PersistentDatumReader(Schema schema, boolean readDirtyBits) {
- this.readDirtyBits = readDirtyBits;
- setSchema(schema);
- }
-
- @Override
- public void setSchema(Schema actual) {
- this.rootSchema = actual;
- super.setSchema(actual);
- }
-
- @SuppressWarnings("unchecked")
- public T newPersistent() {
- if(cachedPersistent == null) {
- cachedPersistent = (T)super.newRecord(null, rootSchema);
- return cachedPersistent; //we can return the cached object
- }
- return (T)cachedPersistent.newInstance(new StateManagerImpl());
- }
-
- @Override
- protected Object newRecord(Object old, Schema schema) {
- if(old != null) {
- return old;
- }
-
- if(schema.equals(rootSchema)) {
- return newPersistent();
- } else {
- return super.newRecord(old, schema);
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public T read(T reuse, Decoder in) throws IOException {
- return (T) read(reuse, rootSchema, in);
- }
-
- public Object read(Object reuse, Schema schema, Decoder decoder)
- throws IOException {
- return super.read(reuse, schema, getResolvingDecoder(decoder));
- }
-
- protected ResolvingDecoder getResolvingDecoder(Decoder decoder)
- throws IOException {
- ResolvingDecoder resolvingDecoder = decoderCache.get(decoder);
- if(resolvingDecoder == null) {
- resolvingDecoder = new FakeResolvingDecoder(rootSchema, decoder);
- decoderCache.put(decoder, resolvingDecoder);
- }
- return resolvingDecoder;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected Object readRecord(Object old, Schema expected, ResolvingDecoder in)
- throws IOException {
-
- Object record = newRecord(old, expected);
-
- //check if top-level
- if(expected.equals(rootSchema) && readDirtyBits) {
- T persistent = (T)record;
- persistent.clear();
-
- boolean[] dirtyFields = IOUtils.readBoolArray(in);
- boolean[] readableFields = IOUtils.readBoolArray(in);
-
- //read fields
- int i = 0;
-
- for (Field f : expected.getFields()) {
- if(readableFields[f.pos()]) {
- int pos = f.pos();
- String name = f.name();
- Object oldDatum = (old != null) ? getField(record, name, pos) : null;
- setField(record, name, pos, read(oldDatum, f.schema(), in));
- }
- }
-
- // Now set changed bits
- for (i = 0; i < dirtyFields.length; i++) {
- if (dirtyFields[i]) {
- persistent.setDirty(i);
- }
- else {
- persistent.clearDirty(i);
- }
- }
- return record;
- } else {
- //since ResolvingDecoder.readFieldOrder is final, we cannot override it
- //so this is a copy of super.readReacord, with the readFieldOrder change
-
- for (Field f : expected.getFields()) {
- int pos = f.pos();
- String name = f.name();
- Object oldDatum = (old != null) ? getField(record, name, pos) : null;
- setField(record, name, pos, read(oldDatum, f.schema(), in));
- }
-
- return record;
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected Object readMap(Object old, Schema expected, ResolvingDecoder in)
- throws IOException {
- StatefulMap<Utf8, ?> map = (StatefulMap<Utf8, ?>) newMap(old, 0);
- Map<Utf8, State> tempStates = null;
- if (readDirtyBits) {
- tempStates = new HashMap<Utf8, State>();
- int size = in.readInt();
- for (int j = 0; j < size; j++) {
- Utf8 key = in.readString(null);
- State state = State.values()[in.readInt()];
- tempStates.put(key, state);
- }
- }
- super.readMap(map, expected, in);
- map.clearStates();
- if (readDirtyBits) {
- for (Entry<Utf8, State> entry : tempStates.entrySet()) {
- map.putState(entry.getKey(), entry.getValue());
- }
- }
- return map;
- }
-
- @Override
- @SuppressWarnings({ "rawtypes" })
- protected Object newMap(Object old, int size) {
- if (old instanceof StatefulHashMap) {
- ((StatefulHashMap)old).reuse();
- return old;
- }
- return new StatefulHashMap<Object, Object>();
- }
-
- /** Called to create new array instances. Subclasses may override to use a
- * different array implementation. By default, this returns a
- * GenericData.Array instance.*/
- @Override
- @SuppressWarnings("rawtypes")
- protected Object newArray(Object old, int size, Schema schema) {
- if (old instanceof ListGenericArray) {
- ((GenericArray) old).clear();
- return old;
- } else return new ListGenericArray(size, schema);
- }
-
- public Persistent clone(Persistent persistent, Schema schema) {
- Persistent cloned = (PersistentBase)persistent.newInstance(new StateManagerImpl());
- List<Field> fields = schema.getFields();
- for(Field field: fields) {
- int pos = field.pos();
- switch(field.schema().getType()) {
- case MAP :
- case ARRAY :
- case RECORD :
- case STRING : ((PersistentBase)cloned).put(pos, cloneObject(
- field.schema(), ((PersistentBase)persistent).get(pos), ((PersistentBase)cloned).get(pos))); break;
- case NULL : break;
- default : ((PersistentBase)cloned).put(pos, ((PersistentBase)persistent).get(pos)); break;
- }
- }
-
- return cloned;
- }
-
- @SuppressWarnings("unchecked")
- protected Object cloneObject(Schema schema, Object toClone, Object cloned) {
- if(toClone == null) {
- return null;
- }
-
- switch(schema.getType()) {
- case MAP :
- Map<Utf8, Object> map = (Map<Utf8, Object>)newMap(cloned, 0);
- for(Map.Entry<Utf8, Object> entry: ((Map<Utf8, Object>)toClone).entrySet()) {
- map.put((Utf8)createString(entry.getKey().toString())
- , cloneObject(schema.getValueType(), entry.getValue(), null));
- }
- return map;
- case ARRAY :
- GenericArray<Object> array = (GenericArray<Object>)
- newArray(cloned, (int)((GenericArray<?>)toClone).size(), schema);
- for(Object element: (GenericArray<Object>)toClone) {
- array.add(cloneObject(schema.getElementType(), element, null));
- }
- return array;
- case RECORD : return clone((Persistent)toClone, schema);
- case STRING : return createString(toClone.toString());
- default : return toClone; //shallow copy is enough
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumWriter.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumWriter.java b/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumWriter.java
index 47cd3ae..e69de29 100644
--- a/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumWriter.java
+++ b/gora-core/src/main/java/org/apache/gora/avro/PersistentDatumWriter.java
@@ -1,123 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.gora.avro;
-
-import java.io.IOException;
-import java.util.Map.Entry;
-
-import org.apache.avro.Schema;
-import org.apache.avro.Schema.Field;
-import org.apache.avro.io.Encoder;
-import org.apache.avro.specific.SpecificDatumWriter;
-import org.apache.avro.util.Utf8;
-import org.apache.gora.persistency.State;
-import org.apache.gora.persistency.StateManager;
-import org.apache.gora.persistency.StatefulMap;
-import org.apache.gora.persistency.impl.PersistentBase;
-import org.apache.gora.util.IOUtils;
-
-/**
- * PersistentDatumWriter writes, fields' dirty and readable information.
- */
-public class PersistentDatumWriter<T extends PersistentBase>
- extends SpecificDatumWriter<T> {
-
- private T persistent = null;
-
- private boolean writeDirtyBits = true;
-
- public PersistentDatumWriter() {
- }
-
- public PersistentDatumWriter(Schema schema, boolean writeDirtyBits) {
- setSchema(schema);
- this.writeDirtyBits = writeDirtyBits;
- }
-
- public void setPersistent(T persistent) {
- this.persistent = persistent;
- }
-
- @Override
- /**exposing this function so that fields can be written individually*/
- public void write(Schema schema, Object datum, Encoder out)
- throws IOException {
- super.write(schema, datum, out);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected void writeRecord(Schema schema, Object datum, Encoder out)
- throws IOException {
-
- if(persistent == null) {
- persistent = (T) datum;
- }
-
- if (!writeDirtyBits) {
- super.writeRecord(schema, datum, out);
- return;
- }
-
- //check if top level schema
- if(schema.equals(persistent.getSchema())) {
- //write readable fields and dirty fields info
- boolean[] dirtyFields = new boolean[schema.getFields().size()];
- boolean[] readableFields = new boolean[schema.getFields().size()];
- StateManager manager = persistent.getStateManager();
-
- int i=0;
- for (@SuppressWarnings("unused") Field field : schema.getFields()) {
- dirtyFields[i] = manager.isDirty(persistent, i);
- readableFields[i] = manager.isReadable(persistent, i);
- i++;
- }
-
- IOUtils.writeBoolArray(out, dirtyFields);
- IOUtils.writeBoolArray(out, readableFields);
-
- for (Field field : schema.getFields()) {
- if(readableFields[field.pos()]) {
- write(field.schema(), getField(datum, field.name(), field.pos()), out);
- }
- }
-
- } else {
- super.writeRecord(schema, datum, out);
- }
- }
-
- @Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected void writeMap(Schema schema, Object datum, Encoder out)
- throws IOException {
-
- if (writeDirtyBits) {
- // write extra state information for maps
- StatefulMap<Utf8, ?> map = (StatefulMap) datum;
- out.writeInt(map.states().size());
- for (Entry<Utf8, State> e2 : map.states().entrySet()) {
- out.writeString(e2.getKey());
- out.writeInt(e2.getValue().ordinal());
- }
- }
- super.writeMap(schema, datum, out);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/avro/store/AvroStore.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/avro/store/AvroStore.java b/gora-core/src/main/java/org/apache/gora/avro/store/AvroStore.java
index ca1573f..f08468b 100644
--- a/gora-core/src/main/java/org/apache/gora/avro/store/AvroStore.java
+++ b/gora-core/src/main/java/org/apache/gora/avro/store/AvroStore.java
@@ -23,14 +23,12 @@ import java.io.DataOutput;
import java.io.IOException;
import java.util.Properties;
-import org.apache.avro.io.BinaryDecoder;
-import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.io.Decoder;
+import org.apache.avro.io.DecoderFactory;
import org.apache.avro.io.Encoder;
-import org.apache.avro.io.JsonDecoder;
-import org.apache.avro.io.JsonEncoder;
+import org.apache.avro.io.EncoderFactory;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.specific.SpecificDatumWriter;
import org.apache.gora.avro.query.AvroQuery;
@@ -220,20 +218,19 @@ public class AvroStore<K, T extends PersistentBase>
protected Encoder createEncoder() throws IOException {
switch(codecType) {
case BINARY:
- return new BinaryEncoder(getOrCreateOutputStream());
+ return EncoderFactory.get().binaryEncoder(getOrCreateOutputStream(), null);
case JSON:
- return new JsonEncoder(schema, getOrCreateOutputStream());
+ return EncoderFactory.get().jsonEncoder(schema, getOrCreateOutputStream());
}
return null;
}
- @SuppressWarnings("deprecation")
protected Decoder createDecoder() throws IOException {
switch(codecType) {
case BINARY:
- return new BinaryDecoder(getOrCreateInputStream());
+ return DecoderFactory.get().binaryDecoder(getOrCreateInputStream(), null);
case JSON:
- return new JsonDecoder(schema, getOrCreateInputStream());
+ return DecoderFactory.get().jsonDecoder(schema, getOrCreateInputStream());
}
return null;
}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/avro/store/DataFileAvroStore.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/avro/store/DataFileAvroStore.java b/gora-core/src/main/java/org/apache/gora/avro/store/DataFileAvroStore.java
index a7beb0e..4bade04 100644
--- a/gora-core/src/main/java/org/apache/gora/avro/store/DataFileAvroStore.java
+++ b/gora-core/src/main/java/org/apache/gora/avro/store/DataFileAvroStore.java
@@ -24,7 +24,6 @@ import org.apache.avro.file.DataFileReader;
import org.apache.avro.file.DataFileWriter;
import org.apache.gora.avro.mapreduce.FsInput;
import org.apache.gora.avro.query.DataFileAvroResult;
-import org.apache.gora.persistency.Persistent;
import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.Query;
import org.apache.gora.query.Result;
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/filter/MapFieldValueFilter.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/filter/MapFieldValueFilter.java b/gora-core/src/main/java/org/apache/gora/filter/MapFieldValueFilter.java
index 2cbeb21..40c7b41 100644
--- a/gora-core/src/main/java/org/apache/gora/filter/MapFieldValueFilter.java
+++ b/gora-core/src/main/java/org/apache/gora/filter/MapFieldValueFilter.java
@@ -106,7 +106,8 @@ public class MapFieldValueFilter<K, T extends PersistentBase> implements Filter<
@Override
public boolean filter(K key, T persistent) {
- int fieldIndex = persistent.getFieldIndex(fieldName);
+ int fieldIndex = persistent.getSchema().getField(fieldName).pos();
+ @SuppressWarnings("unchecked")
Map<Utf8, ?> fieldValue = (Map<Utf8, ?>) persistent.get(fieldIndex);
if (fieldValue == null) {
return filterIfMissing;
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/filter/SingleFieldValueFilter.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/filter/SingleFieldValueFilter.java b/gora-core/src/main/java/org/apache/gora/filter/SingleFieldValueFilter.java
index efdd9cf..a000bc0 100644
--- a/gora-core/src/main/java/org/apache/gora/filter/SingleFieldValueFilter.java
+++ b/gora-core/src/main/java/org/apache/gora/filter/SingleFieldValueFilter.java
@@ -101,7 +101,7 @@ public class SingleFieldValueFilter<K, T extends PersistentBase> implements Filt
@Override
public boolean filter(K key, T persistent) {
- int fieldIndex = persistent.getFieldIndex(fieldName);
+ int fieldIndex = persistent.getSchema().getField(fieldName).pos(); //.getIndexNamed(fieldName); throws org.apache.avro.AvroRuntimeException: Not a union:
Object fieldValue = persistent.get(fieldIndex);
Object operand = operands.get(0);
if (fieldValue == null) {
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/mapreduce/FakeResolvingDecoder.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/mapreduce/FakeResolvingDecoder.java b/gora-core/src/main/java/org/apache/gora/mapreduce/FakeResolvingDecoder.java
index 5fed0c2..e69de29 100644
--- a/gora-core/src/main/java/org/apache/gora/mapreduce/FakeResolvingDecoder.java
+++ b/gora-core/src/main/java/org/apache/gora/mapreduce/FakeResolvingDecoder.java
@@ -1,170 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.gora.mapreduce;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-
-import org.apache.avro.Schema;
-import org.apache.avro.io.Decoder;
-import org.apache.avro.io.ResolvingDecoder;
-import org.apache.avro.io.parsing.Symbol;
-import org.apache.avro.util.Utf8;
-
-/**
- * Avro uses a ResolvingDecoder which resolves two schemas and converts records
- * written by one to the other, and validates the input. However, Gora needs to
- * write extra information along with the data, so the validation is not consistent
- * with the grammer generated by Avro. So we need to fake the ResolvingDecoder (which
- * is sadly hard codec into GenericDatumReader) until we can write our own GrammerGenerator
- * extending ResolvingGrammerGenerator of avro.
- */
-public class FakeResolvingDecoder extends ResolvingDecoder {
-
- public FakeResolvingDecoder(Schema schema, Decoder in) throws IOException {
- super(schema, schema, in);
- }
-
- @Override
- public long arrayNext() throws IOException {
- return in.arrayNext();
- }
-
- @Override
- public Symbol doAction(Symbol input, Symbol top) throws IOException {
- return null;
- }
-
- @Override
- public void init(InputStream in) throws IOException {
- this.in.init(in);
- }
-
- @Override
- public long mapNext() throws IOException {
- return in.mapNext();
- }
-
- @Override
- public double readDouble() throws IOException {
- return in.readDouble();
- }
-
- @Override
- public int readEnum() throws IOException {
- return in.readEnum();
- }
-
- @Override
- public int readIndex() throws IOException {
- return in.readIndex();
- }
-
- @Override
- public long readLong() throws IOException {
- return in.readLong();
- }
-
- @Override
- public void skipAction() throws IOException {
- }
-
- @Override
- public long readArrayStart() throws IOException {
- return in.readArrayStart();
- }
-
- @Override
- public boolean readBoolean() throws IOException {
- return in.readBoolean();
- }
-
- @Override
- public ByteBuffer readBytes(ByteBuffer old) throws IOException {
- return in.readBytes(old);
- }
-
- @Override
- public void readFixed(byte[] bytes, int start, int len) throws IOException {
- in.readFixed(bytes, start, len);
- }
-
- @Override
- public float readFloat() throws IOException {
- return in.readFloat();
- }
-
- @Override
- public int readInt() throws IOException {
- return in.readInt();
- }
-
- @Override
- public long readMapStart() throws IOException {
- return in.readMapStart();
- }
-
- @Override
- public void readNull() throws IOException {
- in.readNull();
- }
-
- @Override
- public Utf8 readString(Utf8 old) throws IOException {
- return in.readString(old);
- }
-
- @Override
- public long skipArray() throws IOException {
- return in.skipArray();
- }
-
- @Override
- public void skipBytes() throws IOException {
- in.skipBytes();
- }
-
- @Override
- protected void skipFixed() throws IOException {
- }
-
- @Override
- public void skipFixed(int length) throws IOException {
- in.skipFixed(length);
- }
-
- @Override
- public long skipMap() throws IOException {
- return in.skipMap();
- }
-
- @Override
- public void skipString() throws IOException {
- }
-
- @Override
- public void skipTopSymbol() throws IOException {
- }
-
- @Override
- public void readFixed(byte[] bytes) throws IOException {
- in.readFixed(bytes);
- }
-}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/mapreduce/GoraMapReduceUtils.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/mapreduce/GoraMapReduceUtils.java b/gora-core/src/main/java/org/apache/gora/mapreduce/GoraMapReduceUtils.java
index 3c17f62..ac90157 100644
--- a/gora-core/src/main/java/org/apache/gora/mapreduce/GoraMapReduceUtils.java
+++ b/gora-core/src/main/java/org/apache/gora/mapreduce/GoraMapReduceUtils.java
@@ -44,13 +44,17 @@ public class GoraMapReduceUtils {
}
}
+ /**
+ * Add our own serializer (obtained via the {@link PersistentSerialization}
+ * wrapper) to any other <code>io.serializations</code> which may be specified
+ * within existing Hadoop configuration.
+ *
+ * @param conf the Hadoop configuration object
+ * @param reuseObjects boolean parameter to reuse objects
+ */
public static void setIOSerializations(Configuration conf, boolean reuseObjects) {
String serializationClass =
PersistentSerialization.class.getCanonicalName();
- if (!reuseObjects) {
- serializationClass =
- PersistentNonReusingSerialization.class.getCanonicalName();
- }
String[] serializations = StringUtils.joinStringArrays(
conf.getStrings("io.serializations"),
"org.apache.hadoop.io.serializer.WritableSerialization",
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentDeserializer.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentDeserializer.java b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentDeserializer.java
index e08d61a..e331b4e 100644
--- a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentDeserializer.java
+++ b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentDeserializer.java
@@ -23,53 +23,51 @@ import java.io.InputStream;
import org.apache.avro.Schema;
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.DecoderFactory;
-import org.apache.gora.avro.PersistentDatumReader;
+import org.apache.avro.specific.SpecificDatumReader;
import org.apache.gora.persistency.Persistent;
-import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.util.AvroUtils;
import org.apache.hadoop.io.serializer.Deserializer;
/**
-* Hadoop deserializer using {@link PersistentDatumReader}
+* Hadoop deserializer using {@link SpecificDatumReader}
* with {@link BinaryDecoder}.
*/
public class PersistentDeserializer
- implements Deserializer<PersistentBase> {
+ implements Deserializer<Persistent> {
private BinaryDecoder decoder;
- private Class<? extends PersistentBase> persistentClass;
+ private Class<? extends Persistent> persistentClass;
private boolean reuseObjects;
- private PersistentDatumReader<PersistentBase> datumReader;
+ private SpecificDatumReader<Persistent> datumReader;
- public PersistentDeserializer(Class<? extends PersistentBase> c, boolean reuseObjects) {
+ public PersistentDeserializer(Class<? extends Persistent> c, boolean reuseObjects) {
this.persistentClass = c;
this.reuseObjects = reuseObjects;
try {
Schema schema = AvroUtils.getSchema(persistentClass);
- datumReader = new PersistentDatumReader<PersistentBase>(schema, true);
+ datumReader = new SpecificDatumReader<Persistent>(schema);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
- //@Override
+ @Override
public void open(InputStream in) throws IOException {
/* It is very important to use a direct buffer, since Hadoop
- * supplies an input stream that is only valid until the end of one
- * record serialization. Each time deserialize() is called, the IS
- * is advanced to point to the right location, so we should not
- * buffer the whole input stream at once.
- */
- decoder = new DecoderFactory().configureDirectDecoder(true)
- .createBinaryDecoder(in, decoder);
+* supplies an input stream that is only valid until the end of one
+* record serialization. Each time deserialize() is called, the IS
+* is advanced to point to the right location, so we should not
+* buffer the whole input stream at once.
+*/
+ decoder = DecoderFactory.get().directBinaryDecoder(in, decoder);
}
- //@Override
+ @Override
public void close() throws IOException { }
@Override
- public PersistentBase deserialize(PersistentBase persistent) throws IOException {
+ public Persistent deserialize(Persistent persistent) throws IOException {
return datumReader.read(reuseObjects ? persistent : null, decoder);
}
}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentNonReusingSerialization.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentNonReusingSerialization.java b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentNonReusingSerialization.java
index c9bd141..e69de29 100644
--- a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentNonReusingSerialization.java
+++ b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentNonReusingSerialization.java
@@ -1,43 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.gora.mapreduce;
-
-import org.apache.gora.persistency.Persistent;
-import org.apache.gora.persistency.impl.PersistentBase;
-import org.apache.hadoop.io.serializer.Deserializer;
-import org.apache.hadoop.io.serializer.Serialization;
-import org.apache.hadoop.io.serializer.Serializer;
-
-public class PersistentNonReusingSerialization
-implements Serialization<PersistentBase> {
-
- @Override
- public boolean accept(Class<?> c) {
- return Persistent.class.isAssignableFrom(c);
- }
-
- @Override
- public Deserializer<PersistentBase> getDeserializer(Class<PersistentBase> c) {
- return new PersistentDeserializer(c, false);
- }
-
- @Override
- public Serializer<PersistentBase> getSerializer(Class<PersistentBase> c) {
- return new PersistentSerializer();
- }
-}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerialization.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerialization.java b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerialization.java
index 5c267eb..008e222 100644
--- a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerialization.java
+++ b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerialization.java
@@ -17,13 +17,13 @@
*/
package org.apache.gora.mapreduce;
-import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.persistency.Persistent;
import org.apache.hadoop.io.serializer.Deserializer;
import org.apache.hadoop.io.serializer.Serialization;
import org.apache.hadoop.io.serializer.Serializer;
-public class PersistentSerialization implements Serialization<PersistentBase> {
+public class PersistentSerialization
+implements Serialization<Persistent> {
@Override
public boolean accept(Class<?> c) {
@@ -31,12 +31,12 @@ public class PersistentSerialization implements Serialization<PersistentBase> {
}
@Override
- public Deserializer<PersistentBase> getDeserializer(Class<PersistentBase> c) {
+ public Deserializer<Persistent> getDeserializer(Class<Persistent> c) {
return new PersistentDeserializer(c, true);
}
@Override
- public Serializer<PersistentBase> getSerializer(Class<PersistentBase> c) {
+ public Serializer<Persistent> getSerializer(Class<Persistent> c) {
return new PersistentSerializer();
}
}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerializer.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerializer.java b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerializer.java
index 27976ab..96ed10b 100644
--- a/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerializer.java
+++ b/gora-core/src/main/java/org/apache/gora/mapreduce/PersistentSerializer.java
@@ -1,13 +1,13 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * regarding copyright ownership. The ASF licenses this file
* to you 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
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -21,37 +21,45 @@ import java.io.IOException;
import java.io.OutputStream;
import org.apache.avro.io.BinaryEncoder;
-import org.apache.gora.avro.PersistentDatumWriter;
-import org.apache.gora.persistency.impl.PersistentBase;
+import org.apache.avro.io.EncoderFactory;
+import org.apache.avro.specific.SpecificDatumWriter;
+import org.apache.gora.persistency.Persistent;
import org.apache.hadoop.io.serializer.Serializer;
/**
- * Hadoop serializer using {@link PersistentDatumWriter}
- * with {@link BinaryEncoder}.
+ * Hadoop serializer using Avro's {@link SpecificDatumWriter}
+ * with {@link BinaryEncoder}.
*/
-public class PersistentSerializer implements Serializer<PersistentBase> {
+public class PersistentSerializer implements Serializer<Persistent> {
- private PersistentDatumWriter<PersistentBase> datumWriter;
- private BinaryEncoder encoder;
+ private SpecificDatumWriter<Persistent> datumWriter;
+ private BinaryEncoder encoder;
public PersistentSerializer() {
- this.datumWriter = new PersistentDatumWriter<PersistentBase>();
+ this.datumWriter = new SpecificDatumWriter<Persistent>();
}
- //@Override
+ @Override
public void close() throws IOException {
encoder.flush();
}
- //@Override
+ /**
+ * Open a connection for the {@link OutputStream}; should be
+ * called before serialization occurs. N.B. the {@link PersistentSerializer#close()}
+ * should be called 'finally' after serialization is complete.
+ */
+ @Override
public void open(OutputStream out) throws IOException {
- encoder = new BinaryEncoder(out);
+ encoder = EncoderFactory.get().directBinaryEncoder(out, null);
}
+ /**
+ * Do the serialization of the {@link Persistent} object
+ */
@Override
- public void serialize(PersistentBase persistent) throws IOException {
+ public void serialize(Persistent persistent) throws IOException {
datumWriter.setSchema(persistent.getSchema());
- datumWriter.setPersistent(persistent);
datumWriter.write(persistent, encoder);
}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java b/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
index e49feda..bc0d59f 100644
--- a/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
+++ b/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
@@ -26,9 +26,11 @@ import java.util.List;
import java.util.NavigableMap;
import java.util.TreeMap;
+
+import org.apache.avro.Schema.Field;
+
import org.apache.gora.persistency.Persistent;
import org.apache.gora.persistency.impl.PersistentBase;
-import org.apache.gora.persistency.impl.StateManagerImpl;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
import org.apache.gora.query.Result;
@@ -37,6 +39,7 @@ import org.apache.gora.query.impl.QueryBase;
import org.apache.gora.query.impl.ResultBase;
import org.apache.gora.store.DataStore;
import org.apache.gora.store.impl.DataStoreBase;
+import org.apache.gora.util.AvroUtils;
/**
* Memory based {@link DataStore} implementation for tests.
@@ -99,19 +102,19 @@ public class MemStore<K, T extends PersistentBase> extends DataStoreBase<K, T> {
@Override
public long deleteByQuery(Query<K, T> query) {
- try{
- long deletedRows = 0;
- Result<K,T> result = query.execute();
-
- while(result.next()) {
- if(delete(result.getKey()))
- deletedRows++;
- }
- return 0;
- }
- catch(Exception e){
- return 0;
- }
+ try{
+ long deletedRows = 0;
+ Result<K,T> result = query.execute();
+
+ while(result.next()) {
+ if(delete(result.getKey()))
+ deletedRows++;
+ }
+ return 0;
+ }
+ catch(Exception e){
+ return 0;
+ }
}
@Override
@@ -142,15 +145,19 @@ public class MemStore<K, T extends PersistentBase> extends DataStoreBase<K, T> {
/**
* Returns a clone with exactly the requested fields shallowly copied
*/
- @SuppressWarnings("unchecked")
private static<T extends Persistent> T getPersistent(T obj, String[] fields) {
- if(Arrays.equals(fields, obj.getFields())) {
+ List<Field> otherFields = obj.getSchema().getFields();
+ String[] otherFieldStrings = new String[otherFields.size()];
+ for(int i = 0; i<otherFields.size(); i++ ){
+ otherFieldStrings[i] = otherFields.get(i).name();
+ }
+ if(Arrays.equals(fields, otherFieldStrings)) {
return obj;
}
- T newObj = (T) obj.newInstance(new StateManagerImpl());
- for(String field:fields) {
- int index = newObj.getFieldIndex(field);
- ((PersistentBase)newObj).put(index, ((PersistentBase)obj).get(index));
+ T newObj = (T) AvroUtils.deepClonePersistent(obj);
+ for(int i = 0; i<otherFields.size(); i++) {
+ int index = otherFields.get(i).pos();
+ newObj.put(index, obj.get(index));
}
return newObj;
}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/persistency/Dirtyable.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/Dirtyable.java b/gora-core/src/main/java/org/apache/gora/persistency/Dirtyable.java
new file mode 100644
index 0000000..bec9674
--- /dev/null
+++ b/gora-core/src/main/java/org/apache/gora/persistency/Dirtyable.java
@@ -0,0 +1,41 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you 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.gora.persistency;
+
+/**
+ * Interface designed to accomodate structures that can be dirty, such as maps
+ * and lists, but whose dirtyness should not be set directly because dirtyness
+ * results from structural modification or content change, and which have no
+ * notion of ordered fields (such as Persistent).
+ */
+public interface Dirtyable {
+
+ /**
+ * Returns whether any of the fields of the object has been modified after
+ * construction or loading.
+ *
+ * @return whether any of the fields of the object has changed
+ */
+ boolean isDirty();
+
+ /**
+ * Clears the dirty state.
+ */
+ void clearDirty();
+
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java b/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java
index 8b02e4a..e69de29 100644
--- a/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java
+++ b/gora-core/src/main/java/org/apache/gora/persistency/ListGenericArray.java
@@ -1,109 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.gora.persistency;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.avro.Schema;
-import org.apache.avro.generic.GenericArray;
-import org.apache.avro.generic.GenericData;
-
-/**
- * An {@link ArrayList} based implementation of Avro {@link GenericArray}.
- */
-public class ListGenericArray<T> implements GenericArray<T>
- , Comparable<ListGenericArray<T>> {
-
- private static final int LIST_DEFAULT_SIZE = 10;
-
- private List<T> list;
- private Schema schema;
-
- public ListGenericArray(Schema schema, List<T> list) {
- this.schema = schema;
- this.list = list;
- }
-
- public ListGenericArray(Schema schema) {
- this(LIST_DEFAULT_SIZE, schema);
- }
-
- public ListGenericArray(int size, Schema schema) {
- this.schema = schema;
- this.list = new ArrayList<T>(size);
- }
-
- @Override
- public void add(T element) {
- list.add(element);
- }
-
- @Override
- public void clear() {
- list.clear();
- }
-
- @Override
- public T peek() {
- return null;
- }
-
- @Override
- public long size() {
- return list.size();
- }
-
- @Override
- public Iterator<T> iterator() {
- return list.iterator();
- }
-
- @Override
- public Schema getSchema() {
- return schema;
- }
-
- @Override
- public int hashCode() {
- return this.list.hashCode();
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- public boolean equals(Object obj) {
- if (obj == this) return true;
- if (!(obj instanceof ListGenericArray)) return false;
- ListGenericArray that = (ListGenericArray)obj;
- if (!schema.equals(that.schema))
- return false;
- return this.compareTo(that) == 0;
- }
-
- @Override
- public int compareTo(ListGenericArray<T> o) {
- return GenericData.get().compare(this, o, schema);
- }
-
- @Override
- public String toString() {
- return list.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java b/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
index b3dd161..dc45f79 100644
--- a/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
+++ b/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
@@ -1,185 +1,119 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you 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.gora.persistency;
-/**
- * Objects that are persisted by Gora implements this interface.
- */
-public interface Persistent extends Cloneable{
+import java.util.List;
- /**
- * Returns the StateManager which manages the persistent
- * state of the object.
- * @return the StateManager of the object
- */
- StateManager getStateManager();
+import org.apache.avro.Schema.Field;
+import org.apache.avro.specific.SpecificRecord;
- /**
- * Constructs a new instance of the object with the given StateManager.
- * This method is intended to be used by Gora framework.
- * @param stateManager the StateManager to manage the persistent state
- * of the object
- * @return a new instance of the object
- */
- Persistent newInstance(StateManager stateManager);
+import org.apache.gora.persistency.Dirtyable;
+
+/**
+* Objects that are persisted by Gora implements this interface.
+*/
+public interface Persistent extends SpecificRecord, Dirtyable {
+
+ public static String DIRTY_BYTES_FIELD_NAME = "__g__dirty";
/**
- * Returns sorted field names of the object
- * @return the field names of the object as a String[]
- */
- String[] getFields();
-
- /**
- * Returns the field name with the given index
- * @param index the index of the field
- * @return the name of the field
- */
- String getField(int index);
-
- /**
- * Returns the index of the field with the given name
- * @param field the name of the field
- * @return the index of the field
- */
- int getFieldIndex(String field);
-
- /**
- * Clears the inner state of the object without any modification
- * to the actual data on the data store. This method should be called
- * before re-using the object to hold the data for another result.
- */
+* Clears the inner state of the object without any modification to the actual
+* data on the data store. This method should be called before re-using the
+* object to hold the data for another result.
+*/
void clear();
-
- /**
- * Returns whether the object is newly constructed.
- * @return true if the object is newly constructed, false if
- * retrieved from a datastore.
- */
- boolean isNew();
-
- /**
- * Sets the state of the object as new for persistency
- */
- void setNew();
-
- /**
- * Clears the new state
- */
- void clearNew();
-
- /**
- * Returns whether any of the fields of the object has been modified
- * after construction or loading.
- * @return whether any of the fields of the object has changed
- */
- boolean isDirty();
-
+
/**
- * Returns whether the field has been modified.
- * @param fieldIndex the offset of the field in the object
- * @return whether the field has been modified.
- */
+* Returns whether the field has been modified.
+*
+* @param fieldIndex
+* the offset of the field in the object
+* @return whether the field has been modified.
+*/
boolean isDirty(int fieldIndex);
/**
- * Returns whether the field has been modified.
- * @param field the name of the field
- * @return whether the field has been modified.
- */
+* Returns whether the field has been modified.
+*
+* @param field
+* the name of the field
+* @return whether the field has been modified.
+*/
boolean isDirty(String field);
-
+
/**
- * Sets all the fields of the object as dirty.
- */
+* Sets all the fields of the object as dirty.
+*/
void setDirty();
-
+
/**
- * Sets the field as dirty.
- * @param fieldIndex the offset of the field in the object
- */
+* Sets the field as dirty.
+*
+* @param fieldIndex
+* the offset of the field in the object
+*/
void setDirty(int fieldIndex);
-
+
/**
- * Sets the field as dirty.
- * @param field the name of the field
- */
+* Sets the field as dirty.
+*
+* @param field
+* the name of the field
+*/
void setDirty(String field);
-
+
/**
- * Clears the field as dirty.
- * @param fieldIndex the offset of the field in the object
- */
+* Clears the field as dirty.
+*
+* @param fieldIndex
+* the offset of the field in the object
+*/
void clearDirty(int fieldIndex);
-
+
/**
- * Clears the field as dirty.
- * @param field the name of the field
- */
+* Clears the field as dirty.
+*
+* @param field
+* the name of the field
+*/
void clearDirty(String field);
-
- /**
- * Clears the dirty state.
- */
- void clearDirty();
-
- /**
- * Returns whether the field has been loaded from the datastore.
- * @param fieldIndex the offset of the field in the object
- * @return whether the field has been loaded
- */
- boolean isReadable(int fieldIndex);
/**
- * Returns whether the field has been loaded from the datastore.
- * @param field the name of the field
- * @return whether the field has been loaded
- */
- boolean isReadable(String field);
-
- /**
- * Sets the field as readable.
- * @param fieldIndex the offset of the field in the object
- */
- void setReadable(int fieldIndex);
+* Get an object which can be used to mark this field as deleted (rather than
+* state unknown, which is indicated by null).
+*
+* @return a tombstone.
+*/
+ public abstract Tombstone getTombstone();
/**
- * Sets the field as readable.
- * @param field the name of the field
- */
- void setReadable(String field);
+* Get a list of fields from this persistent object's schema that are not
+* managed by Gora.
+*
+* @return the unmanaged fields
+*/
+ public List<Field> getUnmanagedFields();
/**
- * Clears the field as readable.
- * @param fieldIndex the offset of the field in the object
- */
- void clearReadable(int fieldIndex);
-
- /**
- * Sets the field as readable.
- * @param field the name of the field
- */
- void clearReadable(String field);
-
- /**
- * Clears the readable state.
+ * Constructs a new instance of the object by using appropriate builder. This
+ * method is intended to be used by Gora framework.
+ *
+ * @return a new instance of the object
*/
- void clearReadable();
-
- Persistent clone();
-
+ Persistent newInstance();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/136fc595/gora-core/src/main/java/org/apache/gora/persistency/State.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/State.java b/gora-core/src/main/java/org/apache/gora/persistency/State.java
index a372ee1..e69de29 100644
--- a/gora-core/src/main/java/org/apache/gora/persistency/State.java
+++ b/gora-core/src/main/java/org/apache/gora/persistency/State.java
@@ -1,37 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.gora.persistency;
-
-/**
- * Persistency state of an object or field.
- */
-public enum State {
-
- /** The object is newly loaded */
- NEW,
-
- /** The value of the field has not been changed after loading*/
- CLEAN,
-
- /** The value of the field has been altered*/
- DIRTY,
-
- /** The object or field is deleted */
- DELETED
-}