Almacenar y consultar Regla de negocio

I have question related to business rules. Let's have a entity Account with some properties (amount, name, type etc.) on which we define business rules.

I store my rules in database table as follows

Rule_id | Field | Operator | value . 

Rule can be like , amount > 1000, name ="abc", type="x" etc. Rules are grouped and mapped to a user.

Account are created in system, and admin has to approve them. When admin login based on his rule set, admin should see relevant accounts.

Like if admin rule set is amount>500, then any account less 500 is not shown to him.

My question is best way to implement it in database, how to query so that relevant accounts can be fetched depending on underlying rule set.

preguntado el 04 de julio de 12 a las 08:07

2 Respuestas

create a user table something like this


 userId | Username | UserType | Rule_id

when a user log-in, join the user table with rule table on Rule_id and generate the condition using a query like this

select 'Select * from Account where '+Field+Operator+value from rules   
where Rule_id=1

The result of this query will give another sql query on executing the same will fetch the accounts that are accessible for that user

result of the above query

Select * from Account where amount>1000

Respondido 04 Jul 12, 09:07

What you describe is quite similar to Oracle's Fine-Grained Access Control (AKA Virtual Private Database). This is primarily a security tool, but it could be used to enforce generic business rules. Conoce más.

Even if you choose not to use FGAC (or can't because you don't have Enterprise Edition) it will give you some hints about how to implement a solution: use sys_context and namespaces to hold the rules, and views referencing sys_context functions to enforce them.

Respondido el 20 de enero de 13 a las 14:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.