您的位置:首页 > 其它

webwork+freemarker+hibernate开发样版图像管理系统

2006-10-21 11:39 591 查看
一、项目背景

为某企业的工艺样版图实现信息化管理,方便对样版图所要进行的人工操作。

1) 带用户,密码登录;

2) 用户身份分级别, 不同身份的用户看不同的样办图;

3) 带搜索功能;

4) 点击样办图显示全图和属性;

二、系统环境

开发环境:Windows XP Eclipse3.1 JDK1.5 Tomcat5.5.17

系统架构:Webwork2.2.4+Freemarker-2.3.8+Hibernate-3.1.3

后台数据库:Mysql-5.0.13

第三方类库:webwork-2.2.4 log4j-1.2.8 hibernate-3.1.3 dwr-1.0 dom4j-1.6.1

mysql-connector-java-3.1.12-bin.jar fileupload-1.1.1 spring-1.2.6 freemarker-2.3.8

三、需求分析
实现用户对图片的浏览、上传、删除等操作,图片的显示可以分为:列表显示、缩略图显示、幻灯片显示,同时能详细显示某个图片的详细描述,上传时间,规格、大小、上传人等。系统管理员可以设置系统用户组,超级用户: 拥有所有功能 添加, 删除, 修改 和浏览所有目录,受限用户: a. 可添加文件, 浏览指定目录b. 只可浏览指定目录文件,系统管理员可以对图片进行分类存储:A) 可以按日期分(09/07/2006);B) 可以按类型分(类型有: a) 电脑袋 b) 旅行包 c) 行李包 d) 公文包 e),创建目录名,同时指定该目录所属用户组。可以对图片文件按要求进行搜索:A) 可以按名称搜索 B) 可以按分类搜索 C) 搜索某时间段产品 ..... 搜索出来的产品可以以缩略图显示 D) 按用户搜索,搜索后显示该用户的所有图片

四、模块设计
分类管理

系统管理员可以增加、删除、编辑图片目录,同时更改图片目录的所属用户组
样版图管理

用户可以查询、上传图片到指定分类的目录路径,删除、编辑(只限管理员身份且具有相应权限)
用户管理

管理员可以增加、删除、编辑用户,指定用户所属用户组

用户组管理

管理员可以增加、删除、编辑用户组信息

系统回收站

存放待删除的图片文件或目录文件(只限管理员身份且具有相应权限)

我的样版图

同样版图管理相似,全部用户可使用,区别在于,只能查询和处理所属用户创建的图象

个人回收站

同系统回收站,区别于用户级和系统级的使用

我的个人信息

登陆系统的用户对个人信息进行修改,密码等

五、数据库设计

CREATE TABLE `scool_catalog` (
`catalog_id` varchar(10) NOT NULL,
`parent_id` varchar(10) NOT NULL default 'FFFFFFFFFF',
`name` varchar(20) NOT NULL,
`refuse_user` text,
`create_date` datetime default NULL,
`level` char(1) NOT NULL default '0',
PRIMARY KEY (`catalog_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `scool_group` (
`group_id` varchar(10) NOT NULL,
`group_name` varchar(20) NOT NULL,
`popedom_value` bigint(64) default NULL,
PRIMARY KEY (`group_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `scool_image` (
`image_id` varchar(10) NOT NULL,
`file_name` varchar(60) NOT NULL,
`is_delete` char(1) NOT NULL default '0',
`catalog_f_id` varchar(10) NOT NULL,
`catalog_s_id` varchar(10) NOT NULL,
`image_name` varchar(60) NOT NULL,
`size` int(32) NOT NULL default '0',
`description` text,
`create_date` datetime NOT NULL,
`WH` varchar(20) default NULL,
`user_name` varchar(20) default NULL,
`operator` varchar(20) default NULL,
`remove_date` datetime default NULL,
PRIMARY KEY (`image_id`),
KEY `title_index` (`file_name`),
KEY `user_name_index` (`user_name`),
KEY `operator_index` (`operator`),
KEY `image_name_index` (`image_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `scool_user` (
`user_name` varchar(20) NOT NULL,
`password` varchar(32) NOT NULL,
`real_name` varchar(10) default NULL,
`sex` char(1) NOT NULL default '0',
`status` char(1) NOT NULL default '0',
`group_id` varchar(10) default NULL,
`role` char(1) NOT NULL default '0',
PRIMARY KEY (`user_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;





六、系统预览





















七、详细设计(节选)

1.数据访问核心类HibernateDao.java

/**
* HibernateDao
*/
package com.school71.imageims.dao;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Iterator;
//import java.lang.reflect.Field;

import com.school71.imageims.model.Garbage;
import com.school71.imageims.model.Image;
import com.school71.imageims.util.GeneratorUtil;
import com.school71.imageims.util.HibernateUtil;
import com.school71.imageims.util.FileUtil;
import com.school71.imageims.cfg.Config;

import org.hibernate.CacheMode;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.proxy.HibernateProxy;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006 2006-9-18 22:38:20
*/
public class HibernateDao {
private static final Log log=LogFactory.getLog(HibernateDao.class);
public static final String SUPER_USER_NAME="root";
/**
*
* @param hql
* @return
* @TODO get a data object by specify hql
*/

@SuppressWarnings("finally")
protected Object getDataByHql(String hql){
Object object=null;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
Query query=session.createQuery(hql);
//.setCacheable(true)
//.setCacheMode(CacheMode.NORMAL);
object=query.uniqueResult();
ts.commit();
} catch (HibernateException e) {
log.error("Error to get a data object by hql=:"+hql,e);
ts.rollback();
}finally{
//closeSession();
return object;
}
}
/**
*
* @param clazz
* @param param
* @param value
* @param operator
* @return
* @TODO
*/
protected Object getData(Class clazz,String[]param,String[]value,String operator){
StringBuffer sb=new StringBuffer();
sb.append("from ");
sb.append(clazz.getSimpleName());
sb.append(" as tb");
sb.append(" where");
for(int i=0;i<param.length;i++){
sb.append(" tb.");
sb.append(param[i]);
sb.append(" =");
sb.append("'");
sb.append(value[i]);
sb.append("'");
if(i!=param.length-1){
sb.append(operator);
}
}
return getDataByHql(sb.toString());
}

protected Object getData(Class clazz,Map<String,String> paramMap,String operator){
StringBuffer sb=new StringBuffer();
sb.append("from ");
sb.append(clazz.getSimpleName());
sb.append(" as tb");
sb.append(" where");
for(Iterator it=paramMap.keySet().iterator();it.hasNext();){
String key=(String)it.next();
sb.append(" tb.");
sb.append(key);
sb.append("='");
sb.append(paramMap.get(key));
sb.append("'");
if(it.hasNext()){
sb.append(operator);
}
}
return getDataByHql(sb.toString());
}

/**
* if close the session then lazy function will not be executed
* @param clazz
* @param key
* @return
* @TODO
*/
@SuppressWarnings("finally")
protected Object getDataByKey(Class clazz,Serializable key){
Object object=null;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
object=session.get(clazz,key);
ts.commit();
} catch (HibernateException e) {
ts.rollback();
log.error("Error to get a "+clazz.getName()+" data object by key="+key,e);
}finally{
//closeSession();
return object;
}
}

@SuppressWarnings("finally")
protected List getDataListByHql(String hql,int pageNo,int pageSize){
List list=null;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
Query query=session.createQuery(hql)
//.setCacheable(true)
//.setCacheMode(CacheMode.NORMAL)
.setFirstResult((pageNo-1) * pageSize)
.setMaxResults(pageSize);

list=query.list();
ts.commit();
} catch (HibernateException e) {
log.error("Occur an error when get list by hql : "+hql,e);
}finally{
//closeSession();
return list;
}
}

@SuppressWarnings("finally")
protected List getDataListByHql(String hql){
List list=null;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
Query query=session.createQuery(hql);
//.setCacheable(true)
//.setCacheMode(CacheMode.NORMAL);
list=query.list();
ts.commit();
} catch (HibernateException e) {
ts.rollback();
log.error("Error to get a list by hql :"+hql,e);
e.printStackTrace();
}finally{
//closeSession();
return list;
}
}
/**
*
* @param hql
* @return
* @TODO
*/
@SuppressWarnings("finally")
protected Integer getDataCountByHql(String hql){
int count=0;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
count=(Integer)session.createQuery(hql).list().iterator().next();
ts.commit();
} catch (HibernateException e) {
ts.rollback();
log.error("Error to get record count");
}finally{
closeSession();
return count;
}

}

@SuppressWarnings("finally")
protected Integer getDataCountByHql(String tempHql,Map paramMap){
int count=0;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
Query query=session.createQuery(tempHql);
query=fillQuery(query,paramMap);
count=(Integer)query.uniqueResult();
ts.commit();
} catch (HibernateException e) {
log.error("Error to count the record count",e);
}finally{
closeSession();
return count;
}
}
/**
*
* @param sql
* @return
* @TODO get data object by specify sql
*/
protected Object getDataBySql(String sql){
return null;
}
/**
*
* @return
* @TODO
*/
protected Session openSession(){
return HibernateUtil.currentSession();
}
/**
*
*
* @TODO
*/
protected void closeSession(){
HibernateUtil.closeSession();
}
/**
*
* @param object
* @return
* @TODO
*/
@SuppressWarnings("finally")
protected boolean saveData(Object object){
boolean isSuccess=false;
Session session = openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
session.save(object);
session.flush();
ts.commit();
isSuccess=true;
} catch (HibernateException e) {
ts.rollback();
log.error("Error to save a data object to database",e);
}finally{
closeSession();
return isSuccess;
}
}

protected int deleteGarbage(List<Garbage> garbageList){
int resCount=0;
for(Iterator it=garbageList.iterator();it.hasNext();){
Garbage garbage=(Garbage)it.next();
if(deleteGarbage(garbage)){
resCount++;
}
}
return resCount;
}
@SuppressWarnings("finally")
protected boolean deleteGarbage(Garbage garbage){
boolean isSuccess=false;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
session.delete(garbage);
StringBuffer sb=new StringBuffer();
sb.append(Config.getFileRootPath());
sb.append("/");
sb.append(garbage.getParentCatalog().getCatalogId());
sb.append("/");
sb.append(garbage.getChildCatalog().getCatalogId());
sb.append("/");
Date date=garbage.getCreateDate();
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
sb.append(calendar.get(Calendar.YEAR));
sb.append("/");
sb.append(calendar.get(Calendar.MONTH)+1);
sb.append("/");
sb.append(calendar.get(Calendar.DAY_OF_MONTH));
String oldDirectoryName=sb.toString();

sb=new StringBuffer();
sb.append(Config.getGarbageRootPath());
sb.append("/");
sb.append(garbage.getParentCatalog().getCatalogId());
sb.append("/");
sb.append(garbage.getChildCatalog().getCatalogId());
String newDirectoryName=sb.toString();
FileUtil.moveFile(garbage.getImageName(),oldDirectoryName,newDirectoryName);
ts.commit();
isSuccess=true;
} catch (HibernateException e) {
ts.rollback();
log.error("Error to delete data object ",e);
}finally{
return isSuccess;
}
}

@SuppressWarnings("finally")
protected boolean saveImage(Image image,File file){
StringBuffer directory=null;
String destFileName=null;
boolean isSuccess=false;
Session session =openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
//String suffix=file.getName().substring(file.getName().lastIndexOf("."));
//String destFileName=GeneratorUtil.getChar10()+suffix;
destFileName=image.getFileName();
//image.setFileName(destFileName);
session.save(image);
directory=new StringBuffer();
directory.append(Config.getFileRootPath());
directory.append("/");
directory.append(image.getParentCatalog().getCatalogId());
directory.append("/");
directory.append(image.getChildCatalog().getCatalogId());
directory.append("/");
Calendar calendar=Calendar.getInstance();
directory.append(calendar.get(Calendar.YEAR));
directory.append("/");
int month=calendar.get(Calendar.MONTH)+1;
directory.append(month<10 ? "0"+month : month);
directory.append("/");
directory.append(calendar.get(Calendar.DAY_OF_MONTH));
FileUtil.saveFile(file,directory.toString(),destFileName);
ts.commit();
isSuccess=true;
} catch (HibernateException e) {
ts.rollback();
log.error("Error to save a image data object"+image.toString());
try {
FileUtil.deleteFile(directory.toString(),destFileName);
} catch (IOException e1) {
log.error("Error to delete the uploaded file when occured a HibernateException",e1);
}
}catch (IOException ex) {
log.error("Error to upload file :"+file.getAbsolutePath());
}finally{
return isSuccess;
}
}

@SuppressWarnings("finally")
protected boolean updateImage(Image image,String oldPCatalogId,String oldCCatalogId){
StringBuffer directory=null;
StringBuffer oldDirectory=null;
boolean isSuccess=false;
Session session =openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
session.update(image);
if(!oldPCatalogId.equals(image.getParentCatalog().getCatalogId())||!oldCCatalogId.equals(image.getChildCatalog().getCatalogId())){
directory=new StringBuffer();
oldDirectory=new StringBuffer();
directory.append(Config.getFileRootPath());
oldDirectory.append(Config.getFileRootPath());
directory.append("/");
oldDirectory.append("/");
directory.append(image.getParentCatalog().getCatalogId());
oldDirectory.append(oldPCatalogId);
directory.append("/");
oldDirectory.append("/");
directory.append(image.getChildCatalog().getCatalogId());
oldDirectory.append(oldCCatalogId);
directory.append("/");
oldDirectory.append("/");
Calendar calendar=Calendar.getInstance();
calendar.setTime(image.getCreateDate());
directory.append(calendar.get(Calendar.YEAR));
oldDirectory.append(calendar.get(Calendar.YEAR));
directory.append("/");
oldDirectory.append("/");
int month=calendar.get(Calendar.MONTH)+1;
directory.append(month<10 ? "0"+month : month);
oldDirectory.append(month<10 ? "0"+month : month);
directory.append("/");
oldDirectory.append("/");
directory.append(calendar.get(Calendar.DAY_OF_MONTH));
oldDirectory.append(calendar.get(Calendar.DAY_OF_MONTH));
FileUtil.moveFile(image.getFileName(),oldDirectory.toString(),directory.toString());
}
ts.commit();
isSuccess=true;
} catch (HibernateException e) {
ts.rollback();
log.error("Error to update a image data object"+image.toString());
try {
FileUtil.moveFile(image.getFileName(),directory.toString(),oldDirectory.toString());
} catch (IOException e1) {
log.error("Error to move the file from "+directory.toString()+" to "+oldDirectory.toString()+" when occured a HibernateException",e1);
}
}catch (IOException ex) {
log.error("Error to move the file from "+oldDirectory.toString()+" to "+directory.toString()+" when occured a IOException");
}finally{
return isSuccess;
}
}
/**
*
* @param object
* @return
* @TODO
*/
@SuppressWarnings("finally")
protected boolean updateData(Object object/*,Serializable key*/){
boolean isSuccess=false;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
// Class clazz=object.getClass();
// Object updateObject=session.get(clazz,key);
// if(updateObject!=null){
// Field[] fs=clazz.getDeclaredFields();
// System.out.println("============"+fs.length);
// for(int i=0;i<fs.length;i++){
// Field field=fs[i];
// System.out.println(field.get(object));
// field.set(updateObject, field.get(object));
// }
// }
//
// session.update(updateObject);

session.update(object);
ts.commit();
isSuccess=true;
} catch (HibernateException e) {
ts.rollback();
e.printStackTrace();
log.error("Error to update a data object",e);
}
// catch (IllegalArgumentException e) {
// e.printStackTrace();
// }catch (IllegalAccessException e) {
// e.printStackTrace();
// }
finally{
closeSession();
return isSuccess;
}
}

@SuppressWarnings("finally")
protected int updateData(String hql,String param,Object[] paramValue){
int count=0;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
count = session.createQuery(hql)
//.setCacheable(true)
// .setCacheMode(CacheMode.NORMAL)
.setParameterList(param,paramValue)
.executeUpdate();
ts.commit();
} catch (HibernateException e) {
log.error("Error to update data by hql "+ hql +"paramValue"+paramValue.toString());

}finally{
return count;
}
}

@SuppressWarnings("finally")
protected int updateData(String hql){
int count=0;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
count=session.createQuery(hql)
//.setCacheable(true)
//.setCacheMode(CacheMode.NORMAL)
.executeUpdate();
ts.commit();
} catch (HibernateException e) {
ts.rollback();
log.error("Error to update by hql :"+hql);
}finally{
return count;
}
}
/**
*
* @param clazz
* @param paramName
* @param paramValue
* @return
* @TODO
*/
protected boolean deleteData(Class clazz,String paramName,String paramValue){
int count=0;
StringBuffer sb=new StringBuffer();
sb.append("delete ");
sb.append(clazz.getSimpleName());
sb.append(" where ");
sb.append(paramName);
sb.append(" ='");
sb.append(paramValue);
sb.append("'");
count=deleteDataByHql(sb.toString());
return count > 0 ? true : false;
}

/**
*
* @param clazz
* @param keyValue
* @return
* @TODO
*/
@SuppressWarnings("finally")
protected boolean deleteData(Class clazz,Serializable keyValue){
boolean isSuccess=false;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
Object object=session.get(clazz,keyValue);
if(object!=null){
session.delete(object);
isSuccess=true;
}
ts.commit();
} catch (HibernateException e) {
ts.rollback();
e.printStackTrace();
}finally{
closeSession();
return isSuccess;
}
}
/**
*
* @param hql
* @param param
* @param paramValue
* @return
* @TODO
*/
@SuppressWarnings("finally")
protected int deleteData(String hql,String param,Object[] paramValue){
int count=0;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
count=session.createQuery(hql)
//.setCacheable(true)
//.setCacheMode(CacheMode.NORMAL)
.executeUpdate();
ts.commit();
} catch (HibernateException e) {
ts.rollback();
log.error("Error to delete data by hql :"+hql +" paramValue "+paramValue.toString());
}finally{
return count;
}
}

@SuppressWarnings("finally")
protected int deleteData(String hql){
int count=0;
Session session=openSession();
Transaction ts=session.getTransaction();
try {
ts.begin();
count=session.createQuery(hql)
//.setCacheable(true)
//.setCacheMode(CacheMode.NORMAL)
.executeUpdate();
ts.commit();
} catch (HibernateException e) {
ts.rollback();
log.error("Error to delete data by hql :"+hql);
}finally{
return count;
}
}
/**
*
* @param hql
* @return
* @TODO delete record batch not cascade delete
*/
@SuppressWarnings("finally")
protected int deleteDataByHql(String hql){
int count=0;
Session session=openSession();
Transaction ts=null;
try {
ts=session.beginTransaction();
count=session.createQuery(hql)
//.setCacheable(true)
//.setCacheMode(CacheMode.NORMAL)
.executeUpdate();
ts.commit();
} catch (HibernateException e) {
ts.rollback();
log.error("Error to delete data object by hql : " +hql,e);
}finally{
closeSession();
return count;
}
}
/**
*
* @param tableName
* @param theClass
* @param where
* @param arg
* @return
* @TODO
*/
protected List executeSQLQuery(String tableName, Class theClass, String where, Object arg[]) {
Session session = openSession();
SQLQuery q = session.createSQLQuery( "select {" + tableName + ".*} from " + tableName + " where " + where);
//System.out.println( "select {" + tableName + ".*} from " + tableName + " where " + where);
q.addEntity( tableName, theClass );
q=fillQuery(q,arg);
List list = q.list();
// closeSession();
return list;
}

private SQLQuery fillQuery(SQLQuery query,Object[] arg){
int l = arg.length;
for (int i = 0; i < l; i++) {
if (arg[i] instanceof Integer) {
query.setInteger( i, ((Integer)arg[i]).intValue() );
}
else if (arg[i] instanceof Short) {
query.setShort( i, ((Short)arg[i]).shortValue() );
}
else if (arg[i] instanceof Long) {
query.setLong( i, ((Long)arg[i]).longValue() );
}
else if (arg[i] instanceof Double) {
query.setDouble( i, ((Double) arg[i]).doubleValue() );
}
else if (arg[i] instanceof Float) {
query.setFloat( i, ((Float) arg[i]).floatValue() );
}
else if (arg[i] instanceof BigDecimal) {
query.setBigDecimal( i, (BigDecimal) arg[i] );
}
else if (arg[i] instanceof BigInteger) {
query.setBigInteger( i, (BigInteger) arg[i] );
}
else if (arg[i] instanceof String) {
query.setString( i, (String) arg[i] );
}
else if (arg[i] instanceof Boolean) {
query.setBoolean( i, ((Boolean) arg[i]).booleanValue() );
}
else if (arg[i] instanceof Date) {
query.setDate( i, (Date) arg[i] );
}
else if (arg[i] instanceof Date) {
query.setDate( i, (Date) arg[i] );
}
else {
throw new IllegalStateException( "bad type" );
}
}
return query;
}
/**
*
* @param query
* @param paramMap
* @return
* @TODO
*/
private Query fillQuery(Query query,Map paramMap){
for(Iterator it=paramMap.keySet().iterator();it.hasNext();){
String key=(String)it.next();
Object object=paramMap.get(key);
if (object instanceof Integer) {
query.setInteger( key, ((Integer)object).intValue() );
}
else if (object instanceof Short) {
query.setShort( key, ((Short)object).shortValue() );
}
else if (object instanceof Long) {
query.setLong( key, ((Long)object).longValue() );
}
else if (object instanceof Double) {
query.setDouble( key, ((Double) object).doubleValue() );
}
else if (object instanceof Float) {
query.setFloat( key, ((Float) object).floatValue() );
}
else if (object instanceof BigDecimal) {
query.setBigDecimal( key, (BigDecimal) object );
}
else if (object instanceof BigInteger) {
query.setBigInteger( key, (BigInteger) object );
}
else if (object instanceof String) {
query.setString( key, (String) object );
}
else if (object instanceof Boolean) {
query.setBoolean( key, ((Boolean) object).booleanValue() );
}
else if (object instanceof Date) {
query.setDate( key, (Date) object );
}
else if (object instanceof Date) {
query.setDate( key, (Date) object );
}
else {
throw new IllegalStateException( "bad type" );
}
}
return query;
}

protected StringBuffer checkHql(StringBuffer sb){
if(log.isDebugEnabled()){
log.debug("sb before delete="+sb.toString());
}
int start=sb.indexOf("where");
if(start!=-1){
start=start+"where".length();
if(log.isDebugEnabled()){
log.debug("=======start="+start);
}
int end=start+" and".length();
if(log.isDebugEnabled()){
log.debug("=====end="+end);
}
//System.out.println("========================="+sb.substring(start,end));
if(" and".equals(sb.substring(start,end))){
sb.delete(start,end);
//System.out.println(" delete");
if(log.isDebugEnabled()){
log.debug(" sb after delete="+sb.toString());
}
}
}
return sb;
}
}

2.1Catalog.java业务对象

/**
* Catalog
*/
package com.school71.imageims.model;

import java.io.Serializable;
import java.util.Date;

/**
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006-9-19 14:11:09
*/
public abstract class Catalog implements Serializable {

private static final long serialVersionUID = -878147387681622373L;
protected String catalogId;
//protected String parentId;
protected String name;
protected String refuseUser;
protected Date createDate;
protected String level;
/**
*
*/
public String toString(){
return "{parentId:'"+this.getParentId()+"',catalogId:'"+catalogId+"',name:'"+name+"',refuseUser:["+refuseUser+"],createDate:"+createDate+"}";
}
/**
* @hibernate.property
* column="CATALOG_ID"
* not-null="true"
* @return Returns the catalogId.
*/
public String getCatalogId() {
return catalogId;
}
/**
* @param catalogId The catalogId to set.
*/
public void setCatalogId(String catalogId) {
this.catalogId = catalogId;
}
/**
* @hibernate.property
* column="CREATE_DATE"
* not-null="true"
* @return Returns the createDate.
*/
public Date getCreateDate() {
return createDate;
}
/**
* @param createDate The createDate to set.
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
/**
* @hibernate.property
* column="NAME"
* not-null="true"
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @hibernate.property
* column="PARENT_ID"
* not-null="true"
* @return Returns the parentId.
*/
//public String getParentId() {
// return parentId;
// }
/**
* @param parentId The parentId to set.
*/
// public void setParentId(String parentId) {
// this.parentId = parentId;
// }
/**
* @hibernate.property
* column="REFUSE_USER"
* @return Returns the refuseUser.
*/
public String getRefuseUser() {
return refuseUser;
}
/**
* @param refuseUser The refuseUser to set.
*/
public void setRefuseUser(String refuseUser) {
this.refuseUser = refuseUser;
}
/**
*
* @return
* @TODO
*/
abstract String getParentId();
/**
*
* @param parentId
* @TODO
*/
abstract void setParentId(String parentId) ;
/**
* @return Returns the level.
*/
public String getLevel() {
return level;
}
/**
* @param level The level to set.
*/
public void setLevel(String level) {
this.level = level;
}
}

2.2 ParentCatalog.java

/**
* ParentCatalog
*/
package com.school71.imageims.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006-9-23 19:43:04
*/
public class ParentCatalog extends Catalog implements Serializable {
/**
* serialVersionUID long
*/
private static final long serialVersionUID = 7116854665183745385L;
public static final String PARENT_ID="FFFFFFFFFF";
private Set<ChildCatalog> children=new HashSet<ChildCatalog>();
private String parentId=PARENT_ID;
public ParentCatalog(){

}

public String toString(){
return "{catalogId:'"+catalogId+"',parentId:'"+parentId+"',name:'"+name+"',refuseUser:'["+refuseUser+"]',createDate:"+createDate+"}";
}
public ParentCatalog(String catalogId){
this.catalogId=catalogId;
}
/**
* @hibernate.one-to-many
* column="CATALOG_ID"
* fetch="join"
* lazy="false"
* @return Returns the children.
*/
public Set<ChildCatalog> getChildren() {
return children;
}

/**
* @param children The children to set.
*/
public void setChildren(Set<ChildCatalog> children) {
this.children = children;
}
/**
* @return Returns the parentId.
*/
public String getParentId() {
return parentId;
}
/**
* @param parentId The parentId to set.
*/
protected void setParentId(String parentId) {
this.parentId = parentId;
}
}

2.3ChildCatalog.java

/**
* ChildCatalog
*/
package com.school71.imageims.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006-9-23 19:43:31
*/
public class ChildCatalog extends Catalog implements Serializable {

/**
* serialVersionUID long
*/
private static final long serialVersionUID = 7760414467495664403L;
private ParentCatalog parent;
private Set<Image> images=new HashSet<Image>();
private String parentId;
public ChildCatalog(){

}
public ChildCatalog(String catalogId){
this.catalogId=catalogId;
}
public String toString(){
return "{catalogId:'"+catalogId+"',parentId:'"+parent.getCatalogId()+"',name:'"+name+
"',refuseUser:'["+refuseUser+"]',createDate:"+createDate+"}";
}
/**
* @hibernate.many-to-one
* column="PARENT_ID"
* fetch="false"
* class="ParentCatalog"
* unique="true" lazy="false"
* @return Returns the parent.
*/
public ParentCatalog getParent() {
return parent;
}

/**
* @param parent The parent to set.
*/
public void setParent(ParentCatalog parent) {
this.parent = parent;
}

/**
* @hibernate.one-to-many
* column="CATALOG_ID"
* @return Returns the images.
*/
public Set<Image> getImages() {
return images;
}

/**
* @param images The images to set.
*/
public void setImages(Set<Image> images) {
this.images = images;
}

@Override
public String getParentId() {
parentId=parent.getCatalogId();
return parentId;
}
@Override
protected void setParentId(String parentId) {
// TODO Auto-generated method stub

}

}

2.4Catalog.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.school71.imageims.model">
<class name="Catalog" abstract="true" table="SCOOL_CATALOG">
<!--
<cache usage="read-write"/>
-->
<id name="catalogId" column="CATALOG_ID">
<generator class="assigned"> </generator>
</id>

<discriminator column="LEVEL" type="java.lang.String"></discriminator>

<property name="parentId" type="java.lang.String" column="PARENT_ID" insert="false" update="false"/>
<property name="level" type="java.lang.String" column="LEVEL" insert="false" update="false"/>
<property name="name" type="java.lang.String" column="NAME"/>
<property name="refuseUser" type="java.lang.String" column="REFUSE_USER"/>
<property name="createDate" type="java.util.Date" column="CREATE_DATE"/>

<subclass name="ParentCatalog" discriminator-value="1">
<set name="children" inverse="true" cascade="all" lazy="true">
<key column="PARENT_ID"></key>
<one-to-many class="ChildCatalog"/>
</set>
</subclass>

<subclass name="ChildCatalog" discriminator-value="2">
<many-to-one name="parent" fetch="select" column="PARENT_ID" class="ParentCatalog" unique="true" lazy="proxy" ></many-to-one>
<set name="images" inverse="true" cascade="all" lazy="true">
<key column="CATALOG_S_ID"></key>
<one-to-many class="Image"/>
</set>

</subclass>

</class>
</hibernate-mapping>

3.1User.java

/**
*
*/
package com.school71.imageims.model;

import java.io.Serializable;

/**s
*
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006 2006-9-19 12:13:49
*/
public class User implements Serializable {

private static final long serialVersionUID = -947206219451031100L;
protected String userName;
protected String password;
protected String role;
protected String status;
protected Group group;

public String toString(){
return "{userName:'"+userName+"',password:'"+password+"'" +
",role:'"+role+"',status:'"+status+"'}";
}
/**
* @hibernate.property
* column="PASSWROD"
* not-null=true
* @return Returns the password.
*/
public String getPassword() {
return password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return Returns the status.
*/
public String getStatus() {
return status;
}
/**
* @param status The status to set.
*/
public void setStatus(String status) {
this.status = status;
}
/**
* @return Returns the userName.
*/
public String getUserName() {
return userName;
}
/**
* @param userName The userName to set.
*/
public void setUserName(String userName) {
this.userName = userName;
}

/**
* @return Returns the role.
*/
public String getRole() {
return role;
}

/**
* @param role The role to set.
*/
public void setRole(String role) {
this.role = role;
}

/**
* @return Returns the group.
*/
public Group getGroup() {
return group;
}
/**
* @param group The group to set.
*/
public void setGroup(Group group) {
this.group = group;
}
}

3.2User.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.school71.imageims.model">
<class name="User" table="SCOOL_USER" dynamic-update="true" dynamic-insert="true">
<!--
<cache usage="read-write"/>
-->
<id name="userName" column="USER_NAME">
<generator class="assigned"> </generator>
</id>
<property name="password" type="java.lang.String" column="PASSWORD" />
<!--
<property name="ruleValue" type="java.lang.Long" column="POPEDOM_VALUE" />
-->
<property name="role" type="java.lang.String" column="ROLE" />
<property name="status" type="java.lang.String" column="STATUS" />
<many-to-one name="group" fetch="join" column="GROUP_ID" class="Group" unique="true" lazy="proxy"></many-to-one>

</class>
<!--
<sql-query name="getCatalogList" callable="true">
<return alias="catalog" class="com.mxca.shop4i.Product.module.Catalog">
<return-property name="catalogId" column="CATALOG_ID"/>
<return-property name="parentId" column="PARENT_ID"/>
<return-property name="title" column="TITLE"/>
</return>
{?=call PKG_CATALOG.GET_CATALOG_LIST_BY_PARENT_ID(?)}
</sql-query>
-->
</hibernate-mapping>

4.1Person.java

/**
*
*/
package com.school71.imageims.model;

import java.util.HashSet;
import java.util.Set;

/**
*
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006 2006-9-19 12:13:43
*/
public class Person extends User {
private static final long serialVersionUID = -2892996858293783495L;
private String realName;
private String sex;
private Set<Image> images=new HashSet<Image>();
public Person(){

}
public Person(String userName){
this.userName=userName;
}
public String toString(){
String str="{userName:'"+userName+"',password:'"+password+"'" +
",role:'"+role+"',status:'"+status+"'" +
",realName:'"+realName+"',sex:'"+sex+"'}";
if(group!=null){
str+=" {groupId:'"+group.getGroupId()+"',groupName:'"+group.getName()+"'}";
}
return str;

}
/**
* @return Returns the realName.
*/
public String getRealName() {
return realName;
}
/**
* @param realName The realName to set.
*/
public void setRealName(String realName) {
this.realName = realName;
}
/**
* @return Returns the sex.
*/
public String getSex() {
return sex;
}
/**
* @param sex The sex to set.
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* @hibernate.one-to-many
* inverse="false" cascade="none" lazy="true"
* @return Returns the images.
*/
public Set<Image> getImages() {
return images;
}
/**
* @param images The images to set.
*/
public void setImages(Set<Image> images) {
this.images = images;
}
}
4.2Person.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.school71.imageims.model">

<class name="Person" table="SCOOL_USER" dynamic-update="true" >
<!--
<cache usage="read-write"/>
-->
<id name="userName" column="USER_NAME" >
<generator class="assigned"> </generator>
</id>
<property name="password" type="java.lang.String" column="PASSWORD" />
<property name="realName" type="java.lang.String" column="REAL_NAME"/>
<property name="sex" type="java.lang.String" column="SEX" />
<property name="status" type="java.lang.String" column="STATUS" />
<!--
<property name="ruleValue" type="java.lang.Long" column="POPEDOM_VALUE" />
-->
<property name="role" type="java.lang.String" column="ROLE" />

<many-to-one column="GROUP_ID" name="group" class="Group" fetch="join" unique="true" lazy="proxy"></many-to-one>

<set name="images" inverse="false" cascade="none" lazy="true">
<key column="USER_NAME"></key>
<one-to-many class="Image"/>
</set>

</class>

<!--
<sql-query name="getCatalogList" callable="true">
<return alias="catalog" class="com.mxca.shop4i.Product.module.Catalog">
<return-property name="catalogId" column="CATALOG_ID"/>
<return-property name="parentId" column="PARENT_ID"/>
<return-property name="title" column="TITLE"/>
</return>
{?=call PKG_CATALOG.GET_CATALOG_LIST_BY_PARENT_ID(?)}
</sql-query>
-->
</hibernate-mapping>

5.1Image.java

package com.school71.imageims.model;

import java.io.Serializable;
import java.util.Date;
import com.school71.imageims.model.ParentCatalog;
import com.school71.imageims.model.ChildCatalog;
/**
*
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006 2006-9-19 12:13:22
*/
public class Image implements Serializable {
private static final long serialVersionUID = 5408841387236059997L;
//private String userName;
private String imageId;
private String fileName;
private String isDelete;
private ParentCatalog parentCatalog;
private ChildCatalog childCatalog;
private Person person;
private String imageName;
private Long size;
private String description;
private Date createDate;
private Date removeDate;
private String WH;
private Person operator;

public String toString(){
String str="{parentId:'"+getParentCatalog().getCatalogId()+"',childCatalogId:'"+getChildCatalog().getCatalogId()+"'";
str+="imageId:'"+imageId+"',fileName:'"+fileName+"',isDelete:'"+isDelete+"',imageName:'"
+imageName+"',size:"+size+",description:'"+description+"',createDate:"+createDate+",WH:'"+WH+"'}";
return str;
}
/**
*
* @return Returns the userName.
*/
//public String getUserName() {
// return userName;
// }
/**
* @param userName The userName to set.
*/
//public void setUserName(String userName) {
// this.userName = userName;
// }
/**
* @hibernate.many-to-one
* column="CATALOG_F_ID"
* unique="true" fetch="join"
* @return Returns the parentCatalog.
*/
public ParentCatalog getParentCatalog() {
return parentCatalog;
}
/**
* @param parentCatalog The parentCatalog to set.
*/
public void setParentCatalog(ParentCatalog parentCatalog) {
this.parentCatalog = parentCatalog;
}
/**
* @hibernate.many-to-one
* column="CATALOG_S_ID"
* unique="true" fetch="join"
* @return Returns the childCatalog.
*/
public ChildCatalog getChildCatalog() {
return childCatalog;
}
/**
* @param catalogSecond The catalogSecond to set.
*/
public void setChildCatalog(ChildCatalog childCatalog) {
this.childCatalog = childCatalog;
}
/**
* @hibernate.property
* column="CREATE_DATE"
* not-null="true"
* @return Returns the createDate.
*/
public Date getCreateDate() {
return createDate;
}
/**
* @param createDate The createDate to set.
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
/**
* @hibernate.property
* column="DESCRIPTION"
* @return Returns the description.
*/
public String getDescription() {
return description;
}
/**
* @param description The description to set.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @hibernate.id
* column="IMAGE_ID"
* generator class="assigned"
* @return Returns the imageId.
*/
public String getImageId() {
return imageId;
}
/**
* @param imageId The imageId to set.
*/
public void setImageId(String imageId) {
this.imageId = imageId;
}
/**
* @hibernate.property
* column="IMAGE_NAME"
* not-null="true"
* @return Returns the imageName.
*/
public String getImageName() {
return imageName;
}
/**
* @param imageName The imageName to set.
*/
public void setImageName(String imageName) {
this.imageName = imageName;
}
/**
* @hibernate.property
* column="IS_DELETE"
* not-null="true"
* @return Returns the isDelete.
*/
public String getIsDelete() {
return isDelete;
}
/**
* @param isDelete The isDelete to set.
*/
public void setIsDelete(String isDelete) {
this.isDelete = isDelete;
}
/**
* @hibernate.property
* column="SIZE"
* not-null="true"
* @return Returns the size.
*/
public Long getSize() {
return size;
}
/**
* @param size The size to set.
*/
public void setSize(Long size) {
this.size = size;
}
/**
* @hibernate.property
* column="FILE_NAME"
* @return Returns the fileName.
*/
public String getFileName() {
return fileName;
}
/**
* @param fileName The fileName to set.
*/
public void setFileName(String fileName) {
this.fileName = fileName;
}
/**
* @hibernate.property
* column="WH"
* not-null="true"
* @return Returns the wH.
*/
public String getWH() {
return WH;
}
/**
* @param wh The wH to set.
*/
public void setWH(String wh) {
WH = wh;
}
/**
* @return Returns the person.
*/
public Person getPerson() {
return person;
}
/**
* @param person The person to set.
*/
public void setPerson(Person person) {
this.person = person;
}
/**
* @return Returns the removeDate.
*/
public Date getRemoveDate() {
return removeDate;
}
/**
* @param removeDate The removeDate to set.
*/
public void setRemoveDate(Date removeDate) {
this.removeDate = removeDate;
}
/**
* @return Returns the operator.
*/
public Person getOperator() {
return operator;
}
/**
* @param operator The operator to set.
*/
public void setOperator(Person operator) {
this.operator = operator;
}

}

5.2Image.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.school71.imageims.model">
<class name="Image" table="SCOOL_IMAGE" dynamic-update="true" dynamic-insert="true">
<!--
<cache usage="read-write"/>
-->
<id name="imageId" column="IMAGE_ID">
<generator class="assigned"> </generator>
</id>

<property name="fileName" type="java.lang.String" column="FILE_NAME" />
<property name="isDelete" type="java.lang.String" column="IS_DELETE" />
<!--
<property name="catalogFId" type="java.lang.String" column="CATALOG_F_ID" not-null="true"/>
-->
<many-to-one name="parentCatalog" column="CATALOG_F_ID" class="ParentCatalog" unique="true" fetch="join" lazy="false"></many-to-one>
<!--
<property name="catalogSId" type="java.lang.String" column="CATALOG_S_ID" not-null="true"/>
-->
<many-to-one name="childCatalog" column="CATALOG_S_ID" class="ChildCatalog" unique="true" fetch="join" lazy="false"></many-to-one>

<many-to-one name="person" column="USER_NAME" class="Person" unique="true" fetch="select" lazy="false"></many-to-one>
<property name="imageName" type="java.lang.String" column="IMAGE_NAME" />
<property name="size" type="java.lang.Long" column="SIZE" />
<property name="description" type="java.lang.String" column="DESCRIPTION"/>
<property name="createDate" type="java.util.Date" column="CREATE_DATE" />
<property name="removeDate" type="java.util.Date" column="REMOVE_DATE" />
<property name="WH" type="java.lang.String" column="WH"/>
<many-to-one name="operator" column="OPERATOR" class="Person" unique="true" fetch="select" lazy="false"></many-to-one>
</class>

</hibernate-mapping>

6.1Group.java

/**
* Group
*/
package com.school71.imageims.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
* @author <a href="mailto:sogui@126.com">sogui</a>
* @version 1.0
* @date 2006-9-19 14:02:38
*/
public class Group implements Serializable{
/**
* serialVersionUID long
*/
private static final long serialVersionUID = 1L;
private String groupId;
private String name;
private Long popedomValue;
private Set<Person> persons=new HashSet<Person>();
public String toString(){
return "{groupId:'"+groupId+"',name:'"+name+"',popedomValue:"+popedomValue+"}";
}
/**
* @hibernate.id
* column="GROUP_ID"
*
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐