📄 userbean.java
字号:
package com.wiley.compBooks.EJwithUML.TimeCardDomain;
import com.wiley.compBooks.EJwithUML.Base.EjbUtil.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
/**
* The User bean holds descriptive information about a User.
* UserBean is the actual entity bean implementation.
*/
public abstract class UserBean extends BasicEntityBean implements UserInt
{
private TimecardLocal currentTimecard;
/** CMP fields */
public abstract String getId();
public abstract void setId(String id);
public abstract String getName();
public abstract void setName(String name);
public abstract String getPassword();
public abstract void setPassword(String password);
public abstract boolean getPasswordChangeFlag();
public abstract void setPasswordChangeFlag(boolean flag);
public TimecardLocal getCurrentTimecard()
{
try
{
if (this.currentTimecard == null)
{
Context initialContext = new InitialContext();
TimecardLocalHome thome = (TimecardLocalHome) initialContext.lookup(
EjbReferenceNames.TIMECARD_HOME);
Collection tcards = thome.findCurrentTimecardForUser(this.getId());
//there should be atmost one timecard marked as current
if (tcards.size() == 1)
{
this.currentTimecard = (TimecardLocal)tcards.iterator().next();
}
}
}
catch(NamingException e)
{
//do nothing
}
catch(FinderException e)
{
//do nothing
}
return currentTimecard;
}
public void setCurrentTimecard(TimecardLocal currentTimecard)
{
this.currentTimecard=currentTimecard;
}
/** Create an EmployeeBean with the specified parameters. This is never called directly. */
public UserPK ejbCreate(String id, String name, String password,
boolean passwordFlag) throws CreateException
{
try
{
setId(id);
setName(name);
setPassword(password);
setPasswordChangeFlag(passwordFlag);
Context initialContext = new InitialContext();
TimecardLocalHome thome = (TimecardLocalHome) initialContext.lookup(
EjbReferenceNames.TIMECARD_HOME);
Collection tcards = thome.findCurrentTimecardForUser(id);
//there should be atmost one timecard marked as current
if (tcards.size() == 1)
{
this.currentTimecard = (TimecardLocal)tcards.iterator().next();
}
else if(tcards.size()>1)
{
throw new CreateException("more than one timecard are marked as current.");
}
return null;
}
catch(Exception exp)
{
throw new CreateException("failed to lookup current timecard-" + exp.toString());
}
}
/** Actions performed after creation. This is never called directly. */
public void ejbPostCreate(String id, String name, String password, boolean passwordFlag)
{
}
/** Answers true if the entered password matches this Employee's password. */
public boolean isPasswordValid(String entered)
{
return getPassword().equals(entered);
}
/** Answers true if the password should be changed. */
public boolean isPasswordChangeRequired()
{
return getPasswordChangeFlag();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -