/*
 * 
 * 新規
 * 2011/2/13
 * 孫奇全
 * 
 */
package com.aimluck.eip.exttimecard;

import java.util.ArrayList;
import java.util.List;

import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.SelectQuery;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;

import com.aimluck.eip.cayenne.om.portlet.ImwTExtTimecardSystemDetail;
import com.aimluck.eip.common.ALAbstractCheckList;
import com.aimluck.eip.orm.DatabaseOrmService;

/**
 * ワークフローカテゴリの複数削除を行うためのクラスです。 <BR>
 *
 */
public class ExtTimecardSystemDetailMultiDelete extends ALAbstractCheckList {

  /** logger */
  private static final JetspeedLogger logger = JetspeedLogFactoryService
      .getLogger(ImwTExtTimecardSystemDetail.class.getName());

  /**
   *
   * @param rundata
   * @param context
   * @param values
   * @param msgList
   * @return
   * @see com.aimluck.eip.common.ALAbstractCheckList#action(org.apache.turbine.util.RunData,
   *      org.apache.velocity.context.Context, java.util.ArrayList,
   *      java.util.ArrayList)
   */
  protected boolean action(RunData rundata, Context context, ArrayList values,
      ArrayList msgList) {
    try {
      DataContext dataContext = DatabaseOrmService.getInstance()
          .getDataContext();

      List intValues = new ArrayList();
      int valuesize = values.size();
      for (int i = 0; i < valuesize; i++) {
        String value = (String) values.get(i);
        //if (!"1".equals(value)) {
          intValues.add(Integer.valueOf(value));
        //}
      }

      SelectQuery query = new SelectQuery(ImwTExtTimecardSystemDetail.class);
      Expression exp1 = ExpressionFactory.inDbExp(
          ImwTExtTimecardSystemDetail.SYSTEM_DETAIL_ID_PK_COLUMN, intValues);
      query.setQualifier(exp1);
      List list = dataContext.performQuery(query);
      if (list == null || list.size() == 0)
        return false;

      dataContext.deleteObjects(list);

      dataContext.commitChanges();
    } catch (Exception ex) {
      logger.error("Exception", ex);
      return false;
    }
    return true;
  }

}
