📄 usertestassocbean.java
字号:
/* * SchoolEJB - CyberDemia's library of EJBs for educational related services. * Copyright (C) 2003 CyberDemia Research and Services * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * See the COPYING file located in the top-level-directory of * the archive of this library for complete text of license. */package com.cyberdemia.school.impl;import javax.ejb.*;import com.cyberdemia.school.*;import java.util.Date;/*** UserTestAssocBean represents a Test that is assigned to a User,* and records a score for a user for a test, etc.** @author Alexander Yap*/public abstract class UserTestAssocBean implements EntityBean{ /** * Gets the User ID of this association. * @return User ID. */ public abstract String getUserId(); /** * Sets the User ID of this association. * @param userId User ID of this association. */ public abstract void setUserId(String userId); /** * Gets the Test ID that is assigned to the User. * @return Test ID. */ public abstract String getTestId(); /** * Sets the Test ID that is assigned to the User. * @param testId Test ID that is assigned to the User. */ public abstract void setTestId(String testId); /** * Gets the current score as an int. * @return Current score */ public abstract int getScore(); /** * Sets the current score as an int. * @param val Current score */ public abstract void setScore(int val); /** * Gets the exceeded test time flag. * @return true if this test's time limit has been exceeded. */ public abstract boolean getExceededTestTime(); /** * Sets the exceeded test time flag. * @param exceeded true if this test's time limit has been exceeded. */ public abstract void setExceededTestTime(boolean exceeded); /** * Gets the maximum score as an int. * This is the maximum value that score can be. * @return Maximum score */ public abstract int getMaxScore(); /** * Sets the maximum score as an int. * @param val Maximum score */ public abstract void setMaxScore(int val); /** * Gets the last modified datetime in milliseconds. * @return Date in milliseconds when this association was last modified/updated. */ public abstract long getLastModifiedMillis(); /** * Sets the last modified datetime in milliseconds. * @param millis Date in milliseconds when this association was last modified/updated. */ public abstract void setLastModifiedMillis(long millis); /** * Gets the last modified datetime. * @return Date when this association was last modified/updated. */ public Date getLastModifiedDateTime() { return new Date(getLastModifiedMillis()); } /** * Sets the last modified datetime. * @param dt Date when this association was last modified/updated. */ public void setLastModifiedDateTime(Date dt) { setLastModifiedMillis(dt.getTime()); } /** * Adds value and the maximum value to score. * @param val Value to add. * @param maxVal The maximum value that val can be. * @return New score. */ public int addScore(int val, int maxVal) { int newVal = getScore() + Math.min(val,maxVal); int newMaxVal = getMaxScore() + maxVal; setScore( newVal ); setMaxScore(newMaxVal); setLastModifiedDateTime( new Date()); return newVal; } /** * Mark that the user has exceeded the time limit for this test. * Once marked as true, it cannot be unmarked. */ public void exceededTestTime() { setExceededTestTime(true); } /** * Checks if the user has exceeded the time limit for this test. * @return true if this test's time limit has been exceeded. */ public boolean isExceededTestTime() { return getExceededTestTime(); } //----------------------------- // Create methods. //----------------------------- public UserTestAssocKey ejbCreate( String testId, String userId) throws CreateException { setUserId(userId); setTestId(testId); setScore(0); setMaxScore(0); setLastModifiedDateTime( new Date()); setExceededTestTime(false); return null; } public void ejbPostCreate( String testId, String userId ) { } //----------------------------- // Container methods. Override in subclasses if appropriate. //----------------------------- public void setEntityContext(EntityContext ctx) { } public void ejbActivate() { } public void ejbPassivate() { } public void ejbLoad() { } public void ejbStore() { } public void ejbRemove() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -