/*
 * SampleDbCreateAction.java
 *
 * Created on 2007/02/01, 10:23
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package weber_4_0_sample.org.itscool.sample_db;

import org.itscool.commons.connection.Transaction;
import org.itscool.commons.connection.TransactionUtil;
import org.itscool.commons.dao.Criteria;
import org.itscool.weber.action.Action;
import org.itscool.weber.action.ActionBucket;
import org.itscool.weber.user.User;
import org.itscool.weber.user.UserDao;
import org.itscool.weber.user.Role;
import org.itscool.weber.user.RoleDao;

/**
 *
 * @author kano
 */
public class SampleDbCreateAction extends Action {
    
    public String doExecute(ActionBucket bucket){
        UserDao userDao = new UserDao();
        Criteria userCrt = new Criteria(User.class);
        userDao.delete(userCrt);
        
        RoleDao roleDao = new RoleDao();
        Criteria roleCrt = new Criteria(Role.class);
        roleDao.delete(roleCrt);
        
        Role role = new Role();
        role.setId(1);
        role.setName("admin");
        roleDao.save(role);
        
        User user = new User();
        user.setRole(role);
        user.setRoleId(role.getId());
        user.setName("admin");
        user.setPwd("admin");
        
        userDao.save(user);
        
        bucket.setAttribute("message", "adminユーザ情報を作成しました");
        
        return "index";
    }
}
