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

com.yuyenews.easy.session.SqlSession Maven / Gradle / Ivy

The newest version!
package com.yuyenews.easy.session;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

import com.yuyenews.easy.base.ExBaseDao;
import com.yuyenews.easy.util.ConnectionUtil;

public class SqlSession extends ExBaseDao {
	
	private String dataSourceName;
	
	/**
	 * 不让外部实例化,强制指定数据源
	 */
	private SqlSession() {}
	
	/**
	 * 指定数据源
	 * @param name mingc
	 * @return duix
	 */
	public static SqlSession get(String name) {
		SqlSession session = new SqlSession();
		session.dataSourceName = name;
		return session;
	}
	
	/**
	 * 查询数据,返回map类型的list集合
	 * @param sql sql
	 * @param args canshu
	 * @return duix
	 */
	public List> selectList(String sql,Object[] args){
		Connection connection = ConnectionUtil.getConnection(dataSourceName);
		return super.selectList(connection, sql, args);
	}
	
	/**
	 * 查询数据,返回list集合
	 * @param sql sql
	 * @param args canshu
	 * @param cls lei
	 * @return duix
	 */
	public  List selectList(String sql,Object[] args,Class cls){
		Connection connection = ConnectionUtil.getConnection(dataSourceName);
		return super.selectList(connection, sql, args,cls);
	}
	
	/**
	 * 查询一条数据,返回map
	 * @param sql sql
	 * @param args canshu
	 * @return duix
	 */
	public Map selectOne(String sql,Object[] args) {
		Connection connection = ConnectionUtil.getConnection(dataSourceName);
		return super.selectOne(connection, sql, args);
	}
	
	/**
	 * 查询一条数据
	 * @param sql sql
	 * @param args canshu
	 * @param cls lei
	 * @return duix
	 */
	public  T selectOne(String sql,Object[] args,Class cls) {
		Connection connection = ConnectionUtil.getConnection(dataSourceName);
		return super.selectOne(connection, sql, args,cls);
	}
	
	/**
	 * 增删改
	 * @param sql sql
	 * @param args canshu
	 * @return duix
	 */
	public int update(String sql,Object[] args) {
		Connection connection = ConnectionUtil.getConnection(dataSourceName);
		return super.update(connection,sql, args);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy