ibatis application of skills

2010-03-30  来源:本站原创  分类:Java  人气:240 

ibatis often encounter a common condition called multiple sql is. Such permission validation piece, I need to know the resources of each user authentication out whether their rights, you need to remove the list of resources on a filter. Resources to the table structure is as follows
Sys_res_row_id (Resource id)
sys_sys_res_row_id (superior resource id)
system_row_id (resources owned system id)

is_enable (if available, that is not disabled)

Sys_res_row_id (Resource id) sys_sys_res_row_id (superior resource id) system_row_id (resources owned system id) is_enable (if available, that is not disabled)

Resources include two concepts: one is the system, there is no superior resources, which sys_sys_res_row_id and system_row_id must be empty. One is the application, the system under the application, application can contain sub-applications, the application must own a system that sys_sys_res_row_id and system_row_id certainly not empty.

The type of user is divided into super-user (usertype = 10), system administrator (21), unit manager (22), general users (30). Super-user on all the systems and the application of systems access. Department of Management of the application under the jurisdiction of the system and the system administrator the right to their role in the application under the single management of the units under the jurisdiction of their systems and their applications, and the role of the administrator under the application of their right to ordinary users of his role application under the right. Role for applications is the role and application of a bind list, if the user belongs to this role have access to their corresponding application permissions. In addition, for system management, single-tube and ordinary users have added applications directly binding function.

System administrators use the table: sys_manager_system administrator and system resources to the table corresponding to Table sys_resource

Unit manager table used: sys_commanger_com unit system administrator resources corresponding table table sys_resource

Users use the table (except super-users who used three types of users): sys_rel_user_role user roles associated with the role of resources associated with the table sys_rel_role_res sys_role role table table table sys_rel_user_resource user resources sys_resource resources associated table (the table is a separate operation table and does not belong and the role and application of binding among the control user can access a separate application)

Ibatis sql written in the following

Wrote,

<sql>
select sys_res_row_id
from (
<isEqual property="userType" compareValue="10">
select t.sys_res_row_id
from sys_resource t
join sys_resource t1 on t.system_row_id =
t1.sys_res_row_id
where t1.is_enable = 1
union
select t6.sys_res_row_id
from sys_resource t6
where t6.sys_sys_res_row_id is null
and t6.is_enable = 1
</ IsEqual>
<isGreaterThan property="userType" compareValue="10">
<isLessThan property="userType" compareValue="30">
select t1.sys_res_row_id
from sys_resource t1
where t1.is_enable = 1
start with sys_res_row_id in
(
<isEqual property="userType" compareValue="21">
select t.sys_res_row_id
from sys_manager_system t
join sys_resource t1 on t1.sys_res_row_id = t.sys_res_row_id
where t1.is_enable = 1 and sys_user_row_id = # userRowId #
</ IsEqual>
<isEqual property="userType" compareValue="22">
select t2.sys_res_row_id
from sys_commanger_com t1
join sys_resource t2
on t1.sys_res_row_id = t2.sys_res_row_id
where t2.is_enable = 1
and t2.isgrantself = 0
and t1.sys_user_row_id = # userRowId #
</ IsEqual>
)
connect by prior sys_res_row_id = sys_sys_res_row_id
union
</ IsLessThan>
<isGreaterThan property="userType" compareValue="10">
select t4.sys_res_row_id
from sys_rel_user_role t1
join sys_role t2
on t1.sys_role_row_id = t2.sys_role_row_id
join sys_rel_role_res t3
on t2.sys_role_row_id = t3.sys_role_row_id
join (select t.sys_res_row_id from sys_resource t join sys_resource t1 on t.system_row_id = t1.sys_res_row_id where t1.is_enable = 1
union
select t6.sys_res_row_id
from sys_resource t6
where t6.sys_sys_res_row_id is null
and t6.is_enable = 1) t4
on t3.sys_res_row_id = t4.sys_res_row_id
where t2.is_enable = 1
and t1.sys_user_row_id = # userRowId #
</ IsGreaterThan>
</ IsGreaterThan>
union select t5.sys_res_row_id
from (select t.sys_res_row_id, t.is_enable from sys_resource t join sys_resource t1 on t.system_row_id = t1.sys_res_row_id where t1.is_enable = 1
union
select t6.sys_res_row_id, t6.is_enable
from sys_resource t6
where t6.sys_sys_res_row_id is null
and t6.is_enable = 1) t5
join sys_rel_user_resource t2 on t5.sys_res_row_id = t2.sys_res_row_id
where t5.is_enable = 1 and t2.sys_user_row_id = # userRowId #
)
</ Sql>

Idea is as follows: The list is divided into three steps union, if the super user (10) directly can remove all of the resources. If a system administrator (21) is first taken out of its jurisdiction system (under the jurisdiction of the system must be available, is_enable = 1), with a start with connect by statements taken out of its sub-applications, this is the first step; removed from its role in the corresponding table resources, this is the second step; from the user and resource binding binding out the resources table, which is the third step; then this three-step list of the union of resources that the system administrator can access applications. If the unit administrator (22) units under its jurisdiction through the corresponding sub-system to find the corresponding application form to take the role of the application of resources to bind the table to take the user application, union; average user (30) from the role of the table and user resources binding table to take applications union;

One of the difficulties:

1. If the system has been disabled, the following applications are not available. So the first step down through the system to find applications directly through is_enable the start with the judge, but when the third step in the second step may not take to the system but also in the application, the application of is_enable = 1, but its own system is disabled at this time will need additional judge, when I connect to judge by their own, that is

Wrote,

select t.sys_res_row_id, t.is_enable from sys_resource t join sys_resource t1 on t.system_row_id = t1.sys_res_row_id where t1.is_enable = 1

2. To join A on? ? Statement, if A is assembled out of a table, can not write in A *, not recognition, should be written clearly which of the field.

3. For the above sql reference period, in ibatis is completed with the include statement

Wrote,

t1.sys_res_row_id in (<include refid="user-enable-resource-id"/>)

相关文章
  • ibatis application of skills 2010-03-30

    ibatis often encounter a common condition called multiple sql is. Such permission validation piece, I need to know the resources of each user authentication out whether their rights, you need to remove the list of resources on a filter. Resources to

  • Detailed Window.open parameters in Javascript 2009-06-30

    [size = large] [/ size] on the parameters Window.open summary (see the book adapted) look at an example: [javascipt:] window.open ( "Webpage.asp?", Derek, "height = 100, width = 100, status = yes, toolbar = yes, menubar = no, location = no

  • Jquery components 2009-07-21

    File upload Ajax File Upload . jQUploader . Multiple File Upload plugin . jQuery File Style . Styling an input type file . Progress Bar Plugin . Form Validation jQuery Validation . Auto Help . Simple jQuery form validation . jQuery XAV - form validat

  • System Architect 2009-10-04

    Software architect in the software industry is an emerging profession, the work function is in a software project development process, the customer needs to regulate the development of conversion plans and text, and to develop the overall framework o

  • Excel field Velocity: JXLS, strongly recommended! 2010-03-29

    Excel field Velocity: JXLS, strongly recommended! I finally found the best view to export excel to achieve: JXLS http://jxls.sourceforge.net/ Use JXLS, can be achieved Velocity results. Will excel view "template-based." The jxls not only be able

  • What is the Internet, product architect, architect's responsibility 2009-10-10

    Architect software, the Internet industry in an emerging profession, job responsibilities in a software project development process, the customer's requirements into specifications and development programs and text, and develop the general framework

  • Turn: javascript pop-up window code complete 2010-01-04

    How to use various forms of Web pop-up window, I think we mostly know more, but that a wide range of pop-up window out how the practice, we today learn about: 1. Shells Kai a full-screen window <html> <body onload="window.open('http://www.ku

  • JQuery's AJAX-based Applications 2010-03-09

    Abstract: In the current upsurge in Web2.0, AJAX are attracting worldwide attention, becoming the most talked-about technical terms. AJAX technology has improved very much WEB application user experience, jQuery simplifies the creation and use of the

  • LAMP programmer wants to read every classic books collection 2010-03-16

    "High Performance MySQL (2nd Edition)" listed This book won the 2009 Jolt Award books are rare books to share practical experience MySQL. Not only can help beginners improve MySQL tips, more experienced MySQL DBA pointed out the ways to develop

  • Web design from good to great detail 6 2010-04-20

    Excellent design and excellent design is the difference between the relatively small. Most people may not be explaining the specific differences in design excellence, but they can find their favorite web design work. Look through the control of sever

  • Architect of the Road 2010-06-07

    Architect Skills Matrix: http://www.opengroup.org/architecture/togaf8-doc/arch/chap30.html Architect (Architecture) is a lot of talent most needed software company, is a software company in the highest-paid technicians. In other words, architects of

  • Software architect journey of growth 2010-06-09

    Software architect is the software industry A new job, job duties is an Software in the project development process a client's Xuqiu Zhuanhuan Wei Gui Fan of the development plan and text, and that project's Zongti Jia Gou , that guide the developmen

  • Guide the path animation (1) 2010-06-16

    Guide the path animation (1) In the previous sections, we have to tell you some animation effects, such as aircraft flying from the peaks, passing glow text and so on, I wonder if you noticed, these animations are straight line trajectory, but in lif

  • Super Android system will be under the command terminal Daquan (b) transfer 2010-06-30

    Very useful, and turning the reboot 1. Role reboot command's role is to restart the computer, it is the system administrator permissions. 2. Format reboot [-n] [-w] [-d] [-f] [-i] 3. The main parameters-n: do not do the reboot before the memory data

  • Handle concurrent access to shared data 2010-07-16

    n use pessimistic locking and optimistic locking n with iBATIS, JDO and Hibernate concurrency n Spring concurrency with recovery after the operation failed Many enterprise applications critical to the company and customer data stored. For example, co

  • SqlMap configuration 2010-08-04

    SqlMap application configuration is iBatis core. This part of the task accounts for 70 iBatis development workload. 1 namespace: <sqlMap namespace="Account">, in this space, to quote the elements of this space, you need to add the namespac

  • SqlMap configuration summary 2010-08-30

    iBatis SqlMap configuration summary SqlMap application configuration is iBatis core. This part of the task accounts for 70% of the workload iBatis development. 1 namespace: <sqlMap namespace="Account"> In this space, to quote the elements

  • Linux will learn the 60 commands 2010-10-16

    ==========[[[ Linux will learn the 60 commands ]]]========== Wandering: I do not find who the original author, but in any case, the original author of this article to extend my most sincere respect! Find online version of the layout is not very easy

  • Production techniques nine Javascript pop-up window (to) 2010-10-23

    Regular Internet friends may have been to so some sites, entered the home will immediately pop up a window, or press a link or button to pop up, usually in the window displays the number of notes, copyright information, warning, welcome to patronize

  • IBM Academy of things with me into 2010-10-31

    Court heard two days ago to the software a Fellow of the IBM China Research Yun report will be organized, in his own words, an exchange of discussion can only be regarded as two-way communication with us more than a one-way transfer knowledge. The th