apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhupeshchawda <...@git.apache.org>
Subject [GitHub] apex-malhar pull request #295: APEXMALHAR-1966: Update cassandra output opre...
Date Thu, 09 Jun 2016 22:25:25 GMT
Github user bhupeshchawda commented on a diff in the pull request:

    https://github.com/apache/apex-malhar/pull/295#discussion_r66532961
  
    --- Diff: contrib/src/main/java/com/datatorrent/contrib/cassandra/CassandraPOJOOutputOperator.java
---
    @@ -162,35 +160,75 @@ public void activate(Context.OperatorContext context)
           }
           getters.add(getter);
         }
    +    super.activate(context);
    +  }
    +
    +  private void populateFieldInfosFromPojo(ColumnDefinitions rsMetaData)
    +  {
    +    fieldInfos = Lists.newArrayList();
    +    Field[] fields = pojoClass.getDeclaredFields();
    +    for (int i = 0; i < rsMetaData.size(); i++) {
    +      String columnName = rsMetaData.getName(i);
    +      String pojoField = getMatchingField(fields, columnName);
    +      if (pojoField != null && pojoField.length() != 0) {
    +        fieldInfos.add(new FieldInfo(columnName, pojoField, null));
    +      } else {
    +        LOG.error("Couldn't find corrosponding pojo field for column: " + columnName);
    +      }
    +    }
    +  }
    +
    +  private String getMatchingField(Field[] fields, String columnName)
    +  {
    +    for (Field f : fields) {
    +      if (f.getName().equalsIgnoreCase(columnName)) {
    +        return f.getName();
    +      }
    +    }
    +    return null;
       }
     
       @Override
       public void deactivate()
       {
       }
     
    +  /**
    +   * {@inheritDoc} <br/>
    +   * If statement/query is not specified by user, insert query is constructed from fileInfo
object and table name.
    +   */
       @Override
       protected PreparedStatement getUpdateCommand()
       {
    +    PreparedStatement statement;
    +    if (query == null) {
    +      statement = prepareStatementFromFieldsAndTableName();
    +    } else {
    +      statement = store.getSession().prepare(query);
    +    }
    +    LOG.debug("Statement is: " + statement.getQueryString());
    +    return statement;
    +  }
    +
    +  private PreparedStatement prepareStatementFromFieldsAndTableName()
    +  {
    +    if (tablename == null || tablename.length() == 0) {
    +      throw new RuntimeException("Please sepcify query or table name.");
    +    }
         StringBuilder queryfields = new StringBuilder();
         StringBuilder values = new StringBuilder();
    -    for (FieldInfo fieldInfo: fieldInfos) {
    +    for (FieldInfo fieldInfo : fieldInfos) {
    --- End diff --
    
    Please remove checkstyle related changes from this PR


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message