Java tutorial
/* * Copyright 2014 MOSPA(Ministry of Security and Public Administration). * * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 * * 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 egovframework.rte.psl.dataaccess; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.support.SqlSessionDaoSupport; /** * Spring? MyBatis ? ? parent DAO ?. * * @author Vincent Han * @since 2.6 * *<pre> * ? ? * ------------ -------- --------------------------- * 2014.01.22 ResultHandler?? listToOutUsingResultHandler() * 2014.07.11 ? selectByPk Deprecated ? getSqlSession *</pre> */ public abstract class EgovAbstractMapper extends SqlSessionDaoSupport { /** * Annotation ? sqlSession(SqlSessionFactoryBean)? * ? super(SqlSessionDaoSupport)? setSqlSessionFactory . * <p> * SqlSessionTemplate? ? ? ? SqlSessionFactory ?. (Batch SqlSessionTemplate ) * </p> * * @param sqlSession SqlSessionFactory MyBatis? ? */ @Resource(name = "sqlSession") public void setSqlSessionFactory(SqlSessionFactory sqlSession) { super.setSqlSessionFactory(sqlSession); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * * @return DBMS ? insert ? count */ public int insert(String queryId) { return getSqlSession().insert(queryId); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ?? ? ?( VO ? Map) * * @return DBMS ? insert ? count */ public int insert(String queryId, Object parameterObject) { return getSqlSession().insert(queryId, parameterObject); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * * @return DBMS ? update ? count */ public int update(String queryId) { return getSqlSession().update(queryId); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??(key ? ??) ? ?( VO ? Map) * * @return DBMS ? update ? count */ public int update(String queryId, Object parameterObject) { return getSqlSession().update(queryId, parameterObject); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * * @return DBMS ? delete ? count */ public int delete(String queryId) { return getSqlSession().delete(queryId); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??(?? key ) ? ?( VO ? Map) * * @return DBMS ? delete ? count */ public int delete(String queryId, Object parameterObject) { return getSqlSession().delete(queryId, parameterObject); } //CHECKSTYLE:OFF /** * ? selectOne() . * @deprecated select() * * @see EgovAbstractMapper.selectOne() */ //CHECKSTYLE:ON @Deprecated public Object selectByPk(String queryId, Object parameterObject) { return getSqlSession().selectOne(queryId, parameterObject); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * * @return ? - SQL mapping ?? resultType/resultMap ? ? ? ?( VO ? Map) */ public <T> T selectOne(String queryId) { return getSqlSession().selectOne(queryId); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??(key) ? ?( VO ? Map) * * @return ? - SQL mapping ?? resultType/resultMap ? ? ? ?( VO ? Map) */ public <T> T selectOne(String queryId, Object parameterObject) { return getSqlSession().selectOne(queryId, parameterObject); } /** * ?? Map ? . * ? ? ?, ? ? ?. * * @param queryId - SQL mapping ID * @param mapKey - ?? ? * * @return ? - SQL mapping ?? resultType/resultMap ? ? ? ?( VO ? Map)? Map */ public <K, V> Map<K, V> selectMap(String queryId, String mapKey) { return getSqlSession().selectMap(queryId, mapKey); } /** * ?? Map ? . * ? ? ?, ? ? ?. * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??( ) ? ?( VO ? Map) * @param mapKey - ?? ? * * @return ? - SQL mapping ?? resultType/resultMap ? ? ? ?( VO ? Map)? Map */ public <K, V> Map<K, V> selectMap(String queryId, Object parameterObject, String mapKey) { return getSqlSession().selectMap(queryId, parameterObject, mapKey); } /** * ?? Map ? . * ? ? ?, ? ? ?. * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??( ) ? ?( VO ? Map) * @param mapKey - ?? ? * @param rowBounds - ?? ? * * @return ? - SQL mapping ?? resultType/resultMap ? ? ? ?( VO ? Map)? Map */ public <K, V> Map<K, V> selectMap(String queryId, Object parameterObject, String mapKey, RowBounds rowBounds) { return getSqlSession().selectMap(queryId, parameterObject, mapKey, rowBounds); } //CHECKSTYLE:OFF /** * ? selectList() . * * @see EgovAbstractMapper.selectList() * @deprecated List<?> */ //CHECKSTYLE:ON @Deprecated public List<?> list(String queryId, Object parameterObject) { return getSqlSession().selectList(queryId, parameterObject); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * * @return List ? - SQL mapping ?? resultType/resultMap ? ? ?( VO ? Map)? List */ public <E> List<E> selectList(String queryId) { return getSqlSession().selectList(queryId); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??( ) ? ?( VO ? Map) * * @return List ? - SQL mapping ?? resultType/resultMap ? ? ?( VO ? Map)? List */ public <E> List<E> selectList(String queryId, Object parameterObject) { return getSqlSession().selectList(queryId, parameterObject); } /** * SQL mapping ? . * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??( ) ? ?( VO ? Map) * @param rowBounds - ?? ? * * @return List ? - SQL mapping ?? resultType/resultMap ? ? ?( VO ? Map)? List */ public <E> List<E> selectList(String queryId, Object parameterObject, RowBounds rowBounds) { return getSqlSession().selectList(queryId, parameterObject, rowBounds); } /** * SQL mapping ? . * ( - pageIndex pageSize skipResults, maxResults ibatis ) * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??( ) ? ?( VO ? Map) * @param pageIndex - ? * @param pageSize - ? (pageSize) * * @return List ? - SQL mapping ?? resultType/resultMap ? ? ?( VO ? Map) List */ public List<?> listWithPaging(String queryId, Object parameterObject, int pageIndex, int pageSize) { int skipResults = pageIndex * pageSize; //int maxResults = (pageIndex * pageSize) + pageSize; RowBounds rowBounds = new RowBounds(skipResults, pageSize); return getSqlSession().selectList(queryId, parameterObject, rowBounds); } /** * SQL ResultHandler ? . * ResultHandler ?? ? handleResult() ? ? ?. * * @param queryId - SQL mapping ID * @param handler - ResultHandler * @return * * @return List ? - SQL mapping ?? resultType/resultMap ? ? ?( VO ? Map)? List */ public void listToOutUsingResultHandler(String queryId, ResultHandler handler) { getSqlSession().select(queryId, handler); } }