Program: 176239
Project: 176239
Buggy source:
/** 
 * Execute batch.
 * @return the int
 */
public int executeBatch(){
  Cassandra.Client conn=null;
  Object pooledConnection=null;
  Map<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>> batchMutationMap=new HashMap<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>>();
  int recordsExecuted=0;
  String batchQuery=CQLTranslator.BATCH_QUERY;
  batchQuery=StringUtils.replace(batchQuery,CQLTranslator.STATEMENT,"String_Node_Str");
  StringBuilder batchQueryBuilder=new StringBuilder(batchQuery);
  try {
    boolean isCql3Enabled=false;
    for (    Node node : nodes) {
      if (node.isDirty()) {
        node.handlePreEvent();
        Object entity=node.getData();
        Object id=node.getEntityId();
        EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(node.getDataClass());
        persistenceUnit=metadata.getPersistenceUnit();
        isUpdate=node.isUpdate();
        MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
        if (isCql3Enabled(metadata)) {
          isCql3Enabled=true;
          List<RelationHolder> relationHolders=getRelationHolders(node);
          String query;
          if (node.isInState(RemovedState.class)) {
            query=onDeleteQuery(metadata,metaModel,id);
          }
 else {
            query=createInsertQuery(metadata,entity,conn,relationHolders,getTtlValues().get(metadata.getTableName()));
          }
          batchQueryBuilder.append(query);
        }
 else {
          if (node.isInState(RemovedState.class)) {
            delete(entity,id);
          }
 else {
            List<RelationHolder> relationHolders=getRelationHolders(node);
            Map<ByteBuffer,Map<String,List<Mutation>>> mutationMap=new HashMap<ByteBuffer,Map<String,List<Mutation>>>();
            mutationMap=prepareMutation(metadata,entity,id,relationHolders,mutationMap);
            recordsExecuted+=mutationMap.size();
            if (!batchMutationMap.containsKey(metadata.getEntityClazz())) {
              batchMutationMap.put(metadata.getEntityClazz(),mutationMap);
            }
 else {
              batchMutationMap.get(metadata.getEntityClazz()).putAll(mutationMap);
            }
            indexNode(node,metadata);
          }
        }
        node.handlePostEvent();
      }
    }
    if (!batchMutationMap.isEmpty()) {
      pooledConnection=getConection();
      conn=getConnection(pooledConnection);
      for (      Class<?> entityClass : batchMutationMap.keySet()) {
        conn.batch_mutate(batchMutationMap.get(entityClass),consistencyLevel);
        batchMutationMap=null;
      }
    }
    if (!nodes.isEmpty() && isCql3Enabled) {
      batchQueryBuilder.append(CQLTranslator.APPLY_BATCH);
      executeCQLQuery(batchQueryBuilder.toString(),isCql3Enabled);
      batchQueryBuilder=null;
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
    throw new KunderaException(e);
  }
 finally {
    clear();
    if (pooledConnection != null) {
      releaseConnection(pooledConnection);
    }
  }
  return recordsExecuted;
}

Fixed version (ground truth):
/** 
 * Execute batch.
 * @return the int
 */
public int executeBatch(){
  Cassandra.Client conn=null;
  Object pooledConnection=null;
  Map<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>> batchMutationMap=new HashMap<Class<?>,Map<ByteBuffer,Map<String,List<Mutation>>>>();
  int recordsExecuted=0;
  String batchQuery=CQLTranslator.BATCH_QUERY;
  batchQuery=StringUtils.replace(batchQuery,CQLTranslator.STATEMENT,"String_Node_Str");
  StringBuilder batchQueryBuilder=new StringBuilder(batchQuery);
  try {
    boolean isCql3Enabled=false;
    for (    Node node : nodes) {
      if (node.isDirty()) {
        node.handlePreEvent();
        Object entity=node.getData();
        Object id=node.getEntityId();
        EntityMetadata metadata=KunderaMetadataManager.getEntityMetadata(node.getDataClass());
        persistenceUnit=metadata.getPersistenceUnit();
        isUpdate=node.isUpdate();
        MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
        if (isCql3Enabled(metadata)) {
          isCql3Enabled=true;
          List<RelationHolder> relationHolders=getRelationHolders(node);
          String query;
          if (node.isInState(RemovedState.class)) {
            query=onDeleteQuery(metadata,metaModel,id);
          }
 else {
            query=createInsertQuery(metadata,entity,conn,relationHolders,getTtlValues().get(metadata.getTableName()));
          }
          batchQueryBuilder.append(query);
        }
 else {
          if (node.isInState(RemovedState.class)) {
            delete(entity,id);
          }
 else {
            List<RelationHolder> relationHolders=getRelationHolders(node);
            Map<ByteBuffer,Map<String,List<Mutation>>> mutationMap=new HashMap<ByteBuffer,Map<String,List<Mutation>>>();
            mutationMap=prepareMutation(metadata,entity,id,relationHolders,mutationMap);
            recordsExecuted+=mutationMap.size();
            if (!batchMutationMap.containsKey(metadata.getEntityClazz())) {
              batchMutationMap.put(metadata.getEntityClazz(),mutationMap);
            }
 else {
              batchMutationMap.get(metadata.getEntityClazz()).putAll(mutationMap);
            }
            indexNode(node,metadata);
          }
        }
        node.handlePostEvent();
      }
    }
    if (!batchMutationMap.isEmpty()) {
      pooledConnection=getConection();
      conn=getConnection(pooledConnection);
      for (      Class<?> entityClass : batchMutationMap.keySet()) {
        conn.batch_mutate(batchMutationMap.get(entityClass),consistencyLevel);
      }
    }
    if (!nodes.isEmpty() && isCql3Enabled) {
      batchQueryBuilder.append(CQLTranslator.APPLY_BATCH);
      executeCQLQuery(batchQueryBuilder.toString(),isCql3Enabled);
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
    throw new KunderaException(e);
  }
 finally {
    clear();
    if (pooledConnection != null) {
      releaseConnection(pooledConnection);
    }
  }
  return recordsExecuted;
}