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 2012/11/03 22:09:14 UTC
svn commit: r1405417 [2/4] - in /gora/trunk: ./ bin/
gora-accumulo/src/main/java/org/apache/gora/accumulo/query/
gora-accumulo/src/main/java/org/apache/gora/accumulo/store/
gora-cassandra/src/main/java/org/apache/gora/cassandra/query/
gora-cassandra/sr...
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/PersistentWSBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/PersistentWSBase.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/PersistentWSBase.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/PersistentWSBase.java Sat Nov 3 21:09:11 2012
@@ -0,0 +1,339 @@
+/**
+ * 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.ws.impl;
+
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.StateManager;
+
+/**
+ * Base classs implementing common functionality for Web services
+ * backed persistent classes.
+ */
+public abstract class PersistentWSBase implements Persistent {
+
+ /**
+ * Maps keys to their own classes
+ */
+ protected static Map<Class<?>, Map<String, Integer>> FIELD_MAP =
+ new HashMap<Class<?>, Map<String,Integer>>();
+
+ /**
+ * Maps fields to their own classes
+ */
+ protected static Map<Class<?>, String[]> FIELDS =
+ new HashMap<Class<?>, String[]>();
+
+ /**
+ * Object used to manage the state of fields
+ */
+ private StateManager stateManager;
+
+ /**
+ * Constructor
+ */
+ protected PersistentWSBase() {
+ this(new StateManagerWSImpl());
+ }
+
+ /**
+ * Constructor using a stateManager object
+ * @param stateManager
+ */
+ protected PersistentWSBase(StateManager stateManager) {
+ this.stateManager = stateManager;
+ stateManager.setManagedPersistent(this);
+ }
+
+ /** Subclasses should call this function for all the persistable fields
+ * in the class to register them.
+ * @param clazz the Persistent class
+ * @param fields the name of the fields of the class
+ */
+ protected static void registerFields(Class<?> clazz, String... fields) {
+ FIELDS.put(clazz, fields);
+ int fieldsLength = fields == null ? 0 :fields.length;
+ HashMap<String, Integer> map = new HashMap<String, Integer>(fieldsLength);
+
+ for(int i=0; i < fieldsLength; i++) {
+ map.put(fields[i], i);
+ }
+ FIELD_MAP.put(clazz, map);
+ }
+
+ @Override
+ /**
+ * Gets the state manager
+ */
+ public StateManager getStateManager() {
+ return stateManager;
+ }
+
+ @Override
+ /**
+ * Gets fields using a specific class
+ */
+ public String[] getFields() {
+ return FIELDS.get(getClass());
+ }
+
+ @Override
+ /**
+ * Gets a specific field from the fields map
+ */
+ public String getField(int index) {
+ return FIELDS.get(getClass())[index];
+ }
+
+ @Override
+ /**
+ * Gets a field index based on the field name
+ */
+ public int getFieldIndex(String field) {
+ return FIELD_MAP.get(getClass()).get(field);
+ }
+
+ @Override
+ /**
+ * Clears maps of fields
+ */
+ public void clear() {
+ // TODO study the specific cases for other datatypes
+ clearDirty();
+ clearReadable();
+ }
+
+ @Override
+ /**
+ * Determines if a class is new or not
+ */
+ public boolean isNew() {
+ return getStateManager().isNew(this);
+ }
+
+ @Override
+ /**
+ * Sets this element as a new one inside the stateManager object
+ */
+ public void setNew() {
+ getStateManager().setNew(this);
+ }
+
+ @Override
+ /**
+ * Clears a new object from the stateManager
+ */
+ public void clearNew() {
+ getStateManager().clearNew(this);
+ }
+
+ @Override
+ /**
+ * Determines if an object has been modified or not
+ */
+ public boolean isDirty() {
+ return getStateManager().isDirty(this);
+ }
+
+ @Override
+ /**
+ * Determines if an object has been modified or not
+ * based on its field index
+ */
+ public boolean isDirty(int fieldIndex) {
+ return getStateManager().isDirty(this, fieldIndex);
+ }
+
+ @Override
+ /**
+ * Determines if an object has been modified or not
+ * based on its field name
+ */
+ public boolean isDirty(String field) {
+ return isDirty(getFieldIndex(field));
+ }
+
+ @Override
+ /**
+ * Sets this class as dirty
+ */
+ public void setDirty() {
+ getStateManager().setDirty(this);
+ }
+
+ @Override
+ /**
+ * Sets a specific field as dirty using its index
+ */
+ public void setDirty(int fieldIndex) {
+ getStateManager().setDirty(this, fieldIndex);
+ }
+
+ @Override
+ /**
+ * Sets a specific field as dirty using its name
+ */
+ public void setDirty(String field) {
+ setDirty(getFieldIndex(field));
+ }
+
+ @Override
+ /**
+ * Clears dirty fields using its index
+ */
+ public void clearDirty(int fieldIndex) {
+ getStateManager().clearDirty(this, fieldIndex);
+ }
+
+ @Override
+ /**
+ * Clears dirty fields using its name
+ */
+ public void clearDirty(String field) {
+ clearDirty(getFieldIndex(field));
+ }
+
+ @Override
+ /**
+ * Clears dirty fields from the state manager
+ */
+ public void clearDirty() {
+ getStateManager().clearDirty(this);
+ }
+
+ @Override
+ /**
+ * Checks if a field is readable using its index
+ */
+ public boolean isReadable(int fieldIndex) {
+ return getStateManager().isReadable(this, fieldIndex);
+ }
+
+ @Override
+ /**
+ * Checks if a field is readable using its name
+ */
+ public boolean isReadable(String field) {
+ return isReadable(getFieldIndex(field));
+ }
+
+ @Override
+ /**
+ * Sets a field as readable using its index
+ */
+ public void setReadable(int fieldIndex) {
+ getStateManager().setReadable(this, fieldIndex);
+ }
+
+ @Override
+ /**
+ * Sets a field as readable using its name
+ */
+ public void setReadable(String field) {
+ setReadable(getFieldIndex(field));
+ }
+
+ @Override
+ /**
+ * Clears this readable object from the state manager
+ */
+ public void clearReadable() {
+ getStateManager().clearReadable(this);
+ }
+
+ @Override
+ /**
+ * Clears a readable object based on its field index
+ * using a stateManager object
+ */
+ public void clearReadable(int fieldIndex) {
+ getStateManager().clearReadable(this, fieldIndex);
+ }
+
+ @Override
+ /**
+ * Clears a readable object based on its field name
+ * using a stateManager object
+ */
+ public void clearReadable(String field) {
+ clearReadable(getFieldIndex(field));
+ }
+
+ @Override
+ /**
+ * Determines if an object is equal to this class
+ */
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ // TODO we should check if the object has schema or not
+ return true;
+ }
+
+ @Override
+ // TODO
+ public int hashCode() {
+ int result = 1;
+ return result;
+ }
+
+ /** ByteBuffer.hashCode() takes into account the position of the
+ * buffer, but we do not want that*/
+ private int getByteBufferHashCode(ByteBuffer buf) {
+ int h = 1;
+ int p = buf.arrayOffset();
+ for (int j = buf.limit() - 1; j >= p; j--)
+ h = 31 * h + buf.get(j);
+ return h;
+ }
+
+ @Override
+ /**
+ * Clones a persistent object
+ */
+ public Persistent clone() {
+ return null;
+ }
+
+ @Override
+ /**
+ * Converts an object to string
+ */
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(super.toString());
+ builder.append(" {\n");
+ // TODO get fields
+ builder.append("}");
+ return builder.toString();
+ }
+
+ /**
+ * Checks if a field is equal between two objects
+ * @param index
+ * @param value
+ * @return
+ */
+ protected boolean isFieldEqual(int index, Object value) {
+ // TODO
+ return true;
+ }
+}
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/StateManagerWSImpl.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/StateManagerWSImpl.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/StateManagerWSImpl.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/persistency/ws/impl/StateManagerWSImpl.java Sat Nov 3 21:09:11 2012
@@ -0,0 +1,149 @@
+/**
+ * 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.ws.impl;
+
+import java.util.BitSet;
+
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.StateManager;
+
+/**
+ * An implementation for the StateManager. This implementation assumes
+ * every Persistent object has it's own StateManager.
+ */
+public class StateManagerWSImpl implements StateManager {
+
+ //TODO: serialize isNew in PersistentSerializer
+ protected boolean isNew;
+ protected BitSet dirtyBits;
+ protected BitSet readableBits;
+
+ /**
+ * Constructor
+ */
+ public StateManagerWSImpl() {
+ }
+
+ /**
+ * Sets dirtyBits and readableBits sizes
+ */
+ public void setManagedPersistent(Persistent persistent) {
+ // dirtyBits = new BitSet(persistent.getSchema().getFields().size());
+ // readableBits = new BitSet(persistent.getSchema().getFields().size());
+ isNew = true;
+ }
+
+ @Override
+ /**
+ * Checks if an object is new or not
+ */
+ public boolean isNew(Persistent persistent) {
+ return isNew;
+ }
+
+ @Override
+ /**
+ * Sets an object as new
+ */
+ public void setNew(Persistent persistent) {
+ this.isNew = true;
+ }
+
+ @Override
+ /**
+ * Clear the new object by setting it as not new
+ */
+ public void clearNew(Persistent persistent) {
+ this.isNew = false;
+ }
+
+ /**
+ * Sets an object as dirty using its index
+ */
+ public void setDirty(Persistent persistent, int fieldIndex) {
+ dirtyBits.set(fieldIndex);
+ readableBits.set(fieldIndex);
+ }
+
+ /**
+ * Determines if an object is dirty or not based on its index
+ */
+ public boolean isDirty(Persistent persistent, int fieldIndex) {
+ return dirtyBits.get(fieldIndex);
+ }
+
+ /**
+ * Determines if an object is dirty
+ */
+ public boolean isDirty(Persistent persistent) {
+ return !dirtyBits.isEmpty();
+ }
+
+ @Override
+ /**
+ * Sets an object as dirty
+ */
+ public void setDirty(Persistent persistent) {
+ dirtyBits.set(0, dirtyBits.size());
+ }
+
+ @Override
+ /**
+ * Marks a persistent object as not dirty using its index
+ */
+ public void clearDirty(Persistent persistent, int fieldIndex) {
+ dirtyBits.clear(fieldIndex);
+ }
+
+ /**
+ * Marks all objects as not dirty
+ */
+ public void clearDirty(Persistent persistent) {
+ dirtyBits.clear();
+ }
+
+ /**
+ * Sets a persistent object as readable using its index
+ */
+ public void setReadable(Persistent persistent, int fieldIndex) {
+ readableBits.set(fieldIndex);
+ }
+
+ /**
+ * Determines if an object is readable using its index
+ */
+ public boolean isReadable(Persistent persistent, int fieldIndex) {
+ return readableBits.get(fieldIndex);
+ }
+
+ @Override
+ /**
+ * Marks an object as non-readable using its index
+ */
+ public void clearReadable(Persistent persistent, int fieldIndex) {
+ readableBits.clear(fieldIndex);
+ }
+
+ /**
+ * Marks all objects as non-readable
+ */
+ public void clearReadable(Persistent persistent) {
+ readableBits.clear();
+ }
+}
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/query/PartitionQuery.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/PartitionQuery.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/PartitionQuery.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/PartitionQuery.java Sat Nov 3 21:09:11 2012
@@ -18,14 +18,12 @@
package org.apache.gora.query;
-import org.apache.gora.persistency.Persistent;
-
/**
* PartitionQuery divides the results of the Query to multi partitions, so that
* queries can be run locally on the nodes that hold the data. PartitionQuery's are
* used for generating Hadoop InputSplits.
*/
-public interface PartitionQuery<K, T extends Persistent> extends Query<K, T> {
+public interface PartitionQuery<K, T> extends Query<K, T> {
/* PartitionQuery interface relaxes the dependency of DataStores to Hadoop*/
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/query/Query.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/Query.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/Query.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/Query.java Sat Nov 3 21:09:11 2012
@@ -20,16 +20,13 @@ package org.apache.gora.query;
import java.io.IOException;
-import org.apache.gora.persistency.Persistent;
import org.apache.gora.store.DataStore;
-import org.apache.hadoop.conf.Configurable;
-import org.apache.hadoop.io.Writable;
/**
* A query to a data store to retrieve objects. Queries are constructed by
* the DataStore implementation via {@link DataStore#newQuery()}.
*/
-public interface Query<K, T extends Persistent> extends Writable, Configurable {
+public interface Query<K, T> {
/**
* Sets the dataStore of this query. Under normal operation, this call
@@ -49,7 +46,7 @@ public interface Query<K, T extends Pers
* Executes the Query on the DataStore and returns the results.
* @return the {@link Result} for the query.
*/
- Result<K,T> execute() throws IOException;
+ Result<K,T> execute() throws Exception, IOException;
// /**
// * Compiles the query for performance and error checking. This
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/query/Result.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/Result.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/Result.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/Result.java Sat Nov 3 21:09:11 2012
@@ -18,10 +18,8 @@
package org.apache.gora.query;
-import java.io.Closeable;
import java.io.IOException;
-import org.apache.gora.persistency.Persistent;
import org.apache.gora.store.DataStore;
/**
@@ -29,7 +27,7 @@ import org.apache.gora.store.DataStore;
* iterated by calling {@link #next()}, {@link #get()}
* and {@link #getKey()}.
*/
-public interface Result<K,T extends Persistent> extends Closeable {
+public interface Result<K,T> {
/**
* Returns the DataStore, that this Result is associated with.
@@ -47,7 +45,7 @@ public interface Result<K,T extends Pers
* Advances to the next element and returns false if at end.
* @return true if end is not reached yet
*/
- boolean next() throws IOException;
+ boolean next() throws Exception, IOException;
/**
* Returns the current key.
@@ -82,9 +80,8 @@ public interface Result<K,T extends Pers
/**
* Returns how far along the result has iterated, a value between 0 and 1.
*/
- float getProgress() throws IOException;
-
- @Override
+ float getProgress() throws IOException, InterruptedException, Exception;
+
void close() throws IOException;
}
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/FileSplitPartitionQuery.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/FileSplitPartitionQuery.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/FileSplitPartitionQuery.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/FileSplitPartitionQuery.java Sat Nov 3 21:09:11 2012
@@ -22,7 +22,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.Query;
import org.apache.hadoop.mapreduce.InputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
@@ -31,7 +31,7 @@ import org.apache.hadoop.mapreduce.lib.i
* Keeps a {@link FileSplit} to represent the partition boundaries.
* FileSplitPartitionQuery is best used with existing {@link InputFormat}s.
*/
-public class FileSplitPartitionQuery<K, T extends Persistent>
+public class FileSplitPartitionQuery<K, T extends PersistentBase>
extends PartitionQueryImpl<K,T> {
private FileSplit split;
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/PartitionQueryImpl.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/PartitionQueryImpl.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/PartitionQueryImpl.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/PartitionQueryImpl.java Sat Nov 3 21:09:11 2012
@@ -23,16 +23,17 @@ import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
import org.apache.gora.store.DataStore;
+import org.apache.gora.store.impl.DataStoreBase;
import org.apache.gora.util.IOUtils;
/**
* Implementation for {@link PartitionQuery}.
*/
-public class PartitionQueryImpl<K, T extends Persistent>
+public class PartitionQueryImpl<K, T extends PersistentBase>
extends QueryBase<K, T> implements PartitionQuery<K, T> {
protected Query<K, T> baseQuery;
@@ -53,7 +54,7 @@ public class PartitionQueryImpl<K, T ext
this.locations = locations;
setStartKey(startKey);
setEndKey(endKey);
- this.dataStore = baseQuery.getDataStore();
+ this.dataStore = (DataStoreBase<K, T>) baseQuery.getDataStore();
}
@Override
@@ -146,7 +147,7 @@ public String[] getLocations() {
//we should override the data store as basequery's data store
//also we may not call super.readFields so that temporary this.dataStore
//is not created at all
- this.dataStore = baseQuery.getDataStore();
+ this.dataStore = (DataStoreBase<K, T>) baseQuery.getDataStore();
}
@Override
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/QueryBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/QueryBase.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/QueryBase.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/QueryBase.java Sat Nov 3 21:09:11 2012
@@ -25,24 +25,27 @@ import java.io.IOException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
-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;
import org.apache.gora.store.DataStore;
+import org.apache.gora.store.impl.DataStoreBase;
import org.apache.gora.util.ClassLoadingUtils;
import org.apache.gora.util.IOUtils;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableUtils;
+import org.apache.hadoop.io.Writable;
import org.apache.hadoop.util.ReflectionUtils;
/**
* Base class for Query implementations.
*/
-public abstract class QueryBase<K, T extends Persistent>
-implements Query<K,T> {
-
- protected DataStore<K,T> dataStore;
+public abstract class QueryBase<K, T extends PersistentBase>
+implements Query<K,T>, Writable, Configurable {
+
+ protected DataStoreBase<K,T> dataStore;
protected String queryString;
protected String[] fields;
@@ -62,11 +65,11 @@ implements Query<K,T> {
private Configuration conf;
public QueryBase(DataStore<K,T> dataStore) {
- this.dataStore = dataStore;
+ this.dataStore = (DataStoreBase<K, T>)dataStore;
}
@Override
- public Result<K,T> execute() throws IOException {
+ public Result<K,T> execute() throws Exception, IOException {
//compile();
return dataStore.execute(this);
}
@@ -80,7 +83,7 @@ implements Query<K,T> {
@Override
public void setDataStore(DataStore<K, T> dataStore) {
- this.dataStore = dataStore;
+ this.dataStore = (DataStoreBase<K, T>)dataStore;
}
@Override
@@ -203,12 +206,10 @@ public String[] getFields() {
return limit;
}
- @Override
public Configuration getConf() {
return conf;
}
- @Override
public void setConf(Configuration conf) {
this.conf = conf;
}
@@ -218,7 +219,7 @@ public String[] getFields() {
public void readFields(DataInput in) throws IOException {
String dataStoreClass = Text.readString(in);
try {
- dataStore = (DataStore<K, T>) ReflectionUtils.newInstance(ClassLoadingUtils.loadClass(dataStoreClass), conf);
+ dataStore = (DataStoreBase<K, T>) ReflectionUtils.newInstance(ClassLoadingUtils.loadClass(dataStoreClass), conf);
dataStore.readFields(in);
} catch (ClassNotFoundException ex) {
throw new IOException(ex);
@@ -242,7 +243,7 @@ public String[] getFields() {
limit = WritableUtils.readVLong(in);
}
- @Override
+ //@Override
public void write(DataOutput out) throws IOException {
//write datastore
Text.writeString(out, dataStore.getClass().getCanonicalName());
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/ResultBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/ResultBase.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/ResultBase.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/impl/ResultBase.java Sat Nov 3 21:09:11 2012
@@ -101,17 +101,18 @@ public abstract class ResultBase<K, T ex
}
@Override
- public final boolean next() throws IOException {
- if(isLimitReached()) {
- return false;
- }
+ public final boolean next() throws Exception, IOException {
+ if(isLimitReached()) {
+ return false;
+ }
+
+ clear();
- clear();
- persistent = getOrCreatePersistent(persistent);
-
- boolean ret = nextInner();
- if(ret) ++offset;
- return ret;
+ persistent = getOrCreatePersistent(persistent);
+ boolean ret = nextInner();
+
+ if(ret) ++offset;
+ return ret;
}
@Override
@@ -125,10 +126,16 @@ public abstract class ResultBase<K, T ex
*/
protected abstract boolean nextInner() throws IOException;
- protected T getOrCreatePersistent(T persistent) throws IOException {
- if(persistent != null) {
- return persistent;
- }
- return dataStore.newPersistent();
+ protected T getOrCreatePersistent(T persistent) throws Exception, IOException {
+ if(persistent != null) {
+ return persistent;
+ }
+ return dataStore.newPersistent();
+ }
+
+ @Override
+ public void close() throws IOException{
+ // TODO Auto-generated method stub
+
}
}
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/PartitionWSQueryImpl.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/PartitionWSQueryImpl.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/PartitionWSQueryImpl.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/PartitionWSQueryImpl.java Sat Nov 3 21:09:11 2012
@@ -0,0 +1,199 @@
+/**
+ * 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.query.ws.impl;
+
+import java.util.Arrays;
+
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.query.PartitionQuery;
+import org.apache.gora.query.Query;
+import org.apache.gora.store.DataStore;
+
+/**
+ * Implementation for {@link PartitionQuery}.
+ */
+//TODO this class should be reviewed when a web service backed datastore has the
+// ability to write partition queries
+public class PartitionWSQueryImpl<K, T extends Persistent>
+ extends QueryWSBase<K, T> implements PartitionQuery<K, T> {
+
+ /**
+ * Base query
+ */
+ protected Query<K, T> baseQuery;
+
+ /**
+ * The places where this query will be executed
+ */
+ protected String[] locations;
+
+ /**
+ * Constructor
+ */
+ public PartitionWSQueryImpl() {
+ super(null);
+ }
+
+ /**
+ * Constructor
+ */
+ public PartitionWSQueryImpl(Query<K, T> baseQuery, String... locations) {
+ this(baseQuery, null, null, locations);
+ }
+
+ /**
+ * Constructor
+ */
+ public PartitionWSQueryImpl(Query<K, T> baseQuery, K startKey, K endKey,
+ String... locations) {
+ super(baseQuery.getDataStore());
+ this.baseQuery = baseQuery;
+ this.locations = locations;
+ setStartKey(startKey);
+ setEndKey(endKey);
+ this.dataStore = baseQuery.getDataStore();
+ }
+
+ @Override
+ /**
+ * Gets the locations where this query will be executed
+ */
+ public String[] getLocations() {
+ return locations;
+ }
+
+ /**
+ * Gets the base query to be used
+ * @return
+ */
+ public Query<K, T> getBaseQuery() {
+ return baseQuery;
+ }
+
+ /* Override everything except start-key/end-key */
+ @Override
+ /**
+ * Gets the fields used
+ */
+ public String[] getFields() {
+ return baseQuery.getFields();
+ }
+
+ @Override
+ /**
+ * Gets the data store used
+ */
+ public DataStore<K, T> getDataStore() {
+ return baseQuery.getDataStore();
+ }
+
+ @Override
+ /**
+ * Gets the timestamp used
+ */
+ public long getTimestamp() {
+ return baseQuery.getTimestamp();
+ }
+
+ @Override
+ /**
+ * Gets the start time used
+ */
+ public long getStartTime() {
+ return baseQuery.getStartTime();
+ }
+
+ @Override
+ /**
+ * Gets the end time used
+ */
+ public long getEndTime() {
+ return baseQuery.getEndTime();
+ }
+
+ @Override
+ /**
+ * Gets the results limit number used
+ */
+ public long getLimit() {
+ return baseQuery.getLimit();
+ }
+
+ @Override
+ /**
+ * Sets the fields to be retrieved
+ */
+ public void setFields(String... fields) {
+ baseQuery.setFields(fields);
+ }
+
+ @Override
+ /**
+ * Sets the timestamp used
+ */
+ public void setTimestamp(long timestamp) {
+ baseQuery.setTimestamp(timestamp);
+ }
+
+ @Override
+ /**
+ * Sets the start time used
+ */
+ public void setStartTime(long startTime) {
+ baseQuery.setStartTime(startTime);
+ }
+
+ @Override
+ /**
+ * Sets the end time used
+ */
+ public void setEndTime(long endTime) {
+ baseQuery.setEndTime(endTime);
+ }
+
+ @Override
+ /**
+ * Sets the time range used
+ */
+ public void setTimeRange(long startTime, long endTime) {
+ baseQuery.setTimeRange(startTime, endTime);
+ }
+
+ @Override
+ /**
+ * Sets the maximum number of records to be retrieved
+ */
+ public void setLimit(long limit) {
+ baseQuery.setLimit(limit);
+ }
+
+ @Override
+ @SuppressWarnings({ "rawtypes" })
+ /**
+ * Determines if this object is equal to another one
+ */
+ public boolean equals(Object obj) {
+ if(obj instanceof PartitionWSQueryImpl) {
+ PartitionWSQueryImpl that = (PartitionWSQueryImpl) obj;
+ return this.baseQuery.equals(that.baseQuery)
+ && Arrays.equals(locations, that.locations);
+ }
+ return false;
+ }
+}
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/QueryWSBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/QueryWSBase.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/QueryWSBase.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/QueryWSBase.java Sat Nov 3 21:09:11 2012
@@ -0,0 +1,329 @@
+/**
+ * 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.query.ws.impl;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.Result;
+import org.apache.gora.store.DataStore;
+
+/**
+ * Base class for Query implementations.
+ */
+public abstract class QueryWSBase<K, T extends Persistent> implements Query<K,T>{
+
+ /**
+ * Data store used for this query
+ */
+ protected DataStore<K,T> dataStore;
+
+ /**
+ * Query represented in a string
+ */
+ protected String queryString;
+
+ /**
+ * Fields to be retrieved
+ */
+ protected String[] fields;
+
+ /**
+ * Range key parameters
+ */
+ protected K startKey;
+ protected K endKey;
+
+ /**
+ * Query time parameters
+ */
+ protected long startTime = -1;
+ protected long endTime = -1;
+
+ /**
+ * Query filter
+ */
+ protected String filter;
+
+ /**
+ * Max number of results to be retrieved
+ */
+ protected long limit = -1;
+
+ /**
+ * Flag to determine whether a query is compiled or not
+ */
+ protected boolean isCompiled = false;
+
+ /** Object that will hold user's authentication tokens for webservice database */
+ private Object authentication;
+
+ /**
+ * Constructor
+ * @param dataStore
+ */
+ public QueryWSBase(DataStore<K,T> dataStore) {
+ this.dataStore = dataStore;
+ }
+
+ @Override
+ /**
+ * Executes the query
+ */
+ public Result<K,T> execute() throws Exception {
+ //compile();
+ return dataStore.execute(this);
+ }
+
+ @Override
+ /**
+ * Sets the data store to be used
+ */
+ public void setDataStore(DataStore<K, T> dataStore) {
+ this.dataStore = dataStore;
+ }
+
+ @Override
+ /**
+ * Gets the data store used for querying
+ */
+ public DataStore<K, T> getDataStore() {
+ return dataStore;
+ }
+
+ @Override
+ /**
+ * Sets the fields to be retrieved
+ */
+ public void setFields(String... fields) {
+ this.fields = fields;
+ }
+
+ @Override
+ /**
+ * Gets the fields to be retrieved
+ */
+ public String[] getFields() {
+ return fields;
+ }
+
+ @Override
+ /**
+ * Sets the key to be used for querying
+ */
+ public void setKey(K key) {
+ setKeyRange(key, key);
+ }
+
+ @Override
+ /**
+ * Sets the start key to be used for querying
+ */
+ public void setStartKey(K startKey) {
+ this.startKey = startKey;
+ }
+
+ @Override
+ /**
+ * Sets the end key to be used for querying
+ */
+ public void setEndKey(K endKey) {
+ this.endKey = endKey;
+ }
+
+ @Override
+ /**
+ * Sets the range key to be used for querying
+ */
+ public void setKeyRange(K startKey, K endKey) {
+ this.startKey = startKey;
+ this.endKey = endKey;
+ }
+
+ @Override
+ /**
+ * Gets the key to be used for querying
+ */
+ public K getKey() {
+ if(startKey == endKey) {
+ return startKey; //address comparison
+ }
+ return null;
+ }
+
+ @Override
+ /**
+ * Gets the start key to be used for querying
+ */
+ public K getStartKey() {
+ return startKey;
+ }
+
+ @Override
+ /**
+ * Gets the end key to be used for querying
+ */
+ public K getEndKey() {
+ return endKey;
+ }
+
+ @Override
+ /**
+ * Sets the timestamp to be used for querying
+ */
+ public void setTimestamp(long timestamp) {
+ setTimeRange(timestamp, timestamp);
+ }
+
+ @Override
+ /**
+ * Sets the start time for querying
+ */
+ public void setStartTime(long startTime) {
+ this.startTime = startTime;
+ }
+
+ @Override
+ /**
+ * Sets the end time for querying
+ */
+ public void setEndTime(long endTime) {
+ this.endTime = endTime;
+ }
+
+ @Override
+ /**
+ * Sets the range time for querying
+ */
+ public void setTimeRange(long startTime, long endTime) {
+ this.startTime = startTime;
+ this.endTime = endTime;
+ }
+
+ @Override
+ /**
+ * Gets the timestamp set
+ */
+ public long getTimestamp() {
+ return startTime == endTime ? startTime : -1;
+ }
+
+ @Override
+ /**
+ * Gets the start time
+ */
+ public long getStartTime() {
+ return startTime;
+ }
+
+ @Override
+ /**
+ * Gets the end time
+ */
+ public long getEndTime() {
+ return endTime;
+ }
+
+ @Override
+ /**
+ * Sets the limit of results to be gotten
+ */
+ public void setLimit(long limit) {
+ this.limit = limit;
+ }
+
+ @Override
+ /**
+ * Gets the number limit of this query
+ */
+ public long getLimit() {
+ return limit;
+ }
+
+ /**
+ * Gets the configuration object
+ * @return
+ */
+ public Object getConf() {
+ return authentication;
+ }
+
+ /**
+ * Sets the configuration object
+ * @param auth
+ */
+ public void setConf(Object auth) {
+ this.authentication = auth;
+ }
+
+ @SuppressWarnings({ "rawtypes" })
+ @Override
+ /**
+ * Determines if this object is equal to a different one
+ */
+ public boolean equals(Object obj) {
+ if(obj instanceof QueryWSBase) {
+ QueryWSBase that = (QueryWSBase) obj;
+ EqualsBuilder builder = new EqualsBuilder();
+ builder.append(dataStore, that.dataStore);
+ builder.append(queryString, that.queryString);
+ builder.append(fields, that.fields);
+ builder.append(startKey, that.startKey);
+ builder.append(endKey, that.endKey);
+ builder.append(filter, that.filter);
+ builder.append(limit, that.limit);
+ return builder.isEquals();
+ }
+ return false;
+ }
+
+ @Override
+ /**
+ * Retrieves the object as hash code
+ */
+ public int hashCode() {
+ HashCodeBuilder builder = new HashCodeBuilder();
+ builder.append(dataStore);
+ builder.append(queryString);
+ builder.append(fields);
+ builder.append(startKey);
+ builder.append(endKey);
+ builder.append(filter);
+ builder.append(limit);
+ return builder.toHashCode();
+ }
+
+ @Override
+ /**
+ * Convets an object to string
+ */
+ public String toString() {
+ ToStringBuilder builder = new ToStringBuilder(this);
+ builder.append("dataStore", dataStore);
+ builder.append("fields", fields);
+ builder.append("startKey", startKey);
+ builder.append("endKey", endKey);
+ builder.append("filter", filter);
+ builder.append("limit", limit);
+
+ return builder.toString();
+ }
+}
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/ResultWSBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/ResultWSBase.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/ResultWSBase.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/query/ws/impl/ResultWSBase.java Sat Nov 3 21:09:11 2012
@@ -0,0 +1,186 @@
+/**
+ * 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.query.ws.impl;
+
+import java.io.IOException;
+
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.Result;
+import org.apache.gora.store.DataStore;
+
+/**
+ * Base class for {@link Result} implementations.
+ */
+public abstract class ResultWSBase<K, T extends Persistent>
+ implements Result<K, T> {
+
+ /**
+ * Data store used
+ */
+ protected final DataStore<K,T> dataStore;
+
+ /**
+ * Query for obtaining this result
+ */
+ protected final Query<K, T> query;
+
+ /**
+ * Key
+ */
+ protected K key;
+
+ /**
+ * Persistent object
+ */
+ protected T persistent;
+
+ /** Query limit */
+ protected long limit;
+
+ /** How far we have proceeded*/
+ protected long offset = 0;
+
+ /**
+ * Constructor
+ * @param dataStore
+ * @param query
+ */
+ public ResultWSBase(DataStore<K,T> dataStore, Query<K,T> query) {
+ this.dataStore = dataStore;
+ this.query = query;
+ this.limit = query.getLimit();
+ }
+
+ @Override
+ /**
+ * Gets the data store used for retrieving this result
+ */
+ public DataStore<K, T> getDataStore() {
+ return dataStore;
+ }
+
+ @Override
+ /**
+ * Gets the query used for this result
+ */
+ public Query<K, T> getQuery() {
+ return query;
+ }
+
+ @Override
+ /**
+ * Gets the persistent object
+ */
+ public T get() {
+ return persistent;
+ }
+
+ @Override
+ /**
+ * Gets the key
+ */
+ public K getKey() {
+ return key;
+ }
+
+ @Override
+ /**
+ * Gets the key class
+ */
+ public Class<K> getKeyClass() {
+ return getDataStore().getKeyClass();
+ }
+
+ @Override
+ /**
+ * Gets the persistent object class
+ */
+ public Class<T> getPersistentClass() {
+ return getDataStore().getPersistentClass();
+ }
+
+ /**
+ * Returns whether the limit for the query is reached.
+ */
+ protected boolean isLimitReached() {
+ if(limit > 0 && offset >= limit) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Clears the persistent object
+ */
+ protected void clear() {
+ if(persistent != null) {
+ persistent.clear();
+ }
+ if(key != null && key instanceof Persistent) {
+ ((Persistent)key).clear();
+ }
+ }
+
+ @Override
+ /**
+ * Returnts the next object from the result's lists
+ */
+ public final boolean next() throws Exception {
+ if(isLimitReached()) {
+ return false;
+ }
+
+ clear();
+
+ persistent = getOrCreatePersistent(persistent);
+ boolean ret = nextInner();
+
+ if(ret) ++offset;
+ return ret;
+ }
+
+ @Override
+ /**
+ * Gets the offset inside the result's list
+ */
+ public long getOffset() {
+ return offset;
+ }
+
+ /**
+ * {@link ResultWSBase#next()} calls this function to read the
+ * actual results.
+ */
+ protected abstract boolean nextInner() throws Exception;
+
+ /**
+ * Creates an object if it does not exists
+ * @param persistent Object to be created if it does not exist
+ * @return
+ * @throws Exception
+ * @throws IOException
+ */
+ protected T getOrCreatePersistent(T persistent) throws Exception, IOException {
+ if(persistent != null) {
+ return persistent;
+ }
+ return dataStore.newPersistent();
+ }
+}
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStore.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStore.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStore.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStore.java Sat Nov 3 21:09:11 2012
@@ -17,9 +17,6 @@
*/
package org.apache.gora.store;
-import java.io.Closeable;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
@@ -29,9 +26,6 @@ import org.apache.gora.persistency.Persi
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
import org.apache.gora.query.Result;
-import org.apache.hadoop.conf.Configurable;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.io.Writable;
/**
* DataStore handles actual object persistence. Objects can be persisted,
@@ -42,12 +36,13 @@ import org.apache.hadoop.io.Writable;
* <p><a name="visibility"><b>Note:</b> Results of updates ({@link #put(Object, Persistent)},
* {@link #delete(Object)} and {@link #deleteByQuery(Query)} operations) are
* guaranteed to be visible to subsequent get / execute operations ONLY
- * after a subsequent call to {@link #flush()}.
+ * after a subsequent call to {@link #flush()}. Additionally, exception
+ * handling is largely DataStore specific and is not largely dealt
+ * with from within this interface.
* @param <K> the class of keys in the datastore
* @param <T> the class of persistent objects in the datastore
*/
-public interface DataStore<K, T extends Persistent> extends Closeable,
- Writable, Configurable {
+public interface DataStore<K, T> {
/**
* Initializes this DataStore.
@@ -57,7 +52,7 @@ public interface DataStore<K, T extends
* @throws IOException
*/
void initialize(Class<K> keyClass, Class<T> persistentClass,
- Properties properties) throws IOException;
+ Properties properties);
/**
* Sets the class of the keys
@@ -94,27 +89,31 @@ public interface DataStore<K, T extends
* to hold the objects. If the schema is already created previously,
* or the underlying data model does not support
* or need this operation, the operation is ignored.
+ * @throws IOException
*/
- void createSchema() throws IOException;
+ void createSchema();
/**
* Deletes the underlying schema or table (or similar) in the datastore
* that holds the objects. This also deletes all the data associated with
* the schema.
+ * @throws IOException
*/
- void deleteSchema() throws IOException;
+ void deleteSchema();
/**
* Deletes all the data associated with the schema, but keeps the
* schema (table or similar) intact.
+ * @throws IOException
*/
- void truncateSchema() throws IOException;
+ void truncateSchema();
/**
* Returns whether the schema that holds the data exists in the datastore.
* @return whether schema exists
+ * @throws IOException
*/
- boolean schemaExists() throws IOException;
+ boolean schemaExists();
/**
* Returns a new instance of the key object. If the object cannot be instantiated
@@ -122,59 +121,67 @@ public interface DataStore<K, T extends
* constructor) it throws an exception. Only use this function if you can
* make sure that the key class has a no-arg constructor.
* @return a new instance of the key object.
+ * @throws IOException
*/
- K newKey() throws IOException;
+ K newKey();
/**
* Returns a new instance of the managed persistent object.
* @return a new instance of the managed persistent object.
+ * @throws IOException
*/
- T newPersistent() throws IOException;
+ T newPersistent();
/**
* Returns the object corresponding to the given key fetching all the fields.
* @param key the key of the object
* @return the Object corresponding to the key or null if it cannot be found
+ * @throws IOException
*/
- T get(K key) throws IOException;
+ T get(K key);
/**
* Returns the object corresponding to the given key.
* @param key the key of the object
* @param fields the fields required in the object. Pass null, to retrieve all fields
* @return the Object corresponding to the key or null if it cannot be found
+ * @throws IOException
*/
- T get(K key, String[] fields) throws IOException;
+ T get(K key, String[] fields);
/**
* Inserts the persistent object with the given key. If an
* object with the same key already exists it will silently
* be replaced. See also the note on
* <a href="#visibility">visibility</a>.
+ * @throws IOException
*/
- void put(K key, T obj) throws IOException;
+ void put(K key, T obj);
/**
* Deletes the object with the given key
* @param key the key of the object
* @return whether the object was successfully deleted
+ * @throws IOException
*/
- boolean delete(K key) throws IOException;
+ boolean delete(K key);
/**
* Deletes all the objects matching the query.
* See also the note on <a href="#visibility">visibility</a>.
* @param query matching records to this query will be deleted
* @return number of deleted records
+ * @throws IOException
*/
- long deleteByQuery(Query<K, T> query) throws IOException;
+ long deleteByQuery(Query<K, T> query);
/**
* Executes the given query and returns the results.
* @param query the query to execute.
* @return the results as a {@link Result} object.
+ * @throws IOException
*/
- Result<K,T> execute(Query<K, T> query) throws IOException;
+ Result<K,T> execute(Query<K, T> query);
/**
* Constructs and returns a new Query.
@@ -189,17 +196,18 @@ public interface DataStore<K, T extends
* is null, then the data store returns the partitions for the default query
* (returning every object)
* @return a List of PartitionQuery's
+ * @throws IOException
*/
- List<PartitionQuery<K,T>> getPartitions(Query<K,T> query)
- throws IOException;
+ List<PartitionQuery<K,T>> getPartitions(Query<K,T> query) throws IOException;
/**
* Forces the write caches to be flushed. DataStore implementations may
* optimize their writing by deferring the actual put / delete operations
* until this moment.
* See also the note on <a href="#visibility">visibility</a>.
+ * @throws IOException
*/
- void flush() throws IOException;
+ void flush();
/**
* Sets the {@link BeanFactory} to use by the DataStore.
@@ -218,15 +226,8 @@ public interface DataStore<K, T extends
* implementation, so that the instance is ready for GC.
* All other DataStore methods cannot be used after this
* method was called. Subsequent calls of this method are ignored.
+ * @throws IOException
*/
- void close() throws IOException;
-
- Configuration getConf();
-
- void setConf(Configuration conf);
-
- void readFields(DataInput in) throws IOException;
-
- void write(DataOutput out) throws IOException;
+ void close();
}
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java Sat Nov 3 21:09:11 2012
@@ -34,7 +34,7 @@ import org.apache.hadoop.conf.Configurat
/**
* A Factory for {@link DataStore}s. DataStoreFactory instances are thread-safe.
*/
-public class DataStoreFactory {
+public class DataStoreFactory{
public static final Logger log = LoggerFactory.getLogger(DataStoreFactory.class);
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/store/WebServiceBackedDataStore.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/WebServiceBackedDataStore.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/WebServiceBackedDataStore.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/WebServiceBackedDataStore.java Sat Nov 3 21:09:11 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.store;
+
+import org.apache.gora.persistency.Persistent;
+
+/**
+ * FileBackedDataStore supplies necessary interfaces to set input
+ * and output paths for data stored which are file based.
+ */
+public interface WebServiceBackedDataStore<K, T extends Persistent> extends DataStore<K, T> {
+
+ void setProvider(String provider);
+
+ String getProvider();
+
+}
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/DataStoreBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/DataStoreBase.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/DataStoreBase.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/DataStoreBase.java Sat Nov 3 21:09:11 2012
@@ -18,6 +18,7 @@
package org.apache.gora.store.impl;
+import java.io.Closeable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@@ -29,9 +30,10 @@ import org.apache.avro.Schema.Field;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.gora.avro.PersistentDatumReader;
import org.apache.gora.avro.PersistentDatumWriter;
+import org.apache.gora.avro.store.AvroStore;
import org.apache.gora.persistency.BeanFactory;
-import org.apache.gora.persistency.Persistent;
import org.apache.gora.persistency.impl.BeanFactoryImpl;
+import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.store.DataStore;
import org.apache.gora.store.DataStoreFactory;
import org.apache.gora.util.AvroUtils;
@@ -39,14 +41,18 @@ import org.apache.gora.util.ClassLoading
import org.apache.gora.util.StringUtils;
import org.apache.gora.util.WritableUtils;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.io.Text;
+import org.apache.hadoop.io.Writable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * A Base class for {@link DataStore}s.
+ * A Base class for Avro persistent {@link DataStore}s.
*/
-public abstract class DataStoreBase<K, T extends Persistent>
-implements DataStore<K, T> {
-
+public abstract class DataStoreBase<K, T extends PersistentBase>
+implements DataStore<K, T>, Configurable, Writable, Closeable {
+
protected BeanFactory<K, T> beanFactory;
protected Class<K> keyClass;
@@ -67,25 +73,27 @@ implements DataStore<K, T> {
protected PersistentDatumReader<T> datumReader;
protected PersistentDatumWriter<T> datumWriter;
+
+ public static final Logger LOG = LoggerFactory.getLogger(AvroStore.class);
public DataStoreBase() {
}
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass,
- Properties properties) throws IOException {
- setKeyClass(keyClass);
- setPersistentClass(persistentClass);
- if(this.beanFactory == null)
- this.beanFactory = new BeanFactoryImpl<K, T>(keyClass, persistentClass);
- schema = this.beanFactory.getCachedPersistent().getSchema();
- fieldMap = AvroUtils.getFieldMap(schema);
-
- autoCreateSchema = DataStoreFactory.getAutoCreateSchema(properties, this);
- this.properties = properties;
-
- datumReader = new PersistentDatumReader<T>(schema, false);
- datumWriter = new PersistentDatumWriter<T>(schema, false);
+ Properties properties) {
+ setKeyClass(keyClass);
+ setPersistentClass(persistentClass);
+ if(this.beanFactory == null)
+ this.beanFactory = new BeanFactoryImpl<K, T>(keyClass, persistentClass);
+ schema = this.beanFactory.getCachedPersistent().getSchema();
+ fieldMap = AvroUtils.getFieldMap(schema);
+
+ autoCreateSchema = DataStoreFactory.getAutoCreateSchema(properties, this);
+ this.properties = properties;
+
+ datumReader = new PersistentDatumReader<T>(schema, false);
+ datumWriter = new PersistentDatumWriter<T>(schema, false);
}
@Override
@@ -110,20 +118,24 @@ implements DataStore<K, T> {
}
@Override
- public K newKey() throws IOException {
+ public K newKey() {
try {
return beanFactory.newKey();
} catch (Exception ex) {
- throw new IOException(ex);
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
+ return null;
}
}
@Override
- public T newPersistent() throws IOException {
+ public T newPersistent() {
try {
return beanFactory.newPersistent();
} catch (Exception ex) {
- throw new IOException(ex);
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
+ return null;
}
}
@@ -138,7 +150,7 @@ implements DataStore<K, T> {
}
@Override
- public T get(K key) throws IOException {
+ public T get(K key) {
return get(key, getFieldsToQuery(null));
};
@@ -171,24 +183,31 @@ implements DataStore<K, T> {
return conf;
}
- @Override
@SuppressWarnings("unchecked")
- public void readFields(DataInput in) throws IOException {
+ public void readFields(DataInput in) {
try {
Class<K> keyClass = (Class<K>) ClassLoadingUtils.loadClass(Text.readString(in));
Class<T> persistentClass = (Class<T>)ClassLoadingUtils.loadClass(Text.readString(in));
Properties props = WritableUtils.readProperties(in);
initialize(keyClass, persistentClass, props);
} catch (ClassNotFoundException ex) {
- throw new IOException(ex);
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
+ } catch (IOException e) {
+ LOG.error(e.getMessage());
+ LOG.error(e.getStackTrace().toString());
}
}
- @Override
- public void write(DataOutput out) throws IOException {
- Text.writeString(out, getKeyClass().getCanonicalName());
- Text.writeString(out, getPersistentClass().getCanonicalName());
- WritableUtils.writeProperties(out, properties);
+ public void write(DataOutput out) {
+ try {
+ Text.writeString(out, getKeyClass().getCanonicalName());
+ Text.writeString(out, getPersistentClass().getCanonicalName());
+ WritableUtils.writeProperties(out, properties);
+ } catch (IOException e) {
+ LOG.error(e.getMessage());
+ LOG.error(e.getStackTrace().toString());
+ }
}
@Override
@@ -206,7 +225,7 @@ implements DataStore<K, T> {
@Override
/** Default implementation deletes and recreates the schema*/
- public void truncateSchema() throws IOException {
+ public void truncateSchema() {
deleteSchema();
createSchema();
}
Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/FileBackedDataStoreBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/FileBackedDataStoreBase.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/FileBackedDataStoreBase.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/FileBackedDataStoreBase.java Sat Nov 3 21:09:11 2012
@@ -27,8 +27,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import org.apache.gora.avro.store.AvroStore;
import org.apache.gora.mapreduce.GoraMapReduceUtils;
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
import org.apache.gora.query.Result;
@@ -42,11 +43,13 @@ import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Base implementations for {@link FileBackedDataStore} methods.
*/
-public abstract class FileBackedDataStoreBase<K, T extends Persistent>
+public abstract class FileBackedDataStoreBase<K, T extends PersistentBase>
extends DataStoreBase<K, T> implements FileBackedDataStore<K, T> {
protected long inputSize; //input size in bytes
@@ -56,10 +59,12 @@ public abstract class FileBackedDataStor
protected InputStream inputStream;
protected OutputStream outputStream;
+
+ public static final Logger LOG = LoggerFactory.getLogger(AvroStore.class);
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass,
- Properties properties) throws IOException {
+ Properties properties) {
super.initialize(keyClass, persistentClass, properties);
if(properties != null) {
if(this.inputPath == null) {
@@ -122,17 +127,28 @@ public InputStream getInputStream() {
}
/** Opens an OutputStream for the output Hadoop path */
- protected OutputStream createOutputStream() throws IOException {
- Path path = new Path(outputPath);
- FileSystem fs = path.getFileSystem(getConf());
- return fs.create(path);
+ protected OutputStream createOutputStream() {
+ OutputStream conf = null;
+ try{
+ Path path = new Path(outputPath);
+ FileSystem fs = path.getFileSystem(getConf());
+ conf = fs.create(path);
+ }catch(IOException ex){
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
+ }
+ return conf;
}
protected InputStream getOrCreateInputStream() throws IOException {
- if(inputStream == null) {
- inputStream = createInputStream();
+ try{
+ if(inputStream == null) {
+ inputStream = createInputStream();
+ }
+ return inputStream;
+ }catch(IOException ex){
+ throw new IOException(ex);
}
- return inputStream;
}
protected OutputStream getOrCreateOutputStream() throws IOException {
@@ -143,25 +159,37 @@ public InputStream getInputStream() {
}
@Override
- public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query)
- throws IOException {
- List<InputSplit> splits = GoraMapReduceUtils.getSplits(getConf(), inputPath);
- List<PartitionQuery<K, T>> queries = new ArrayList<PartitionQuery<K,T>>(splits.size());
-
- for(InputSplit split : splits) {
- queries.add(new FileSplitPartitionQuery<K, T>(query, (FileSplit) split));
+ public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query){
+ List<InputSplit> splits = null;
+ List<PartitionQuery<K, T>> queries = null;
+ try{
+ splits = GoraMapReduceUtils.getSplits(getConf(), inputPath);
+ queries = new ArrayList<PartitionQuery<K,T>>(splits.size());
+
+ for(InputSplit split : splits) {
+ queries.add(new FileSplitPartitionQuery<K, T>(query, (FileSplit) split));
+ }
+ }catch(IOException ex){
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
}
-
return queries;
}
@Override
- public Result<K, T> execute(Query<K, T> query) throws IOException {
- if(query instanceof FileSplitPartitionQuery) {
- return executePartial((FileSplitPartitionQuery<K, T>) query);
- } else {
- return executeQuery(query);
+ public Result<K, T> execute(Query<K, T> query) {
+ Result<K, T> results = null;
+ try{
+ if(query instanceof FileSplitPartitionQuery) {
+ results = executePartial((FileSplitPartitionQuery<K, T>) query);
+ } else {
+ results = executeQuery(query);
+ }
+ }catch(IOException ex){
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
}
+ return results;
}
/**
@@ -178,51 +206,66 @@ public InputStream getInputStream() {
throws IOException;
@Override
- public void flush() throws IOException {
- if(outputStream != null)
- outputStream.flush();
+ public void flush() {
+ try{
+ if(outputStream != null)
+ outputStream.flush();
+ }catch(IOException ex){
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
+ }
}
@Override
- public void createSchema() throws IOException {
+ public void createSchema() {
}
@Override
- public void deleteSchema() throws IOException {
+ public void deleteSchema() {
throw new OperationNotSupportedException("delete schema is not supported for " +
"file backed data stores");
}
@Override
- public boolean schemaExists() throws IOException {
+ public boolean schemaExists() {
return true;
}
@Override
- public void write(DataOutput out) throws IOException {
- super.write(out);
- org.apache.gora.util.IOUtils.writeNullFieldsInfo(out, inputPath, outputPath);
- if(inputPath != null)
- Text.writeString(out, inputPath);
- if(outputPath != null)
- Text.writeString(out, outputPath);
+ public void write(DataOutput out) {
+ try{
+ super.write(out);
+ org.apache.gora.util.IOUtils.writeNullFieldsInfo(out, inputPath, outputPath);
+ if(inputPath != null)
+ Text.writeString(out, inputPath);
+ if(outputPath != null)
+ Text.writeString(out, outputPath);
+ }catch(IOException ex){
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
+ }
}
@Override
- public void readFields(DataInput in) throws IOException {
- super.readFields(in);
- boolean[] nullFields = org.apache.gora.util.IOUtils.readNullFieldsInfo(in);
- if(!nullFields[0])
- inputPath = Text.readString(in);
- if(!nullFields[1])
- outputPath = Text.readString(in);
+ public void readFields(DataInput in) {
+ try{
+ super.readFields(in);
+ boolean[] nullFields = org.apache.gora.util.IOUtils.readNullFieldsInfo(in);
+ if(!nullFields[0])
+ inputPath = Text.readString(in);
+ if(!nullFields[1])
+ outputPath = Text.readString(in);
+ }catch(IOException ex){
+ LOG.error(ex.getMessage());
+ LOG.error(ex.getStackTrace().toString());
+ }
}
@Override
- public void close() throws IOException {
- IOUtils.closeStream(inputStream);
- IOUtils.closeStream(outputStream);
- inputStream = null;
- outputStream = null;
+ public void close() {
+ IOUtils.closeStream(inputStream);
+ IOUtils.closeStream(outputStream);
+ inputStream = null;
+ outputStream = null;
}
}
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSBackedDataStoreBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSBackedDataStoreBase.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSBackedDataStoreBase.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSBackedDataStoreBase.java Sat Nov 3 21:09:11 2012
@@ -0,0 +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.
+ */
+
+package org.apache.gora.store.ws.impl;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.Result;
+import org.apache.gora.store.WebServiceBackedDataStore;
+import org.apache.gora.util.OperationNotSupportedException;
+
+/**
+ * Base implementations for {@link WebServiceBackedDataStore} methods.
+ */
+public abstract class WSBackedDataStoreBase<K, T extends Persistent>
+ extends WSDataStoreBase<K, T> implements WebServiceBackedDataStore<K, T> {
+
+ @Override
+ /**
+ * Initializes a web service backed data store
+ * @throws IOException
+ */
+ public void initialize(Class<K> keyClass, Class<T> persistentClass,
+ Properties properties) {
+ super.initialize(keyClass, persistentClass, properties);
+ }
+
+ @Override
+ /**
+ * Executes a query inside a web service backed data store
+ */
+ public Result<K, T> execute(Query<K, T> query) {
+ try {
+ return executeQuery(query);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Executes a normal Query reading the whole data. #execute() calls this function
+ * for non-PartitionQuery's.
+ */
+ protected abstract Result<K,T> executeQuery(Query<K,T> query)
+ throws IOException;
+
+ @Override
+ /**
+ * Flushes objects into the data store
+ */
+ public void flush() {
+ }
+
+ @Override
+ /**
+ * Creates schema into the data store
+ */
+ public void createSchema() {
+ }
+
+ @Override
+ /**
+ * Deletes schema from the data store
+ */
+ public void deleteSchema() {
+ throw new OperationNotSupportedException("delete schema is not supported for " +
+ "file backed data stores");
+ }
+
+ @Override
+ /**
+ * Verifies if a schema exists
+ */
+ public boolean schemaExists() {
+ return true;
+ }
+
+ @Override
+ /**
+ * Writes an object into the data
+ */
+ public void write(Object out) throws Exception {
+ super.write(out);
+ }
+
+ @Override
+ /**
+ * Reads fields from an object
+ */
+ public void readFields(Object in) throws Exception {
+ super.readFields(in);
+ }
+
+ @Override
+ /**
+ * Closes the data store
+ */
+ public void close() {
+ }
+}
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreBase.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreBase.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreBase.java Sat Nov 3 21:09:11 2012
@@ -0,0 +1,193 @@
+/**
+ * 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.store.ws.impl;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.store.DataStore;
+import org.apache.gora.util.StringUtils;
+
+/**
+ * A Base class for persistent objects{@link DataStore}s.
+ */
+public abstract class WSDataStoreBase<K, T extends Persistent>
+implements DataStore<K, T>{
+
+ /**
+ * Class of the key to be used
+ */
+ protected Class<K> keyClass;
+
+ /**
+ * Class of the persistent object
+ */
+ protected Class<T> persistentClass;
+
+ /**
+ * The web service provider's name
+ */
+ private String wsProvider;
+
+ /**
+ * The authentication object to be used for our provider
+ */
+ protected Object authentication;
+
+ /**
+ * Properties object
+ */
+ protected Properties properties;
+
+ /**
+ * Default constructor
+ */
+ public WSDataStoreBase() {
+ }
+
+ @Override
+ /**
+ * Initializes the web services backed data store
+ */
+ public void initialize(Class<K> keyClass, Class<T> persistentClass,
+ Properties properties) {
+ setKeyClass(keyClass);
+ setPersistentClass(persistentClass);
+ }
+
+ @Override
+ /**
+ * Sets the persistent class to be used
+ */
+ public void setPersistentClass(Class<T> persistentClass) {
+ this.persistentClass = persistentClass;
+ }
+
+ @Override
+ /**
+ * Gets the persistent class being used
+ */
+ public Class<T> getPersistentClass() {
+ return persistentClass;
+ }
+
+ @Override
+ /**
+ * Gets the key class being used
+ */
+ public Class<K> getKeyClass() {
+ return keyClass;
+ }
+
+ @Override
+ /**
+ * Sets the key class to be used
+ */
+ public void setKeyClass(Class<K> keyClass) {
+ if(keyClass != null)
+ this.keyClass = keyClass;
+ }
+
+ /**
+ * Gets the configuration (authentication) object
+ * @return Object containing the authentication values
+ */
+ public Object getConf() {
+ return authentication;
+ }
+
+ /**
+ * Sets the configuration (authentication) object
+ */
+ public void setConf(Object auth) {
+ this.authentication = auth;
+ }
+
+ /**
+ * Reads fields from an object
+ * @param obj
+ * @throws Exception
+ */
+ public void readFields(Object obj) throws Exception {
+ }
+
+ /**
+ * Writes an object
+ * @param obj
+ * @throws Exception
+ */
+ public void write(Object obj) throws Exception {
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(obj instanceof WSDataStoreBase) {
+ @SuppressWarnings("rawtypes")
+ WSDataStoreBase that = (WSDataStoreBase) obj;
+ return that.equals(this);
+ }
+ return false;
+ }
+
+ @Override
+ /** Default implementation deletes and recreates the schema*/
+ public void truncateSchema() {
+ deleteSchema();
+ createSchema();
+ }
+
+ /**
+ * Returns the name of the schema to use for the persistent class.
+ *
+ * First the schema name in the defined properties is returned. If null then
+ * the provided mappingSchemaName is returned. If this is null too,
+ * the class name, without the package, of the persistent class is returned.
+ * @param mappingSchemaName the name of the schema as read from the mapping file
+ * @param persistentClass persistent class
+ */
+ protected String getSchemaName(String mappingSchemaName, Class<?> persistentClass) {
+ String schemaName = WSDataStoreFactory.getDefaultSchemaName(properties, this);
+ if(schemaName != null) {
+ return schemaName;
+ }
+
+ if(mappingSchemaName != null) {
+ return mappingSchemaName;
+ }
+
+ return StringUtils.getClassname(persistentClass);
+ }
+
+ /**
+ * Gets web service provider name
+ * @return
+ */
+ public String getWSProvider() {
+ return wsProvider;
+ }
+
+ /**
+ * Sets web service provider name
+ * @param wsProvider
+ */
+ public void setWsProvider(String wsProvider) {
+ this.wsProvider = wsProvider;
+ }
+}