All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jiucheng.plugin.db.BaseDaoImpl Maven / Gradle / Ivy

The newest version!
package org.jiucheng.plugin.db;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

import org.jiucheng.ioc.annotation.Impl;
import org.jiucheng.ioc.annotation.Repository;
import org.jiucheng.orm.SQLHelper;
import org.jiucheng.orm.dialect.Dialect;
import org.jiucheng.orm.dialect.impl.MySQLDialect;
import org.jiucheng.orm.support.DruidDataSourceBuilder;
import org.jiucheng.orm.util.EntityUtil;
import org.jiucheng.orm.util.JdbcUtil;

@Repository("baseDao")
public class BaseDaoImpl implements IBaseDao {
    
    @Impl(MySQLDialect.class)
    private Dialect dialect;
    
    @Impl(DruidDataSourceBuilder.class)
    private DruidDataSourceBuilder druidDataSourceBuilder;
    
    public  Serializable save(T entity) {
        return EntityUtil.save(getDialect(), getConn(), entity);
    }
    
    public  Serializable saveOrUpdate(T entity) {
        return EntityUtil.saveOrUpdate(getDialect(), getConn(), entity);
    }
    
    public  boolean update(T entity) {
        return EntityUtil.update(getDialect(), getConn(), entity);
    }

    public  int delete(T entity) {
        return EntityUtil.delete(getDialect(), getConn(), entity);
    }

    public  List list(T entity) {
        return EntityUtil.list(getDialect(), getConn(), entity);
    }
    
    private Dialect getDialect() {
        return dialect;
    }
    
    public Connection getConn() {
        return druidDataSourceBuilder.getConn();
    }

    public Serializable saveBySQL(SQLHelper sh) {
        return JdbcUtil.save(getConn(), sh);
    }

    public boolean updateBySQL(SQLHelper sh) {
        if(JdbcUtil.update(getConn(), sh) > 0 ) {
            return true;
        }
        return false;
    }

    public boolean deleteBySQL(SQLHelper sh) {
        if(JdbcUtil.delete(getConn(), sh) > 0) {
            return true;
        }
        return false;
    }

    @SuppressWarnings("rawtypes")
    public List listBySQL(SQLHelper sh) {
        return JdbcUtil.list(getConn(), sh);
    }
    
    public  List listBySQL(Class clazz, SQLHelper sh) {
    	ResultSet rs = JdbcUtil.getResultSet(getConn(), sh);
    	return EntityUtil.resultSetToListEntity(dialect, rs, clazz);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy