📄 productaction.java
字号:
package hibernate;
import hibernate.iml.Product;
import hibernate.iml.ProductOperation;
import java.util.Collection;
import java.util.Date;
import net.sf.hibernate.HibernateException;
public class ProductAction {
// Fields
private String id;
private String unitName;
private String musicname;
private String accessory;
private Date inDate;
/** pagestr property */
private String pagestr;
/** page property */
private String page;
private int pageSize;
private String method;
private final String strSQLOrder = " order by InDate desc";
public Collection getSelect(){
Collection collection = null;
String sqlString = " from Product" + strSQLOrder;
int Page = 1;
if((page!=null)&&(!page.equals(""))&&(!page.equalsIgnoreCase("null"))){
Page = Integer.parseInt(page);
} page = "1";
Page = (Page<1)?1:Page;
try {
ProductOperation opHandle = new ProductOperation();
collection = opHandle.getAll(sqlString,Page,"product.jsp?page=");
pagestr = opHandle.getPageStr();
pageSize = opHandle.getPageSize();
} catch (HibernateException e) {
e.printStackTrace();
}
return collection;
}
public Collection getFirst(){
Collection collection = null;
String sqlString = " from Product";
sqlString += strSQLOrder;
try {
ProductOperation opHandle = new ProductOperation();
opHandle.setPageSize(8);
collection = opHandle.getAll(sqlString,1,"");
} catch (HibernateException e) {
e.printStackTrace();
}
return collection;
}
public Product getInfo(){
Product object = null;
try {
ProductOperation opHandle = new ProductOperation();
object = (Product)opHandle.getInfo(Product.class,id);
} catch (HibernateException e) {
e.printStackTrace();
}
return object;
}
public boolean insert(){
boolean returnCode = true;
if(isValid()){
Product object = new Product();
object.setAccessory(this.accessory);
object.setInDate(new Date());
object.setMusicname(this.musicname);
object.setUnitName(this.unitName);
try {
ProductOperation opHandle = new ProductOperation();
opHandle.insert(object);
} catch (HibernateException e) {
returnCode = false;
e.printStackTrace();
}
}else returnCode = false;
return returnCode;
}
public boolean delete(String path){
if( (id == null)||(id.equals(""))||(id.equals(" "))||(id.equals("null")) ) return false;
boolean returnCode = true;
try {
ProductOperation opHandle = new ProductOperation();
opHandle.delete(path,id);
} catch (HibernateException e) {
returnCode = false;
e.printStackTrace();
}
return returnCode;
}
private boolean isValid(){
boolean returnCode = true;
if( (unitName == null)||(unitName.equals(""))||(unitName.equals(" "))||(unitName.equals("null")) ) returnCode = false;
if( (accessory == null)||(accessory.equals(""))||(accessory.equals(" "))||(accessory.equals("null")) ) returnCode = false;
if( (musicname == null)||(musicname.equals(""))||(musicname.equals(" "))||(musicname.equals("null")) ) returnCode = false;
return returnCode;
}
// Property accessors
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getUnitName() {
return this.unitName;
}
public void setUnitName(String unitName) {
this.unitName = unitName;
}
public String getMusicname() {
return this.musicname;
}
public void setMusicname(String musicname) {
this.musicname = musicname;
}
public String getAccessory() {
return this.accessory;
}
public void setAccessory(String accessory) {
this.accessory = accessory;
}
public Date getInDate() {
return this.inDate;
}
public void setInDate(Date inDate) {
this.inDate = inDate;
}
public String getPagestr() {
return pagestr;
}
public void setPagestr(String pagestr) {
this.pagestr = pagestr;
}
/**
* Returns the page.
* @return String
*/
public String getPage() {
return page;
}
/**
* Set the page.
* @param page The page to set
*/
public void setPage(String page) {
this.page = page;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -