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

📄 boardfacadebean.java

📁 用java编写的留言版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * setSessionContext method comment
 * @param ctx javax.ejb.SessionContext
 * @exception java.rmi.RemoteException The exception description.
 */
public void setSessionContext(javax.ejb.SessionContext ctx) throws java.rmi.RemoteException {
	mySessionCtx = ctx;
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 4:02:10 PM)
 * @return java.util.List
 * @param boardName java.lang.String
 * @param threadID int
 * @exception java.rmi.RemoteException The exception description.
 */
public java.util.List getBoardNames() throws java.rmi.RemoteException {
	java.util.Vector names = new java.util.Vector();
	
	java.sql.Connection conn = null;
	java.sql.PreparedStatement stmt = null;
	java.sql.ResultSet rs = null;

	try {
		conn = getPooledConnection();
		String sqlString = "SELECT DB2ADMIN.BOARD.NAME AS NAME FROM DB2ADMIN.BOARD";
		stmt = conn.prepareStatement(sqlString);
		rs = stmt.executeQuery();
		marshalBoardNames(rs, names);
	}
	catch (Exception e) {
		throw new RemoteException("Database exception: " + e);
	}
	finally {
		if (rs != null) { try { rs.close(); } catch (java.sql.SQLException e) {}}
		if (stmt != null) { try { stmt.close(); } catch (java.sql.SQLException e) {}}
		if (conn != null) { try { conn.close(); } catch (java.sql.SQLException e) {}}
	}
	
	return names;
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 3:50:04 PM)
 * @return java.sql.Connection
 * @param dataSource java.lang.String
 * @param driver java.lang.String
 * @param URL java.lang.String
 * @param userID java.lang.String
 * @param password java.lang.String
 */
private java.sql.Connection getPooledConnection() {
	Properties env = mySessionCtx.getEnvironment();
	String dataSource = env.getProperty("dataSource");
	String ctxFactory = env.getProperty("ctxFactory");
	String driverName = env.getProperty("jdbcDriver");
	String URL = env.getProperty("dbURL");
	String userID = env.getProperty("dbUserID");
	String password = env.getProperty("dbPassword");
	return getPooledConnection(dataSource, ctxFactory, driverName, URL, userID, password);
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 3:50:04 PM)
 * @return java.sql.Connection
 * @param dataSource java.lang.String
 * @param driver java.lang.String
 * @param URL java.lang.String
 * @param userID java.lang.String
 * @param password java.lang.String
 */
private java.sql.Connection getPooledConnection(String dataSource, String ctxFactory, String driver, String URL, String userID, String password) {
    java.sql.Connection conn = null;

    try {
        Properties parms = new Properties();
        parms.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, ctxFactory);
        javax.naming.Context context = new javax.naming.InitialContext(parms);
        javax.sql.DataSource ds = (javax.sql.DataSource) context.lookup(dataSource);
        conn = ds.getConnection(userID, password);
    }
    catch (Throwable t) {
        // DataSource not found. Use a standard JDBC Connection
        try {
            Class.forName(driver);
            conn = java.sql.DriverManager.getConnection(URL, userID, password);
        }
        catch (Throwable t2) {
            t2.printStackTrace();
        }
    }

    return conn;
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 9:55:04 PM)
 * @return com.bitterjava.bbs.ejb.Post
 * @param boardName java.lang.String
 * @param threadID int
 * @param postID int
 * @exception java.rmi.RemoteException The exception description.
 * @exception javax.ejb.FinderException The exception description.
 */
public com.bitterjava.bbs.Post getPost(String boardName, int threadID, int postID) throws java.rmi.RemoteException, javax.ejb.FinderException {
	Post post = getPostHome().findByPrimaryKey(new PostKey(boardName, threadID, postID));
	return marshalDataObject(post);;
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 4:02:10 PM)
 * @return java.util.List
 * @param boardName java.lang.String
 * @param threadID int
 * @exception java.rmi.RemoteException The exception description.
 */
public java.util.List getPostHeaders(String boardName, int threadID) throws java.rmi.RemoteException {
	java.util.Vector headers = new java.util.Vector();
	
	java.sql.Connection conn = null;
	java.sql.PreparedStatement stmt = null;
	java.sql.ResultSet rs = null;

	try {
		conn = getPooledConnection();
		String sqlString = "SELECT DB2ADMIN.POST.SUBJECT AS SUBJECT, DB2ADMIN.POST.AUTHOR AS AUTHOR, DB2ADMIN.POST.POSTID AS POSTID, DB2ADMIN.POST.DATE AS DATE FROM DB2ADMIN.POST WHERE ((DB2ADMIN.POST.BOARDNAME = ?) AND (DB2ADMIN.POST.THREADID = ?)) ORDER BY POSTID";
		stmt = conn.prepareStatement(sqlString);
		stmt.setString(1, boardName);
		stmt.setInt(2, threadID);
		rs = stmt.executeQuery();
		marshalPostHeaders(rs, headers);
	}
	catch (Exception e) {
		throw new RemoteException("Database exception: " + e);
	}
	finally {
		if (rs != null) { try { rs.close(); } catch (java.sql.SQLException e) {}}
		if (stmt != null) { try { stmt.close(); } catch (java.sql.SQLException e) {}}
		if (conn != null) { try { conn.close(); } catch (java.sql.SQLException e) {}}
	}
	
	return headers;
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 4:02:10 PM)
 * @return java.util.List
 * @param boardName java.lang.String
 * @param threadID int
 * @exception java.rmi.RemoteException The exception description.
 */
public java.util.List getThreadHeaders(String boardName) throws java.rmi.RemoteException {
	java.util.Vector headers = new java.util.Vector();
	
	java.sql.Connection conn = null;
	java.sql.PreparedStatement stmt = null;
	java.sql.ResultSet rs = null;

	try {
		conn = getPooledConnection();
		String sqlString = "SELECT DB2ADMIN.THREAD.THREADID AS THREADID, DB2ADMIN.THREAD.NAME AS NAME FROM DB2ADMIN.THREAD WHERE (DB2ADMIN.THREAD.BOARDNAME = ?)";
		stmt = conn.prepareStatement(sqlString);
		stmt.setString(1, boardName);
		rs = stmt.executeQuery();
		marshalThreadHeaders(rs, headers);
	}
	catch (Exception e) {
		throw new RemoteException("Database exception: " + e);
	}
	finally {
		if (rs != null) { try { rs.close(); } catch (java.sql.SQLException e) {}}
		if (stmt != null) { try { stmt.close(); } catch (java.sql.SQLException e) {}}
		if (conn != null) { try { conn.close(); } catch (java.sql.SQLException e) {}}
	}
	
	return headers;
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 4:15:45 PM)
 * @param rs java.sql.ResultSet
 * @param headers java.util.List
 */
private void marshalBoardNames(java.sql.ResultSet rs, java.util.List names) throws java.sql.SQLException {
	while (rs.next()) {
		String name = rs.getString(1);
		names.add(name);
	}
}

/**
 * Insert the method's description here.
 * Creation date: (9/27/2001 10:31:29 AM)
 * @return com.bitterjava.bbs.ejb.Post
 * @param postEjb com.bitterjava.bbs.ejb.Post
 */
private com.bitterjava.bbs.Board marshalDataObject(Board boardEjb) throws RemoteException {
	com.bitterjava.bbs.Board board = new com.bitterjava.bbs.Board();
	board.setName(boardEjb.getName());

	java.util.Vector threads = new java.util.Vector();
	java.util.Collection threadEjbs = boardEjb.getThreads();
	java.util.Iterator iter = threadEjbs.iterator();
	while (iter.hasNext()) {
		java.lang.Object o = iter.next();
		com.bitterjava.bbs.ejb.Thread threadEjb = resolveThread(o);
		com.bitterjava.bbs.Thread thread = marshalDataObject(threadEjb);
		threads.addElement(thread);
	}
		
	board.setThreads(threads);
	return board;
}

/**
 * Insert the method's description here.
 * Creation date: (9/27/2001 10:31:29 AM)
 * @return com.bitterjava.bbs.ejb.Post
 * @param postEjb com.bitterjava.bbs.ejb.Post
 */
private com.bitterjava.bbs.Post marshalDataObject(Post postEjb) throws RemoteException {
	com.bitterjava.bbs.Post post = new com.bitterjava.bbs.Post();
	post.setAuthor(postEjb.getAuthor());
	post.setDate(postEjb.getDate());
	post.setPostID(postEjb.getPostID());
	post.setSubject(postEjb.getSubject());
	post.setText(postEjb.getText());
	return post;
}

/**
 * Insert the method's description here.
 * Creation date: (9/27/2001 10:31:29 AM)
 * @return com.bitterjava.bbs.ejb.Post
 * @param postEjb com.bitterjava.bbs.ejb.Post
 */
private com.bitterjava.bbs.Thread marshalDataObject(Thread threadEjb) throws RemoteException {
	com.bitterjava.bbs.Thread thread = new com.bitterjava.bbs.Thread();
	thread.setName(threadEjb.getName());
	thread.setThreadID(threadEjb.getThreadID());
			
	java.util.Vector posts = new java.util.Vector();
	java.util.Collection postEjbs = threadEjb.getPosts();
	java.util.Iterator iter = postEjbs.iterator();
	while (iter.hasNext()) {
		java.lang.Object o = iter.next();
		com.bitterjava.bbs.ejb.Post postEjb = resolvePost(o);
		com.bitterjava.bbs.Post post = marshalDataObject(postEjb);
		posts.addElement(post);
	}
	thread.setPosts(posts);
	return thread;
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 4:15:45 PM)
 * @param rs java.sql.ResultSet
 * @param headers java.util.List
 */
private void marshalPostHeaders(java.sql.ResultSet rs, java.util.List headers) throws java.sql.SQLException {
	while (rs.next()) {
		com.bitterjava.bbs.PostHeader header = new com.bitterjava.bbs.PostHeader();
		header.setSubject(rs.getString(1));
		header.setAuthor(rs.getString(2));
		header.setPostID(rs.getInt(3));
		header.setDate(rs.getDate(4));
		headers.add(header);
	}
}

/**
 * Insert the method's description here.
 * Creation date: (9/28/2001 4:15:45 PM)
 * @param rs java.sql.ResultSet
 * @param headers java.util.List
 */
private void marshalThreadHeaders(java.sql.ResultSet rs, java.util.List headers) throws java.sql.SQLException {
	while (rs.next()) {
		com.bitterjava.bbs.ThreadHeader header = new com.bitterjava.bbs.ThreadHeader();
		header.setThreadID(rs.getInt(1));
		header.setName(rs.getString(2));
		headers.add(header);
	}
}
}

⌨️ 快捷键说明

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