⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataloaderbean.java

📁 考勤管理系统源码
💻 JAVA
字号:
package com.wiley.compBooks.EJwithUML.TimeCardWorkflow;

import com.wiley.compBooks.EJwithUML.Base.EjbUtil.*;
import com.wiley.compBooks.EJwithUML.Dtos.*;
import com.wiley.compBooks.EJwithUML.TimeCardDomain.*;
import com.wiley.compBooks.EJwithUML.Base.ApplicationExceptions.*;
import java.util.*;
import java.rmi.*;
import javax.ejb.*;
import javax.naming.*;
import java.sql.SQLException;
import java.util.logging.*;


/**
 * The DataLoader allows test clients to load test data for the TimeCard Application.
 *
 * DataLoaderBean is the actual session bean implementation.
 *
 */
public class DataLoaderBean extends BasicSessionBean implements DataLoaderInt
{
  public void ejbCreate() throws CreateException
  {
  }

  public void ejbPostCreate()
  {
  }

  /** Creates a Client. */
  public void createClient(long clientId, String name, String description)
      throws CreateException
  {
    try
    {
      System.out.println("In createClient()");
      Context initialContext = getInitialContext();
      ClientLocalHome chome = (ClientLocalHome) initialContext.lookup(
                                                EjbReferenceNames.CLIENT_HOME);
      chome.create(clientId, name, description);
      System.out.println("Done DataLoaderBean.createClient()");
    }
    catch (NamingException e)
    {
      throw new CreateException("Client Bean Not Found");
    }
  }

  /** Creates a Project. */
  public void createProject(long projectId, String name, String description,
                            long clientId) throws CreateException
  {
    try
    {
      System.out.println("In createProject");
      Context initialContext = getInitialContext();
      ProjectLocalHome phome = (ProjectLocalHome) initialContext.lookup(
                                               EjbReferenceNames.PROJECT_HOME);
      ClientLocalHome chome = (ClientLocalHome)initialContext.lookup(
                                                 EjbReferenceNames.CLIENT_HOME);
      ClientLocal client = chome.findByPrimaryKey(new ClientPK(clientId));
      phome.create(projectId, name, description, client);
      System.out.println("Done createProject");
    }
    catch (NamingException e)
    {
      throw new CreateException("Client/Project Bean Not Found.");
    }
    catch (FinderException e)
    {
      throw new CreateException("Client Not Found.");
    }


  }

  /** Creates a ChargeCode. */
  public void createChargeCode(long ccodeId, String name, String description,
                               long projectId) throws CreateException
  {
    try
    {
      System.out.println("In createChargeCode");
      Context initialContext = getInitialContext();
      ChargeCodeLocalHome cchome = (ChargeCodeLocalHome)initialContext.lookup(
                                             EjbReferenceNames.CHARGECODE_HOME);
      ProjectLocalHome phome = (ProjectLocalHome) initialContext.lookup(
                                                EjbReferenceNames.PROJECT_HOME);
      ProjectLocal project = phome.findByPrimaryKey(new ProjectPK(projectId));
      cchome.create(ccodeId, name, description, project);
      System.out.println("Done createChargeCode");
    }
    catch (NamingException e)
    {
      throw new CreateException("ChargeCode/Project Bean Not Found");
    }
    catch (FinderException e)
    {
      throw new CreateException("Project Not Found");
    }
  }

  /** Creates a User. */
  public void createUser(String userId, String name, String password,
                         boolean isPasswordTemp) throws CreateException
  {
    try
    {
      System.out.println("In createUser");
      Context initialContext = getInitialContext();
      UserLocalHome uhome = (UserLocalHome)initialContext.lookup(
                             EjbReferenceNames.USER_HOME);
      uhome.create(userId, name, password, isPasswordTemp);
      System.out.println("Done createUser");
    }
    catch (NamingException e)
    {
      throw new CreateException("User Bean Not Found");
    }

  }

  /** Creates a Timecard. */
  public void createTimecard(String cardId, Date startDate, Date endDate,
                             boolean isCurrent, String userId)
      throws CreateException
  {
    try
    {
      System.out.println("In createTimecard");
      Context initialContext = getInitialContext();
      UserLocalHome uhome = (UserLocalHome)initialContext.lookup(
                             EjbReferenceNames.USER_HOME);
      UserLocal user = uhome.findByPrimaryKey(new UserPK(userId));
      TimecardLocalHome thome = (TimecardLocalHome) initialContext.lookup(
                                EjbReferenceNames.TIMECARD_HOME);
      if (user == null)
      {
        throw new CreateException("could not find user" + userId);
      }
      thome.create(cardId, startDate, endDate, isCurrent, user);
      System.out.println("Done createTimecard");
    }
    catch (NamingException e)
    {
      throw new CreateException("User/Timecard Bean Not Found");
    }
    catch (FinderException e)
    {
      throw new CreateException("User Not Found");
    }
  }

  /** Creates a TimeEntry. */
  public void createTimeEntry(String tentryId, Date date, int hours, long ccodeId,
                              String cardId) throws CreateException
  {
    try
    {
      System.out.println("In createTimeEntry");
      Context initialContext = getInitialContext();
      TimecardLocalHome tchome = (TimecardLocalHome)initialContext.lookup(
                                 EjbReferenceNames.TIMECARD_HOME);
      TimecardLocal tcard = (TimecardLocal)tchome.findByPrimaryKey(new TimecardPK(cardId));
      ChargeCodeLocalHome chome = (ChargeCodeLocalHome) initialContext.lookup(
                                   EjbReferenceNames.CHARGECODE_HOME);
      ChargeCodeLocal ccode = chome.findByPrimaryKey(new ChargeCodePK(ccodeId));
      TimeEntryLocalHome tehome = (TimeEntryLocalHome)initialContext.lookup(
                                  EjbReferenceNames.TIME_ENTRY_HOME);
      if (ccode == null)
      {
        throw new CreateException("could not find ccode-" + ccodeId);
      }
      if (tcard == null)
      {
        throw new CreateException("could not find tcard-" + cardId);
      }
      tehome.create(tentryId, date, hours, ccode, tcard);
      System.out.println("Done createTimeEntry");
    }
    catch (NamingException e)
    {
      throw new CreateException("Timecard/ChargeCode/TimeEntry Bean Not Found");
    }
    catch (FinderException e)
    {
      throw new CreateException("Timecard/ChargeCode Not Found");
    }
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -