?? layouteo.java
字號:
package book.portal.table;
import java.sql.*;
import java.util.Vector;
import book.portal.*;
public class LayoutEO {
protected int id;//代表數據庫中layout_id列
protected int userId;//代表數據庫中user_id列
protected String colNarrowLeft;//代表數據庫中col_narrow_left列
protected String colNarrowRight;//代表數據庫中col_narrow_right列
protected String colWide;//代表數據庫中col_wide列
protected String activeStatus = "Y";//代表數據庫中active_status列
public LayoutEO() {//無參的構造方法
this.id = -1;
}
public LayoutEO(int id) {//有參的構造方法,參數為portlet_id
this.id = id;
if (!FromDb())//如果有找到該id的layout
this.id = -1;
}
public boolean FromDb() {//從數據庫中讀出,并更新bean
int row = -1;
//讀記錄的sql語句
String sql = "select * from ajax_layout where layout_id=" + this.id
+ " and active_status='Y'";
ResultSet rs = DbManager.getResultSet(sql);//執行sql語句并返回ResultSet
try {
rs.last();//移動到最后一行
row = rs.getRow();//得到總記錄數
if (row == 1) {//如果只查詢到一條記錄,則代表該記錄存在并更新該類的屬性
this.userId = rs.getInt("USER_ID");
this.colNarrowLeft = rs.getString("COL_NARROW_LEFT");
this.colNarrowRight = rs.getString("COL_NARROW_RIGHT");
this.colWide = rs.getString("COL_WIDE");
this.activeStatus = rs.getString("ACTIVE_STATUS");
return true;
} else
return false;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
try {//最后關閉ResutltSet,Statement.并釋放連接
if (rs != null)
rs.close();
if (rs.getStatement() != null)
rs.getStatement().close();
DbManager.releaseConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public boolean ToDb() {//更新數據庫,并重新設置bean
if (getId() == -1)//如果此時id為-1
{
return false;
} else {
//更新該記錄的sql語句
String sql = "update ajax_layout set user_id=" + getUserId()
+ ",col_narrow_left='" + getColNarrowLeft()
+ "',col_narrow_right='" + getColNarrowRight()
+ "',col_wide='" + getColWide() + "',active_status='"
+ getActiveStatus() + "' where layout_id=" + getId();
DbManager.excute(sql);//執行sql語句
return FromDb();//重新讀出bean的屬性
}
}
public String getActiveStatus() {
return activeStatus;
}
public void setActiveStatus(String activeStatus) {
this.activeStatus = activeStatus;
}
public String getColNarrowLeft() {
return colNarrowLeft;
}
public void setColNarrowLeft(String colNarrowLeft) {
this.colNarrowLeft = colNarrowLeft;
}
public String getColNarrowRight() {
return colNarrowRight;
}
public void setColNarrowright(String colNarrowRight) {
this.colNarrowRight = colNarrowRight;
}
public String getColWide() {
return colWide;
}
public void setColWide(String colWide) {
this.colWide = colWide;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public static LayoutEO getInstance ( UserEO user )//獲得該用戶layout的方法
{
LayoutEO layout = new LayoutEO();//定義LayoutEO對象
//查詢該用戶所使用layout的sql語句
String sql = "select layout_id from ajax_layout where user_id="+user.getId();
try {
ResultSet rs = DbManager.getResultSet(sql);//獲得記錄集
rs.last();//移動記錄集到最后
if (rs.getRow()==1)//如果只查詢到一條記錄,則初始化該layout,并返回該layout
{
int layoutId = rs.getInt("LAYOUT_ID");
return new LayoutEO(layoutId);
}
} catch (SQLException e) {
e.printStackTrace();
}
return layout;
}
public Vector getWide()//將逗號分割符分割的數字轉化為Vector
{
if ( getColWide()==null&&getColWide().equals("") )
return new Vector();
return Util.parseCSV(getColWide());
}
public Vector getNarrowRight()//將逗號分割符分割的數字轉化為Vector
{
if ( getColNarrowRight()==null&&getColNarrowRight().equals("") )
return new Vector();
return Util.parseCSV(getColNarrowRight());
}
public Vector getNarrowLeft()//將逗號分割符分割的數字轉化為Vector
{
if ( getColNarrowLeft()==null&&getColNarrowLeft().equals("") )
return new Vector();
return Util.parseCSV(getColNarrowLeft());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -