text:
require 'rails_helper'

describe Api::V1::RollbacksController, 'POST to #create' do
  render_views

  before { login_as_api_user }

  let(:rollback_attributes) { attributes_for :rollback }
  let(:record)        {
    create :measure, operation_date: Date.yesterday.to_date
  }

  context 'when rollback is valid' do
    before { record }

    it 'responds with success + redirect' do
      post :create, rollback: rollback_attributes

      expect(response.status).to eq 201
      expect(response.location).to eq api_rollbacks_url
    end

    it 'performs a rollback' do
      Sidekiq::Testing.inline! do
        expect {
          create(:rollback, date: Date.today.ago(1.month).to_date)
        }.to change { Measure.count }.from(1).to(0)
      end
    end
  end

  context 'when rollback is not valid' do
    let(:response_pattern) {
      {
        errors: Hash
      }.ignore_extra_keys!
    }

    it 'returns errors for rollback' do
      post :create, rollback: { date: '', keep: '' }

      expect(response.status).to eq 422
      expect(response.body).to match_json_expression response_pattern
    end
  end
end

describe Api::V1::RollbacksController, 'GET to #index' do
  render_views

  before {
    login_as_api_user
  }

  let!(:rollback) { create :rollback }

  let(:response_pattern) {
    { rollbacks:
      [
        {
          id: rollback.id,
          user_id: rollback.user_id,
          reason: rollback.reason,
          enqueued_at: wildcard_matcher,
          date: rollback.date.to_s,
          keep: rollback.keep
        }.ignore_extra_keys!
      ].ignore_extra_values!
    }.ignore_extra_keys!
  }

  it 'returns scheduled rollbacks' do
    get :index, format: :json

    expect(response.status).to eq 200
    expect(response.body).to match_json_expression response_pattern
    expect(response.body).to match_json_expression pagination_pattern
  end

  context 'when records are not present' do
    before do
      rollback.delete
    end

    it 'returns empty rollbacks array' do
      get :index, format: :json

      expect(response.status).to eq 200
      expect(JSON.parse(response.body)['rollbacks']).to eq []
    end
  end
end


text:
package org.thingml.xtext.helpers;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.thingml.xtext.constraints.ThingMLHelpers;
import org.thingml.xtext.thingML.CompositeState;
import org.thingml.xtext.thingML.Property;
import org.thingml.xtext.thingML.Region;
import org.thingml.xtext.thingML.Session;
import org.thingml.xtext.thingML.State;
import org.thingml.xtext.thingML.StateContainer;
import org.thingml.xtext.thingML.Type;

/**
 * Created by ffl on 10.05.2016.
 */
public class StateContainerHelper {

    public static List<State> allContainedStates(StateContainer self) {
        return ThingMLHelpers.<State>allContainedElementsOfType(self, State.class);
    }

   public static List<StateContainer> allContainedRegions(StateContainer self) {
       final List<StateContainer> result = new ArrayList<StateContainer>();
       result.add(self);
       result.addAll(ThingMLHelpers.<StateContainer>allContainedElementsOfType(self, CompositeState.class));
       result.addAll(ThingMLHelpers.<StateContainer>allContainedElementsOfType(self, Region.class));
       return result;
    }

    public static List<StateContainer> allContainedRegionsAndSessions(StateContainer self) {
    	List<StateContainer> result = new ArrayList<StateContainer>();
        result.add(self);
        result.addAll(ThingMLHelpers.<StateContainer>allContainedElementsOfType(self, StateContainer.class));
        return result;
    }

    public static List<Session> allContainedSessions(StateContainer self) {
    	List<Session> result = new ArrayList<Session>();
        result.addAll(ThingMLHelpers.<Session>allContainedElementsOfType(self, Session.class));
        return result;
    }

    public static List<Property> allContainedProperties(StateContainer self) {
        final List<Property> result = new ArrayList<Property>();
        for(State s : allContainedStates(self)) {
            result.addAll(s.getProperties());
        }
        return result;
    }

    public static List<CompositeState> allContainedCompositeStates(StateContainer self) {
        final List<CompositeState> result = new ArrayList<CompositeState>();
        for(State s : allContainedStates(self)) {
            if (s instanceof CompositeState) {
                result.add((CompositeState)s);
            }
        }
        return result;
    }

    public static List<State> allContainedSimpleStates(StateContainer self) {
        final List<State> result = allContainedStates(self);
        result.removeAll(allContainedCompositeStates(self));
        return result;
    }

    public static Set<Type> allUsedTypes(StateContainer self) {
        Set<Type> result = new HashSet<Type>();
        for(Property p : allContainedProperties(self)) {
            result.add(p.getTypeRef().getType());
        }
        return result;
    }

}

redpajama_set_name: RedPajamaGithub


text:
// ZAP: 2012/01/12 Reflected the rename of the class ExtensionPopupMenu to
//      ExtensionPopupMenuItem, added the methods addMenu(ExtensionPopupMenu menu),
//      removeMenu(ExtensionPopupMenu menu), handleMenu and handleMenuItem and
//      changed the method show to use the methods handleMenu and handleMenuItem.
// ZAP: 2012/02/19 Removed the Delete button
// ZAP: 2012/03/03 Moved popups to stdmenus extension
// ZAP: 2012/04/23 Added @Override annotation to the appropriate method.
// ZAP: 2012/06/06 Issue 323: Added isDummyItem to support dynamic menus
// ZAP: 2012/08/01 Issue 332: added support for Modes
// ZAP: 2012/10/07 Added support for prepareShow() that is run on PopupMenu before showing it
// ZAP: 2012/10/08 Added check for PopupMenu safeness
// ZAP: 2013/04/14 Issue 592: Do not show the main pop up menu if it doesn't have visible pop up
// menu items
// ZAP: 2013/04/14 Issue 598: Replace/update "old" pop up menu items
// ZAP: 2013/11/16 Issue 878: ExtensionPopupMenuItem#getMenuIndex() as no effect in MainPopupMenu
// ZAP: 2013/11/16 Issue 901: Pop up menu "succeed" separator is not added when using sub-menu in
// MainPopupMenu
// ZAP: 2013/11/16 Issue 900: IllegalArgumentException when invoking the main pop up menu with
// menus or super menus with high menu index
// ZAP: 2014/03/23 Changed to use PopupMenuUtils.isAtLeastOneChildComponentVisible(Component).
// ZAP: 2014/03/23 Issue 609: Provide a common interface to query the state and
// access the data (HttpMessage and HistoryReference) displayed in the tabs
// ZAP: 2014/03/23 Issue 1079: Remove misplaced main pop up menu separators
// ZAP: 2014/03/23 Issue 1088: Deprecate the method ExtensionPopupMenu#prepareShow
// ZAP: 2014/08/14 Issue 1302: Context menu item action might not get executed
// ZAP: 2015/01/22 Use ExtensionPopupMenu for super menus
// ZAP: 2019/06/01 Normalise line endings.
// ZAP: 2019/06/05 Normalise format/style.
// ZAP: 2020/11/26 Use Log4j 2 classes for logging.
// ZAP: 2022/02/03 Removed deprecated prepareShow method
// ZAP: 2022/08/05 Address warns with Java 18 (Issue 7389).
package org.parosproxy.paros.view;

import java.awt.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.parosproxy.paros.control.Control;
import org.parosproxy.paros.control.Control.Mode;
import org.parosproxy.paros.extension.ExtensionHookMenu;
import org.parosproxy.paros.extension.ExtensionPopupMenuItem;
import org.zaproxy.zap.extension.ExtensionPopupMenu;
import org.zaproxy.zap.extension.history.PopupMenuPurgeSites;
import org.zaproxy.zap.view.messagecontainer.MessageContainer;
import org.zaproxy.zap.view.popup.ExtensionPopupMenuComponent;
import org.zaproxy.zap.view.popup.PopupMenuUtils;
import org.zaproxy.zap.view.popup.PopupMenuUtils.PopupMenuInvokerWrapper;

@SuppressWarnings("serial")
public class MainPopupMenu extends JPopupMenu {

    private static final long serialVersionUID = -3021348328961418293L;

    private List<JMenuItem> itemList = null;
    private PopupMenuPurgeSites popupMenuPurgeSites = null;
    // ZAP: Added support for submenus
    Map<String, JMenu> superMenus = new HashMap<>();
    View view = null;
    private static final Logger log = LogManager.getLogger(MainPopupMenu.class);

    /**
     * The change listener responsible for updating the {@code pathSelectedMenu} when the path to
     * the currently selected menu item changes.
     *
     * @see #pathSelectedMenu
     * @see MenuSelectionListenerInstaller
     */
    private MenuSelectionChangeListener menuSelectionChangeListener;

    /**
     * The path to the currently selected menu item, {@code null} when there are no selected menus
     * or the pop up menu was cancelled.
     *
     *
Used in the method {@code setVisible(boolean)} to inform the {@code
     * ExtensionPopupMenuComponent}s of which menu is selected when the pop up menu is hidden.
     *
     * @see #menuSelectionChangeListener
     * @see #setVisible(boolean)
     */
    private MenuElement[] pathSelectedMenu;

    public MainPopupMenu(View view) {
        super();
        initialize();
        this.view = view;
    }

    /** @param arg0 */
    public MainPopupMenu(String arg0, View view) {
        super(arg0);
        this.view = view;
    }

    public MainPopupMenu(List<JMenuItem> itemList, View view) {
        this(view);
        this.itemList = itemList;
    }

    /** This method initializes this */
    private void initialize() {
        // this.setVisible(true);

        // added pre-set popup menu here
        //        this.add(getPopupFindMenu());
        // this.add(getPopupDeleteMenu());
        this.add(getPopupMenuPurgeSites());

        this.menuSelectionChangeListener = new MenuSelectionChangeListener();
        addPopupMenuListener(new MenuSelectionListenerInstaller());
    }

    public void show(final MessageContainer<?> invoker, final int x, final int y) {
        showImpl(PopupMenuUtils.getPopupMenuInvokerWrapper(invoker), x, y);
    }

    @Override
    public synchronized void show(Component invoker, int x, int y) {
        showImpl(PopupMenuUtils.getPopupMenuInvokerWrapper(invoker), x, y);
    }

    private synchronized void showImpl(PopupMenuInvokerWrapper invoker, final int x, final int y) {

        for (int i = 0; i < getComponentCount(); i++) {
            final Component component = getComponent(i);
            try {
                if (component != null && component instanceof ExtensionPopupMenuItem) {
                    ExtensionPopupMenuItem menuItem = (ExtensionPopupMenuItem) component;
                    // ZAP: prevents a NullPointerException when the treeSite doesn't have a node
                    // selected and a popup menu option (Delete/Purge) is selected
                    menuItem.setVisible(invoker.isEnable(menuItem));

                    if (Control.getSingleton().getMode().equals(Mode.safe) && !menuItem.isSafe()) {
                        // Safe mode, disable all nor safe menu items
                        menuItem.setEnabled(false);
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }

        for (int i = 0; i < itemList.size(); i++) {
            final JMenuItem menuItem = itemList.get(i);
            if (menuItem instanceof ExtensionPopupMenuItem) {
                handleMenuItem(invoker, (ExtensionPopupMenuItem) menuItem);
            } else if (menuItem instanceof ExtensionPopupMenu) {
                ExtensionPopupMenu item = (ExtensionPopupMenu) menuItem;
                handleMenu(invoker, item);
            }
        }
        PopupMenuUtils.removeTopAndBottomSeparators(this);

        if (PopupMenuUtils.isAtLeastOneChildComponentVisible(this)) {
            super.show(invoker.getComponent(), x, y);
        }
    }

    /**
     * {@inheritDoc}
     *
     *
Overridden to call the method {@code
     * ExtensionPopupMenuComponent#dismissed(ExtensionPopupMenuComponent)} of child {@code
     * ExtensionPopupMenuComponent}s when the pop up menu is hidden.
     *
     * @see ExtensionPopupMenuComponent#dismissed(ExtensionPopupMenuComponent)
     */
    @Override
    public void setVisible(boolean b) {
        super.setVisible(b);
        if (!b) {
            ExtensionPopupMenuComponent selectedMenuComponent = null;
            if (pathSelectedMenu != null) {
                MenuElement selectedMenuElement = pathSelectedMenu[pathSelectedMenu.length - 1];
                if (PopupMenuUtils.isExtensionPopupMenuComponent(selectedMenuElement)) {
                    selectedMenuComponent = (ExtensionPopupMenuComponent) selectedMenuElement;
                }
                pathSelectedMenu = null;
            }

            for (int i = 0; i < getComponentCount(); i++) {
                Component component = getComponent(i);
                if (PopupMenuUtils.isExtensionPopupMenuComponent(component)) {
                    ((ExtensionPopupMenuComponent) component).dismissed(selectedMenuComponent);
                }
            }
        }
    }

    private void handleMenuItem(
            PopupMenuInvokerWrapper popupMenuInvoker, ExtensionPopupMenuItem menuItem) {
        try {
            if (menuItem == ExtensionHookMenu.POPUP_MENU_SEPARATOR) {
                PopupMenuUtils.addSeparatorIfNeeded(this);
            } else {
                if (popupMenuInvoker.isEnable(menuItem)) {
                    if (menuItem.isSubMenu()) {
                        final JMenu superMenu =
                                getSuperMenu(
                                        menuItem.getParentMenuName(),
                                        menuItem.getParentMenuIndex());
                        if (menuItem.precedeWithSeparator()) {
                            PopupMenuUtils.addSeparatorIfNeeded(superMenu.getPopupMenu());
                        }
                        if (menuItem.isDummyItem()) {
                            // This assumes the dummy item is the first of the children - non dummy
                            // children will enable this
                            superMenu.setEnabled(false);
                        } else {
                            superMenu.add(menuItem);
                            superMenu.setEnabled(true);
                        }
                        if (menuItem.succeedWithSeparator()) {
                            superMenu.addSeparator();
                        }

                    } else {
                        if (menuItem.precedeWithSeparator()) {
                            PopupMenuUtils.addSeparatorIfNeeded(this);
                        }
                        addMenuItem(menuItem, menuItem.getMenuIndex());
                        if (menuItem.succeedWithSeparator()) {
                            this.addSeparator();
                        }
                    }
                }
            }
            if (Control.getSingleton().getMode().equals(Mode.safe) && !menuItem.isSafe()) {
                // Safe mode, disable all nor safe menu items
                menuItem.setEnabled(false);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    private void handleMenu(PopupMenuInvokerWrapper popupMenuInvoker, ExtensionPopupMenu menu) {
        try {
            if (popupMenuInvoker.isEnable(menu)) {
                if (menu.isSubMenu()) {
                    final JMenu superMenu =
                            getSuperMenu(menu.getParentMenuName(), menu.getParentMenuIndex());
                    if (menu.precedeWithSeparator()) {
                        PopupMenuUtils.addSeparatorIfNeeded(superMenu.getPopupMenu());
                    }
                    superMenu.add(menu);
                    if (menu.succeedWithSeparator()) {
                        superMenu.addSeparator();
                    }

                } else {
                    if (menu.precedeWithSeparator()) {
                        PopupMenuUtils.addSeparatorIfNeeded(this);
                    }

                    addMenuItem(menu, menu.getMenuIndex());
                    if (menu.succeedWithSeparator()) {
                        this.addSeparator();
                    }
                }
                if (Control.getSingleton().getMode().equals(Mode.safe) && !menu.isSafe()) {
                    // Safe mode, disable all nor safe menus
                    menu.setEnabled(false);
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    // ZAP: Added support for submenus
    private JMenu getSuperMenu(String name, int index) {
        JMenu superMenu = superMenus.get(name);
        if (superMenu == null) {
            // Use an ExtensionPopupMenu so child menus are dismissed
            superMenu =
                    new ExtensionPopupMenu(name) {

                        private static final long serialVersionUID = 6825880451078204378L;

                        @Override
                        public boolean isEnableForComponent(Component invoker) {
                            return true;
                        }
                    };
            superMenus.put(name, superMenu);
            addMenuItem(superMenu, index);
        }
        return superMenu;
    }

    private void addMenuItem(JMenuItem menuItem, int index) {
        int correctIndex;
        if ((index < 0 && index != -1) || (index > getComponentCount())) {
            correctIndex = -1;
        } else {
            correctIndex = index;
        }
        add(menuItem, correctIndex);
    }

    private PopupMenuPurgeSites getPopupMenuPurgeSites() {
        if (popupMenuPurgeSites == null) {
            popupMenuPurgeSites = new PopupMenuPurgeSites();
        }
        return popupMenuPurgeSites;
    }

    // ZAP: added addMenu and removeMenu to support dynamic changing of menus

    public void addMenu(ExtensionPopupMenuItem menu) {
        itemList.add(menu);
    }

    public void removeMenu(ExtensionPopupMenuItem menu) {
        itemList.remove(menu);
    }

    public void addMenu(ExtensionPopupMenu menu) {
        itemList.add(menu);
    }

    public void removeMenu(ExtensionPopupMenu menu) {
        itemList.remove(menu);
    }

    /**
     * A {@code ChangeListener} responsible for updating the {@code pathSelectedMenu} when the path
     * to the currently selected menu item changes.
     *
     * @see #pathSelectedMenu
     * @see MenuSelectionManager#getSelectedPath()
     * @see MenuSelectionListenerInstaller
     */
    private class MenuSelectionChangeListener implements ChangeListener {

        @Override
        public void stateChanged(ChangeEvent e) {
            pathSelectedMenu = MenuSelectionManager.defaultManager().getSelectedPath();
        }
    }

    /**
     * A {@code PopupMenuListener} responsible for adding and removing the {@code
     * menuSelectionChangeListener} when the menu becomes visible and invisible, respectively. It
     * also sets the {@code pathSelectedMenu} to {@code null} when the menu is cancelled.
     *
     * @see #menuSelectionChangeListener
     * @see #pathSelectedMenu
     * @see PopupMenuListener
     */
    private class MenuSelectionListenerInstaller implements PopupMenuListener {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            MenuSelectionManager.defaultManager().addChangeListener(menuSelectionChangeListener);
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            MenuSelectionManager.defaultManager().removeChangeListener(menuSelectionChangeListener);
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            pathSelectedMenu = null;
        }
    }
}


text:
@interface PMProtoCategoryTableViewController : UITableViewController
@property (assign, nonatomic) id delegate;
@end
@protocol PMProtoCategoryTableViewControllerDelegate
- (void)didSelectProtoCategory:(PMCategory *)category;

@end


text:
(function() {
  'use strict';

  angular.module('hansei.ui')
    .directive('card', ['board', function(board) {
      return {
        restrict: 'E',
        templateUrl: '/templates/_card.html',
        scope: {
          card:   '=',
          column: '=',
          index:  '='
        },
        controller: ['$scope', '$timeout', 'api', 'user', 'view',
        function($scope, $timeout, api, user, view) {

          var column = $scope.column;

          var isEmpty = function(str) { return Boolean(str.match(/^\s*$/)); };

          var unlock = function(card) {
            api.cardUnlock(board.id, card.id, function(unlockWorked) {
              if (unlockWorked) board.forgetCardLock(card.id);
            });
          };

          $scope.board = board;
          $scope.view  = view;
          $scope.user  = user;

          $scope.isEditable = function(card) {
            // (!board.weHaveCardLocks || (card.locked && !card.lockedByAnother))
            //   && !board.locked
            //   && !card.lockedByAnother"

            if (card.locked && card.lockedByAnother) {
              return false;
            }

            if (!card.locked && board.weHaveCardLocks) {
              return false;
            }

            if (board.locked && !board.isFacilitator) {
              return false;
            }

            return true;
          };

          $scope.getCardLock = function(card) {
            if (board.card(card.id).locked) return;
            api.cardLock(board.id, card.id, function(gotLock) {
              if (gotLock) {
                // so we can reestablish on websocket reconnect
                board.rememberCardLock(card.id);
              } else {
                $scope.editform.$cancel();  // no lock, dude.
              }
            });
          };

          $scope.checkCardContent = function(card, content, columnId, id) {
            if (isEmpty(content)) {
              board.forgetCardLock(card.id);
              api.cardVaporize(board.id, card.id);
            } else {
              // Update implicitly unlocks
              api.cardUpdate(board.id, columnId, {id: id, content: content});
            }
            // the false returned will close the editor and not update the model.
            // (model update will happen when the event is pushed from the server)
            return false;
          };

          $scope.cancel = function(card) {  // Zap the card if previous content was empty
            if (isEmpty(card.content)) {
              board.forgetCardLock(card.id);
              api.cardVaporize(board.id, card.id);
            } else {
              unlock(card);
            }
          };

          $scope.combineThings = function($event, $data, destCardId) {
            if ($data.pile) {
              api.boardCombinePiles(board.id, {
                sourceColumnId: $data.sourceColumnId,
                sourcePosition: $data.sourcePosition,
                destCardId:     destCardId
              });
            } else {
              api.boardCombineCards(board.id, {
                sourceCardId: $data.id,
                destCardId:   destCardId
              });
            }
          };

          $scope.editorShow = function(card) {
            if (board.card(card.id).locked) return;
            $scope.editform.$show();
          };

          $scope.isEditorVisible = function(card) {
            if (!$scope.editform) return false;
            return $scope.editform.$visible;
          };

          $scope.upvote = function(card, event) {
            $scope.votePop = true;
            $timeout(function() { $scope.votePop = false; }, 500);
            if (board.card(card.id).locked) return;
            console.log('yo');
            if (board.weHaveCardLocks)      return;
            console.log('yo2');
            if (board.votesRemaining === 0) return;
            console.log('yo3');
            api.cardUpvote(board.shortid, board.column(card.column).id, card.id);
          };

          $scope.unupvote = function(card) {
            $scope.votePop = true;
            $timeout(function() { $scope.votePop = false; }, 500);
            api.cardUnupvote(board.id, column.id, card.id);
          };

          $scope.moveTo = function(card, column, force) {
            if (!force) {
              if (board.card(card.id).locked) return;
              if (board.weHaveCardLocks)      return;
            }
            $scope.editform.$cancel();
            console.log('moving', card.id, column.title);
            api.boardMoveCard(board.id, {
              cardId:       card.id,
              destColumnId: column.id,
              destPosition: column.cardSlots.length + 1
            });
          };

          $scope.trash = function(card) {
            console.log('trashing', card.id);
            if (isEmpty(card.content)) {
              api.cardVaporize(board.id, card.id);
            } else {
              $scope.editform.$cancel();
              $scope.moveTo(card, board.trash, true);
            }
          };

          $scope.color = function(card, color) {
            if (board.card(card.id).locked) return;
            if (board.weHaveCardLocks)      return;
            api.cardColor(board.id, card.column, card.id, color);
          };

        }],
        link: function(scope, element) {

          // If we were the one who created this card, let's edit it!
          if (scope.card.you && scope.card.newlyCreated) {
            board.cardLock(scope.card);
            scope.editform.$show();
            delete scope.card.you;
            delete scope.card.newlyCreated;
          }

        }
      };
    }])
})();


text:
using std::string;

INIReader::INIReader(const string& filename)
{
    _error = ini_parse(filename.c_str(), ValueHandler, this);
}

int INIReader::ParseError() const
{
    return _error;
}

string INIReader::Get(const string& section, const string& name, const string& default_value) const
{
    string key = MakeKey(section, name);
    // Use _values.find() here instead of _values.at() to support pre C++11 compilers
    return _values.count(key) ? _values.find(key)->second : default_value;
}

string INIReader::GetString(const string& section, const string& name, const string& default_value) const
{
    const string str = Get(section, name, "");
    return str.empty() ? default_value : str;
}

long INIReader::GetInteger(const string& section, const string& name, long default_value) const
{
    string valstr = Get(section, name, "");
    const char* value = valstr.c_str();
    char* end;
    // This parses "1234" (decimal) and also "0x4D2" (hex)
    long n = strtol(value, &end, 0);
    return end > value ? n : default_value;
}

double INIReader::GetReal(const string& section, const string& name, double default_value) const
{
    string valstr = Get(section, name, "");
    const char* value = valstr.c_str();
    char* end;
    double n = strtod(value, &end);
    return end > value ? n : default_value;
}

bool INIReader::GetBoolean(const string& section, const string& name, bool default_value) const
{
    string valstr = Get(section, name, "");
    // Convert to lower case to make string comparisons case-insensitive
    std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower);
    if (valstr == "true" || valstr == "yes" || valstr == "on" || valstr == "1")
        return true;
    else if (valstr == "false" || valstr == "no" || valstr == "off" || valstr == "0")
        return false;
    else
        return default_value;
}

bool INIReader::HasSection(const string& section) const
{
    const string key = MakeKey(section, "");
    std::map<string, string>::const_iterator pos = _values.lower_bound(key);
    if (pos == _values.end())
        return false;
    // Does the key at the lower_bound pos start with "section"?
    return pos->first.compare(0, key.length(), key) == 0;
}

bool INIReader::HasValue(const string& section, const string& name) const
{
    string key = MakeKey(section, name);
    return _values.count(key);
}

string INIReader::MakeKey(const string& section, const string& name)
{
    string key = section + "=" + name;
    // Convert to lower case to make section/name lookups case-insensitive
    std::transform(key.begin(), key.end(), key.begin(), ::tolower);
    return key;
}

int INIReader::ValueHandler(void* user, const char* section, const char* name,
                            const char* value)
{
    INIReader* reader = static_cast<INIReader*>(user);
    string key = MakeKey(section, name);
    if (reader->_values[key].size() > 0)
        reader->_values[key] += "\n";
    reader->_values[key] += value;
    return 1;
}


text:
#ifndef __HIREDIS_LIBEVENT_H__

#define __HIREDIS_LIBEVENT_H__

#include <event2/event.h>

#ifdef __cplusplus
extern "C" {
#endif

//////////////////////////////////////

#define DEFAULT_REDIS_PORT (6379)

typedef void* redis_context_handle;

//////////////////////////////////////

#if !defined(TURN_NO_HIREDIS)

void redis_async_init(void);

redis_context_handle redisLibeventAttach(struct event_base *base, char *ip, int port, char *pwd, int db);

void send_message_to_redis(redis_context_handle rch, const char *command, const char *key, const char *format,...);

int is_redis_asyncconn_good(redis_context_handle rch);

#endif
/* TURN_NO_HIREDIS */

#ifdef __cplusplus
}
#endif

#endif
/*__HIREDIS_LIBEVENT_H__*/


text:
namespace aura {
namespace test {
class AuraTestHelper;
}
}

namespace base {
class MessageLoopForUI;
}

namespace wm {
class WMState;
}

namespace views {

class ViewsTestHelperAura : public ViewsTestHelper {
 public:
  ViewsTestHelperAura(base::MessageLoopForUI* message_loop,
                      ui::ContextFactory* context_factory);
  virtual ~ViewsTestHelperAura();

  // Overridden from ViewsTestHelper:
  virtual void SetUp() OVERRIDE;
  virtual void TearDown() OVERRIDE;
  virtual gfx::NativeView GetContext() OVERRIDE;

 private:
  ui::ContextFactory* context_factory_;
  scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
  scoped_ptr<wm::WMState> wm_state_;

  DISALLOW_COPY_AND_ASSIGN(ViewsTestHelperAura);
};

}  // namespace views

#endif  // UI_VIEWS_TEST_VIEWS_TEST_HELPER_AURA_H_


text:
package jsystem.runner.projectsync;

import java.util.Properties;
import jsystem.framework.FrameworkOptions;
import jsystem.runner.agent.server.RunnerAgent;

/**
 * jsystem.properties related utility methods.
 * @author goland
 */
public class JsystemPropertiesUtils {

	/**
	 */
	public static FrameworkOptions[] PROPERTIES_TO_FILTER =
		new FrameworkOptions[]{FrameworkOptions.DISABLE_OLD_SCENARIO_CONVERT,
		                       FrameworkOptions.EXCEL_COMMAND,
		                       FrameworkOptions.HTML_OLD_DIRECTORY,
		                       FrameworkOptions.HTML_OLD_PATH,
		                       FrameworkOptions.LOG_FOLDER,
		                       FrameworkOptions.TEST_VM_PARMS,
		                       FrameworkOptions.TESTS_CLASS_FOLDER,
		                       FrameworkOptions.TESTS_SOURCE_FOLDER,
		                       FrameworkOptions.RESOURCES_SOURCE_FOLDER,
		                       FrameworkOptions.USED_SUT_FILE};

	/**
	 * Gets a map of properties and removes from it all properties
	 * that should not be updated in agent's jsystem.propeties file.
	 * @see RunnerAgent#setJsystemProperties(Properties)
	 */
	public static void filterJsystemProperties(Properties props){
		for (FrameworkOptions o: PROPERTIES_TO_FILTER){
			props.remove(o.toString());
		}
	}
}


text:
package org.bigtesting.routd.tests;

import org.bigtesting.routd.RegexRouter;

/**
 *
 * @author Luis Antunes
 */
public class TestRegexRouter extends RouterContractTest<RegexRouter> {

    @Override
    protected RegexRouter newRouter() {
        return new RegexRouter();
    }
}


text:
Slice::Slice(
		unsigned int id,
		unsigned int section,
		boost::shared_ptr<ConnectedComponent> component) :
	_id(id),
	_section(section),
	_component(component) {}

unsigned int
Slice::getId() const {

	return _id;
}

unsigned int
Slice::getSection() const {

	return _section;
}

boost::shared_ptr<ConnectedComponent>
Slice::getComponent() const {

	return _component;
}

void
Slice::intersect(const Slice& other) {

	_component = boost::make_shared<ConnectedComponent>(getComponent()->intersect(*other.getComponent()));

	setBoundingBoxDirty();
	setHashDirty();
}

void
Slice::translate(const util::point<int>& pt)
{
	_component = boost::make_shared<ConnectedComponent>(getComponent()->translate(pt));

	setBoundingBoxDirty();
	setHashDirty();
}

bool
Slice::operator==(const Slice& other) const
{
	return getSection() == other.getSection() && (*getComponent()) == (*other.getComponent());
}

BoundingBox
Slice::computeBoundingBox() const {

	const util::rect<double>& componentBoundingBox = getComponent()->getBoundingBox();

	return BoundingBox(
			componentBoundingBox.minX*getResolutionX(),
			componentBoundingBox.minY*getResolutionY(),
			 _section                *getResolutionZ(),
			componentBoundingBox.maxX*getResolutionX(),
			componentBoundingBox.maxY*getResolutionY(),
			(_section + 1)           *getResolutionZ());
}


text:
package models.daos;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import utils.Urn;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import play.Logger;
import utils.JdbcUtil;
import wherehows.common.enums.OwnerType;
import wherehows.common.schemas.DatasetCapacityRecord;
import wherehows.common.schemas.DatasetCaseSensitiveRecord;
import wherehows.common.schemas.DatasetComplianceRecord;
import wherehows.common.schemas.DatasetConstraintRecord;
import wherehows.common.schemas.DeploymentRecord;
import wherehows.common.schemas.DatasetFieldIndexRecord;
import wherehows.common.schemas.DatasetFieldSchemaRecord;
import wherehows.common.schemas.DatasetIndexRecord;
import wherehows.common.schemas.DatasetInventoryItemRecord;
import wherehows.common.schemas.DatasetOwnerRecord;
import wherehows.common.schemas.DatasetPartitionKeyRecord;
import wherehows.common.schemas.DatasetPartitionRecord;
import wherehows.common.schemas.DatasetRecord;
import wherehows.common.schemas.DatasetReferenceRecord;
import wherehows.common.schemas.DatasetSchemaInfoRecord;
import wherehows.common.schemas.DatasetSecurityRecord;
import wherehows.common.schemas.DatasetTagRecord;
import wherehows.common.utils.PreparedStatementUtil;
import wherehows.common.utils.StringUtil;
import wherehows.common.writers.DatabaseWriter;

public class DatasetInfoDao {

  private static final String DATASET_DEPLOYMENT_TABLE = "dataset_deployment";
  private static final String DATASET_CAPACITY_TABLE = "dataset_capacity";
  private static final String DATASET_TAG_TABLE = "dataset_tag";
  private static final String DATASET_CASE_SENSITIVE_TABLE = "dataset_case_sensitivity";
  private static final String DATASET_REFERENCE_TABLE = "dataset_reference";
  private static final String DATASET_PARTITION_TABLE = "dataset_partition";
  private static final String DATASET_COMPLIANCE_TABLE = "dataset_privacy_compliance";
  private static final String DATASET_SECURITY_TABLE = "dataset_security";
  private static final String DATASET_OWNER_TABLE = "dataset_owner";
  private static final String DATASET_OWNER_UNMATCHED_TABLE = "stg_dataset_owner_unmatched";
  private static final String DATASET_CONSTRAINT_TABLE = "dataset_constraint";
  private static final String DATASET_INDEX_TABLE = "dataset_index";
  private static final String DATASET_SCHEMA_TABLE = "dataset_schema_info";
  private static final String DATASET_FIELD_DETAIL_TABLE = "dict_field_detail";
  private static final String DATASET_INVENTORY_TABLE = "dataset_inventory";
  private static final String EXTERNAL_USER_TABLE = "dir_external_user_info";
  private static final String EXTERNAL_GROUP_TABLE = "dir_external_group_user_map";

  private static final DatabaseWriter DEPLOYMENT_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_DEPLOYMENT_TABLE);
  private static final DatabaseWriter CAPACITY_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_CAPACITY_TABLE);
  private static final DatabaseWriter TAG_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_TAG_TABLE);
  private static final DatabaseWriter CASE_SENSITIVE_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_CASE_SENSITIVE_TABLE);
  private static final DatabaseWriter REFERENCE_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_REFERENCE_TABLE);
  private static final DatabaseWriter PARTITION_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_PARTITION_TABLE);
  private static final DatabaseWriter COMPLIANCE_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_COMPLIANCE_TABLE);
  private static final DatabaseWriter SECURITY_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_SECURITY_TABLE);
  private static final DatabaseWriter OWNER_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_OWNER_TABLE);
  private static final DatabaseWriter OWNER_UNMATCHED_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_OWNER_UNMATCHED_TABLE);
  private static final DatabaseWriter CONSTRAINT_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_CONSTRAINT_TABLE);
  private static final DatabaseWriter INDEX_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_INDEX_TABLE);
  private static final DatabaseWriter DICT_DATASET_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, "dict_dataset");
  private static final DatabaseWriter SCHEMA_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_SCHEMA_TABLE);
  private static final DatabaseWriter FIELD_DETAIL_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_FIELD_DETAIL_TABLE);
  private static final DatabaseWriter INVENTORY_WRITER =
      new DatabaseWriter(JdbcUtil.wherehowsJdbcTemplate, DATASET_INVENTORY_TABLE);

  public static final String GET_DATASET_DEPLOYMENT_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_DEPLOYMENT_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_DEPLOYMENT_BY_URN =
      "SELECT * FROM " + DATASET_DEPLOYMENT_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String DELETE_DATASET_DEPLOYMENT_BY_DATASET_ID =
      "DELETE FROM " + DATASET_DEPLOYMENT_TABLE + " WHERE dataset_id=?";

  public static final String GET_DATASET_CAPACITY_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_CAPACITY_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_CAPACITY_BY_URN =
      "SELECT * FROM " + DATASET_CAPACITY_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String DELETE_DATASET_CAPACITY_BY_DATASET_ID =
      "DELETE FROM " + DATASET_CAPACITY_TABLE + " WHERE dataset_id=?";

  public static final String GET_DATASET_TAG_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_TAG_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_TAG_BY_URN =
      "SELECT * FROM " + DATASET_TAG_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String DELETE_DATASET_TAG_BY_DATASET_ID = "DELETE FROM " + DATASET_TAG_TABLE + " WHERE dataset_id=?";

  public static final String GET_DATASET_CASE_SENSITIVE_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_CASE_SENSITIVE_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_CASE_SENSITIVE_BY_URN =
      "SELECT * FROM " + DATASET_CASE_SENSITIVE_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String GET_DATASET_REFERENCE_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_REFERENCE_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_REFERENCE_BY_URN =
      "SELECT * FROM " + DATASET_REFERENCE_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String DELETE_DATASET_REFERENCE_BY_DATASET_ID =
      "DELETE FROM " + DATASET_REFERENCE_TABLE + " WHERE dataset_id=?";

  public static final String GET_DATASET_PARTITION_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_PARTITION_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_PARTITION_BY_URN =
      "SELECT * FROM " + DATASET_PARTITION_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String GET_DATASET_COMPLIANCE_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_COMPLIANCE_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_COMPLIANCE_BY_URN =
      "SELECT * FROM " + DATASET_COMPLIANCE_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String GET_DATASET_SECURITY_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_SECURITY_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_SECURITY_BY_URN =
      "SELECT * FROM " + DATASET_SECURITY_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String GET_DATASET_OWNER_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_OWNER_TABLE + " WHERE dataset_id = :dataset_id ORDER BY sort_id";

  public static final String GET_DATASET_OWNER_BY_URN =
      "SELECT * FROM " + DATASET_OWNER_TABLE + " WHERE dataset_urn = :dataset_urn ORDER BY sort_id";

  public static final String DELETE_DATASET_OWNER_BY_DATASET_ID =
      "DELETE FROM " + DATASET_OWNER_TABLE + " WHERE dataset_id=?";

  public static final String GET_USER_BY_USER_ID = "SELECT * FROM " + EXTERNAL_USER_TABLE + " WHERE user_id = :user_id";

  public static final String GET_APP_ID_BY_GROUP_ID =
      "SELECT app_id FROM " + EXTERNAL_GROUP_TABLE + " WHERE group_id = :group_id GROUP BY app_id";

  public static final String GET_DATASET_CONSTRAINT_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_CONSTRAINT_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_CONSTRAINT_BY_URN =
      "SELECT * FROM " + DATASET_CONSTRAINT_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String DELETE_DATASET_CONSTRAINT_BY_DATASET_ID =
      "DELETE FROM " + DATASET_CONSTRAINT_TABLE + " WHERE dataset_id=?";

  public static final String GET_DATASET_INDEX_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_INDEX_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_INDEX_BY_URN =
      "SELECT * FROM " + DATASET_INDEX_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String DELETE_DATASET_INDEX_BY_DATASET_ID =
      "DELETE FROM " + DATASET_INDEX_TABLE + " WHERE dataset_id=?";

  public static final String GET_DATASET_SCHEMA_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_SCHEMA_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String GET_DATASET_SCHEMA_BY_URN =
      "SELECT * FROM " + DATASET_SCHEMA_TABLE + " WHERE dataset_urn = :dataset_urn";

  public static final String UPDATE_DICT_DATASET_WITH_SCHEMA_CHANGE =
      "UPDATE dict_dataset SET `schema`=?, `schema_type`=?, `fields`=?, `source`=?, `modified_time`=? WHERE `id`=?";

  public static final String GET_DATASET_FIELDS_BY_DATASET_ID =
      "SELECT * FROM " + DATASET_FIELD_DETAIL_TABLE + " WHERE dataset_id = :dataset_id";

  public static final String DELETE_DATASET_FIELDS_BY_DATASET_ID =
      "DELETE FROM " + DATASET_FIELD_DETAIL_TABLE + " WHERE dataset_id=?";

  public static final String UPDATE_DATASET_FIELD_INDEXED_BY_FIELDNAME =
      "UPDATE " + DATASET_FIELD_DETAIL_TABLE + " SET is_indexed=? WHERE dataset_id=? AND field_name=?";

  public static final String UPDATE_DATASET_FIELD_PARTITIONED_BY_FIELDNAME =
      "UPDATE " + DATASET_FIELD_DETAIL_TABLE + " SET is_partitioned=? WHERE dataset_id=? AND field_name=?";

  public static final String GET_DATASET_INVENTORY_ITEMS =
      "SELECT * FROM " + DATASET_INVENTORY_TABLE + " WHERE data_platform = :data_platform AND native_name = :native_name "
          + "AND data_origin = :data_origin ORDER BY event_date DESC LIMIT :limit";

  public static final String INSERT_DATASET_INVENTORY_ITEM =
      PreparedStatementUtil.prepareInsertTemplateWithColumn("REPLACE", DATASET_INVENTORY_TABLE,
          DatasetInventoryItemRecord.getInventoryItemColumns());

  private static final String UrnRegex = "urn:li:dataset:\\(urn:li:dataPlatform:(\\w*),\\s?([^\\s]*),\\s?(\\w*)\\)";

  private static Pattern UrnPattern = Pattern.compile(UrnRegex);

  private static String urnToUri(String urn) {
    // from urn:li:dataset:(urn:li:dataPlatform:p, nativeName, dataOrigin) to p:///nativeName
    Matcher m = UrnPattern.matcher(urn);
    if(m.matches()) {
      String platform = m.group(1) + "://";
      String datasetName = m.group(2).replace(".", "/");
      return platform + (datasetName.startsWith("/") ? "" : "/") + datasetName;
    }
    return null;
  }

  private static Object[] findIdAndUrn(Integer datasetId)
      throws SQLException {
    final String urn = datasetId != null ? DatasetDao.getDatasetById(datasetId).get("urn").toString() : null;
    return new Object[]{datasetId, urn};
  }

  private static Object[] findIdAndUrn(String urn)
      throws SQLException {
    final Integer datasetId = urn != null ? Integer.valueOf(DatasetDao.getDatasetByUrn(urn).get("id").toString()) : null;
    return new Object[]{datasetId, urn};
  }

  private static Object[] findDataset(JsonNode root) {
    // use dataset id to find dataset first
    final JsonNode idNode = root.path("datasetId");
    if (!idNode.isMissingNode() && !idNode.isNull()) {
      try {
        final Object[] idUrn = findIdAndUrn(idNode.asInt());
        if (idUrn[0] != null && idUrn[1] != null) {
          return idUrn;
        }
      } catch (Exception ex) {
      }
    }

    // use dataset uri to find dataset
    final JsonNode properties = root.path("datasetProperties");
    if (!properties.isMissingNode() && !properties.isNull()) {
      final JsonNode uri = properties.path("uri");
      if (!uri.isMissingNode() && !uri.isNull()) {
        try {
          final Object[] idUrn = findIdAndUrn(uri.asText());
          if (idUrn[0] != null && idUrn[1] != null) {
            return idUrn;
          }
        } catch (Exception ex) {
        }
      }
    }

    // use dataset urn to find dataset
    final JsonNode urnNode = root.path("urn");
    if (!urnNode.isMissingNode() && !urnNode.isNull()) {
      try {
        final Object[] idUrn = findIdAndUrn(urnToUri(urnNode.asText()));
        if (idUrn[0] != null && idUrn[1] != null) {
          return idUrn;
        }
      } catch (Exception ex) {
      }
    }

    return new Object[]{null, null};
  }

  public static List<DeploymentRecord> getDatasetDeploymentByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_DEPLOYMENT_BY_DATASET_ID, params);

    List<DeploymentRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DeploymentRecord record = new DeploymentRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static List<DeploymentRecord> getDatasetDeploymentByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_DEPLOYMENT_BY_URN, params);

    List<DeploymentRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DeploymentRecord record = new DeploymentRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static void updateDatasetDeployment(JsonNode root)
      throws Exception {
    final JsonNode deployment = root.path("deploymentInfo");
    if (deployment.isMissingNode() || !deployment.isArray()) {
      throw new IllegalArgumentException(
          "Dataset deployment info update error, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();
    // om.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);

    for (final JsonNode deploymentInfo : deployment) {
      DeploymentRecord record = om.convertValue(deploymentInfo, DeploymentRecord.class);
      record.setDatasetId(datasetId);
      record.setDatasetUrn(urn);
      record.setModifiedTime(System.currentTimeMillis() / 1000);
      DEPLOYMENT_WRITER.append(record);
    }

    // remove old info then insert new info
    DEPLOYMENT_WRITER.execute(DELETE_DATASET_DEPLOYMENT_BY_DATASET_ID, new Object[]{datasetId});
    DEPLOYMENT_WRITER.insert();
  }

  public static List<DatasetCapacityRecord> getDatasetCapacityByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_CAPACITY_BY_DATASET_ID, params);

    List<DatasetCapacityRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetCapacityRecord record = new DatasetCapacityRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static List<DatasetCapacityRecord> getDatasetCapacityByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_CAPACITY_BY_URN, params);

    List<DatasetCapacityRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetCapacityRecord record = new DatasetCapacityRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static void updateDatasetCapacity(JsonNode root)
      throws Exception {
    final JsonNode capacity = root.path("capacity");
    if (capacity.isMissingNode() || !capacity.isArray()) {
      throw new IllegalArgumentException(
          "Dataset capacity info update error, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    for (final JsonNode capacityInfo : capacity) {
      DatasetCapacityRecord record = om.convertValue(capacityInfo, DatasetCapacityRecord.class);
      record.setDatasetId(datasetId);
      record.setDatasetUrn(urn);
      record.setModifiedTime(System.currentTimeMillis() / 1000);
      CAPACITY_WRITER.append(record);
    }

    // remove old info then insert new info
    CAPACITY_WRITER.execute(DELETE_DATASET_CAPACITY_BY_DATASET_ID, new Object[]{datasetId});
    CAPACITY_WRITER.insert();
  }

  public static List<DatasetTagRecord> getDatasetTagByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_TAG_BY_DATASET_ID, params);

    List<DatasetTagRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetTagRecord record = new DatasetTagRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static List<DatasetTagRecord> getDatasetTagByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_TAG_BY_URN, params);

    List<DatasetTagRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetTagRecord record = new DatasetTagRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static void updateDatasetTags(JsonNode root)
      throws Exception {
    final JsonNode tags = root.path("tags");
    if (tags.isMissingNode() || !tags.isArray()) {
      throw new IllegalArgumentException(
          "Dataset tag info update error, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    for (final JsonNode tag : tags) {
      DatasetTagRecord record = new DatasetTagRecord();
      record.setTag(tag.asText());
      record.setDatasetId(datasetId);
      record.setDatasetUrn(urn);
      record.setModifiedTime(System.currentTimeMillis() / 1000);
      TAG_WRITER.append(record);
    }

    // remove old info then insert new info
    TAG_WRITER.execute(DELETE_DATASET_TAG_BY_DATASET_ID, new Object[]{datasetId});
    TAG_WRITER.insert();
  }

  public static DatasetCaseSensitiveRecord getDatasetCaseSensitivityByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_CASE_SENSITIVE_BY_DATASET_ID, params);

    DatasetCaseSensitiveRecord record = new DatasetCaseSensitiveRecord();
    record.convertToRecord(result);
    return record;
  }

  public static DatasetCaseSensitiveRecord getDatasetCaseSensitivityByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_CASE_SENSITIVE_BY_URN, params);

    DatasetCaseSensitiveRecord record = new DatasetCaseSensitiveRecord();
    record.convertToRecord(result);
    return record;
  }

  public static void updateDatasetCaseSensitivity(JsonNode root)
      throws Exception {
    final JsonNode properties = root.path("datasetProperties");
    if (properties.isMissingNode() || properties.isNull()) {
      throw new IllegalArgumentException(
          "Dataset properties update fail, missing necessary fields: " + root.toString());
    }
    final JsonNode caseSensitivity = properties.path("caseSensitivity");
    if (caseSensitivity.isMissingNode() || caseSensitivity.isNull()) {
      throw new IllegalArgumentException(
          "Dataset properties update fail, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    DatasetCaseSensitiveRecord record = om.convertValue(caseSensitivity, DatasetCaseSensitiveRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    try {
      DatasetCaseSensitiveRecord result = getDatasetCaseSensitivityByDatasetId(datasetId);
      String[] columns = record.getDbColumnNames();
      Object[] columnValues = record.getAllValuesToString();
      String[] conditions = {"dataset_id"};
      Object[] conditionValues = new Object[]{datasetId};
      CASE_SENSITIVE_WRITER.update(columns, columnValues, conditions, conditionValues);
    } catch (EmptyResultDataAccessException ex) {
      CASE_SENSITIVE_WRITER.append(record);
      CASE_SENSITIVE_WRITER.insert();
    }
  }

  public static List<DatasetReferenceRecord> getDatasetReferenceByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_REFERENCE_BY_DATASET_ID, params);

    List<DatasetReferenceRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetReferenceRecord record = new DatasetReferenceRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static List<DatasetReferenceRecord> getDatasetReferenceByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_REFERENCE_BY_URN, params);

    List<DatasetReferenceRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetReferenceRecord record = new DatasetReferenceRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static void updateDatasetReference(JsonNode root)
      throws Exception {
    final JsonNode references = root.path("references");
    if (references.isMissingNode() || !references.isArray()) {
      throw new IllegalArgumentException(
          "Dataset reference info update fail, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    for (final JsonNode reference : references) {
      DatasetReferenceRecord record = om.convertValue(reference, DatasetReferenceRecord.class);
      record.setDatasetId(datasetId);
      record.setDatasetUrn(urn);
      record.setModifiedTime(System.currentTimeMillis() / 1000);
      REFERENCE_WRITER.append(record);
    }

    // remove old info then insert new info
    REFERENCE_WRITER.execute(DELETE_DATASET_REFERENCE_BY_DATASET_ID, new Object[]{datasetId});
    REFERENCE_WRITER.insert();
  }

  public static DatasetPartitionRecord getDatasetPartitionByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_PARTITION_BY_DATASET_ID, params);

    DatasetPartitionRecord record = new DatasetPartitionRecord();
    record.convertToRecord(result);
    return record;
  }

  public static DatasetPartitionRecord getDatasetPartitionByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_PARTITION_BY_URN, params);

    DatasetPartitionRecord record = new DatasetPartitionRecord();
    record.convertToRecord(result);
    return record;
  }

  public static void updateDatasetPartition(JsonNode root)
      throws Exception {
    final JsonNode partition = root.path("partitionSpec");
    if (partition.isMissingNode() || partition.isNull()) {
      throw new IllegalArgumentException(
          "Dataset reference info update fail, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    DatasetPartitionRecord record = om.convertValue(partition, DatasetPartitionRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    try {
      DatasetPartitionRecord result = getDatasetPartitionByDatasetId(datasetId);
      String[] columns = record.getDbColumnNames();
      Object[] columnValues = record.getAllValuesToString();
      String[] conditions = {"dataset_id"};
      Object[] conditionValues = new Object[]{datasetId};
      PARTITION_WRITER.update(columns, columnValues, conditions, conditionValues);
    } catch (EmptyResultDataAccessException ex) {
      PARTITION_WRITER.append(record);
      PARTITION_WRITER.insert();
    }

    // update dataset field partitioned
    if (record.getPartitionKeys() != null) {
      for (DatasetPartitionKeyRecord partitionKey : record.getPartitionKeys()) {
        List<String> fieldNames = partitionKey.getFieldNames();
        for (String fieldName : fieldNames) {
          FIELD_DETAIL_WRITER.execute(UPDATE_DATASET_FIELD_PARTITIONED_BY_FIELDNAME,
              new Object[]{"Y", datasetId, fieldName});
        }
      }
    }
  }

  public static DatasetComplianceRecord getDatasetComplianceByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_COMPLIANCE_BY_DATASET_ID, params);

    DatasetComplianceRecord record = new DatasetComplianceRecord();
    record.convertToRecord(result);
    return record;
  }

  public static DatasetComplianceRecord getDatasetComplianceByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_COMPLIANCE_BY_URN, params);

    DatasetComplianceRecord record = new DatasetComplianceRecord();
    record.convertToRecord(result);
    return record;
  }

  public static void updateDatasetCompliance(JsonNode root)
      throws Exception {
    final JsonNode security = root.path("privacyCompliancePolicy");
    if (security.isMissingNode() || security.isNull()) {
      throw new IllegalArgumentException(
          "Dataset security info update fail, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    DatasetComplianceRecord record = om.convertValue(security, DatasetComplianceRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    try {
      DatasetComplianceRecord result = getDatasetComplianceByDatasetId(datasetId);
      String[] columns = record.getDbColumnNames();
      Object[] columnValues = record.getAllValuesToString();
      String[] conditions = {"dataset_id"};
      Object[] conditionValues = new Object[]{datasetId};
      COMPLIANCE_WRITER.update(columns, columnValues, conditions, conditionValues);
    } catch (EmptyResultDataAccessException ex) {
      COMPLIANCE_WRITER.append(record);
      COMPLIANCE_WRITER.insert();
    }
  }

  public static DatasetSecurityRecord getDatasetSecurityByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_SECURITY_BY_DATASET_ID, params);

    DatasetSecurityRecord record = new DatasetSecurityRecord();
    record.convertToRecord(result);
    return record;
  }

  public static DatasetSecurityRecord getDatasetSecurityByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_SECURITY_BY_URN, params);

    DatasetSecurityRecord record = new DatasetSecurityRecord();
    record.convertToRecord(result);
    return record;
  }

  public static void updateDatasetSecurity(JsonNode root)
      throws Exception {
    final JsonNode security = root.path("securitySpecification");
    if (security.isMissingNode() || security.isNull()) {
      throw new IllegalArgumentException(
          "Dataset security info update fail, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    DatasetSecurityRecord record = om.convertValue(security, DatasetSecurityRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    try {
      DatasetSecurityRecord result = getDatasetSecurityByDatasetId(datasetId);
      String[] columns = record.getDbColumnNames();
      Object[] columnValues = record.getAllValuesToString();
      String[] conditions = {"dataset_id"};
      Object[] conditionValues = new Object[]{datasetId};
      SECURITY_WRITER.update(columns, columnValues, conditions, conditionValues);
    } catch (EmptyResultDataAccessException ex) {
      SECURITY_WRITER.append(record);
      SECURITY_WRITER.insert();
    }
  }

  public static List<DatasetOwnerRecord> getDatasetOwnerByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_OWNER_BY_DATASET_ID, params);

    List<DatasetOwnerRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetOwnerRecord record = new DatasetOwnerRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static List<DatasetOwnerRecord> getDatasetOwnerByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_OWNER_BY_URN, params);

    List<DatasetOwnerRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetOwnerRecord record = new DatasetOwnerRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static void updateDatasetOwner(JsonNode root)
      throws Exception {
    final JsonNode owners = root.path("owners");
    if (owners.isMissingNode() || !owners.isArray()) {
      throw new IllegalArgumentException(
          "Dataset owner info update fail, missing necessary fields: " + root.toString());
    }

    final JsonNode ownerSourceNode = root.path("source");
    String ownerSource = null;
    if (!ownerSourceNode.isNull() && !ownerSourceNode.isMissingNode()) {
        ownerSource = ownerSourceNode.asText();
    }

    final Integer datasetId;
    final String urn;
    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      datasetId = 0;
      urn = root.path("datasetProperties").path("uri").asText();
    } else {
      datasetId = (Integer) idUrn[0];
      urn = (String) idUrn[1];
    }

    final JsonNode auditHeader = root.path("auditHeader");
    final Long eventTime = auditHeader != null ? auditHeader.path("time").asLong() / 1000 : null;

    ObjectMapper om = new ObjectMapper();

    List<DatasetOwnerRecord> ownerList = new ArrayList<>();
    for (final JsonNode owner : owners) {
      DatasetOwnerRecord record = om.convertValue(owner, DatasetOwnerRecord.class);
      record.setDatasetId(datasetId);
      record.setDatasetUrn(urn);
      record.setSourceTime(eventTime);
      record.setCreatedTime(eventTime);
      record.setModifiedTime(System.currentTimeMillis() / 1000);

      final String ownerString = record.getOwner();
      int lastIndex = ownerString.lastIndexOf(':');
      if (lastIndex >= 0) {
        record.setOwner(ownerString.substring(lastIndex + 1));
        record.setNamespace(ownerString.substring(0, lastIndex));
      } else {
        record.setNamespace("");
      }
      Map<String, Object> ownerInfo = getOwnerByOwnerId(record.getOwner());
      Integer appId = 0;
      String isActive = "N";
      if (ownerInfo.containsKey("app_id")) {
        appId = StringUtil.toInt(ownerInfo.get("app_id"));
        isActive = appId == 301 ? "Y" : appId == 300 ? (String) ownerInfo.get("is_active") : "N";
      }
      record.setAppId(appId);
      record.setIsActive(isActive);
      String ownerTypeString = record.getOwnerType();
      record.setIsGroup(ownerTypeString != null && ownerTypeString.equalsIgnoreCase("group") ? "Y" : "N");

      if (datasetId == 0 || appId == 0) {
        String sql = PreparedStatementUtil.prepareInsertTemplateWithColumn("REPLACE", DATASET_OWNER_UNMATCHED_TABLE,
            record.getDbColumnForUnmatchedOwner());
        OWNER_UNMATCHED_WRITER.execute(sql, record.getValuesForUnmatchedOwner());
      } else {
        ownerList.add(record);
      }
    }

    mergeDatasetOwners(ownerList, datasetId, urn, ownerSource);
  }

  public static void updateKafkaDatasetOwner(String datasetUrn, String owners, String ownerSource, Long sourceUnixTime)
      throws Exception {
    if (datasetUrn == null) {
      return;
    }

    Integer datasetId = 0;
    try {
      datasetId = Integer.parseInt(DatasetDao.getDatasetByUrn(datasetUrn).get("id").toString());
    } catch (Exception e) {
      Logger.error("Exception in updateKafkaDatasetOwner: " + e.getMessage());
    }
    if (datasetId == 0) {
      return;
    }

    List<DatasetOwnerRecord> ownerList = new ArrayList<>();
    if (owners != null) {
      String[] ownerArray = owners.split(",");
      for (String owner : ownerArray) {
        String ownerName = null;
        String namespace = null;
        String ownerIdType = null;
        String isGroup = "N";
        if (owner != null) {
          int lastIndex = owner.lastIndexOf(':');
          if (lastIndex != -1) {
            ownerName = owner.substring(lastIndex + 1);
            namespace = owner.substring(0, lastIndex);
            if (namespace != null && namespace.equalsIgnoreCase("urn:li:griduser")) {
              isGroup = "Y";
              ownerIdType = "GROUP";
            } else {
              ownerIdType = "PERSON";
            }
          }
          DatasetOwnerRecord record = new DatasetOwnerRecord();
          record.setDatasetId(datasetId);
          record.setDatasetUrn(datasetUrn);
          record.setOwnerType("Producer");
          record.setOwner(ownerName);
          record.setOwnerType(ownerIdType);
          record.setIsGroup(isGroup);
          record.setIsActive("Y");
          record.setNamespace(namespace);
          record.setOwnerSource(ownerSource);
          record.setSourceTime(sourceUnixTime);
          record.setCreatedTime(sourceUnixTime);
          record.setModifiedTime(System.currentTimeMillis() / 1000);
          ownerList.add(record);
        }
      }
    }

    mergeDatasetOwners(ownerList, datasetId, datasetUrn, ownerSource);
  }

  private static void mergeDatasetOwners(List<DatasetOwnerRecord> newOwnerList, Integer datasetId, String datasetUrn,
      String source)
      throws Exception {
    List<DatasetOwnerRecord> oldOwnerList = new ArrayList<>();
    try {
      oldOwnerList.addAll(getDatasetOwnerByDatasetUrn(datasetUrn));
    } catch (Exception ex) {
    }

    Integer sortId = 0;
    Map<String, DatasetOwnerRecord> uniqueRecords = new HashMap<>();
    List<DatasetOwnerRecord> combinedList = new ArrayList<>();
    if (newOwnerList != null) {
      for (DatasetOwnerRecord owner : newOwnerList) {
        owner.setSortId(sortId++);
        uniqueRecords.put(owner.getOwner(), owner);
        combinedList.add(owner);
      }
    }

    for (DatasetOwnerRecord owner : oldOwnerList) {
      DatasetOwnerRecord exist = uniqueRecords.get(owner.getOwner());
      if (exist != null) {
        exist.setDbIds(owner.getDbIds());
        exist.setCreatedTime(StringUtil.toLong(owner.getCreatedTime()));

        // take the higher priority owner category
        exist.setOwnerCategory(OwnerType.chooseOwnerType(exist.getOwnerCategory(), owner.getOwnerCategory()));

        // merge owner source as comma separated list
        exist.setOwnerSource(mergeOwnerSource(exist.getOwnerSource(), owner.getOwnerSource()));
        exist.setConfirmedBy(owner.getConfirmedBy());
        exist.setConfirmedOn(owner.getConfirmedOn());
      } else {
        if (!(source != null && source.equalsIgnoreCase(owner.getOwnerSource()))) {
          owner.setSortId(sortId++);
          uniqueRecords.put(owner.getOwner(), owner);
          combinedList.add(owner);
        }
      }
    }

    // remove old info then insert new info
    OWNER_WRITER.execute(DELETE_DATASET_OWNER_BY_DATASET_ID, new Object[]{datasetId});
    for (DatasetOwnerRecord record : combinedList) {
      OWNER_WRITER.append(record);
    }
    OWNER_WRITER.insert();
  }

  public static String mergeOwnerSource(String source, String oldSourceList) {
    if (source == null) {
      return oldSourceList;
    }
    if (oldSourceList == null) {
      return source;
    }
    if (oldSourceList.contains(source)) {
      return oldSourceList;
    }
    return source + "," + oldSourceList;
  }

  public static Map<String, Object> getUserByUserId(String userId)
      throws SQLException {
    Map<String, Object> params = new HashMap<>();
    params.put("user_id", userId);
    return JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_USER_BY_USER_ID, params);
  }

  public static Map<String, Object> getGroupMapByGroupId(String groupId)
      throws SQLException {
    Map<String, Object> params = new HashMap<>();
    params.put("group_id", groupId);
    return JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_APP_ID_BY_GROUP_ID, params);
  }

  public static Map<String, Object> getOwnerByOwnerId(String ownerId)
      throws SQLException {
    try {
      return getUserByUserId(ownerId);
    } catch (EmptyResultDataAccessException ex) {
    }

    try {
      return getGroupMapByGroupId(ownerId);
    } catch (EmptyResultDataAccessException ex) {
    }
    Logger.debug("Can't find owner (user or group): " + ownerId);
    return new HashMap<>();
  }

  public static List<DatasetConstraintRecord> getDatasetConstraintByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_CONSTRAINT_BY_DATASET_ID, params);

    List<DatasetConstraintRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetConstraintRecord record = new DatasetConstraintRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static List<DatasetConstraintRecord> getDatasetConstraintByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_CONSTRAINT_BY_URN, params);

    List<DatasetConstraintRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetConstraintRecord record = new DatasetConstraintRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static void updateDatasetConstraint(JsonNode root)
      throws Exception {
    final JsonNode constraints = root.path("constraints");
    if (constraints.isMissingNode() || !constraints.isArray()) {
      throw new IllegalArgumentException(
          "Dataset constraints info update fail, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    for (final JsonNode constraint : constraints) {
      DatasetConstraintRecord record = om.convertValue(constraint, DatasetConstraintRecord.class);
      record.setDatasetId(datasetId);
      record.setDatasetUrn(urn);
      record.setModifiedTime(System.currentTimeMillis() / 1000);
      CONSTRAINT_WRITER.append(record);
    }

    // remove old info then insert new info
    CONSTRAINT_WRITER.execute(DELETE_DATASET_CONSTRAINT_BY_DATASET_ID, new Object[]{datasetId});
    CONSTRAINT_WRITER.insert();
  }

  public static List<DatasetIndexRecord> getDatasetIndexByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_INDEX_BY_DATASET_ID, params);

    List<DatasetIndexRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetIndexRecord record = new DatasetIndexRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static List<DatasetIndexRecord> getDatasetIndexByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    List<Map<String, Object>> results =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_INDEX_BY_URN, params);

    List<DatasetIndexRecord> records = new ArrayList<>();
    for (Map<String, Object> result : results) {
      DatasetIndexRecord record = new DatasetIndexRecord();
      record.convertToRecord(result);
      records.add(record);
    }
    return records;
  }

  public static void updateDatasetIndex(JsonNode root)
      throws Exception {
    final JsonNode indices = root.path("indices");
    if (indices.isMissingNode() || !indices.isArray()) {
      throw new IllegalArgumentException(
          "Dataset indices info update fail, missing necessary fields: " + root.toString());
    }

    final Object[] idUrn = findDataset(root);
    if (idUrn[0] == null || idUrn[1] == null) {
      throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
    }
    final Integer datasetId = (Integer) idUrn[0];
    final String urn = (String) idUrn[1];

    ObjectMapper om = new ObjectMapper();

    for (final JsonNode index : indices) {
      DatasetIndexRecord record = om.convertValue(index, DatasetIndexRecord.class);
      record.setDatasetId(datasetId);
      record.setDatasetUrn(urn);
      record.setModifiedTime(System.currentTimeMillis() / 1000);
      INDEX_WRITER.append(record);

      // update dataset field indexed
      for (DatasetFieldIndexRecord rec : record.getIndexedFields()) {
        String fieldPath = rec.getFieldPath();
        int lastIndex = fieldPath.lastIndexOf('.'); // if not found, index = -1
        String fieldName = fieldPath.substring(lastIndex + 1);
        FIELD_DETAIL_WRITER.execute(UPDATE_DATASET_FIELD_INDEXED_BY_FIELDNAME, new Object[]{"Y", datasetId, fieldName});
      }
    }

    // remove old info then insert new info
    INDEX_WRITER.execute(DELETE_DATASET_INDEX_BY_DATASET_ID, new Object[]{datasetId});
    INDEX_WRITER.insert();
  }

  public static DatasetSchemaInfoRecord getDatasetSchemaByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_SCHEMA_BY_DATASET_ID, params);

    DatasetSchemaInfoRecord record = new DatasetSchemaInfoRecord();
    record.convertToRecord(result);
    return record;
  }

  public static DatasetSchemaInfoRecord getDatasetSchemaByDatasetUrn(String datasetUrn)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_urn", datasetUrn);
    Map<String, Object> result =
        JdbcUtil.wherehowsNamedJdbcTemplate.queryForMap(GET_DATASET_SCHEMA_BY_URN, params);

    DatasetSchemaInfoRecord record = new DatasetSchemaInfoRecord();
    record.convertToRecord(result);
    return record;
  }

  public static void updateDatasetSchema(JsonNode root)
      throws Exception {
    final JsonNode schema = root.path("schema");
    if (schema.isMissingNode() || schema.isNull()) {
      throw new IllegalArgumentException(
          "Dataset schema update fail, missing necessary fields: " + root.toString());
    }

    Integer datasetId = 0;
    String urn = null;
    final Object[] idUrn = findDataset(root);
    if (idUrn[0] != null && idUrn[1] != null) {
      datasetId = (Integer) idUrn[0];
      urn = (String) idUrn[1];
    } else if (root.get("datasetProperties") != null && root.get("datasetProperties").get("uri") != null) {
      urn = root.path("datasetProperties").path("uri").asText();
    } else if (root.get("urn") != null) {
      urn = urnToUri(root.get("urn").asText());
    } else {
      Logger.info("Can't identify dataset URN, abort process.");
      return;
    }

    ObjectMapper om = new ObjectMapper();

    DatasetSchemaInfoRecord rec = om.convertValue(schema, DatasetSchemaInfoRecord.class);
    rec.setDatasetId(datasetId);
    rec.setDatasetUrn(urn);
    rec.setModifiedTime(System.currentTimeMillis() / 1000);

    // insert dataset and get ID if necessary
    if (datasetId == 0) {
      DatasetRecord record = new DatasetRecord();
      record.setUrn(urn);
      record.setSourceCreatedTime("" + rec.getCreateTime() / 1000);
      record.setSchema(rec.getOriginalSchema().getText());
      record.setSchemaType(rec.getOriginalSchema().getFormat());
      record.setFields((String) StringUtil.objectToJsonString(rec.getFieldSchema()));
      record.setSource("API");

      Urn urnType = new Urn(urn);
      record.setDatasetType(urnType.datasetType);
      String[] urnPaths = urnType.abstractObjectName.split("/");
      record.setName(urnPaths[urnPaths.length - 1]);

      DICT_DATASET_WRITER.append(record);
      DICT_DATASET_WRITER.close();

      datasetId = Integer.valueOf(DatasetDao.getDatasetByUrn(urn).get("id").toString());
      rec.setDatasetId(datasetId);
    }
    // if dataset already exist in dict_dataset, update info
    else {
      DICT_DATASET_WRITER.execute(UPDATE_DICT_DATASET_WITH_SCHEMA_CHANGE,
          new Object[]{rec.getOriginalSchema().getText(), rec.getOriginalSchema().getFormat(),
              StringUtil.objectToJsonString(rec.getFieldSchema()), "API", System.currentTimeMillis() / 1000, datasetId});
    }

    // get old dataset fields info
    List<Map<String, Object>> oldInfo;
    try {
      oldInfo = getDatasetFieldsByDatasetId(datasetId);
    } catch (DataAccessException ex) {
      oldInfo = new ArrayList<>();
    }

    for (DatasetFieldSchemaRecord field : rec.getFieldSchema()) {
      field.setDatasetId(datasetId);
      String fieldPath = field.getFieldPath();
      int lastIndex = fieldPath.lastIndexOf('.'); // if not found, index = -1
      field.setFieldName(fieldPath.substring(lastIndex + 1));
      field.setParentPath(lastIndex > 0 ? fieldPath.substring(0, lastIndex) : "");

      // merge old info into updated list
      for (Map<String, Object> old : oldInfo) {
        if (datasetId.equals(StringUtil.toInt(old.get("dataset_id"))) && field.getFieldName()
            .equals(old.get("field_name")) && field.getParentPath().equals(old.get("parent_path"))) {
          field.setNamespace((String) old.get("namespace"));
          field.setCommentIds((String) old.get("comment_ids"));
          field.setDefaultCommentId(StringUtil.toInt(old.get("default_comment_id")));
          field.setPartitioned("Y".equals(old.get("is_partitioned")));
          field.setIndexed("Y".equals(old.get("is_indexed")));
        }
      }
    }
    // remove old info then insert new info
    FIELD_DETAIL_WRITER.execute(DELETE_DATASET_FIELDS_BY_DATASET_ID, new Object[]{datasetId});
    if (rec.getFieldSchema().size() > 0) {
      String sql = PreparedStatementUtil.prepareInsertTemplateWithColumn(DATASET_FIELD_DETAIL_TABLE,
          rec.getFieldSchema().get(0).getFieldDetailColumns());
      for (DatasetFieldSchemaRecord field : rec.getFieldSchema()) {
        FIELD_DETAIL_WRITER.execute(sql, field.getFieldDetailValues());
      }
    }

    // insert/update new schema info
    try {
      DatasetSchemaInfoRecord result = getDatasetSchemaByDatasetId(datasetId);
      String[] columns = rec.getDbColumnNames();
      Object[] columnValues = rec.getAllValuesToString();
      String[] conditions = {"dataset_id"};
      Object[] conditionValues = new Object[]{datasetId};
      SCHEMA_WRITER.update(columns, columnValues, conditions, conditionValues);
    } catch (EmptyResultDataAccessException ex) {
      SCHEMA_WRITER.append(rec);
      SCHEMA_WRITER.insert();
    }
  }

  public static List<Map<String, Object>> getDatasetFieldsByDatasetId(int datasetId)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("dataset_id", datasetId);
    return JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_FIELDS_BY_DATASET_ID, params);
  }

  public static List<Map<String, Object>> getDatasetInventoryItems(String dataPlatform,
      String nativeName, String dataOrigin, int limit)
      throws DataAccessException {
    Map<String, Object> params = new HashMap<>();
    params.put("data_platform", dataPlatform);
    params.put("native_name", nativeName);
    params.put("data_origin", dataOrigin);
    params.put("limit", limit);
    return JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_DATASET_INVENTORY_ITEMS, params);
  }

  public static void updateDatasetInventory(JsonNode root)
      throws Exception {
    final JsonNode auditHeader = root.path("auditHeader");
    final JsonNode dataPlatform = root.path("dataPlatformUrn");
    final JsonNode datasetList = root.path("datasetList");

    if (auditHeader.isMissingNode() || dataPlatform.isMissingNode() || datasetList.isMissingNode()) {
      throw new IllegalArgumentException(
          "Dataset inventory info update fail, " + "Json missing necessary fields: " + root.toString());
    }

    final Long eventTime = auditHeader.get("time").asLong();
    final String eventDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date(eventTime));
    final String dataPlatformUrn = dataPlatform.asText();

    final ObjectMapper om = new ObjectMapper();

    for (JsonNode datasetItem : datasetList) {
      try {
        DatasetInventoryItemRecord item = om.convertValue(datasetItem, DatasetInventoryItemRecord.class);
        item.setDataPlatformUrn(dataPlatformUrn);
        item.setEventDate(eventDate);
        INVENTORY_WRITER.execute(INSERT_DATASET_INVENTORY_ITEM, item.getInventoryItemValues());
      } catch (Exception ex) {
        Logger.debug("Dataset inventory item insertion error. ", ex);
      }
    }
  }
}


text:
package ch.usi.dag.disl.utilinstr.codemerger;

import java.util.List;
import java.util.Set;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.CodeSizeEvaluator;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TryCatchBlockNode;

import ch.usi.dag.disl.dynamicbypass.DynamicBypassCheck;
import ch.usi.dag.disl.exception.DiSLFatalException;
import ch.usi.dag.disl.util.AsmHelper.ClonedCode;

public abstract class CodeMerger {

	private static final String DBCHECK_CLASS = Type.getInternalName(
			DynamicBypassCheck.class);
	private static final String DBCHECK_METHOD = "executeUninstrumented";
	private static final String DBCHECK_DESC = "()Z";

	private static final int ALLOWED_SIZE = 64 * 1024; // 64KB limit

	// NOTE: the originalCN and instrumentedCN will be destroyed in the process
	// NOTE: abstract or native methods should not be included in the
	//       changedMethods list
	public static ClassNode mergeClasses(ClassNode originalCN,
			ClassNode instrumentedCN, Set<String> changedMethods,
			boolean splitLongMethods) {

		// NOTE: that instrumentedCN can contain added fields
		//       - has to be returned

		if(changedMethods == null) {
			throw new DiSLFatalException(
					"Set of changed methods cannot be null");
		}

		// no changed method - no merging
		if (changedMethods.isEmpty()) {
			return instrumentedCN;
		}

		// merge methods one by one
		for (MethodNode instrMN : instrumentedCN.methods) {

			// We will construct the merged method node in the instrumented
			// class node

			// skip unchanged methods
			if(! changedMethods.contains(instrMN.name + instrMN.desc)) {
				continue;
			}

			MethodNode origMN = getMethodNode(originalCN, instrMN.name,
					instrMN.desc);

			InsnList ilist = instrMN.instructions;
			List<TryCatchBlockNode> tcblist = instrMN.tryCatchBlocks;

			// crate copy of the original instruction list
			// this copy will be destroyed during merging
			// we need the original code if the method is too long
			ClonedCode origCodeCopy = ClonedCode.create (
				origMN.instructions, origMN.tryCatchBlocks
			);

			// create copy of the lists for splitting
			ClonedCode splitCopy = null;
			if (splitLongMethods) {
				splitCopy = ClonedCode.create (ilist, tcblist);
			}

			// add reference to the original code
			LabelNode origCodeL = new LabelNode();
			ilist.add(origCodeL);

			// add original code
			ilist.add(origCodeCopy.getInstructions());
			// add exception handlers of the original code
			tcblist.addAll(origCodeCopy.getTryCatchBlocks());

			// if the dynamic bypass is activated (non-zero value returned)
			// then jump to original code
			ilist.insert(new JumpInsnNode(Opcodes.IFNE, origCodeL));
			ilist.insert(new MethodInsnNode(Opcodes.INVOKESTATIC,
					DBCHECK_CLASS, DBCHECK_METHOD, DBCHECK_DESC));

			// calculate the code size and if it is larger then allowed size,
			// skip it
			CodeSizeEvaluator cse = new CodeSizeEvaluator(null);
			instrMN.accept(cse);

			if (cse.getMaxSize() > ALLOWED_SIZE) {

				if(splitLongMethods) {

					// return originally instrumented code back to the instrMN
					instrMN.instructions = splitCopy.getInstructions();
					instrMN.tryCatchBlocks = splitCopy.getTryCatchBlocks();

					// split methods
					splitLongMethods(instrumentedCN, origMN, instrMN);

					// next method
					continue;
				}

				// insert original code into the instrumented method node
				instrMN.instructions = origMN.instructions;
				instrMN.tryCatchBlocks = origMN.tryCatchBlocks;

				// print error msg
				System.err.println("WARNING: code of the method "
						+ instrumentedCN.name + "." + instrMN.name
						+ " is larger ("
						+ cse.getMaxSize()
						+ ") then allowed size (" +
						+ ALLOWED_SIZE
						+ ") - skipping");
			}
		}

		return instrumentedCN;
	}

	private static void splitLongMethods(ClassNode instrumentedCN,
			MethodNode origMN, MethodNode instrMN) {

		// TODO jb ! add splitting for to long methods
		//  - ignore clinit - output warning
		//  - output warning if splitted is to large and ignore

		// check the code size of the instrumented method
		// add if to the original method that jumps to the renamed instrumented method
		// add original method to the instrumented code
		// rename instrumented method
	}

	private static MethodNode getMethodNode(ClassNode cnToSearch,
			String methodName, String methodDesc) {

		for (MethodNode mn : cnToSearch.methods) {
			if (methodName.equals(mn.name) && methodDesc.equals(mn.desc)) {
				return mn;
			}
		}

		throw new RuntimeException(
				"Code merger fatal error: method for merge not found");
	}
}


text:
<!--
id: 994588872
link: http://tumblr.atmos.org/post/994588872/typewith-me-live-text-document-collaboration
slug: typewith-me-live-text-document-collaboration
date: Sun Aug 22 2010 14:36:36 GMT-0700 (PDT)
publish: 2010-08-022
tags:
title: TypeWith.me: Live Text Document Collaboration!
-->

TypeWith.me: Live Text Document Collaboration!
==============================================

[http://typewith.me/](http://typewith.me/)


text:
package co.nubetech.hiho.merge;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.log4j.Logger;

import co.nubetech.hiho.common.HIHOConf;
import co.nubetech.hiho.dedup.HihoTuple;

public class MergeKeyMapper<K extends Writable, V extends Writable> extends
		Mapper<K, V, HihoTuple<K>, HihoValue<V>> {

	final static Logger logger = Logger
			.getLogger(co.nubetech.hiho.dedup.DedupKeyMapper.class);
	protected Boolean isOld;

	@Override
	protected void setup(Mapper.Context context) throws IOException,
			InterruptedException {

		Configuration conf = context.getConfiguration();
		InputSplit is = context.getInputSplit();
		FileSplit fs = (FileSplit) is;
		Path splitPath = fs.getPath();

		if (splitPath.toString().contains(conf.get(HIHOConf.MERGE_OLD_PATH))) {
			isOld = true;
		} else if (splitPath.toString().contains(
				conf.get(HIHOConf.MERGE_NEW_PATH))) {
			isOld = false;
		} else {
			throw new IOException("File " + splitPath
					+ " is not under new path"
					+ conf.get(HIHOConf.MERGE_NEW_PATH) + " and old path"
					+ conf.get(HIHOConf.MERGE_OLD_PATH));
		}
	}

	@Override
	public void map(K key, V val, Context context) throws IOException,
			InterruptedException {
		if (key == null) {
			context.getCounter(MergeRecordCounter.BAD_RECORD).increment(1l);
			throw new IOException("Key is null");
		}
		if (isOld) {
			context.getCounter(MergeRecordCounter.TOTAL_RECORDS_OLD).increment(
					1l);
		} else {
			context.getCounter(MergeRecordCounter.TOTAL_RECORDS_NEW).increment(
					1l);
		}
		HihoValue<V> hihoValue = new HihoValue<V>();
		hihoValue.setVal(val);
		hihoValue.setIsOld(isOld);
		HihoTuple<K> hihoTuple = new HihoTuple<K>();
		hihoTuple.setKey(key);
		context.write(hihoTuple, hihoValue);
	}

}