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

cn.sylinx.hbatis.ext.mirage.DefaultMirageCacheQuery Maven / Gradle / Ivy

There is a newer version: 2.0.0.RELEASE
Show newest version
package cn.sylinx.hbatis.ext.mirage;

import java.util.List;
import java.util.Map;

import cn.sylinx.hbatis.db.cache.CacheQuery;
import cn.sylinx.hbatis.db.common.Record;
import cn.sylinx.hbatis.db.mapper.ModelBuilder;
import cn.sylinx.hbatis.db.mapper.QueryMapper;
import cn.sylinx.hbatis.ext.parse.SqlParser;
import cn.sylinx.hbatis.ext.res.ClasspathSqlResource;
import cn.sylinx.hbatis.kit.Tuple;

public class DefaultMirageCacheQuery implements MirageCacheQuery {

	private CacheQuery cacheQuery;

	public DefaultMirageCacheQuery(CacheQuery cacheQuery) {
		this.cacheQuery = cacheQuery;
	}

	@Override
	public List> queryForMapList(ClasspathSqlResource sqlResource, Map params) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);
		return cacheQuery.queryMap(st, pms);
	}

	@Override
	public List queryForRecords(ClasspathSqlResource sqlResource, Map params) {
		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);

		return cacheQuery.queryRecords(st, pms);
	}

	@Override
	public Record queryFirstRecord(ClasspathSqlResource sqlResource, Map params) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);

		return cacheQuery.queryFirstRecord(st, pms);
	}

	@Override
	public List queryObjectArrayList(ClasspathSqlResource sqlResource, Map params) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);

		return cacheQuery.query(st, pms);
	}

	@Override
	public Object[] queryFirstObjectArray(ClasspathSqlResource sqlResource, Map params) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);

		return cacheQuery.queryFirst(st, pms);
	}

	@Override
	public Map queryFirstForMap(ClasspathSqlResource sqlResource, Map params) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);

		return cacheQuery.queryFirstMap(st, pms);
	}

	@Override
	public  List query(ClasspathSqlResource sqlResource, Map params, Class clz) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);
		QueryMapper mapper = ModelBuilder.buildQueryMapper(clz);
		return cacheQuery.query(st, mapper, pms);
	}

	@Override
	public  T queryFirst(ClasspathSqlResource sqlResource, Map params, Class clz) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);
		QueryMapper mapper = ModelBuilder.buildQueryMapper(clz);
		return cacheQuery.queryFirst(st, mapper, pms);
	}

	@Override
	public  List queryObjectList(ClasspathSqlResource sqlResource, Map params, Class clz) {

		Tuple tp = SqlParser.parseSql(sqlResource, params);
		String st = (String) tp.get(0);
		Object[] pms = (Object[]) tp.get(1);
		
		return cacheQuery.queryObject(st, clz, pms);
	}
	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy