tk.mybatis.mapper.mapperhelper.EntityHelper Java Examples
The following examples show how to use
tk.mybatis.mapper.mapperhelper.EntityHelper.
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: CountMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
/** * 批量删除 * @author Frodez * @date 2019-12-25 */ public String countByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectCount(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #2
Source File: IdTest.java From Mapper with MIT License | 6 votes |
@Test public void testSingleId(){ EntityHelper.initEntityNameMap(UserSingleId.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserSingleId.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertTrue(column.isId()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals(1, resultMap.getResultMappings().size()); Assert.assertTrue(resultMap.getResultMappings().get(0).getFlags().contains(ResultFlag.ID)); Assert.assertEquals("<where> AND name = #{name}</where>", SqlHelper.wherePKColumns(UserSingleId.class)); }
Example #3
Source File: OGNL.java From Mapper with MIT License | 6 votes |
/** * 检查 paremeter 对象中指定的 fields 是否全是 null,如果是则抛出异常 * * @param parameter * @param fields * @return */ public static boolean notAllNullParameterCheck(Object parameter, String fields) { if (parameter != null) { try { Set<EntityColumn> columns = EntityHelper.getColumns(parameter.getClass()); Set<String> fieldSet = new HashSet<String>(Arrays.asList(fields.split(","))); for (EntityColumn column : columns) { if (fieldSet.contains(column.getProperty())) { Object value = column.getEntityField().getValue(parameter); if (value != null) { return true; } } } } catch (Exception e) { throw new MapperException(SAFE_DELETE_ERROR, e); } } throw new MapperException(SAFE_DELETE_EXCEPTION); }
Example #4
Source File: IdTest.java From Mapper with MIT License | 6 votes |
@Test public void testCompositeKeys(){ EntityHelper.initEntityNameMap(UserCompositeKeys.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserCompositeKeys.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(2, columns.size()); Assert.assertEquals(2, entityTable.getEntityClassPKColumns().size()); for (EntityColumn column : columns) { Assert.assertTrue(column.isId()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals(2, resultMap.getResultMappings().size()); Assert.assertTrue(resultMap.getResultMappings().get(0).getFlags().contains(ResultFlag.ID)); Assert.assertTrue(resultMap.getResultMappings().get(1).getFlags().contains(ResultFlag.ID)); Assert.assertEquals("<where> AND name = #{name} AND orgId = #{orgId}</where>", SqlHelper.wherePKColumns(UserCompositeKeys.class)); }
Example #5
Source File: IdListProvider.java From Mapper with MIT License | 6 votes |
/** * 拼接条件 * * @param sql * @param entityClass */ private void appendWhereIdList(StringBuilder sql, Class<?> entityClass, boolean notEmpty){ Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); if(notEmpty){ sql.append("<bind name=\"notEmptyListCheck\" value=\"@tk.mybatis.mapper.additional.idlist.IdListProvider@notEmpty("); sql.append("idList, 'idList 不能为空')\"/>"); } sql.append("<where>"); sql.append("<foreach collection=\"idList\" item=\"id\" separator=\",\" open=\""); sql.append(column.getColumn()); sql.append(" in "); sql.append("(\" close=\")\">"); sql.append("#{id}"); sql.append("</foreach>"); sql.append("</where>"); } else { throw new MapperException("继承 ByIdList 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } }
Example #6
Source File: UpdateByDifferProvider.java From Mapper with MIT License | 6 votes |
/** * 乐观锁字段条件 * * @param entityClass * @return */ public String whereVersion(Class<?> entityClass) { Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass); boolean hasVersion = false; String result = ""; for (EntityColumn column : columnSet) { if (column.getEntityField().isAnnotationPresent(Version.class)) { if (hasVersion) { throw new VersionException(entityClass.getCanonicalName() + " 中包含多个带有 @Version 注解的字段,一个类中只能存在一个带有 @Version 注解的字段!"); } hasVersion = true; result = " AND " + column.getColumnEqualsHolder(NEWER); } } return result; }
Example #7
Source File: UpdateByDifferProvider.java From Mapper with MIT License | 6 votes |
/** * where主键条件 * * @param entityClass * @return */ public String wherePKColumns(Class<?> entityClass, boolean useVersion) { StringBuilder sql = new StringBuilder(); sql.append("<where>"); //获取全部列 Set<EntityColumn> columnSet = EntityHelper.getPKColumns(entityClass); //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值 for (EntityColumn column : columnSet) { sql.append(" AND " + column.getColumnEqualsHolder(NEWER)); } if (useVersion) { sql.append(whereVersion(entityClass)); } sql.append("</where>"); return sql.toString(); }
Example #8
Source File: AggregationProvider.java From Mapper with MIT License | 6 votes |
public static String aggregationGroupBy(Class<?> entityClass, String wrapKeyword, AggregateCondition condition) { if (condition.getGroupByProperties() != null && condition.getGroupByProperties().size() > 0) { EntityTable entityTable = EntityHelper.getEntityTable(entityClass); Map<String, EntityColumn> propertyMap = entityTable.getPropertyMap(); StringBuilder groupByBuilder = new StringBuilder(); for (String property : condition.getGroupByProperties()) { if (groupByBuilder.length() == 0) { groupByBuilder.append(" GROUP BY "); } else { groupByBuilder.append(", "); } groupByBuilder.append(propertyMap.get(property).getColumn()); } return groupByBuilder.toString(); } return ""; }
Example #9
Source File: AggregationProvider.java From Mapper with MIT License | 6 votes |
public static String aggregationSelectClause(Class<?> entityClass, String wrapKeyword, AggregateCondition condition) { Assert.notEmpty(condition.getAggregateProperty(), "aggregateProperty must have length; it must not be null or empty"); Assert.notNull(condition.getAggregateType(), "aggregateType is required; it must not be null"); EntityTable entityTable = EntityHelper.getEntityTable(entityClass); Map<String, EntityColumn> propertyMap = entityTable.getPropertyMap(); StringBuilder selectBuilder = new StringBuilder(); selectBuilder.append(condition.getAggregateType().name()); String columnName = propertyMap.get(condition.getAggregateProperty()).getColumn(); selectBuilder.append("(").append(columnName).append(")"); selectBuilder.append(" AS "); if (StringUtil.isNotEmpty(condition.getAggregateAliasName())) { selectBuilder.append(condition.getAggregateAliasName()); } else { selectBuilder.append(wrapKeyword(wrapKeyword, columnName)); } if (condition.getGroupByProperties() != null && condition.getGroupByProperties().size() > 0) { for (String property : condition.getGroupByProperties()) { selectBuilder.append(", "); columnName = propertyMap.get(property).getColumn(); selectBuilder.append(columnName).append(" AS ").append(wrapKeyword(wrapKeyword, columnName)); } } return selectBuilder.toString(); }
Example #10
Source File: IdsProvider.java From Mapper with MIT License | 6 votes |
/** * 根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String selectByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //将返回值修改为实体类型 setResultType(ms, entityClass); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectAllColumns(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #11
Source File: IdsProvider.java From Mapper with MIT License | 6 votes |
/** * 根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String deleteByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #12
Source File: IdsMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
/** * 批量查询 * @author Frodez * @date 2019-12-25 */ public String selectByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //将返回值修改为实体类型 setResultType(ms, entityClass); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectAllColumns(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #13
Source File: IdsProvider.java From tk-mybatis with MIT License | 6 votes |
/** * 根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String selectByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //将返回值修改为实体类型 setResultType(ms, entityClass); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.selectAllColumns(entityClass)); sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #14
Source File: IdsMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
/** * 批量删除 * @author Frodez * @date 2019-12-25 */ public String deleteByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #15
Source File: IdsProvider.java From tk-mybatis with MIT License | 6 votes |
/** * 根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段 * * @param ms * @return */ public String deleteByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in (${_parameter})"); } else { throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #16
Source File: SpecialProvider.java From tk-mybatis with MIT License | 6 votes |
/** * 批量插入 * * @param ms */ public String insertList(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); //开始拼sql StringBuilder sql = new StringBuilder(); sql.append(SqlHelper.insertIntoTable(entityClass, tableName(entityClass))); sql.append(SqlHelper.insertColumns(entityClass, true, false, false)); sql.append(" VALUES "); sql.append("<foreach collection=\"list\" item=\"record\" separator=\",\" >"); sql.append("<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">"); //获取全部列 Set<EntityColumn> columnList = EntityHelper.getColumns(entityClass); //当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值 for (EntityColumn column : columnList) { if (!column.isId() && column.isInsertable()) { sql.append(column.getColumnHolder("record") + ","); } } sql.append("</trim>"); sql.append("</foreach>"); return sql.toString(); }
Example #17
Source File: BaseDeleteProvider.java From Mapper with MIT License | 6 votes |
/** * 通过条件删除 * * @param ms * @return */ public String delete(MappedStatement ms) { Class<?> entityClass = getEntityClass(ms); StringBuilder sql = new StringBuilder(); //如果设置了安全删除,就不允许执行不带查询条件的 delete 方法 if (getConfig().isSafeDelete()) { sql.append(SqlHelper.notAllNullParameterCheck("_parameter", EntityHelper.getColumns(entityClass))); } // 如果是逻辑删除,则修改为更新表,修改逻辑删除字段的值 if (SqlHelper.hasLogicDeleteColumn(entityClass)) { sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass))); sql.append("<set>"); sql.append(SqlHelper.logicDeleteColumnEqualsValue(entityClass, true)); sql.append("</set>"); MetaObjectUtil.forObject(ms).setValue("sqlCommandType", SqlCommandType.UPDATE); } else { sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass))); } sql.append(SqlHelper.whereAllIfColumns(entityClass, isNotEmpty())); return sql.toString(); }
Example #18
Source File: SelectPartialMapperProvider.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
public String partialByIds(MappedStatement ms) { final Class<?> entityClass = getEntityClass(ms); String tableName = tableName(entityClass); StringBuilder sql = new StringBuilder(); sql.append("SELECT "); sql.append(tableName).append(".${fieldName} "); sql.append(SqlHelper.fromTable(entityClass, tableName)); Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass); if (columnList.size() == 1) { EntityColumn column = columnList.iterator().next(); sql.append(" where "); sql.append(column.getColumn()); sql.append(" in "); sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">"); sql.append(" #{item} "); sql.append("</foreach>"); } else { throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段"); } return sql.toString(); }
Example #19
Source File: ColumnTypeTest.java From Mapper with MIT License | 5 votes |
@Test public void testTypehandler(){ EntityHelper.initEntityNameMap(UserTypehandler.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserTypehandler.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("name", column.getColumn()); Assert.assertEquals("name", column.getProperty()); Assert.assertEquals("name = #{name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder()); Assert.assertEquals("name = #{record.name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder("record")); Assert.assertEquals("#{name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder()); Assert.assertEquals("#{record.name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record")); Assert.assertEquals("#{record.name, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record", "suffix")); Assert.assertEquals("#{record.namesuffix, typeHandler=org.apache.ibatis.type.BlobTypeHandler},", column.getColumnHolder("record", "suffix", ",")); Assert.assertNotNull(column.getTypeHandler()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString()); Assert.assertEquals(1, resultMap.getResultMappings().size()); ResultMapping resultMapping = resultMap.getResultMappings().get(0); Assert.assertEquals("name", resultMapping.getColumn()); Assert.assertEquals("name", resultMapping.getProperty()); Assert.assertNull(resultMapping.getJdbcType()); Assert.assertEquals(BlobTypeHandler.class, resultMapping.getTypeHandler().getClass()); }
Example #20
Source File: NameStyleTest.java From Mapper with MIT License | 5 votes |
@Test public void testNormal(){ EntityHelper.initEntityNameMap(UserNormal.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserNormal.class); Assert.assertNotNull(entityTable); Assert.assertEquals("UserNormal", entityTable.getName()); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("userName", column.getColumn()); Assert.assertEquals("userName", column.getProperty()); Assert.assertEquals("userName = #{userName}", column.getColumnEqualsHolder()); Assert.assertEquals("userName = #{record.userName}", column.getColumnEqualsHolder("record")); Assert.assertEquals("#{userName}", column.getColumnHolder()); Assert.assertEquals("#{record.userName}", column.getColumnHolder("record")); Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix")); Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ",")); Assert.assertNull(column.getTypeHandler()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString()); Assert.assertEquals(1, resultMap.getResultMappings().size()); ResultMapping resultMapping = resultMap.getResultMappings().get(0); Assert.assertEquals("userName", resultMapping.getColumn()); Assert.assertEquals("userName", resultMapping.getProperty()); Assert.assertNull(resultMapping.getJdbcType()); Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass()); }
Example #21
Source File: NameStyleTest.java From Mapper with MIT License | 5 votes |
@Test public void testUppercase(){ EntityHelper.initEntityNameMap(UserUppercase.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserUppercase.class); Assert.assertNotNull(entityTable); Assert.assertEquals("USERUPPERCASE", entityTable.getName()); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("USERNAME", column.getColumn()); Assert.assertEquals("userName", column.getProperty()); Assert.assertEquals("USERNAME = #{userName}", column.getColumnEqualsHolder()); Assert.assertEquals("USERNAME = #{record.userName}", column.getColumnEqualsHolder("record")); Assert.assertEquals("#{userName}", column.getColumnHolder()); Assert.assertEquals("#{record.userName}", column.getColumnHolder("record")); Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix")); Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ",")); Assert.assertNull(column.getTypeHandler()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString()); Assert.assertEquals(1, resultMap.getResultMappings().size()); ResultMapping resultMapping = resultMap.getResultMappings().get(0); Assert.assertEquals("USERNAME", resultMapping.getColumn()); Assert.assertEquals("userName", resultMapping.getProperty()); Assert.assertNull(resultMapping.getJdbcType()); Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass()); }
Example #22
Source File: NameStyleTest.java From Mapper with MIT License | 5 votes |
@Test public void testLowercase(){ EntityHelper.initEntityNameMap(UserLowercase.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserLowercase.class); Assert.assertNotNull(entityTable); Assert.assertEquals("userlowercase", entityTable.getName()); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("username", column.getColumn()); Assert.assertEquals("userName", column.getProperty()); Assert.assertEquals("username = #{userName}", column.getColumnEqualsHolder()); Assert.assertEquals("username = #{record.userName}", column.getColumnEqualsHolder("record")); Assert.assertEquals("#{userName}", column.getColumnHolder()); Assert.assertEquals("#{record.userName}", column.getColumnHolder("record")); Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix")); Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ",")); Assert.assertNull(column.getTypeHandler()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString()); Assert.assertEquals(1, resultMap.getResultMappings().size()); ResultMapping resultMapping = resultMap.getResultMappings().get(0); Assert.assertEquals("username", resultMapping.getColumn()); Assert.assertEquals("userName", resultMapping.getProperty()); Assert.assertNull(resultMapping.getJdbcType()); Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass()); }
Example #23
Source File: ColumnTest.java From Mapper with MIT License | 5 votes |
@Test public void testColumn(){ EntityHelper.initEntityNameMap(UserColumn.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserColumn.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("user_name", column.getColumn()); Assert.assertEquals("name", column.getProperty()); Assert.assertEquals("user_name = #{name}", column.getColumnEqualsHolder()); Assert.assertEquals("user_name = #{record.name}", column.getColumnEqualsHolder("record")); Assert.assertEquals("#{name}", column.getColumnHolder()); Assert.assertEquals("#{record.name}", column.getColumnHolder("record")); Assert.assertEquals("#{record.name}", column.getColumnHolder("record", "suffix")); Assert.assertEquals("#{record.namesuffix},", column.getColumnHolder("record", "suffix", ",")); Assert.assertNull(column.getTypeHandler()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString()); Assert.assertEquals(1, resultMap.getResultMappings().size()); ResultMapping resultMapping = resultMap.getResultMappings().get(0); Assert.assertEquals("user_name", resultMapping.getColumn()); Assert.assertEquals("name", resultMapping.getProperty()); Assert.assertNull(resultMapping.getJdbcType()); Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass()); }
Example #24
Source File: KeySqlTest.java From Mapper with MIT License | 5 votes |
@Test public void testUseGeneratedKeys(){ EntityHelper.initEntityNameMap(UserJDBC.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserJDBC.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("JDBC", column.getGenerator()); Assert.assertTrue(column.isIdentity()); } }
Example #25
Source File: KeySqlTest.java From Mapper with MIT License | 5 votes |
@Test public void testDialect(){ EntityHelper.initEntityNameMap(UserDialect.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserDialect.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("SELECT LAST_INSERT_ID()", column.getGenerator()); Assert.assertEquals(ORDER.AFTER, column.getOrder()); Assert.assertTrue(column.isIdentity()); } }
Example #26
Source File: KeySqlTest.java From Mapper with MIT License | 5 votes |
@Test public void testSql(){ EntityHelper.initEntityNameMap(UserSql.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserSql.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("select seq.nextval from dual", column.getGenerator()); Assert.assertEquals(ORDER.BEFORE, column.getOrder()); Assert.assertTrue(column.isIdentity()); } }
Example #27
Source File: ColumnTypeTest.java From Mapper with MIT License | 5 votes |
@Test public void testAll(){ EntityHelper.initEntityNameMap(UserAll.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserAll.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("user_name", column.getColumn()); Assert.assertEquals("name", column.getProperty()); Assert.assertEquals("user_name = #{name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder()); Assert.assertEquals("user_name = #{record.name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnEqualsHolder("record")); Assert.assertEquals("#{name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder()); Assert.assertEquals("#{record.name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record")); Assert.assertEquals("#{record.name, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler}", column.getColumnHolder("record", "suffix")); Assert.assertEquals("#{record.namesuffix, jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler},", column.getColumnHolder("record", "suffix", ",")); Assert.assertNotNull(column.getTypeHandler()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString()); Assert.assertEquals(1, resultMap.getResultMappings().size()); ResultMapping resultMapping = resultMap.getResultMappings().get(0); Assert.assertEquals("user_name", resultMapping.getColumn()); Assert.assertEquals("name", resultMapping.getProperty()); Assert.assertNotNull(resultMapping.getJdbcType()); Assert.assertEquals(BlobTypeHandler.class, resultMapping.getTypeHandler().getClass()); }
Example #28
Source File: KeySqlTest.java From Mapper with MIT License | 5 votes |
@Test public void testAll(){ EntityHelper.initEntityNameMap(UserAll.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserAll.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("JDBC", column.getGenerator()); Assert.assertTrue(column.isIdentity()); } }
Example #29
Source File: KeySqlTest.java From Mapper with MIT License | 5 votes |
@Test public void testAll2(){ EntityHelper.initEntityNameMap(UserAll2.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserAll2.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("SELECT LAST_INSERT_ID()", column.getGenerator()); Assert.assertEquals(ORDER.AFTER, column.getOrder()); Assert.assertTrue(column.isIdentity()); } }
Example #30
Source File: ColumnTypeTest.java From Mapper with MIT License | 5 votes |
@Test public void testJdbcTypeBlob(){ EntityHelper.initEntityNameMap(UserJdbcTypeBlob.class, config); EntityTable entityTable = EntityHelper.getEntityTable(UserJdbcTypeBlob.class); Assert.assertNotNull(entityTable); Set<EntityColumn> columns = entityTable.getEntityClassColumns(); Assert.assertEquals(1, columns.size()); for (EntityColumn column : columns) { Assert.assertEquals("name", column.getColumn()); Assert.assertEquals("name", column.getProperty()); Assert.assertEquals("name = #{name, jdbcType=BLOB}", column.getColumnEqualsHolder()); Assert.assertEquals("name = #{record.name, jdbcType=BLOB}", column.getColumnEqualsHolder("record")); Assert.assertEquals("#{name, jdbcType=BLOB}", column.getColumnHolder()); Assert.assertEquals("#{record.name, jdbcType=BLOB}", column.getColumnHolder("record")); Assert.assertEquals("#{record.name, jdbcType=BLOB}", column.getColumnHolder("record", "suffix")); Assert.assertEquals("#{record.namesuffix, jdbcType=BLOB},", column.getColumnHolder("record", "suffix", ",")); Assert.assertNull(column.getTypeHandler()); } ResultMap resultMap = entityTable.getResultMap(configuration); Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString()); Assert.assertEquals(1, resultMap.getResultMappings().size()); ResultMapping resultMapping = resultMap.getResultMappings().get(0); Assert.assertEquals("name", resultMapping.getColumn()); Assert.assertEquals("name", resultMapping.getProperty()); Assert.assertNotNull(resultMapping.getJdbcType()); Assert.assertEquals(JdbcType.BLOB, resultMapping.getJdbcType()); Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass()); }