📄 objectdao.java
字号:
/**
$Id: ObjectDAO.java,v 1.2 2008/07/01 07:47:22 leonchunlai Exp $
Copyright (C) 2007- Leon Chunlai.
All rights reserved.
This API provides us with convenience to access the database using Hibernate. The goal is
to enable the API to be mostly reused, so all the types are 'Object'. And it also gives the
methods as many as possible so that it can solve most of the problems you will meet.
To use this API, I suggest that you use the 'GOF Adapter Pattern' to make this interface 'ObjectDAO'
suit your interface. The specific ways are as follows:
1.in the implementing class of your interface, you use this 'dao.ObjectDAO' directly;
eg.
public interface StudentDAO{
public abstract List queryAllStudents();
}
public class StudentDAOImpl implements StudentDAO{
ObjectDAO objectDAO=new ObjectDAOImpl(new Student());
public List queryAllStudents(){
return objectDAO.queryAllObjects();
}
}
2.let the implementing class of your interface extend 'dao.impl.ObjectDAOImpl', then
use 'dao.impl.ObjectDAOImpl' methods to suit your interface
eg.
public interface StudentDAO{
public abstract List queryAllStudents();
}
public class StudentDAOImpl extends ObjectDAOImpl{
public StudentDAOImpl(Student student){
super(student);
}
public List queryAllStudents(){
return queryAllObjects(Student);
}
}
*/
package org.HumResManSys.dao;
import java.util.List;
import org.hibernate.Session;
/**
* @author Leon chunlai
* @version: 1.0 $, $Date: 2008/07/01 07:47:22 $
*/
public interface ObjectDAO {
/** this method enables you to query all the objects.
*
* 查找所有对象
*/
public abstract List queryAllObjects();
/** this method enables you to query all the objects, and the return results will be ordered
* by id
*
* 查找所有对象,返回时按ID排序
*/
public abstract List queryAllObjectsOrderByID();
/** this method enables you to query all the objects, and the return results will be ordered
* by the condition you gived. And the condition should be one of the entity's attribute name.
*
* 查找所有对象,返回时按条件排序
*/
public abstract List queryAllObjectsOrderByCondition(String condition);
/** this method enables you to query one object, and you need to give the entity's id.
*
* 按ID查找对象
*/
public abstract Object queryOneObjectByID(String id);
/**
* 按条件查找一个对象
*
* @param conditionName
* @param conditionValue
* @return Object
*/
public Object queryOneObjectByCondition(String conditionName,String conditionValue);
/** this method enables you to query one object by the condition you gived. The conditionName
* should be one of the entity's attribute name. you should give the 'conditionName' and the
* 'conditionValue'. eg. conditionName='id' conditionValue='3' means you want to query one
* object whose id equals to '3'.
*
* 按属性查找对象
*/
public abstract List queryObjectsByCondition(String conditionName,String conditionValue);
/** this method enables you to query all the objects. the return results will be ordered
* by id, and the return type is List.
*
* 按ID查找对象,返回List
*/
public abstract List queryOneObjectByIDReturnList(String id);
/** this method enables you to query objects and the query condition is the entity you gived.
* eg. object.setId('1');object.setName('leon');Then 'queryObjectsByEntityIgnoreCase(object)'
* is like: select * from object where id='1' and name='leon'.Also the values ignore case.
*
* 按实体类来查找对象,忽略各个属性的大小写,返回List
*/
public abstract List queryObjectsByEntityIgnoreCase(Object object);
/** this method enables you to query objects and the query condition is the entity you gived.
* eg. object.setId('1');object.setName('leon');Then 'queryObjectsByEntityEnableLike(object)'
* is like: select * from object where id='%1%' and name='%leon%'.
*
* 按实体类来查找对象,各个属性模糊查找,返回List
*/
public abstract List queryObjectsByEntityEnableLike(Object object);
/** this method enables you to query objects and the query condition is the entity you gived.
* eg. object.setId('1');object.setName('leon');Then 'queryObjectsByEntity(object)'
* is like: select * from object where id='1' and name='leon'.
*
* 按实体类来查找对象
*/
public abstract List queryObjectsByEntity(Object object);
/** on the web, when the data we queried from the database are too many. Then we need to divide
* all the data into groups, and each group will be shown in one web page. eg. if 'firstResult=
* 0 maxResults=10', then it will fetch the data from row 1 to row 10.if 'firstResult=10
* maxResults=10', then it will fetch the data from row 11 to row 20.
*
* 分页查询,查询结果按Id排序
*/
public abstract List queryObjectsByPageOrderById(int firstResult,int maxResults);
/** this method is nearly the same as the method above, but the return results will be ordered by
* the condition you gived.
*
* 分页查询,查询结果按指定的条件排序
*/
public abstract List queryObjectsByPageOrderByCondition(String Condition,int firstResult,int maxResults);
/** this method enables you to insert a row into the table. But using Hibernate, we manipulate the
* table throught an entity. So the parameter of this method is an entity.
*
* 添加一个对象
*/
public abstract boolean createObject(Object object);
/** this method enables you to update a row int the table.
*
* 修改信息对象
*/
public abstract boolean updateObject(Object object);
/** this method enables you to delete a row in the table by id.
*
* 按ID删除对象
*/
public abstract boolean deleteObjectByID(String id);
/**删除对象
*
* @param object
* @return
*/
public abstract boolean deleteObject(Object object);
/**按条件删除对象
*
* @param conditionName
* @param conditionValue
* @return
*/
public boolean deleteObjectByCondition(String conditionName,String conditionValue);
public Session getCurrentSession();
/**
* close session
*
*/
public void closeSession();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -