📄 threadbean.java
字号:
package com.bitterjava.bbs.ejb;
import java.rmi.RemoteException;
import java.security.Identity;
import java.util.Properties;
import javax.ejb.*;
/**
* This is an Entity Bean class with CMP fields
*/
public class ThreadBean implements EntityBean {
public String boardName;
private javax.ejb.EntityContext entityContext = null;
public String name;
final static long serialVersionUID = 3206093459760846163L;
public int threadID;
private java.util.Vector posts;
private PostHome postHome = null;
/**
* This method was generated for supporting the associations.
* @return java.util.Vector
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
protected java.util.Vector _getLinks() {
java.util.Vector links = new java.util.Vector();
return links;
}
/**
* This method was generated for supporting the associations.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
protected void _initLinks() {}
/**
* This method was generated for supporting the associations.
* @exception java.rmi.RemoteException The exception description.
* @exception javax.ejb.RemoveException The exception description.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
protected void _removeLinks() throws java.rmi.RemoteException, javax.ejb.RemoveException {
java.util.Enumeration links = _getLinks().elements();
while (links.hasMoreElements()) {
try {
((com.ibm.ivj.ejb.associations.interfaces.Link) (links.nextElement())).remove();
}
catch (javax.ejb.FinderException e) {} //Consume Finder error since I am going away
}
}
/**
* Insert the method's description here.
* Creation date: (9/25/2001 2:06:15 PM)
* @return int
* @param author java.lang.String
* @param date java.util.Date
* @param subject java.lang.String
* @param text java.lang.String
*/
public int addPost(String author, java.util.Date date, String subject, String text) throws RemoteException, CreateException {
int nextID = 0;
for (int i = 0; i < posts.size(); i++) {
Post post = resolvePost(i);
int postID = post.getPostID();
nextID = Math.max(nextID, postID+1);
}
Post newPost = getPostHome().create(boardName, nextID, threadID);
newPost.setAuthor(author);
newPost.setDate(new java.sql.Date(date.getTime()));
newPost.setSubject(subject);
newPost.setText(text);
posts.addElement(newPost);
return nextID;
}
/**
* ejbActivate method comment
* @exception java.rmi.RemoteException The exception description.
*/
public void ejbActivate() throws java.rmi.RemoteException {
_initLinks();
}
/**
* ejbCreate method for a CMP entity bean
* @param argBoardName java.lang.String
* @param argThreadID int
* @exception javax.ejb.CreateException The exception description.
* @exception java.rmi.RemoteException The exception description.
*/
public void ejbCreate(java.lang.String argBoardName, int argThreadID) throws javax.ejb.CreateException, java.rmi.RemoteException {
_initLinks();
// All CMP fields should be initialized here.
boardName = argBoardName;
threadID = argThreadID;
name = "";
posts = new java.util.Vector();
}
/**
* ejbLoad method comment
* @exception java.rmi.RemoteException The exception description.
*/
public void ejbLoad() throws java.rmi.RemoteException {
_initLinks();
try {
posts = new java.util.Vector();
java.util.Enumeration e = getPostHome().findAllForThread(boardName, threadID);
while (e.hasMoreElements()) {
posts.addElement(e.nextElement());
}
}
catch (FinderException e) {
}
catch (NullPointerException e) {
}
}
/**
* ejbPassivate method comment
* @exception java.rmi.RemoteException The exception description.
*/
public void ejbPassivate() throws java.rmi.RemoteException {}
/**
* ejbPostCreate method for a CMP entity bean
* @param argBoardName java.lang.String
* @param argThreadID int
* @exception java.rmi.RemoteException The exception description.
*/
public void ejbPostCreate(java.lang.String argBoardName, int argThreadID) throws java.rmi.RemoteException {}
/**
* ejbRemove method comment
* @exception java.rmi.RemoteException The exception description.
* @exception javax.ejb.RemoveException The exception description.
*/
public void ejbRemove() throws java.rmi.RemoteException, javax.ejb.RemoveException {
_removeLinks();
removeAllPosts();
}
/**
* ejbStore method comment
* @exception java.rmi.RemoteException The exception description.
*/
public void ejbStore() throws java.rmi.RemoteException {}
/**
* Insert the method's description here.
* Creation date: (9/25/2001 1:52:03 PM)
* @return java.lang.String
*/
public String getBoardName() {
return boardName;
}
/**
* getEntityContext method comment
* @return javax.ejb.EntityContext
*/
public javax.ejb.EntityContext getEntityContext() {
return entityContext;
}
/**
* Getter method for name
* @return java.lang.String
*/
public java.lang.String getName() {
return name;
}
/**
* Insert the method's description here.
* Creation date: (9/25/2001 4:56:27 PM)
* @return com.bitterjava.bbs.ejb.Post
* @param postID int
* @exception java.rmi.RemoteException The exception description.
*/
public Post getPost(int postID) throws java.rmi.RemoteException {
Post rcPost = null;
for (int i = 0; i < posts.size(); i++) {
Post thisPost = resolvePost(i);
int thisID = thisPost.getPostID();
if (thisID == postID) {
rcPost = thisPost;
break;
}
}
return rcPost;
}
/**
* Insert the method's description here.
* Creation date: (9/25/2001 2:01:08 PM)
* @return com.bitterjava.bbs.ejb.PostHome
*/
private PostHome getPostHome() {
if (postHome == null) {
try {
Properties env = entityContext.getEnvironment();
String providerURL = env.getProperty("providerURL");
String postHomeName = env.getProperty("postHomeName");
String ctxFactory = env.getProperty("ctxFactory");
Properties p = new Properties();
p.put("java.naming.provider.url", providerURL);
p.put("java.naming.factory.initial", ctxFactory);
javax.naming.InitialContext ic = new javax.naming.InitialContext(p);
java.lang.Object homeObject = ic.lookup(postHomeName);
postHome = (PostHome)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)homeObject, PostHome.class);
}
catch (Exception e) {
}
}
return postHome;
}
/**
* Insert the method's description here.
* Creation date: (9/25/2001 2:04:46 PM)
* @return java.util.Collection
*/
public java.util.Collection getPosts() {
return posts;
}
/**
* Insert the method's description here.
* Creation date: (9/25/2001 1:43:35 PM)
* @return int
*/
public int getThreadID() {
return threadID;
}
/**
* Insert the method's description here.
* Creation date: (9/26/2001 10:23:53 PM)
* @exception java.rmi.RemoteException The exception description.
* @exception javax.ejb.RemoveException The exception description.
*/
public void removeAllPosts() throws java.rmi.RemoteException, javax.ejb.RemoveException {
for (int i = 0; i < posts.size(); i++) {
Post thisPost = resolvePost(i);
thisPost.remove();
}
posts = new java.util.Vector();
}
/**
* Insert the method's description here.
* Creation date: (9/25/2001 2:14:20 PM)
* @param post com.bitterjava.bbs.ejb.Post
*/
public void removePost(Post post) throws RemoteException, RemoveException {
for (int i = 0; i < posts.size(); i++) {
Post thisPost = resolvePost(i);
if (thisPost.isIdentical(post)) {
posts.remove(i);
thisPost.remove();
break;
}
}
}
/**
* Insert the method's description here.
* Creation date: (9/27/2001 9:52:05 AM)
* @return com.bitterjava.bbs.ejb.Post
* @param postIndex int
*/
private Post resolvePost(int postIndex) {
java.lang.Object o = posts.elementAt(postIndex);
Post postEjb = (Post)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)o, Post.class);
return postEjb;
}
/**
* setEntityContext method comment
* @param ctx javax.ejb.EntityContext
* @exception java.rmi.RemoteException The exception description.
*/
public void setEntityContext(javax.ejb.EntityContext ctx) throws java.rmi.RemoteException {
entityContext = ctx;
}
/**
* Setter method for name
* @param newValue java.lang.String
*/
public void setName(java.lang.String newValue) {
this.name = newValue;
}
/**
* unsetEntityContext method comment
* @exception java.rmi.RemoteException The exception description.
*/
public void unsetEntityContext() throws java.rmi.RemoteException {
entityContext = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -