private LanguageDriver getLanguageDriver(Method method) { Lang lang = method.getAnnotation(Lang.class); Class<?> langClass = null; if (lang != null) { langClass = lang.value(); } return assistant.getLanguageDriver(langClass); }
@Select("SELECT permission_team.id AS id, permission_id, team_id, status AS status_value, permission_team.time AS time, " + "permission.cluster AS cluster, permission.path AS path, team.name AS team_name " + "FROM permission_team, permission, team " + "WHERE permission_team.permission_id = permission.id AND permission_team.team_id = team.id " + "AND cluster = #{cluster} AND path IN (#{paths}) AND status = #{status}") @Lang(MybatisExtendedLanguageDriver.class) List<PermissionTeam> listByPaths(@Param("cluster") String cluster, @Param("paths") List<String> paths, @Param("status") int status);
/** * get third menu by menu URL and super menu URL * @param url * @param superUrl * @param role_id * @return */ @Lang(RawLanguageDriver.class) @Select("SELECT A.menu_id,A.menu_name,A.menulevcod,A.supmenucode,A.menuurl,A.menuico,A.sort " + "FROM system_menu A, system_role_menu C " + "WHERE A.menu_id=C.menu_id " + "AND A.menuurl=#{url} " + "AND C.role_id=#{role_id} " + "AND EXISTS(SELECT 1 FROM system_menu B WHERE B.menuurl=#{superUrl} AND A.supmenucode=B.menu_id)") Menu getLeafMenuByUrl(@Param("url") String url, @Param("superUrl") String superUrl, @Param("role_id") int role_id);
/** * get second menu by menu URL * @param menuurl * @param role_id * @return */ @Lang(RawLanguageDriver.class) @Select("SELECT A.menu_id,A.menu_name,A.menulevcod,A.supmenucode,A.menuurl,A.menuico,A.sort " + "FROM system_menu A, system_role_menu B " + "WHERE A.menu_id=B.menu_id " + "AND A.menulevcod='2' " + "AND B.role_id=#{role_id} " + "AND A.menuurl=#{menuurl}") Menu getSecondLevelMenuByUrl(@Param("menuurl") String menuurl, @Param("role_id") int role_id);
@Lang(MybatisExtendedLanguageDriver.class) @Select("SELECT DISTINCT user.id, user.name, user.time FROM user, user_team WHERE user_team.team_id IN (#{teams}) " + "AND user_team.user_id = user.id AND user_team.status >= #{status} AND user_team.role >= #{role}") List<User> list(@Param("teams") Set<Long> teams, @Param("status") int status, @Param("role") int role);
@Lang(RawLanguageDriver.class) @Select("SELECT firstName, lastName FROM names WHERE lastName LIKE #{name}") List<Name> selectRawWithMapper(Parameter p);
@Lang(XMLLanguageDriver.class) @Select("<script>SELECT firstName <if test=\"includeLastName != null\">, lastName</if> FROM names WHERE lastName LIKE #{name}</script>") List<Name> selectXmlWithMapper(Parameter p);
@Lang(XMLLanguageDriver.class) @Select("SELECT firstName, lastName FROM names WHERE lastName LIKE #{name} and 0 < 1") List<Name> selectXmlWithMapperAndSqlSymbols(Parameter p);
@Lang(FreeMarkerLanguageDriver.class) @Select("preparedIn.ftl") List<Name> findByNames(@Param("ids") List<String> ids);
@Lang(FreeMarkerLanguageDriver.class) @Select("prepared.ftl") Name findUsingParams(@Param("innerObject") PreparedParam.InnerClass innerClass);
/** * Simple query that is loaded from template. */ @Lang(FreeMarkerLanguageDriver.class) @Select("getAllNames.ftl") List<Name> getAllNames();
/** * Simple query with prepared statement parameter. */ @Lang(FreeMarkerLanguageDriver.class) @Select("findName.ftl") Name findName(@Param("name") String name);
/** * This query is to demonstrate that FreeMarker does not break the compatibility with this behaviour. */ @Lang(FreeMarkerLanguageDriver.class) @Select("select * from names" + " where firstName = <@p name='noSuchPropertyOnString'/>" + " or firstName = <@p name='oneMoreUnexistingProperty'/>") List<Name> getNamesOddBehaviourFreeMarkerLang(String name);
@Lang(CustomizedDataContextTest.CustomFreeMarkerLanguageDriver.class) @Select("findUsingCustomizedContext.ftl") List<Name> find();
/** * This is doesn't work - because params objects are unsupported when using * auto-generated prepared parameters (it is impossible to add parameters * to MyBatis engine). This call will throw exception. */ @Lang(FreeMarkerLanguageDriver.class) @Select("prepared.ftl") Name findUsingParamsObject(PreparedParam param);
/** * If any whitespace found inside @Select text, it is interpreted as inline script, not template name. * It is convenient to avoid creating templates when script is really small. */ @Lang(FreeMarkerLanguageDriver.class) @Select("select * from names where id in (${ids?join(',')})") List<Name> findNamesByIds(@Param("ids") List<Integer> ids);
/** * There are no @Param annotation on argument. This means NameParam instance * will be passed into driver as is, not as Map entry. So, we need to support this case. * Because in driver we need to add some another properties into template model, * and NameParam is not Map, we are need to wrap passed parameter object into * {@link org.mybatis.scripting.freemarker.ParamObjectAdapter} before processing template. */ @Lang(FreeMarkerLanguageDriver.class) @Select("select * from names where id = <@p name='id'/> and id = ${id}") Name find(NameParam nameParam);
/** * Get a YiXin configure * @param cust_id * @return */ @Select("SELECT A.cust_id, A.yx_account, A.token, A.timestamp, A.biz_class, A.subscribe_msg, A.welcome_msg, A.appid, A.secret, A.api_url FROM yixin_config A WHERE A.cust_id=#{cust_id}") @Lang(RawLanguageDriver.class) YiXinConfig get(int cust_id);
/** * Get all active configures * @return */ @Select("SELECT A.cust_id, A.yx_account, A.token, A.timestamp, A.biz_class, A.subscribe_msg, A.welcome_msg, A.appid, A.secret, A.api_url FROM yixin_config A, customer C, customer_service S WHERE A.cust_id=C.cust_id AND A.cust_id=S.cust_id AND C.status='AVAILABLE' AND S.status='AVAILABLE' AND S.service_type='YIXIN'") @Lang(RawLanguageDriver.class) List<YiXinConfig> availableList();
/** * Add YiXin configure * @param config * @return */ @Insert("INSERT INTO yixin_config(cust_id,yx_account,token,subscribe_msg,welcome_msg,biz_class,appid,secret,api_url) VALUES (#{cust_id},#{yx_account},#{token},#{subscribe_msg},#{welcome_msg},#{biz_class},#{appid},#{secret},#{api_url})") @Lang(RawLanguageDriver.class) int save(YiXinConfig config);
/** * Delete YiXin configure * @param cust_id * @return */ @Delete("DELETE FROM yixin_config WHERE cust_id=#{cust_id}") @Lang(RawLanguageDriver.class) int delete(int cust_id);
/** * update YiXin configure * @param config * @return */ @Update("UPDATE yixin_config A SET A.yx_account=#{yx_account},A.subscribe_msg=#{subscribe_msg}, A.welcome_msg=#{welcome_msg}, A.secret=#{secret}, A.appid=#{appid} WHERE A.cust_id=#{cust_id}") @Lang(RawLanguageDriver.class) int update(YiXinConfig config);
/** * check if exists configure with the given api_url * @param api_url * @return */ @Select("SELECT COUNT(1) FROM yixin_config A WHERE A.api_url=#{api_url}") @Lang(RawLanguageDriver.class) int checkConfig(String api_url);