gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject svn commit: r1405417 [3/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...
Date Sat, 03 Nov 2012 21:09:14 GMT
Added: gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreFactory.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreFactory.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreFactory.java (added)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/store/ws/impl/WSDataStoreFactory.java Sat Nov  3 21:09:11 2012
@@ -0,0 +1,428 @@
+/**
+ * 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.io.InputStream;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.store.DataStore;
+import org.apache.gora.util.ClassLoadingUtils;
+import org.apache.gora.util.GoraException;
+import org.apache.gora.util.ReflectionUtils;
+
+/**
+ * A Factory for {@link DataStore}s. DataStoreFactory instances are thread-safe.
+ */
+public class WSDataStoreFactory{
+
+  public static final Logger log = LoggerFactory.getLogger(WSDataStoreFactory.class);
+
+  public static final String GORA_DEFAULT_PROPERTIES_FILE = "gora.properties";
+
+  public static final String GORA_DEFAULT_DATASTORE_KEY = "gora.datastore.default";
+
+  public static final String GORA = "gora";
+
+  public static final String DATASTORE = "datastore";
+
+  private static final String GORA_DATASTORE = GORA + "." + DATASTORE + ".";
+
+  public static final String AUTO_CREATE_SCHEMA = "autocreateschema";
+
+  public static final String INPUT_PATH  = "input.path";
+
+  public static final String OUTPUT_PATH = "output.path";
+
+  public static final String MAPPING_FILE = "mapping.file";
+
+	public static final String SCHEMA_NAME = "schema.name";
+
+  /**
+   * Do not use! Deprecated because it shares system wide state. 
+   * Use {@link #createProps()} instead.
+   */
+  @Deprecated()
+  public static final Properties properties = createProps();
+  
+  /**
+   * Creates a new {@link Properties}. It adds the default gora configuration
+   * resources. This properties object can be modified and used to instantiate
+   * store instances. It is recommended to use a properties object for a single
+   * store, because the properties object is passed on to store initialization
+   * methods that are able to store the properties as a field.   
+   * @return The new properties object.
+   */
+  public static Properties createProps() {
+    try {
+    Properties properties = new Properties();
+      InputStream stream = WSDataStoreFactory.class.getClassLoader()
+        .getResourceAsStream(GORA_DEFAULT_PROPERTIES_FILE);
+      if(stream != null) {
+        try {
+          properties.load(stream);
+          return properties;
+        } finally {
+          stream.close();
+        }
+      } else {
+        log.warn(GORA_DEFAULT_PROPERTIES_FILE + " not found, properties will be empty.");
+      }
+      return properties;
+    } catch(Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  private WSDataStoreFactory() { }
+
+  private static <K, T extends Persistent> void initializeDataStore(
+      DataStore<K, T> dataStore, Class<K> keyClass, Class<T> persistent,
+      Properties properties) throws IOException, Exception {
+    dataStore.initialize(keyClass, persistent, properties);
+  }
+
+  /**
+   * Instantiate a new {@link DataStore}. Uses default properties. Uses 'null' schema.
+   * 
+   * @param dataStoreClass The datastore implementation class.
+   * @param keyClass The key class.
+   * @param persistent The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  public static <D extends DataStore<K,T>, K, T extends Persistent>
+  D createDataStore(Class<D> dataStoreClass
+      , Class<K> keyClass, Class<T> persistent, Object auth) throws GoraException {
+    return createDataStore(dataStoreClass, keyClass, persistent, auth, createProps(), null);
+  }
+
+  /**
+   * Instantiate a new {@link DataStore}. Uses default properties.
+   * 
+   * @param dataStoreClass The datastore implementation class.
+   * @param keyClass The key class.
+   * @param persistent The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @param schemaName A default schemaname that will be put on the properties.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  public static <D extends DataStore<K,T>, K, T extends Persistent>
+  D createDataStore(Class<D> dataStoreClass , Class<K> keyClass, 
+      Class<T> persistent, Object auth, String schemaName) throws GoraException {
+    return createDataStore(dataStoreClass, keyClass, persistent, auth, createProps(), schemaName);
+  }
+
+  /**
+   * Instantiate a new {@link DataStore}.
+   * 
+   * @param dataStoreClass The datastore implementation class.
+   * @param keyClass The key class.
+   * @param persistent The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @param properties The properties to be used be the store.
+   * @param schemaName A default schemaname that will be put on the properties.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  @SuppressWarnings("unchecked")
+  public static <D extends DataStore<K,T>, K, T extends Persistent>
+  D createDataStore(Class<D> dataStoreClass, Class<K> keyClass
+      , Class<T> persistent, Object auth, Properties properties, String schemaName) 
+  throws GoraException {
+    try {
+      setDefaultSchemaName(properties, schemaName);
+      D dataStore =
+        ReflectionUtils.newInstance(dataStoreClass);
+      if ( auth != null) {
+        ((WSDataStoreBase<K, Persistent>)dataStore).setConf(auth);
+      }
+      initializeDataStore(dataStore, keyClass, persistent, properties);
+      return dataStore;
+
+    } catch (GoraException ex) {
+      throw ex;
+    } catch(Exception ex) {
+      throw new GoraException(ex);
+    }
+  }
+
+  /**
+   * Instantiate a new {@link DataStore}. Uses 'null' schema.
+   * 
+   * @param dataStoreClass The datastore implementation class.
+   * @param keyClass The key class.
+   * @param persistent The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @param properties The properties to be used be the store.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  public static <D extends DataStore<K,T>, K, T extends Persistent>
+  D createDataStore(Class<D> dataStoreClass
+      , Class<K> keyClass, Class<T> persistent, Object auth, Properties properties) 
+  throws GoraException {
+    return createDataStore(dataStoreClass, keyClass, persistent, auth, properties, null);
+  }
+
+  /**
+   * Instantiate a new {@link DataStore}. Uses default properties. Uses 'null' schema.
+   * 
+   * @param dataStoreClass The datastore implementation class.
+   * @param keyClass The key class.
+   * @param persistentClass The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  public static <D extends DataStore<K,T>, K, T extends Persistent>
+  D getDataStore( Class<D> dataStoreClass, Class<K> keyClass,
+      Class<T> persistentClass, Object auth) throws GoraException {
+
+    return createDataStore(dataStoreClass, keyClass, persistentClass, auth, createProps(), null);
+  }
+
+  /**
+   * Instantiate a new {@link DataStore}. Uses default properties. Uses 'null' schema.
+   * 
+   * @param dataStoreClass The datastore implementation class <i>as string</i>.
+   * @param keyClass The key class.
+   * @param persistentClass The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  @SuppressWarnings("unchecked")
+  public static <K, T extends Persistent> DataStore<K, T> getDataStore(
+      String dataStoreClass, Class<K> keyClass, Class<T> persistentClass, Object auth)
+      throws GoraException {
+    try {
+      Class<? extends DataStore<K,T>> c
+        = (Class<? extends DataStore<K, T>>) Class.forName(dataStoreClass);
+      return createDataStore(c, keyClass, persistentClass, auth, createProps(), null);
+    } catch(GoraException ex) {
+      throw ex;
+    } catch (Exception ex) {
+      throw new GoraException(ex);
+    }
+  }
+
+  /**
+   * Instantiate a new {@link DataStore}. Uses default properties. Uses 'null' schema.
+   * 
+   * @param dataStoreClass The datastore implementation class <i>as string</i>.
+   * @param keyClass The key class <i>as string</i>.
+   * @param persistentClass The value class <i>as string</i>.
+   * @param conf {@link Configuration} to be used be the store.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  @SuppressWarnings({ "unchecked" })
+  public static <K, T extends Persistent> DataStore<K, T> getDataStore(
+      String dataStoreClass, String keyClass, String persistentClass, Object auth)
+    throws GoraException {
+
+    try {
+      Class<? extends DataStore<K,T>> c
+          = (Class<? extends DataStore<K, T>>) Class.forName(dataStoreClass);
+      Class<K> k = (Class<K>) ClassLoadingUtils.loadClass(keyClass);
+      Class<T> p = (Class<T>) ClassLoadingUtils.loadClass(persistentClass);
+      return createDataStore(c, k, p, auth, createProps(), null);
+    } catch(GoraException ex) {
+      throw ex;
+    } catch (Exception ex) {
+      throw new GoraException(ex);
+    }
+  }
+
+  /**
+   * Instantiate <i>the default</i> {@link DataStore}. Uses default properties. Uses 'null' schema.
+   * 
+   * @param keyClass The key class.
+   * @param persistent The value class.
+   * @param conf {@link Configuration} to be used be the store.
+   * @return A new store instance.
+   * @throws GoraException
+   */
+  @SuppressWarnings("unchecked")
+  public static <K, T extends Persistent> DataStore<K, T> getDataStore(
+      Class<K> keyClass, Class<T> persistent, Object auth) throws GoraException {
+    Properties createProps = createProps();
+    Class<? extends DataStore<K, T>> c;
+    try {
+      c = (Class<? extends DataStore<K, T>>) Class.forName(getDefaultDataStore(createProps));
+    } catch (Exception ex) {
+      throw new GoraException(ex);
+    }
+    return createDataStore(c, keyClass, persistent, auth, createProps, null);
+  }
+
+  /**
+   * Tries to find a property with the given baseKey. First the property
+   * key constructed as "gora.&lt;classname&gt;.&lt;baseKey&gt;" is searched.
+   * If not found, the property keys for all superclasses is recursively
+   * tested. Lastly, the property key constructed as
+   * "gora.datastore.&lt;baseKey&gt;" is searched.
+   * @return the first found value, or defaultValue
+   */
+  public static String findProperty(Properties properties
+      , DataStore<?, ?> store, String baseKey, String defaultValue) {
+
+    //recursively try the class names until the base class
+    Class<?> clazz = store.getClass();
+    while(true) {
+      String fullKey = GORA + "." + org.apache.gora.util.StringUtils.getClassname(clazz) + "." + baseKey;
+      String value = getProperty(properties, fullKey);
+      if(value != null) {
+        return value;
+      }
+      //try once with lowercase
+      value = getProperty(properties, fullKey.toLowerCase());
+      if(value != null) {
+        return value;
+      }
+
+      if(clazz.equals(WSDataStoreBase.class)) {
+        break;
+      }
+      clazz = clazz.getSuperclass();
+      if(clazz == null) {
+        break;
+      }
+    }
+    //try with "datastore"
+    String fullKey = GORA + "." + DATASTORE + "." + baseKey;
+    String value = getProperty(properties, fullKey);
+    if(value != null) {
+      return value;
+    }
+    return defaultValue;
+  }
+
+  /**
+   * Tries to find a property with the given baseKey. First the property
+   * key constructed as "gora.&lt;classname&gt;.&lt;baseKey&gt;" is searched.
+   * If not found, the property keys for all superclasses is recursively
+   * tested. Lastly, the property key constructed as
+   * "gora.datastore.&lt;baseKey&gt;" is searched.
+   * @return the first found value, or throws IOException
+   */
+  public static String findPropertyOrDie(Properties properties
+      , DataStore<?, ?> store, String baseKey) throws IOException {
+    String val = findProperty(properties, store, baseKey, null);
+    if(val == null) {
+      throw new IOException("Property with base name \""+baseKey+"\" could not be found, make " +
+      		"sure to include this property in gora.properties file");
+    }
+    return val;
+  }
+
+  public static boolean findBooleanProperty(Properties properties
+      , DataStore<?, ?> store, String baseKey, String defaultValue) {
+    return Boolean.parseBoolean(findProperty(properties, store, baseKey, defaultValue));
+  }
+
+  public static boolean getAutoCreateSchema(Properties properties
+      , DataStore<?,?> store) {
+    return findBooleanProperty(properties, store, AUTO_CREATE_SCHEMA, "true");
+  }
+
+  /**
+   * Returns the input path as read from the properties for file-backed data stores.
+   */
+  public static String getInputPath(Properties properties, DataStore<?,?> store) {
+    return findProperty(properties, store, INPUT_PATH, null);
+  }
+
+  /**
+   * Returns the output path as read from the properties for file-backed data stores.
+   */
+  public static String getOutputPath(Properties properties, DataStore<?,?> store) {
+    return findProperty(properties, store, OUTPUT_PATH, null);
+  }
+
+  public static String getMappingFile(Properties properties, DataStore<?,?> store
+      , String defaultValue) {
+    return findProperty(properties, store, MAPPING_FILE, defaultValue);
+  }
+
+  private static String getDefaultDataStore(Properties properties) {
+    return getProperty(properties, GORA_DEFAULT_DATASTORE_KEY);
+  }
+
+  private static String getProperty(Properties properties, String key) {
+    return getProperty(properties, key, null);
+  }
+
+  private static String getProperty(Properties properties, String key, String defaultValue) {
+    if (properties == null) {
+      return defaultValue;
+    }
+    String result = properties.getProperty(key);
+    if (result == null) {
+      return defaultValue;
+    }
+    return result;
+  }
+
+  /**
+   * Set a property
+   */
+  private static void setProperty(Properties properties, String baseKey, String value) {
+    if(value != null) {
+      properties.setProperty(GORA_DATASTORE + baseKey, value);
+    }
+  }
+
+  /**
+   * Sets a property for the datastore of the given class
+   */
+  private static<D extends DataStore<K,T>, K, T extends Persistent>
+  void setProperty(Properties properties, Class<D> dataStoreClass, String baseKey, String value) {
+    properties.setProperty(GORA+"."+org.apache.gora.util.StringUtils.getClassname(dataStoreClass)+"."+baseKey, value);
+  }
+
+  /**
+   * Gets the default schema name of a given store class 
+   */
+  public static String getDefaultSchemaName(Properties properties, DataStore<?,?> store) {
+    return findProperty(properties, store, SCHEMA_NAME, null);
+  }
+
+  /**
+   * Sets the default schema name.
+   */
+  public static void setDefaultSchemaName(Properties properties, String schemaName) {
+    if (schemaName != null) {
+      setProperty(properties, SCHEMA_NAME, schemaName);
+    }
+  }
+
+  /**
+   * Sets the default schema name to be used by the datastore of the given class
+   */
+  public static<D extends DataStore<K,T>, K, T extends Persistent>
+  void setDefaultSchemaName(Properties properties, Class<D> dataStoreClass, String schemaName) {
+    setProperty(properties, dataStoreClass, SCHEMA_NAME, schemaName);
+  }
+}

Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/util/IOUtils.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/util/IOUtils.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/util/IOUtils.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/util/IOUtils.java Sat Nov  3 21:09:11 2012
@@ -42,7 +42,7 @@ import org.apache.avro.ipc.ByteBufferInp
 import org.apache.avro.ipc.ByteBufferOutputStream;
 import org.apache.gora.avro.PersistentDatumReader;
 import org.apache.gora.avro.PersistentDatumWriter;
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.hadoop.io.DataOutputBuffer;
@@ -162,7 +162,7 @@ public class IOUtils {
   /**
    * Serializes the field object using the datumWriter.
    */
-  public static<T extends Persistent> void serialize(OutputStream os,
+  public static<T extends PersistentBase> void serialize(OutputStream os,
       PersistentDatumWriter<T> datumWriter, Schema schema, Object object)
       throws IOException {
 
@@ -174,7 +174,7 @@ public class IOUtils {
   /**
    * Serializes the field object using the datumWriter.
    */
-  public static<T extends Persistent> byte[] serialize(PersistentDatumWriter<T> datumWriter
+  public static<T extends PersistentBase> byte[] serialize(PersistentDatumWriter<T> datumWriter
       , Schema schema, Object object) throws IOException {
     ByteArrayOutputStream os = new ByteArrayOutputStream();
     serialize(os, datumWriter, schema, object);
@@ -252,7 +252,7 @@ public class IOUtils {
    * Deserializes the field object using the datumReader.
    */
   @SuppressWarnings("unchecked")
-  public static<K, T extends Persistent> K deserialize(InputStream is,
+  public static<K, T extends PersistentBase> K deserialize(InputStream is,
       PersistentDatumReader<T> datumReader, Schema schema, K object)
       throws IOException {
     decoder = DecoderFactory.defaultFactory().createBinaryDecoder(is, decoder);
@@ -263,7 +263,7 @@ public class IOUtils {
    * Deserializes the field object using the datumReader.
    */
   @SuppressWarnings("unchecked")
-  public static<K, T extends Persistent> K deserialize(byte[] bytes,
+  public static<K, T extends PersistentBase> K deserialize(byte[] bytes,
       PersistentDatumReader<T> datumReader, Schema schema, K object)
       throws IOException {
     decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, decoder);
@@ -274,7 +274,7 @@ public class IOUtils {
   /**
    * Serializes the field object using the datumWriter.
    */
-  public static<T extends Persistent> byte[] deserialize(PersistentDatumWriter<T> datumWriter
+  public static<T extends PersistentBase> byte[] deserialize(PersistentDatumWriter<T> datumWriter
       , Schema schema, Object object) throws IOException {
     ByteArrayOutputStream os = new ByteArrayOutputStream();
     serialize(os, datumWriter, schema, object);

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/GoraTestDriver.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/GoraTestDriver.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/GoraTestDriver.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/GoraTestDriver.java Sat Nov  3 21:09:11 2012
@@ -71,11 +71,8 @@ public class GoraTestDriver {
    */
   public void setUp() throws Exception {
     log.info("setting up test");
-    try {
-      for(DataStore store : dataStores) {
-        store.truncateSchema();
-      }
-    }catch (IOException ignore) {
+    for(DataStore store : dataStores) {
+      store.truncateSchema();
     }
   }
     

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/avro/TestPersistentDatumReader.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/avro/TestPersistentDatumReader.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/avro/TestPersistentDatumReader.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/avro/TestPersistentDatumReader.java Sat Nov  3 21:09:11 2012
@@ -29,6 +29,7 @@ import org.apache.gora.examples.generate
 import org.apache.gora.examples.generated.WebPage;
 import org.apache.gora.memory.store.MemStore;
 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;
@@ -46,12 +47,12 @@ public class TestPersistentDatumReader {
     = new PersistentDatumReader<WebPage>();
   private Configuration conf = new Configuration();
   
-  private void testClone(Persistent persistent) throws IOException {
-    Persistent cloned = webPageDatumReader.clone(persistent, persistent.getSchema());
+  private void testClone(PersistentBase persistent) throws IOException {
+    PersistentBase cloned = ((PersistentBase)webPageDatumReader.clone(persistent, persistent.getSchema()));
     assertClone(persistent, cloned);
   }
   
-  private void assertClone(Persistent persistent, Persistent cloned) {
+  private void assertClone(PersistentBase persistent, PersistentBase cloned) {
     Assert.assertNotNull("cloned object is null", cloned);
     Assert.assertEquals("cloned object is not equal to original object", persistent, cloned);
   }

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/avro/store/TestAvroStore.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/avro/store/TestAvroStore.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/avro/store/TestAvroStore.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/avro/store/TestAvroStore.java Sat Nov  3 21:09:11 2012
@@ -95,27 +95,27 @@ public class TestAvroStore {
   }
 
   @Test
-  public void testNewInstance() throws IOException {
+  public void testNewInstance() throws IOException, Exception {
     DataStoreTestUtil.testNewPersistent(employeeStore);
   }
 
   @Test
-  public void testCreateSchema() throws IOException {
+  public void testCreateSchema() throws IOException, Exception {
     DataStoreTestUtil.testCreateEmployeeSchema(employeeStore);
   }
 
   @Test
-  public void testAutoCreateSchema() throws IOException {
+  public void testAutoCreateSchema() throws IOException, Exception {
     DataStoreTestUtil.testAutoCreateSchema(employeeStore);
   }
 
   @Test
-  public void testPut() throws IOException {
+  public void testPut() throws IOException, Exception {
     DataStoreTestUtil.testPutEmployee(employeeStore);
   }
 
   @Test
-  public void testQuery() throws IOException {
+  public void testQuery() throws IOException, Exception {
     createWebPageData(webPageStore);
     webPageStore.close();
 
@@ -124,7 +124,7 @@ public class TestAvroStore {
   }
 
   @Test
-  public void testQueryBinaryEncoder() throws IOException {
+  public void testQueryBinaryEncoder() throws IOException, Exception {
     webPageStore.setCodecType(CodecType.BINARY);
     webPageStore.setInputPath(webPageStore.getOutputPath());
 
@@ -136,7 +136,7 @@ public class TestAvroStore {
   //AvroStore should be closed so that Hadoop file is completely flushed,
   //so below test is copied and modified to close the store after pushing data
   public static void testQueryWebPages(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
 
     Query<String, WebPage> query = store.newQuery();
     Result<String, WebPage> result = query.execute();

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/mapreduce/MapReduceTestUtils.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/mapreduce/MapReduceTestUtils.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/mapreduce/MapReduceTestUtils.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/mapreduce/MapReduceTestUtils.java Sat Nov  3 21:09:11 2012
@@ -31,6 +31,7 @@ import org.apache.gora.examples.mapreduc
 import org.apache.gora.examples.mapreduce.WordCount;
 import org.apache.gora.query.Query;
 import org.apache.gora.store.DataStore;
+import org.apache.gora.store.impl.DataStoreBase;
 import org.apache.hadoop.conf.Configuration;
 import org.junit.Assert;
 
@@ -43,7 +44,7 @@ public class MapReduceTestUtils {
       , Configuration conf) 
   throws Exception {
     
-    dataStore.setConf(conf);
+	((DataStoreBase<String, WebPage>)dataStore).setConf(conf);
     
     //create input
     WebPageDataCreator.createWebPageData(dataStore);
@@ -69,8 +70,9 @@ public class MapReduceTestUtils {
   public static void testWordCount(Configuration conf, 
       DataStore<String,WebPage> inStore, DataStore<String, 
       TokenDatum> outStore) throws Exception {
-    inStore.setConf(conf);
-    outStore.setConf(conf);
+	  //Datastore now has to be a Hadoop based datastore
+    ((DataStoreBase<String,WebPage>)inStore).setConf(conf);
+    ((DataStoreBase<String,TokenDatum>)outStore).setConf(conf);
     
     //create input
     WebPageDataCreator.createWebPageData(inStore);
@@ -95,7 +97,7 @@ public class MapReduceTestUtils {
   }
   
   private static void assertTokenCount(DataStore<String, TokenDatum> outStore,
-      String token, int count) throws IOException {
+      String token, int count) throws IOException, Exception {
     TokenDatum datum = outStore.get(token, null);
     Assert.assertNotNull("token:" + token + " cannot be found in datastore", datum);
     Assert.assertEquals("count for token:" + token + " is wrong", count, datum.getCount());

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/mock/store/MockDataStore.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/mock/store/MockDataStore.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/mock/store/MockDataStore.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/mock/store/MockDataStore.java Sat Nov  3 21:09:11 2012
@@ -57,49 +57,47 @@ public class MockDataStore extends DataS
   }
 
   @Override
-  public void close() throws IOException {
+  public void close() {
   }
 
   @Override
-  public void createSchema() throws IOException {
+  public void createSchema() {
   }
 
   @Override
-  public void deleteSchema() throws IOException {
+  public void deleteSchema() {
   }
 
   @Override
-  public void truncateSchema() throws IOException {
+  public void truncateSchema() {
   }
 
   @Override
-  public boolean schemaExists() throws IOException {
+  public boolean schemaExists() {
     return true;
   }
 
   @Override
-  public boolean delete(String key) throws IOException {
+  public boolean delete(String key) {
     return false;
   }
 
   @Override
-  public long deleteByQuery(Query<String, MockPersistent> query)
-      throws IOException {
+  public long deleteByQuery(Query<String, MockPersistent> query) {
     return 0;
   }
 
   @Override
-  public Result<String, MockPersistent> execute(
-      Query<String, MockPersistent> query) throws IOException {
+  public Result<String, MockPersistent> execute(Query<String, MockPersistent> query) {
     return null;
   }
 
   @Override
-  public void flush() throws IOException {
+  public void flush() {
   }
 
   @Override
-  public MockPersistent get(String key, String[] fields) throws IOException {
+  public MockPersistent get(String key, String[] fields) {
     return null;
   }
 
@@ -133,7 +131,7 @@ public class MockDataStore extends DataS
   }
 
   @Override
-  public void put(String key, MockPersistent obj) throws IOException {
+  public void put(String key, MockPersistent obj) {
   }
 
   @Override

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/persistency/impl/TestPersistentBase.java Sat Nov  3 21:09:11 2012
@@ -108,7 +108,7 @@ public class TestPersistentBase {
   }
   
   @Test
-  public void testClone() throws IOException {
+  public void testClone() throws IOException, Exception {
     //more tests for clone are in TestPersistentDatumReader
     @SuppressWarnings("unchecked")
     MemStore<String, Employee> store = DataStoreFactory.getDataStore(

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestBase.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestBase.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestBase.java Sat Nov  3 21:09:11 2012
@@ -53,10 +53,11 @@ public abstract class DataStoreTestBase 
   protected DataStore<String,WebPage> webPageStore;
 
   @Deprecated
-  protected abstract DataStore<String,Employee> createEmployeeDataStore() throws IOException ;
+  protected abstract DataStore<String,Employee> createEmployeeDataStore() throws IOException;
 
   @Deprecated
   protected abstract DataStore<String,WebPage> createWebPageDataStore() throws IOException;
+  
 
   /** junit annoyingly forces BeforeClass to be static, so this method
    * should be called from a static block
@@ -118,7 +119,7 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testNewInstance() throws IOException {
+  public void testNewInstance() throws IOException, Exception {
     log.info("test method: testNewInstance");
     DataStoreTestUtil.testNewPersistent(employeeStore);
   }
@@ -153,7 +154,7 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testDeleteSchema() throws IOException {
+  public void testDeleteSchema() throws IOException, Exception {
     log.info("test method: testDeleteSchema");
     DataStoreTestUtil.testDeleteSchema(webPageStore);
   }
@@ -165,7 +166,7 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testPut() throws IOException {
+  public void testPut() throws IOException, Exception {
     log.info("test method: testPut");
     Employee employee = DataStoreTestUtil.testPutEmployee(employeeStore);
     assertPut(employee);
@@ -175,7 +176,7 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testPutNested() throws IOException {
+  public void testPutNested() throws IOException, Exception {
     log.info("test method: testPutNested");
 
     String revUrl = "foo.com:http/";
@@ -201,7 +202,7 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testPutArray() throws IOException {
+  public void testPutArray() throws IOException, Exception {
     log.info("test method: testPutArray");
     webPageStore.createSchema();
     WebPage page = webPageStore.newPersistent();
@@ -222,7 +223,7 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testPutBytes() throws IOException {
+  public void testPutBytes() throws IOException, Exception {
     log.info("test method: testPutBytes");
     webPageStore.createSchema();
     WebPage page = webPageStore.newPersistent();
@@ -241,7 +242,7 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testPutMap() throws IOException {
+  public void testPutMap() throws IOException, Exception {
     log.info("test method: testPutMap");
     webPageStore.createSchema();
 
@@ -261,108 +262,108 @@ public abstract class DataStoreTestBase 
   }
 
   @Test
-  public void testUpdate() throws IOException {
+  public void testUpdate() throws IOException, Exception {
     log.info("test method: testUpdate");
     DataStoreTestUtil.testUpdateEmployee(employeeStore);
     DataStoreTestUtil.testUpdateWebPage(webPageStore);
   }
 
-  public void testEmptyUpdate() throws IOException {
+  public void testEmptyUpdate() throws IOException, Exception {
     DataStoreTestUtil.testEmptyUpdateEmployee(employeeStore);
   }
 
   @Test
-  public void testGet() throws IOException {
+  public void testGet() throws IOException, Exception {
     log.info("test method: testGet");
     DataStoreTestUtil.testGetEmployee(employeeStore);
   }
 
   @Test
-  public void testGetWithFields() throws IOException {
+  public void testGetWithFields() throws IOException, Exception {
     log.info("test method: testGetWithFields");
     DataStoreTestUtil.testGetEmployeeWithFields(employeeStore);
   }
 
   @Test
-  public void testGetWebPage() throws IOException {
+  public void testGetWebPage() throws IOException, Exception {
     log.info("test method: testGetWebPage");
     DataStoreTestUtil.testGetWebPage(webPageStore);
   }
 
   @Test
-  public void testGetWebPageDefaultFields() throws IOException {
+  public void testGetWebPageDefaultFields() throws IOException, Exception {
     log.info("test method: testGetWebPageDefaultFields");
     DataStoreTestUtil.testGetWebPageDefaultFields(webPageStore);
   }
 
   @Test
-  public void testGetNonExisting() throws Exception {
+  public void testGetNonExisting() throws Exception, Exception {
     log.info("test method: testGetNonExisting");
     DataStoreTestUtil.testGetEmployeeNonExisting(employeeStore);
   }
 
  @Test
-  public void testQuery() throws IOException {
+  public void testQuery() throws IOException, Exception {
     log.info("test method: testQuery");
     DataStoreTestUtil.testQueryWebPages(webPageStore);
   }
 
   @Test
-  public void testQueryStartKey() throws IOException {
+  public void testQueryStartKey() throws IOException, Exception {
     log.info("test method: testQueryStartKey");
     DataStoreTestUtil.testQueryWebPageStartKey(webPageStore);
   }
 
   @Test
-  public void testQueryEndKey() throws IOException {
+  public void testQueryEndKey() throws IOException, Exception {
     log.info("test method: testQueryEndKey");
     DataStoreTestUtil.testQueryWebPageEndKey(webPageStore);
   }
 
   @Test
-  public void testQueryKeyRange() throws IOException {
+  public void testQueryKeyRange() throws IOException, Exception {
     log.info("test method: testQueryKetRange");
     DataStoreTestUtil.testQueryWebPageKeyRange(webPageStore);
   }
 
  @Test
-  public void testQueryWebPageSingleKey() throws IOException {
+  public void testQueryWebPageSingleKey() throws IOException, Exception {
    log.info("test method: testQueryWebPageSingleKey");
     DataStoreTestUtil.testQueryWebPageSingleKey(webPageStore);
   }
 
   @Test
-  public void testQueryWebPageSingleKeyDefaultFields() throws IOException {
+  public void testQueryWebPageSingleKeyDefaultFields() throws IOException, Exception {
     log.info("test method: testQuerySingleKeyDefaultFields");
     DataStoreTestUtil.testQueryWebPageSingleKeyDefaultFields(webPageStore);
   }
 
   @Test
-  public void testQueryWebPageQueryEmptyResults() throws IOException {
+  public void testQueryWebPageQueryEmptyResults() throws IOException, Exception {
     log.info("test method: testQueryEmptyResults");
     DataStoreTestUtil.testQueryWebPageEmptyResults(webPageStore);
   }
 
   @Test
-  public void testDelete() throws IOException {
+  public void testDelete() throws IOException, Exception {
     log.info("test method: testDelete");
     DataStoreTestUtil.testDelete(webPageStore);
   }
 
   @Test
-  public void testDeleteByQuery() throws IOException {
+  public void testDeleteByQuery() throws IOException, Exception {
     log.info("test method: testDeleteByQuery");
     DataStoreTestUtil.testDeleteByQuery(webPageStore);
   }
 
   @Test
-  public void testDeleteByQueryFields() throws IOException {
+  public void testDeleteByQueryFields() throws IOException, Exception {
     log.info("test method: testQueryByQueryFields");
     DataStoreTestUtil.testDeleteByQueryFields(webPageStore);
   }
 
   @Test
-  public void testGetPartitions() throws IOException {
+  public void testGetPartitions() throws IOException, Exception {
     log.info("test method: testGetPartitions");
     DataStoreTestUtil.testGetPartitions(webPageStore);
   }

Modified: gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java (original)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java Sat Nov  3 21:09:11 2012
@@ -68,7 +68,7 @@ public class DataStoreTestUtil {
   private static final int NUM_KEYS = 4;
 
   public static <K, T extends Persistent> void testNewPersistent(
-      DataStore<K,T> dataStore) throws IOException {
+      DataStore<K,T> dataStore) throws IOException, Exception {
 
     T obj1 = dataStore.newPersistent();
     T obj2 = dataStore.newPersistent();
@@ -81,7 +81,7 @@ public class DataStoreTestUtil {
   }
 
   public static <K> Employee createEmployee(
-      DataStore<K, Employee> dataStore) throws IOException {
+      DataStore<K, Employee> dataStore) throws IOException, Exception {
 
     Employee employee = dataStore.newPersistent();
     employee.setName(new Utf8("Random Joe"));
@@ -92,13 +92,13 @@ public class DataStoreTestUtil {
   }
 
   public static void testAutoCreateSchema(DataStore<String,Employee> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     //should not throw exception
     dataStore.put("foo", createEmployee(dataStore));
   }
 
   public static void testCreateEmployeeSchema(DataStore<String, Employee> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     dataStore.createSchema();
 
     //should not throw exception
@@ -106,7 +106,7 @@ public class DataStoreTestUtil {
   }
 
   public static void testTruncateSchema(DataStore<String, WebPage> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     dataStore.createSchema();
     WebPageDataCreator.createWebPageData(dataStore);
     dataStore.truncateSchema();
@@ -115,7 +115,7 @@ public class DataStoreTestUtil {
   }
 
   public static void testDeleteSchema(DataStore<String, WebPage> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     dataStore.createSchema();
     WebPageDataCreator.createWebPageData(dataStore);
     dataStore.deleteSchema();
@@ -125,7 +125,7 @@ public class DataStoreTestUtil {
   }
 
   public static<K, T extends Persistent> void testSchemaExists(
-      DataStore<K, T> dataStore) throws IOException {
+      DataStore<K, T> dataStore) throws IOException, Exception {
     dataStore.createSchema();
 
     Assert.assertTrue(dataStore.schemaExists());
@@ -135,7 +135,7 @@ public class DataStoreTestUtil {
   }
 
   public static void testGetEmployee(DataStore<String, Employee> dataStore)
-    throws IOException {
+    throws IOException, Exception {
     dataStore.createSchema();
     Employee employee = DataStoreTestUtil.createEmployee(dataStore);
     String ssn = employee.getSsn().toString();
@@ -148,13 +148,13 @@ public class DataStoreTestUtil {
   }
 
   public static void testGetEmployeeNonExisting(DataStore<String, Employee> dataStore)
-    throws IOException {
+    throws IOException, Exception {
     Employee employee = dataStore.get("_NON_EXISTING_SSN_FOR_EMPLOYEE_");
     Assert.assertNull(employee);
   }
 
   public static void testGetEmployeeWithFields(DataStore<String, Employee> dataStore)
-    throws IOException {
+    throws IOException, Exception {
     Employee employee = DataStoreTestUtil.createEmployee(dataStore);
     String ssn = employee.getSsn().toString();
     dataStore.put(ssn, employee);
@@ -176,14 +176,14 @@ public class DataStoreTestUtil {
   }
 
   public static Employee testPutEmployee(DataStore<String, Employee> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     dataStore.createSchema();
     Employee employee = DataStoreTestUtil.createEmployee(dataStore);
     return employee;
   }
 
   public static void testEmptyUpdateEmployee(DataStore<String, Employee> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     dataStore.createSchema();
     long ssn = 1234567890L;
     String ssnStr = Long.toString(ssn);
@@ -213,7 +213,7 @@ public class DataStoreTestUtil {
   }
 
   public static void testUpdateEmployee(DataStore<String, Employee> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     dataStore.createSchema();
     long ssn = 1234567890L;
     long now = System.currentTimeMillis();
@@ -250,7 +250,7 @@ public class DataStoreTestUtil {
   }
 
   public static void testUpdateWebPage(DataStore<String, WebPage> dataStore)
-  throws IOException {
+  throws IOException, Exception {
     dataStore.createSchema();
 
     String[] urls = {"http://a.com/a", "http://b.com/b", "http://c.com/c",
@@ -332,7 +332,7 @@ public class DataStoreTestUtil {
     }
   }
 
-  public static void assertWebPage(WebPage page, int i) {
+  public static void assertWebPage(WebPage page, int i) throws Exception{
     Assert.assertNotNull(page);
 
     Assert.assertEquals(URLS[i], page.getUrl().toString());
@@ -364,7 +364,7 @@ public class DataStoreTestUtil {
   }
 
   private static void testGetWebPage(DataStore<String, WebPage> store, String[] fields)
-    throws IOException {
+    throws IOException, Exception {
     createWebPageData(store);
 
     for(int i=0; i<URLS.length; i++) {
@@ -373,17 +373,17 @@ public class DataStoreTestUtil {
     }
   }
 
-  public static void testGetWebPage(DataStore<String, WebPage> store) throws IOException {
+  public static void testGetWebPage(DataStore<String, WebPage> store) throws IOException, Exception {
     testGetWebPage(store, WebPage._ALL_FIELDS);
   }
 
   public static void testGetWebPageDefaultFields(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
     testGetWebPage(store, null);
   }
 
   private static void testQueryWebPageSingleKey(DataStore<String, WebPage> store
-      , String[] fields) throws IOException {
+      , String[] fields) throws IOException, Exception {
 
     createWebPageData(store);
 
@@ -400,18 +400,18 @@ public class DataStoreTestUtil {
   }
 
   public static void testQueryWebPageSingleKey(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
     testQueryWebPageSingleKey(store, WebPage._ALL_FIELDS);
   }
 
   public static void testQueryWebPageSingleKeyDefaultFields(
-      DataStore<String, WebPage> store) throws IOException {
+      DataStore<String, WebPage> store) throws IOException, Exception {
     testQueryWebPageSingleKey(store, null);
   }
 
   public static void testQueryWebPageKeyRange(DataStore<String, WebPage> store,
       boolean setStartKeys, boolean setEndKeys)
-  throws IOException {
+  throws IOException, Exception {
     createWebPageData(store);
 
     //create sorted set of urls
@@ -450,27 +450,27 @@ public class DataStoreTestUtil {
   }
 
   public static void testQueryWebPages(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
     testQueryWebPageKeyRange(store, false, false);
   }
 
   public static void testQueryWebPageStartKey(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
     testQueryWebPageKeyRange(store, true, false);
   }
 
   public static void testQueryWebPageEndKey(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
     testQueryWebPageKeyRange(store, false, true);
   }
 
   public static void testQueryWebPageKeyRange(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
     testQueryWebPageKeyRange(store, true, true);
   }
 
   public static void testQueryWebPageEmptyResults(DataStore<String, WebPage> store)
-    throws IOException {
+    throws IOException, Exception {
     createWebPageData(store);
 
     //query empty results
@@ -486,12 +486,12 @@ public class DataStoreTestUtil {
   }
 
   public static<K,T extends Persistent> void assertEmptyResults(Query<K, T> query)
-    throws IOException {
+    throws IOException, Exception {
     assertNumResults(query, 0);
   }
 
   public static<K,T extends Persistent> void assertNumResults(Query<K, T>query
-      , long numResults) throws IOException {
+      , long numResults) throws IOException, Exception {
     Result<K, T> result = query.execute();
     int actualNumResults = 0;
     while(result.next()) {
@@ -502,13 +502,13 @@ public class DataStoreTestUtil {
   }
 
   public static void testGetPartitions(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
     createWebPageData(store);
     testGetPartitions(store, store.newQuery());
   }
 
   public static void testGetPartitions(DataStore<String, WebPage> store
-      , Query<String, WebPage> query) throws IOException {
+      , Query<String, WebPage> query) throws IOException, Exception {
     List<PartitionQuery<String, WebPage>> partitions = store.getPartitions(query);
 
     Assert.assertNotNull(partitions);
@@ -523,7 +523,7 @@ public class DataStoreTestUtil {
 
   public static void assertPartitions(DataStore<String, WebPage> store,
       Query<String, WebPage> query, List<PartitionQuery<String,WebPage>> partitions)
-  throws IOException {
+  throws IOException, Exception {
 
     int count = 0, partitionsCount = 0;
     Map<String, Integer> results = new HashMap<String, Integer>();
@@ -571,7 +571,7 @@ public class DataStoreTestUtil {
     }
   }
 
-  public static void testDelete(DataStore<String, WebPage> store) throws IOException {
+  public static void testDelete(DataStore<String, WebPage> store) throws IOException, Exception {
     WebPageDataCreator.createWebPageData(store);
     //delete one by one
 
@@ -589,7 +589,7 @@ public class DataStoreTestUtil {
   }
 
   public static void testDeleteByQuery(DataStore<String, WebPage> store)
-    throws IOException {
+    throws IOException, Exception {
 
     Query<String, WebPage> query;
 
@@ -643,7 +643,7 @@ public class DataStoreTestUtil {
   }
 
   public static void testDeleteByQueryFields(DataStore<String, WebPage> store)
-  throws IOException {
+  throws IOException, Exception {
 
     Query<String, WebPage> query;
 

Added: gora/trunk/gora-core/src/test/java/org/apache/gora/store/WSDataStoreTestBase.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/test/java/org/apache/gora/store/WSDataStoreTestBase.java?rev=1405417&view=auto
==============================================================================
--- gora/trunk/gora-core/src/test/java/org/apache/gora/store/WSDataStoreTestBase.java (added)
+++ gora/trunk/gora-core/src/test/java/org/apache/gora/store/WSDataStoreTestBase.java Sat Nov  3 21:09:11 2012
@@ -0,0 +1,279 @@
+/**
+ * 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 java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.gora.GoraTestDriver;
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.store.DataStore;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * A base class for {@link DataStore} tests. This is just a convenience
+ * class, which actually only uses {@link DataStoreTestUtil} methods to
+ * run the tests. Not all test cases can extend this class (like TestHBaseStore),
+ * so all test logic should reside in DataStoreTestUtil class.
+ * 
+ */
+public abstract class WSDataStoreTestBase<K, T extends Persistent> {
+
+  public static final Logger log = LoggerFactory.getLogger(WSDataStoreTestBase.class);
+
+  protected static GoraTestDriver testDriver;
+
+  protected DataStore<K, T> dataStore;
+  
+  private static boolean setUpClassCalled = false;
+  
+  public Class<K> persistentKeyClass;
+  public Class<T> persistentValClass;
+
+  protected abstract DataStore<K,T> createDataStore();
+  
+  /** junit annoyingly forces BeforeClass to be static, so this method
+   * should be called from a static block
+   */
+  protected static void setTestDriver(GoraTestDriver driver) {
+    testDriver = driver;
+  }
+
+  public void setPersistentKeyClass(Class<K> pKeyClass){
+	  persistentKeyClass = pKeyClass;
+  }
+  
+  public void setPersistentValClass(Class<T> pValClass){
+	  persistentValClass = pValClass;
+  }
+  
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    if(testDriver != null && !setUpClassCalled) {
+      log.info("setting up class");
+      testDriver.setUpClass();
+      setUpClassCalled = true;
+    }
+  }
+
+  @AfterClass
+  public static void tearDownClass() throws Exception {
+	log.info("tearing down class");
+    //if(testDriver != null) 
+    //  testDriver.tearDownClass();
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    //There is an issue in JUnit 4 tests in Eclipse where TestSqlStore static
+    //methods are not called BEFORE setUpClass. I think this is a bug in 
+    //JUnitRunner in Eclipse. Below is a workaround for that problem.
+    if(!setUpClassCalled) setUpClass();  
+    log.info("setting up test");
+    if(dataStore == null){
+      if(testDriver != null) {
+        dataStore = testDriver.createDataStore(persistentKeyClass, persistentValClass);
+        testDriver.setUp();
+      } else {
+        dataStore = createDataStore();
+        dataStore.truncateSchema();
+      }
+    }
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    log.info("tearing down test");
+    if(testDriver != null)
+      testDriver.tearDown();
+  }
+  
+  @Test
+  public void testNewInstance() throws IOException, Exception {
+    log.info("test method: testNewInstance");
+    DataStoreTestUtil.testNewPersistent(dataStore);
+  }
+
+  @Test
+  public void testCreateSchema() throws Exception {
+    log.info("test method: testCreateSchema");
+    assertSchemaExists("person");
+  }
+
+  // Override this to assert that schema is created correctly
+  public void assertSchemaExists(String schemaName) throws Exception {
+  }
+
+  @Test
+  public void testAutoCreateSchema() throws Exception {
+    log.info("test method: testAutoCreateSchema");
+    assertAutoCreateSchema();
+  }
+
+  public void assertAutoCreateSchema() throws Exception {
+    assertSchemaExists("person");
+  }
+
+  @Test
+  public  void testTruncateSchema() throws Exception {
+    log.info("test method: testTruncateSchema");
+    assertSchemaExists("person");
+  }
+
+  @Test
+  public void testDeleteSchema() throws IOException, Exception {
+    log.info("test method: testDeleteSchema");
+    assertDeleteSchema();
+  }
+  
+  public void assertDeleteSchema(){
+  }
+
+  @Test
+  public void testSchemaExists() throws Exception {
+    log.info("test method: testSchemaExists");
+    Assert.assertTrue(dataStore.schemaExists());
+  }
+
+  @Test
+  public void testPut() throws IOException, Exception {
+    log.info("test method: testPut");
+    assertPut();
+  }
+
+  public void assertPut() throws IOException {
+  }
+
+  @Test
+  public void testPutNested() throws IOException, Exception {
+    log.info("test method: testPutNested");
+
+  }
+
+  @Test
+  public void testPutArray() throws IOException, Exception {
+    log.info("test method: testPutArray");
+    assertPutArray();
+  }
+
+  public void assertPutArray() throws IOException {
+  }
+
+  @Test
+  public void testPutBytes() throws IOException, Exception {
+    log.info("test method: testPutBytes");
+    byte[] contentBytes = "example content in example.com".getBytes();
+
+    assertPutBytes(contentBytes);
+  }
+
+  public void assertPutBytes(byte[] contentBytes) throws IOException {
+  }
+
+  @Test
+  public void testPutMap() throws IOException, Exception {
+    log.info("test method: testPutMap");
+    assertPutMap();
+  }
+
+  public void assertPutMap() throws IOException {
+  }
+
+  @Test
+  public void testUpdate() throws IOException, Exception {
+    log.info("test method: testUpdate");
+    assertTestUpdateDataStore();
+  }
+
+  public void assertTestUpdateDataStore(){
+  }
+  
+  @Test
+  public void testEmptyUpdate() throws IOException, Exception {
+  }
+
+  @Test
+  public void testGet() throws IOException, Exception {
+    log.info("test method: testGet");
+    assertTestGetDataStore();
+  }
+  
+  public void assertTestGetDataStore() throws IOException {
+  }
+  
+  @Test
+  public void testGetWithFields() throws IOException, Exception {
+    log.info("test method: testGetWithFields");
+  }
+
+ @Test
+  public void testQuery() throws IOException, Exception {
+    log.info("test method: testQuery");
+    assertTestQueryDataStore();
+  }
+ 
+  public void assertTestQueryDataStore() throws IOException {
+  }
+
+  @Test
+  public void testQueryStartKey() throws IOException, Exception {
+    log.info("test method: testQueryStartKey");
+  }
+
+  @Test
+  public void testQueryEndKey() throws IOException, Exception {
+    log.info("test method: testQueryEndKey");
+  }
+
+  @Test
+  public void testQueryKeyRange() throws IOException, Exception {
+    log.info("test method: testQueryKetRange");
+    assertTestQueryKeyRange();
+  }
+
+  public void assertTestQueryKeyRange(){}
+  
+  @Test
+  public void testDelete() throws IOException, Exception {
+    log.info("test method: testDelete");
+    assertTestDeleteDataStore();
+  }
+  public void assertTestDeleteDataStore(){}
+  
+  @Test
+  public void testDeleteByQuery() throws IOException, Exception {
+    log.info("test method: testDeleteByQuery");
+    assertTestDeleteByQueryDataStore();
+  }
+  public void assertTestDeleteByQueryDataStore(){
+  }
+  
+  @Test
+  public void testDeleteByQueryFields() throws IOException, Exception {
+    log.info("test method: testQueryByQueryFields");
+  }
+
+}

Modified: gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseGetResult.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseGetResult.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseGetResult.java (original)
+++ gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseGetResult.java Sat Nov  3 21:09:11 2012
@@ -22,6 +22,7 @@ import java.io.IOException;
 
 import org.apache.gora.hbase.store.HBaseStore;
 import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.Query;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.Result;
@@ -29,7 +30,7 @@ import org.apache.hadoop.hbase.client.Re
 /**
  * An {@link HBaseResult} based on the result of a HBase {@link Get} query.
  */
-public class HBaseGetResult<K, T extends Persistent> extends HBaseResult<K,T> {
+public class HBaseGetResult<K, T extends PersistentBase> extends HBaseResult<K,T> {
 
   private Result result;
   

Modified: gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseQuery.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseQuery.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseQuery.java (original)
+++ gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseQuery.java Sat Nov  3 21:09:11 2012
@@ -19,6 +19,7 @@
 package org.apache.gora.hbase.query;
 
 import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.Query;
 import org.apache.gora.query.impl.QueryBase;
 import org.apache.gora.store.DataStore;
@@ -26,7 +27,7 @@ import org.apache.gora.store.DataStore;
 /**
  * HBase specific implementation of the {@link Query} interface.
  */
-public class HBaseQuery<K, T extends Persistent> extends QueryBase<K, T> {
+public class HBaseQuery<K, T extends PersistentBase> extends QueryBase<K, T> {
 
   public HBaseQuery() {
     super(null);

Modified: gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseResult.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseResult.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseResult.java (original)
+++ gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseResult.java Sat Nov  3 21:09:11 2012
@@ -24,6 +24,7 @@ import java.io.IOException;
 
 import org.apache.gora.hbase.store.HBaseStore;
 import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.Query;
 import org.apache.gora.query.impl.ResultBase;
 import org.apache.hadoop.hbase.client.Result;
@@ -31,7 +32,7 @@ import org.apache.hadoop.hbase.client.Re
 /**
  * Base class for {@link Result} implementations for HBase.  
  */
-public abstract class HBaseResult<K, T extends Persistent> 
+public abstract class HBaseResult<K, T extends PersistentBase> 
   extends ResultBase<K, T> {
 
   public HBaseResult(HBaseStore<K,T> dataStore, Query<K, T> query) {

Modified: gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseScannerResult.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseScannerResult.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseScannerResult.java (original)
+++ gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/query/HBaseScannerResult.java Sat Nov  3 21:09:11 2012
@@ -22,6 +22,7 @@ import java.io.IOException;
 
 import org.apache.gora.hbase.store.HBaseStore;
 import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.Query;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
@@ -29,7 +30,7 @@ import org.apache.hadoop.hbase.client.Re
 /**
  * Result of a query based on an HBase scanner.
  */
-public class HBaseScannerResult<K, T extends Persistent> 
+public class HBaseScannerResult<K, T extends PersistentBase> 
   extends HBaseResult<K, T> {
 
   private final ResultScanner scanner;

Modified: gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java (original)
+++ gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java Sat Nov  3 21:09:11 2012
@@ -46,11 +46,11 @@ import org.apache.gora.hbase.query.HBase
 import org.apache.gora.hbase.store.HBaseMapping.HBaseMappingBuilder;
 import org.apache.gora.hbase.util.HBaseByteInterface;
 import org.apache.gora.persistency.ListGenericArray;
-import org.apache.gora.persistency.Persistent;
 import org.apache.gora.persistency.State;
 import org.apache.gora.persistency.StateManager;
 import org.apache.gora.persistency.StatefulHashMap;
 import org.apache.gora.persistency.StatefulMap;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.PartitionQuery;
 import org.apache.gora.query.Query;
 import org.apache.gora.query.impl.PartitionQueryImpl;
@@ -77,7 +77,7 @@ import org.jdom.input.SAXBuilder;
  * DataStore for HBase. Thread safe.
  *
  */
-public class HBaseStore<K, T extends Persistent> extends DataStoreBase<K, T>
+public class HBaseStore<K, T extends PersistentBase> extends DataStoreBase<K, T>
 implements Configurable {
 
   public static final Logger LOG = LoggerFactory.getLogger(HBaseStore.class);
@@ -101,35 +101,42 @@ implements Configurable {
 
   @Override
   public void initialize(Class<K> keyClass, Class<T> persistentClass,
-      Properties properties) throws IOException {
-    super.initialize(keyClass, persistentClass, properties);
-    this.conf = HBaseConfiguration.create(getConf());
-
-    admin = new HBaseAdmin(this.conf);
-
+      Properties properties) {
     try {
+      
+      super.initialize(keyClass, persistentClass, properties);
+      this.conf = HBaseConfiguration.create(getConf());
+      admin = new HBaseAdmin(this.conf);
       mapping = readMapping(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE));
+      
     } catch (FileNotFoundException ex) {
       try {
         mapping = readMapping(getConf().get(PARSE_MAPPING_FILE_KEY, DEPRECATED_MAPPING_FILE));
         LOG.warn(DEPRECATED_MAPPING_FILE + " is deprecated, please rename the file to "
             + DEFAULT_MAPPING_FILE);
       } catch (FileNotFoundException ex1) {
-        throw ex; //throw the original exception
+          LOG.error(ex1.getMessage());
+          LOG.error(ex1.getStackTrace().toString());
+          //throw (ex1); //throw the original exception
       } catch (Exception ex1) {
         LOG.warn(DEPRECATED_MAPPING_FILE + " is deprecated, please rename the file to "
             + DEFAULT_MAPPING_FILE);
         throw new RuntimeException(ex1);
-      }
+      } 
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
+    
     if(autoCreateSchema) {
       createSchema();
     }
-
-    boolean autoflush = this.conf.getBoolean("hbase.client.autoflush.default", false);
-    table = new HBaseTableConnection(getConf(), getSchemaName(), autoflush);
+    try{
+      boolean autoflush = this.conf.getBoolean("hbase.client.autoflush.default", false);
+      table = new HBaseTableConnection(getConf(), getSchemaName(), autoflush);
+    } catch(IOException ex2){
+      LOG.error(ex2.getMessage());
+      LOG.error(ex2.getStackTrace().toString());
+    }
   }
 
   @Override
@@ -139,109 +146,136 @@ implements Configurable {
   }
 
   @Override
-  public void createSchema() throws IOException {
-    if(schemaExists()) {
-      return;
+  public void createSchema() {
+    try{
+      if(schemaExists()) {
+        return;
+      }
+      HTableDescriptor tableDesc = mapping.getTable();
+  
+      admin.createTable(tableDesc);
+    } catch(IOException ex2){
+      LOG.error(ex2.getMessage());
+      LOG.error(ex2.getStackTrace().toString());
     }
-    HTableDescriptor tableDesc = mapping.getTable();
-
-    admin.createTable(tableDesc);
   }
 
   @Override
-  public void deleteSchema() throws IOException {
-    if(!schemaExists()) {
-      return;
+  public void deleteSchema() {
+    try{
+      if(!schemaExists()) {
+        return;
+      }
+      admin.disableTable(getSchemaName());
+      admin.deleteTable(getSchemaName());
+    } catch(IOException ex2){
+      LOG.error(ex2.getMessage());
+      LOG.error(ex2.getStackTrace().toString());
     }
-    admin.disableTable(getSchemaName());
-    admin.deleteTable(getSchemaName());
   }
 
   @Override
-  public boolean schemaExists() throws IOException {
-    return admin.tableExists(mapping.getTableName());
+  public boolean schemaExists() {
+    try{
+      return admin.tableExists(mapping.getTableName());
+    } catch(IOException ex2){
+      LOG.error(ex2.getMessage());
+      LOG.error(ex2.getStackTrace().toString());
+      return false;
+    }
   }
 
   @Override
-  public T get(K key, String[] fields) throws IOException {
-    fields = getFieldsToQuery(fields);
-    Get get = new Get(toBytes(key));
-    addFields(get, fields);
-    Result result = table.get(get);
-    return newInstance(result, fields);
+  public T get(K key, String[] fields) {
+    try{
+      fields = getFieldsToQuery(fields);
+      Get get = new Get(toBytes(key));
+      addFields(get, fields);
+      Result result = table.get(get);
+      return newInstance(result, fields);
+    } catch(IOException ex2){
+      LOG.error(ex2.getMessage());
+      LOG.error(ex2.getStackTrace().toString());
+      return null;
+    }
   }
 
   @SuppressWarnings({ "unchecked", "rawtypes" })
   @Override
-  public void put(K key, T persistent) throws IOException {
-    Schema schema = persistent.getSchema();
-    StateManager stateManager = persistent.getStateManager();
-    byte[] keyRaw = toBytes(key);
-    Put put = new Put(keyRaw);
-    Delete delete = new Delete(keyRaw);
-    boolean hasPuts = false;
-    boolean hasDeletes = false;
-    Iterator<Field> iter = schema.getFields().iterator();
-    for (int i = 0; iter.hasNext(); i++) {
-      Field field = iter.next();
-      if (!stateManager.isDirty(persistent, i)) {
-        continue;
-      }
-      Type type = field.schema().getType();
-      Object o = persistent.get(i);
-      HBaseColumn hcol = mapping.getColumn(field.name());
-      switch(type) {
-        case MAP:
-          if(o instanceof StatefulMap) {
-            StatefulHashMap<Utf8, ?> map = (StatefulHashMap<Utf8, ?>) o;
-            for (Entry<Utf8, State> e : map.states().entrySet()) {
-              Utf8 mapKey = e.getKey();
-              switch (e.getValue()) {
-                case DIRTY:
-                  byte[] qual = Bytes.toBytes(mapKey.toString());
-                  byte[] val = toBytes(map.get(mapKey), field.schema().getValueType());
-                  put.add(hcol.getFamily(), qual, val);
-                  hasPuts = true;
-                  break;
-                case DELETED:
-                  qual = Bytes.toBytes(mapKey.toString());
-                  hasDeletes = true;
-                  delete.deleteColumn(hcol.getFamily(), qual);
-                  break;
+  public void put(K key, T persistent) {
+    try{
+      Schema schema = persistent.getSchema();
+      StateManager stateManager = persistent.getStateManager();
+      byte[] keyRaw = toBytes(key);
+      Put put = new Put(keyRaw);
+      Delete delete = new Delete(keyRaw);
+      boolean hasPuts = false;
+      boolean hasDeletes = false;
+      Iterator<Field> iter = schema.getFields().iterator();
+      for (int i = 0; iter.hasNext(); i++) {
+        Field field = iter.next();
+        if (!stateManager.isDirty(persistent, i)) {
+          continue;
+        }
+        Type type = field.schema().getType();
+        Object o = persistent.get(i);
+        HBaseColumn hcol = mapping.getColumn(field.name());
+        switch(type) {
+          case MAP:
+            if(o instanceof StatefulMap) {
+              StatefulHashMap<Utf8, ?> map = (StatefulHashMap<Utf8, ?>) o;
+              for (Entry<Utf8, State> e : map.states().entrySet()) {
+                Utf8 mapKey = e.getKey();
+                switch (e.getValue()) {
+                  case DIRTY:
+                    byte[] qual = Bytes.toBytes(mapKey.toString());
+                    byte[] val = toBytes(map.get(mapKey), field.schema().getValueType());
+                    put.add(hcol.getFamily(), qual, val);
+                    hasPuts = true;
+                    break;
+                  case DELETED:
+                    qual = Bytes.toBytes(mapKey.toString());
+                    hasDeletes = true;
+                    delete.deleteColumn(hcol.getFamily(), qual);
+                    break;
+                }
+              }
+            } else {
+              Set<Map.Entry> set = ((Map)o).entrySet();
+              for(Entry entry: set) {
+                byte[] qual = toBytes(entry.getKey());
+                byte[] val = toBytes(entry.getValue());
+                put.add(hcol.getFamily(), qual, val);
+                hasPuts = true;
               }
             }
-          } else {
-            Set<Map.Entry> set = ((Map)o).entrySet();
-            for(Entry entry: set) {
-              byte[] qual = toBytes(entry.getKey());
-              byte[] val = toBytes(entry.getValue());
-              put.add(hcol.getFamily(), qual, val);
-              hasPuts = true;
-            }
-          }
-          break;
-        case ARRAY:
-          if(o instanceof GenericArray) {
-            GenericArray arr = (GenericArray) o;
-            int j=0;
-            for(Object item : arr) {
-              byte[] val = toBytes(item);
-              put.add(hcol.getFamily(), Bytes.toBytes(j++), val);
-              hasPuts = true;
+            break;
+          case ARRAY:
+            if(o instanceof GenericArray) {
+              GenericArray arr = (GenericArray) o;
+              int j=0;
+              for(Object item : arr) {
+                byte[] val = toBytes(item);
+                put.add(hcol.getFamily(), Bytes.toBytes(j++), val);
+                hasPuts = true;
+              }
             }
-          }
-          break;
-        default:
-          put.add(hcol.getFamily(), hcol.getQualifier(), toBytes(o, field.schema()));
-          hasPuts = true;
-          break;
+            break;
+          default:
+            put.add(hcol.getFamily(), hcol.getQualifier(), toBytes(o, field.schema()));
+            hasPuts = true;
+            break;
+        }
       }
-    }
-    if (hasPuts) {
-      table.put(put);
-    }
-    if (hasDeletes) {
-      table.delete(delete);
+      if (hasPuts) {
+        table.put(put);
+      }
+      if (hasDeletes) {
+        table.delete(delete);
+      }
+    } catch(IOException ex2){
+      LOG.error(ex2.getMessage());
+      LOG.error(ex2.getStackTrace().toString());
     }
   }
 
@@ -254,42 +288,55 @@ implements Configurable {
    * @return always true
    */
   @Override
-  public boolean delete(K key) throws IOException {
-    table.delete(new Delete(toBytes(key)));
-    //HBase does not return success information and executing a get for
-    //success is a bit costly
-    return true;
+  public boolean delete(K key) {
+    try{
+      table.delete(new Delete(toBytes(key)));
+      //HBase does not return success information and executing a get for
+      //success is a bit costly
+      return true;
+    } catch(IOException ex2){
+      LOG.error(ex2.getMessage());
+      LOG.error(ex2.getStackTrace().toString());
+      return false;
+    }
   }
 
   @Override
-  public long deleteByQuery(Query<K, T> query) throws IOException {
-
-    String[] fields = getFieldsToQuery(query.getFields());
-    //find whether all fields are queried, which means that complete
-    //rows will be deleted
-    boolean isAllFields = Arrays.equals(fields
-        , getBeanFactory().getCachedPersistent().getFields());
-
-    org.apache.gora.query.Result<K, T> result = query.execute();
-
-    ArrayList<Delete> deletes = new ArrayList<Delete>();
-    while(result.next()) {
-      Delete delete = new Delete(toBytes(result.getKey()));
-      deletes.add(delete);
-      if(!isAllFields) {
-        addFields(delete, query);
+  public long deleteByQuery(Query<K, T> query) {
+    try {
+      String[] fields = getFieldsToQuery(query.getFields());
+      //find whether all fields are queried, which means that complete
+      //rows will be deleted
+      boolean isAllFields = Arrays.equals(fields
+          , getBeanFactory().getCachedPersistent().getFields());
+  
+      org.apache.gora.query.Result<K, T> result = null;
+      result = query.execute();
+      ArrayList<Delete> deletes = new ArrayList<Delete>();
+      while(result.next()) {
+        Delete delete = new Delete(toBytes(result.getKey()));
+        deletes.add(delete);
+        if(!isAllFields) {
+          addFields(delete, query);
+        }
       }
+      table.delete(deletes);
+      return deletes.size();
+    } catch (Exception e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+      return -1;
     }
-    //TODO: delete by timestamp, etc
-
-    table.delete(deletes);
-
-    return deletes.size();
   }
 
   @Override
-  public void flush() throws IOException {
-    table.flushCommits();
+  public void flush() {
+    try{
+      table.flushCommits();
+    }catch(IOException ex){
+      LOG.error(ex.getMessage());
+      LOG.error(ex.getStackTrace().toString());
+    }
   }
 
   @Override
@@ -348,26 +395,30 @@ implements Configurable {
   }
 
   @Override
-  public org.apache.gora.query.Result<K, T> execute(Query<K, T> query)
-      throws IOException {
-
-    //check if query.fields is null
-    query.setFields(getFieldsToQuery(query.getFields()));
-
-    if(query.getStartKey() != null && query.getStartKey().equals(
-        query.getEndKey())) {
-      Get get = new Get(toBytes(query.getStartKey()));
-      addFields(get, query.getFields());
-      addTimeRange(get, query);
-      Result result = table.get(get);
-      return new HBaseGetResult<K,T>(this, query, result);
-    } else {
-      ResultScanner scanner = createScanner(query);
-
-      org.apache.gora.query.Result<K,T> result
-      = new HBaseScannerResult<K,T>(this,query, scanner);
-
-      return result;
+  public org.apache.gora.query.Result<K, T> execute(Query<K, T> query){
+    try{
+      //check if query.fields is null
+      query.setFields(getFieldsToQuery(query.getFields()));
+  
+      if(query.getStartKey() != null && query.getStartKey().equals(
+          query.getEndKey())) {
+        Get get = new Get(toBytes(query.getStartKey()));
+        addFields(get, query.getFields());
+        addTimeRange(get, query);
+        Result result = table.get(get);
+        return new HBaseGetResult<K,T>(this, query, result);
+      } else {
+        ResultScanner scanner = createScanner(query);
+  
+        org.apache.gora.query.Result<K,T> result
+        = new HBaseScannerResult<K,T>(this,query, scanner);
+  
+        return result;
+      }
+    }catch(IOException ex){
+      LOG.error(ex.getMessage());
+      LOG.error(ex.getStackTrace().toString());
+      return null;
     }
   }
 
@@ -593,8 +644,13 @@ implements Configurable {
   }
 
   @Override
-  public void close() throws IOException {
-    table.close();
+  public void close() {
+    try{
+      table.close();
+    }catch(IOException ex){
+      LOG.error(ex.getMessage());
+      LOG.error(ex.getStackTrace().toString());
+    }
   }
 
   @Override

Modified: gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlQuery.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlQuery.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlQuery.java (original)
+++ gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlQuery.java Sat Nov  3 21:09:11 2012
@@ -18,14 +18,14 @@
 
 package org.apache.gora.sql.query;
 
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.impl.QueryBase;
 import org.apache.gora.sql.store.SqlStore;
 
 /**
  * Query implementation covering SQL queries
  */
-public class SqlQuery<K, T extends Persistent> extends QueryBase<K, T> {
+public class SqlQuery<K, T extends PersistentBase> extends QueryBase<K, T> {
 
   public SqlQuery() {
     super(null);

Modified: gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlResult.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlResult.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlResult.java (original)
+++ gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/query/SqlResult.java Sat Nov  3 21:09:11 2012
@@ -22,14 +22,14 @@ import java.io.IOException;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.Query;
 import org.apache.gora.query.impl.ResultBase;
 import org.apache.gora.sql.store.SqlStore;
 import org.apache.gora.sql.util.SqlUtils;
 import org.apache.gora.store.DataStore;
 
-public class SqlResult<K, T extends Persistent> extends ResultBase<K, T> {
+public class SqlResult<K, T extends PersistentBase> extends ResultBase<K, T> {
 
   private ResultSet resultSet;
   private PreparedStatement statement;

Modified: gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/HSqlInsertUpdateStatement.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/HSqlInsertUpdateStatement.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/HSqlInsertUpdateStatement.java (original)
+++ gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/HSqlInsertUpdateStatement.java Sat Nov  3 21:09:11 2012
@@ -23,12 +23,12 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.util.Map.Entry;
 
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.sql.store.Column;
 import org.apache.gora.sql.store.SqlMapping;
 import org.apache.gora.sql.store.SqlStore;
 
-public class HSqlInsertUpdateStatement<K, T extends Persistent>
+public class HSqlInsertUpdateStatement<K, T extends PersistentBase>
 extends InsertUpdateStatement<K, T> {
 
   public HSqlInsertUpdateStatement(SqlStore<K, T> store, SqlMapping mapping,

Modified: gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatement.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatement.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatement.java (original)
+++ gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatement.java Sat Nov  3 21:09:11 2012
@@ -24,12 +24,12 @@ import java.util.SortedMap;
 import java.util.TreeMap;
 
 import org.apache.avro.Schema;
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.sql.store.Column;
 import org.apache.gora.sql.store.SqlMapping;
 import org.apache.gora.sql.store.SqlStore;
 
-public abstract class InsertUpdateStatement<K, V extends Persistent> {
+public abstract class InsertUpdateStatement<K, V extends PersistentBase> {
 
   protected class ColumnData {
     protected Object object;

Modified: gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatementFactory.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatementFactory.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatementFactory.java (original)
+++ gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/InsertUpdateStatementFactory.java Sat Nov  3 21:09:11 2012
@@ -17,14 +17,14 @@
  */
 package org.apache.gora.sql.statement;
 
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.sql.store.SqlMapping;
 import org.apache.gora.sql.store.SqlStore;
 import org.apache.gora.sql.store.SqlStore.DBVendor;
 
 public class InsertUpdateStatementFactory {
 
-  public static <K, T extends Persistent>
+  public static <K, T extends PersistentBase>
   InsertUpdateStatement<K, T> createStatement(SqlStore<K, T> store,
       SqlMapping mapping, DBVendor dbVendor) {
     switch(dbVendor) {

Modified: gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/MySqlInsertUpdateStatement.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/MySqlInsertUpdateStatement.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/MySqlInsertUpdateStatement.java (original)
+++ gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/statement/MySqlInsertUpdateStatement.java Sat Nov  3 21:09:11 2012
@@ -24,13 +24,13 @@ import java.sql.SQLException;
 import java.util.Map.Entry;
 
 import org.apache.avro.Schema;
-import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.sql.store.Column;
 import org.apache.gora.sql.store.SqlMapping;
 import org.apache.gora.sql.store.SqlStore;
 import org.apache.gora.util.StringUtils;
 
-public class MySqlInsertUpdateStatement<K, V extends Persistent> extends InsertUpdateStatement<K, V> {
+public class MySqlInsertUpdateStatement<K, V extends PersistentBase> extends InsertUpdateStatement<K, V> {
 
   public MySqlInsertUpdateStatement(SqlStore<K, V> store, SqlMapping mapping, String tableName) {
     super(store, mapping, tableName);

Modified: gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/store/SqlStore.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/store/SqlStore.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/store/SqlStore.java (original)
+++ gora/trunk/gora-sql/src/main/java/org/apache/gora/sql/store/SqlStore.java Sat Nov  3 21:09:11 2012
@@ -47,8 +47,8 @@ import org.apache.avro.specific.Specific
 import org.apache.avro.util.Utf8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.gora.persistency.Persistent;
 import org.apache.gora.persistency.StateManager;
+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;
@@ -94,7 +94,7 @@ import org.jdom.input.SAXBuilder;
  * re-write as per GORA-86
  * Please see https://issues.apache.org/jira/browse/GORA-86
  */
-public class SqlStore<K, T extends Persistent> extends DataStoreBase<K, T> {
+public class SqlStore<K, T extends PersistentBase> extends DataStoreBase<K, T> {
 
   /** The vendor of the DB */
   public static enum DBVendor {
@@ -164,7 +164,7 @@ public class SqlStore<K, T extends Persi
   }
 
   @Override
-  public void close() throws IOException {
+  public void close() {
   //TODO
   }
 
@@ -175,8 +175,7 @@ public class SqlStore<K, T extends Persi
   
   
   @Override
-  public void createSchema() throws IOException {
-  //TODO
+  public void createSchema() {
   }
 
   private void getColumnConstraint() throws IOException {
@@ -184,40 +183,40 @@ public class SqlStore<K, T extends Persi
   }
 
   @Override
-  public void deleteSchema() throws IOException {
+  public void deleteSchema() {
   //TODO
   }
 
   @Override
-  public boolean schemaExists() throws IOException {
+  public boolean schemaExists() {
   //TODO
   return false;
   }
 
   @Override
-  public boolean delete(K key) throws IOException {
+  public boolean delete(K key) {
   //TODO
   return false;
   }
   
   @Override
-  public long deleteByQuery(Query<K, T> query) throws IOException {
+  public long deleteByQuery(Query<K, T> query) {
   //TODO
   return 0;
   }
 
-  public void flush() throws IOException {
+  public void flush() {
   //TODO
   }
 
   @Override
-  public T get(K key, String[] requestFields) throws IOException {
+  public T get(K key, String[] requestFields) {
   //TODO
   return null;
   }
 
   @Override
-  public Result<K, T> execute(Query<K, T> query) throws IOException {
+  public Result<K, T> execute(Query<K, T> query) {
   //TODO
   return null;
   }
@@ -262,7 +261,7 @@ public class SqlStore<K, T extends Persi
   }
 
   @Override
-  public void put(K key, T persistent) throws IOException {
+  public void put(K key, T persistent) {
   //TODO
   }
 

Modified: gora/trunk/gora-sql/src/test/java/org/apache/gora/sql/store/TestSqlStore.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-sql/src/test/java/org/apache/gora/sql/store/TestSqlStore.java?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-sql/src/test/java/org/apache/gora/sql/store/TestSqlStore.java (original)
+++ gora/trunk/gora-sql/src/test/java/org/apache/gora/sql/store/TestSqlStore.java Sat Nov  3 21:09:11 2012
@@ -40,6 +40,7 @@ public class TestSqlStore extends DataSt
   public TestSqlStore() {
   }
 
+  @SuppressWarnings("deprecation")
   @Override
   protected DataStore<String, Employee> createEmployeeDataStore() throws IOException {
     SqlStore<String, Employee> store = new SqlStore<String, Employee>();
@@ -47,6 +48,7 @@ public class TestSqlStore extends DataSt
     return store;
   }
 
+  @SuppressWarnings("deprecation")
   @Override
   protected DataStore<String, WebPage> createWebPageDataStore() throws IOException {
     SqlStore<String, WebPage> store = new SqlStore<String, WebPage>();

Modified: gora/trunk/gora-tutorial/conf/gora.properties
URL: http://svn.apache.org/viewvc/gora/trunk/gora-tutorial/conf/gora.properties?rev=1405417&r1=1405416&r2=1405417&view=diff
==============================================================================
--- gora/trunk/gora-tutorial/conf/gora.properties (original)
+++ gora/trunk/gora-tutorial/conf/gora.properties Sat Nov  3 21:09:11 2012
@@ -18,8 +18,6 @@
 ##if it is not passed to the DataStoreFactory#createDataStore() method.
 gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
 #gora.datastore.default=org.apache.gora.cassandra.store.CassandraStore
-#gora.avrostore.output.path=hdfs://localhost:9000/path/to/dfs/data/gora.avrostore.logmanager.output
-#gora.avrostore.output.path=file:///tmp/gora.avrostore.logmanager.output
 
 ##whether to create schema automatically if not exists.
 gora.datastore.autocreateschema=true



Mime
View raw message