Java Code Examples for org.apache.ibatis.session.Configuration#getTypeHandlerRegistry()
The following examples show how to use
org.apache.ibatis.session.Configuration#getTypeHandlerRegistry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutorTestHelper.java From mybaties with Apache License 2.0 | 6 votes |
public static MappedStatement createSelectAuthorWithIDof99MappedStatement(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config,"SELECT * FROM author WHERE id = 99"), SqlCommandType.SELECT) .statementType(StatementType.STATEMENT) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>()).build()) .resultMaps(new ArrayList<ResultMap>() { { add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).build()); add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build()); } }).build()); } }).build(); return ms; }
Example 2
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 6 votes |
public static MappedStatement prepareUpdateAuthorMappedStatement(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "updateAuthor", new StaticSqlSource(config,"UPDATE author SET username = ?, password = ?, email = ?, bio = ? WHERE id = ?"), SqlCommandType.UPDATE) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build()); add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); } }).build()) .cache(authorCache).build(); return ms; }
Example 3
Source File: ExecutorTestHelper.java From mybaties with Apache License 2.0 | 6 votes |
public static MappedStatement prepareSelectAuthorViaOutParams(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "selectAuthorViaOutParams", new StaticSqlSource(config, "{call selectAuthorViaOutParams(?,?,?,?,?)}"), SqlCommandType.SELECT) .statementType(StatementType.CALLABLE) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); } }).build()) .resultMaps(new ArrayList<ResultMap>()) .cache(authorCache).build(); return ms; }
Example 4
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 6 votes |
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT) .parameterMap( new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build()); add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build()); } }).build()) .cache(authorCache) .keyGenerator(new Jdbc3KeyGenerator()) .keyProperty("id") .build(); return ms; }
Example 5
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 6 votes |
public static MappedStatement prepareSelectAuthorViaOutParams(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "selectAuthorViaOutParams", new StaticSqlSource(config, "{call selectAuthorViaOutParams(?,?,?,?,?)}"), SqlCommandType.SELECT) .statementType(StatementType.CALLABLE) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build()); } }).build()) .resultMaps(new ArrayList<ResultMap>()) .cache(authorCache).build(); return ms; }
Example 6
Source File: ResultSetWrapper.java From mybatis with Apache License 2.0 | 5 votes |
public ResultSetWrapper(ResultSet rs, Configuration configuration) throws SQLException { super(); this.typeHandlerRegistry = configuration.getTypeHandlerRegistry(); this.resultSet = rs; final ResultSetMetaData metaData = rs.getMetaData(); final int columnCount = metaData.getColumnCount(); for (int i = 1; i <= columnCount; i++) { columnNames.add(configuration.isUseColumnLabel() ? metaData.getColumnLabel(i) : metaData.getColumnName(i)); jdbcTypes.add(JdbcType.forCode(metaData.getColumnType(i))); classNames.add(metaData.getColumnClassName(i)); } }
Example 7
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 5 votes |
public static MappedStatement prepareSelectOneAuthorMappedStatement(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final ResultMap rm = new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).build()); add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "favouriteSection", "favourite_section", registry.getTypeHandler(Section.class)).build()); } }).build(); MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config,"SELECT * FROM author WHERE id = ?"), SqlCommandType.SELECT) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); } }).build()) .resultMaps(new ArrayList<ResultMap>() { { add(rm); } }) .cache(authorCache).build(); return ms; }
Example 8
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 5 votes |
public static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config,"SELECT * FROM author WHERE id = ?"), SqlCommandType.SELECT) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); } }).build()) .resultMaps(new ArrayList<ResultMap>() { { add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, null, "id", registry.getTypeHandler(Integer.class)).javaType(int.class).flags(new ArrayList<ResultFlag>() { { add(ResultFlag.CONSTRUCTOR); } }).build()); add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "favouriteSection", "favourite_section", registry.getTypeHandler(Section.class)).build()); } }).build()); } }) .cache(authorCache) .build(); return ms; }
Example 9
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 5 votes |
public static MappedStatement prepareInsertAuthorProc(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "insertAuthorProc", new StaticSqlSource(config,"{call insertAuthor(?,?,?,?)}"), SqlCommandType.INSERT) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build()); } }).build()) .cache(authorCache).build(); return ms; }
Example 10
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 5 votes |
public static MappedStatement prepareComplexSelectBlogMappedStatement(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final SqlSource sqlSource = new StaticSqlSource(config, "SELECT b.id, b.author_id, b.title, a.username, a.password, a.email, a.bio" + " FROM blog b" + " INNER JOIN author a ON b.author_id = a.id" + " WHERE b.id = ?"); final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", int.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); } }).build(); final ResultMap resultMap = new ResultMap.Builder(config, "defaultResultMap", Blog.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "title", "title", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.id", "author_id", registry.getTypeHandler(int.class)).build()); add(new ResultMapping.Builder(config, "author.username", "username", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.password", "password", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.email", "email", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.bio", "bio", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "posts", "id", registry.getTypeHandler(int.class)).javaType(List.class).nestedQueryId("selectPostsForBlog").build()); } }).build(); return new MappedStatement.Builder(config, "selectBlogById", sqlSource, SqlCommandType.SELECT) .parameterMap(parameterMap) .resultMaps(new ArrayList<ResultMap>() { { add(resultMap); } }).build(); }
Example 11
Source File: ParameterMapping.java From mybatis with Apache License 2.0 | 5 votes |
private void resolveTypeHandler() { //如果没有指定特殊的typeHandler,则根据javaType,jdbcType来查表确定一个默认的typeHandler if (parameterMapping.typeHandler == null && parameterMapping.javaType != null) { Configuration configuration = parameterMapping.configuration; TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry(); parameterMapping.typeHandler = typeHandlerRegistry.getTypeHandler(parameterMapping.javaType, parameterMapping.jdbcType); } }
Example 12
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 5 votes |
public static MappedStatement prepareSelectBlogByIdAndAuthor(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final SqlSource sqlSource = new StaticSqlSource(config,"SELECT b.id, b.author_id, b.title, a.username, a.password, a.email, a.bio" + " FROM blog b" + " INNER JOIN author a ON b.author_id = a.id" + " WHERE b.id = ? and a.id = ?"); final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Map.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "blogId", registry.getTypeHandler(int.class)).build()); add(new ParameterMapping.Builder(config, "authorId", registry.getTypeHandler(int.class)).build()); } }).build(); final ResultMap resultMap = new ResultMap.Builder(config, "defaultResultMap", Blog.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "title", "title", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.id", "author_id", registry.getTypeHandler(int.class)).build()); add(new ResultMapping.Builder(config, "author.username", "username", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.password", "password", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.email", "email", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "author.bio", "bio", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "posts", "id", registry.getTypeHandler(int.class)).javaType(List.class).nestedQueryId("selectPostsForBlog").build()); } }).build(); return new MappedStatement.Builder(config, "selectBlogByIdAndAuthor", sqlSource, SqlCommandType.SELECT) .parameterMap(parameterMap) .resultMaps(new ArrayList<ResultMap>() { { add(resultMap); } }).build(); }
Example 13
Source File: ResultSetWrapper.java From mybaties with Apache License 2.0 | 5 votes |
public ResultSetWrapper(ResultSet rs, Configuration configuration) throws SQLException { super(); this.typeHandlerRegistry = configuration.getTypeHandlerRegistry(); this.resultSet = rs; final ResultSetMetaData metaData = rs.getMetaData(); final int columnCount = metaData.getColumnCount(); for (int i = 1; i <= columnCount; i++) { columnNames.add(configuration.isUseColumnLabel() ? metaData.getColumnLabel(i) : metaData.getColumnName(i)); jdbcTypes.add(JdbcType.forCode(metaData.getColumnType(i))); classNames.add(metaData.getColumnClassName(i)); } }
Example 14
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 5 votes |
public static MappedStatement prepareDeleteAuthorMappedStatement(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); MappedStatement ms = new MappedStatement.Builder(config, "deleteAuthor", new StaticSqlSource(config,"DELETE FROM author WHERE id = ?"), SqlCommandType.DELETE) .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); } }).build()) .cache(authorCache) .build(); return ms; }
Example 15
Source File: ExecutorTestHelper.java From mybaties with Apache License 2.0 | 5 votes |
public static MappedStatement prepareInsertAuthorMappedStatementWithBeforeAutoKey(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final ResultMap rm = new ResultMap.Builder(config, "keyResultMap", Integer.class, new ArrayList<ResultMapping>()) .build(); MappedStatement kms = new MappedStatement.Builder(config, "insertAuthor!selectKey", new StaticSqlSource(config,"SELECT 123456 as id FROM SYSIBM.SYSDUMMY1"), SqlCommandType.SELECT) .keyProperty("id") .resultMaps(new ArrayList<ResultMap>() { { add(rm); } }) .build(); config.addMappedStatement(kms); MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new DynamicSqlSource(config, new TextSqlNode("INSERT INTO author (id,username,password,email,bio,favourite_section) values(#{id},#{username},#{password},#{email},#{bio:VARCHAR},#{favouriteSection})")), SqlCommandType.INSERT) .parameterMap( new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(Integer.class)).build()); add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build()); add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build()); } }).build()) .cache(authorCache) .keyGenerator(new SelectKeyGenerator(kms, true)) .keyProperty("id") .build(); return ms; }
Example 16
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 5 votes |
public static MappedStatement prepareInsertAuthorMappedStatementWithBeforeAutoKey(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final ResultMap rm = new ResultMap.Builder(config, "keyResultMap", Integer.class, new ArrayList<ResultMapping>()) .build(); MappedStatement kms = new MappedStatement.Builder(config, "insertAuthor!selectKey", new StaticSqlSource(config,"SELECT 123456 as id FROM SYSIBM.SYSDUMMY1"), SqlCommandType.SELECT) .keyProperty("id") .resultMaps(new ArrayList<ResultMap>() { { add(rm); } }) .build(); config.addMappedStatement(kms); MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new DynamicSqlSource(config, new TextSqlNode("INSERT INTO author (id,username,password,email,bio,favourite_section) values(#{id},#{username},#{password},#{email},#{bio:VARCHAR},#{favouriteSection})")), SqlCommandType.INSERT) .parameterMap( new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(Integer.class)).build()); add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build()); add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build()); add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build()); } }).build()) .cache(authorCache) .keyGenerator(new SelectKeyGenerator(kms, true)) .keyProperty("id") .build(); return ms; }
Example 17
Source File: DefaultResultSetHandlerTest.java From mybatis with Apache License 2.0 | 4 votes |
/** * Contrary to the spec, some drivers require case-sensitive column names when getting result. * * @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a> */ @Test public void shouldRetainColumnNameCase() throws Exception { final Configuration config = new Configuration(); final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final MappedStatement ms = new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps( new ArrayList<ResultMap>() { { add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "cOlUmN1", "CoLuMn1", registry.getTypeHandler(Integer.class)).build()); } }).build()); } }).build(); final Executor executor = null; final ParameterHandler parameterHandler = null; final ResultHandler resultHandler = null; final BoundSql boundSql = null; final RowBounds rowBounds = new RowBounds(0, 100); final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds); when(stmt.getResultSet()).thenReturn(rs); when(rs.getMetaData()).thenReturn(rsmd); when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY); when(rs.next()).thenReturn(true).thenReturn(false); when(rs.getInt("CoLuMn1")).thenReturn(100); when(rs.wasNull()).thenReturn(false); when(rsmd.getColumnCount()).thenReturn(1); when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1"); when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER); when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName()); when(stmt.getConnection()).thenReturn(conn); when(conn.getMetaData()).thenReturn(dbmd); when(dbmd.supportsMultipleResultSets()).thenReturn(false); // for simplicity. final List<Object> results = fastResultSetHandler.handleResultSets(stmt); assertEquals(1, results.size()); assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1")); }
Example 18
Source File: DefaultResultSetHandlerTest.java From mybaties with Apache License 2.0 | 4 votes |
/** * Contrary to the spec, some drivers require case-sensitive column names when getting result. * * @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a> */ @Test public void shouldRetainColumnNameCase() throws Exception { final Configuration config = new Configuration(); final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final MappedStatement ms = new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps( new ArrayList<ResultMap>() { { add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "cOlUmN1", "CoLuMn1", registry.getTypeHandler(Integer.class)).build()); } }).build()); } }).build(); final Executor executor = null; final ParameterHandler parameterHandler = null; final ResultHandler resultHandler = null; final BoundSql boundSql = null; final RowBounds rowBounds = new RowBounds(0, 100); final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds); when(stmt.getResultSet()).thenReturn(rs); when(rs.getMetaData()).thenReturn(rsmd); when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY); when(rs.next()).thenReturn(true).thenReturn(false); when(rs.getInt("CoLuMn1")).thenReturn(100); when(rs.wasNull()).thenReturn(false); when(rsmd.getColumnCount()).thenReturn(1); when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1"); when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER); when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName()); when(stmt.getConnection()).thenReturn(conn); when(conn.getMetaData()).thenReturn(dbmd); when(dbmd.supportsMultipleResultSets()).thenReturn(false); // for simplicity. final List<Object> results = fastResultSetHandler.handleResultSets(stmt); assertEquals(1, results.size()); assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1")); }
Example 19
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 4 votes |
public static MappedStatement prepareSelectPostMappedStatement(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.section, p.subject, p.body, pt.tag_id," + " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" + " FROM post p" + " LEFT OUTER JOIN post_tag pt ON pt.post_id = p.id" + " LEFT OUTER JOIN tag t ON pt.tag_id = t.id" + " LEFT OUTER JOIN comment c ON c.post_id = p.id" + " WHERE p.id = ?"); final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); } }).build(); final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build()); } }).build(); final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build()); } }).build(); config.addResultMap(tagResultMap); config.addResultMap(commentResultMap); final ResultMap postResultMap = new ResultMap.Builder(config, "", Post.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "blog", "blog_id", registry.getTypeHandler(int.class)).javaType(Blog.class).nestedQueryId("selectBlogById").build()); add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build()); add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build()); add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build()); add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build()); } }).build(); return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT) .parameterMap(parameterMap) .resultMaps(new ArrayList<ResultMap>() { { add(postResultMap); } }).build(); }
Example 20
Source File: ExecutorTestHelper.java From mybatis with Apache License 2.0 | 4 votes |
public static MappedStatement prepareSelectPostWithBlogByAuthorMappedStatement(final Configuration config) { final TypeHandlerRegistry registry = config.getTypeHandlerRegistry(); final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.author_id, p.section, p.subject, p.body, pt.tag_id," + " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" + " FROM post p" + " LEFT OUTER JOIN post_tag pt ON pt.post_id = p.id" + " LEFT OUTER JOIN tag t ON pt.tag_id = t.id" + " LEFT OUTER JOIN comment c ON c.post_id = p.id" + " WHERE p.id = ?"); final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() { { add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build()); } }).build(); final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build()); } }).build(); final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build()); } }).build(); config.addResultMap(tagResultMap); config.addResultMap(commentResultMap); final ResultMap postResultMap = new ResultMap.Builder(config, "postResultMap", Post.class, new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)) .flags(new ArrayList<ResultFlag>() { { add(ResultFlag.ID); } }).build()); add(new ResultMapping.Builder(config, "blog").nestedQueryId("selectBlogByIdAndAuthor").composites(new ArrayList<ResultMapping>() { { add(new ResultMapping.Builder(config, "authorId", "author_id", registry.getTypeHandler(int.class)).build()); add(new ResultMapping.Builder(config, "blogId", "blog_id", registry.getTypeHandler(int.class)).build()); } }).build()); add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build()); add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build()); add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build()); add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build()); add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build()); } }).build(); return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT) .parameterMap(parameterMap) .resultMaps(new ArrayList<ResultMap>() { { add(postResultMap); } }).build(); }