org.tinygroup.dao.AbstractDao Maven / Gradle / Ivy
/**
* Copyright (c) 1997-2013, www.tinygroup.org ([email protected]).
*
* Licensed under the GPL, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.tinygroup.dao;
import org.tinygroup.dao.hibernate.HibernateBaseDaoImpl;
import org.tinygroup.dao.query.PagingObject;
import org.tinygroup.dao.query.QueryObject;
import org.tinygroup.dao.util.DaoUtil;
import org.tinygroup.logger.Logger;
import org.tinygroup.logger.LoggerFactory;
import javax.annotation.Resource;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 抽象Dao
*
* @author luoguo
*
* @param
*/
public abstract class AbstractDao implements
DaoInterface {
private Logger logger = LoggerFactory.getLogger(AbstractDao.class);
private Class entityClass;
public AbstractDao() {
entityClass = (Class) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
@Resource
HibernateBaseDaoImpl basicDaoService;// basicDaoService对应BasicDaoImpl成为数据访问组件的bean名字
protected HibernateBaseDaoImpl getBaseDaoImpl() {
return basicDaoService;
}
public T save(T object) {
try {
return (T) basicDaoService.save(object);
} catch (Exception e) {
logger.errorMessage("保存对象失败",e);
}
return null;
}
public T update(T object) {
try {
return (T) basicDaoService.update(object);
} catch (Exception e) {
logger.errorMessage("更新对象失败",e);
}
return null;
}
public T delete(T object) {
try {
basicDaoService.delete(object);
} catch (Exception e) {
logger.errorMessage("删除对象失败",e);
}
return object;
}
public Collection save(Collection objects) {
try {
return (Collection) basicDaoService.save(objects);
} catch (Exception e) {
logger.errorMessage("保存对象集合失败",e);
}
return null;
}
public Collection delete(Collection objects) {
try {
basicDaoService.delete(objects);
} catch (Exception e) {
logger.errorMessage("删除对象集合失败",e);
}
return null;
}
public T[] save(T[] objects) {
try {
return (T[]) basicDaoService.save(objects);
} catch (Exception e) {
logger.errorMessage("保存对象数组失败",e);
}
return null;
}
public T[] delete(T[] objects) {
try {
return (T[]) basicDaoService.delete(objects);
} catch (Exception e) {
logger.errorMessage("删除对象数组失败",e);
}
return null;
}
public Collection update(Collection objects) {
try {
return (Collection) basicDaoService.update(objects);
} catch (Exception e) {
logger.errorMessage("更新对象集合失败",e);
}
return null;
}
public T[] update(T[] objects) {
try {
return (T[]) basicDaoService.update(objects);
} catch (Exception e) {
logger.errorMessage("更新对象数组失败",e);
}
return null;
}
public Collection query(QueryObject queryObject) {
queryObject = checkNull(queryObject);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy