gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hsapu...@apache.org
Subject svn commit: r1412995 - in /gora/trunk: gora-core/src/main/java/org/apache/gora/store/impl/DataStoreBase.java gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java
Date Fri, 23 Nov 2012 17:34:33 GMT
Author: hsaputra
Date: Fri Nov 23 17:34:32 2012
New Revision: 1412995

URL: http://svn.apache.org/viewvc?rev=1412995&view=rev
Log:
GORA-186 Show better errors when a field is missing in HBase mapping (Alfonso Nishikawa via
hsaputra)

Modified:
    gora/trunk/gora-core/src/main/java/org/apache/gora/store/impl/DataStoreBase.java
    gora/trunk/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java

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=1412995&r1=1412994&r2=1412995&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 Fri Nov
23 17:34:32 2012
@@ -82,18 +82,19 @@ public abstract class DataStoreBase<K, T
   @Override
   public void initialize(Class<K> keyClass, Class<T> persistentClass,
       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);
+    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

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=1412995&r1=1412994&r2=1412995&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 Fri Nov
23 17:34:32 2012
@@ -220,6 +220,10 @@ implements Configurable {
         Type type = field.schema().getType();
         Object o = persistent.get(i);
         HBaseColumn hcol = mapping.getColumn(field.name());
+        if (hcol == null) {
+          throw new RuntimeException("HBase mapping for field ["+ persistent.getClass().getName()
+
+              "#"+ field.name()+"] not found. Wrong gora-hbase-mapping.xml?");
+        }
         switch(type) {
           case MAP:
             if(o instanceof StatefulMap) {
@@ -322,9 +326,9 @@ implements Configurable {
       }
       table.delete(deletes);
       return deletes.size();
-    } catch (Exception e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
+    } catch (Exception ex) {
+      LOG.error(ex.getMessage());
+      LOG.error(ex.getStackTrace().toString());
       return -1;
     }
   }
@@ -438,8 +442,11 @@ implements Configurable {
   private void addFields(Get get, String[] fieldNames) {
     for (String f : fieldNames) {
       HBaseColumn col = mapping.getColumn(f);
+      if (col == null) {
+        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
+            "Wrong gora-hbase-mapping.xml?");
+      }
       Schema fieldSchema = fieldMap.get(f).schema();
-
       switch (fieldSchema.getType()) {
         case MAP:
         case ARRAY:
@@ -455,6 +462,10 @@ implements Configurable {
     String[] fields = query.getFields();
     for (String f : fields) {
       HBaseColumn col = mapping.getColumn(f);
+      if (col == null) {
+        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
+            "Wrong gora-hbase-mapping.xml?");
+      }
       Schema fieldSchema = fieldMap.get(f).schema();
       switch (fieldSchema.getType()) {
         case MAP:
@@ -472,6 +483,10 @@ implements Configurable {
     String[] fields = query.getFields();
     for (String f : fields) {
       HBaseColumn col = mapping.getColumn(f);
+      if (col == null) {
+        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
+            "Wrong gora-hbase-mapping.xml?");
+      }
       Schema fieldSchema = fieldMap.get(f).schema();
       switch (fieldSchema.getType()) {
         case MAP:
@@ -505,6 +520,10 @@ implements Configurable {
     StateManager stateManager = persistent.getStateManager();
     for (String f : fields) {
       HBaseColumn col = mapping.getColumn(f);
+      if (col == null) {
+        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
+            "Wrong gora-hbase-mapping.xml?");
+      }
       Field field = fieldMap.get(f);
       Schema fieldSchema = field.schema();
       switch(fieldSchema.getType()) {
@@ -634,8 +653,12 @@ implements Configurable {
         }
       }
     } catch(IOException ex) {
+      LOG.error(ex.getMessage());
+      LOG.error(ex.getStackTrace().toString());
       throw ex;
     } catch(Exception ex) {
+      LOG.error(ex.getMessage());
+      LOG.error(ex.getStackTrace().toString());
       throw new IOException(ex);
     }
 



Mime
View raw message