数据驱动的业务规则。 [英] Data driven business rules.

查看:219
本文介绍了数据驱动的业务规则。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL SERVER 2005。



我有一张表

  table1(ID,col1,col2,col3,col4); 

现在我有一个商业逻辑,如:

 如果col1> = 126和col2> 1,则col3 = 0 
如果col1> = 126和col2 < 1然后col3 = col1 + col4

现在我要做的是将所有这些规则存储在数据库中并使其数据驱动。这样做的原因是给终端用户更多的灵活性。如果明天业务规则发生变化,最终用户可以通过GUI更改弹性。例如。如果明天企业想将比较值从126改为200,那么他们应该能够通过界面来改变。尽可能地,我试图给出灵活性,例如改变列的能力,因为业务应该能够改变规则,而不是col1,他们可以将新规则更改为col2。如果可能,他们也可以有能力改变运算符,而不是> =他们可以将其更改为< =。



我想更改数据驱动所以当值在表中发生变化时,我们不需要更改代码。



可以在数据库中执行此操作吗?有人可以建议支持该业务规则的数据模型是数据驱动的吗?

解决方案

不要在数据库中存储代码。数据库用于数据。代码是代码。



请参阅内部你可以在数据库中存储像126和200这样的值,但是我会把他们在配置文件中。但是,一旦用户想要这么大的灵活性,您必须为他们设计一个数据驱动的业务规则引擎,那么您完全可以重新发明。



以下方式为您提供噩梦:




  • 安全风险,因为用户指定的表达式为代码注入攻击

  • 可测试性,因为如果规则引擎包含建设性语法,则无法预测操作范围。

  • 性能,因为在运行服务器之前,用户会添加大量任意表达式和排序条件,这些条件不会经过性能测试和优化。 >
  • 维护,因为用户将习惯于他们可以执行任何的想法,但他们可以想象报告比您编写代码更复杂您的业​​务规则要处理。






更新:有业务规则平台,一个href =http://www.jboss.org/drools =nofollow> Drools ,但这些应该有自己的语言来执行业务规则。 SQL不是最好的语言。


I am using SQL SERVER 2005.

I have a table

table1(ID,col1,col2,col3,col4);

Now I have a business logic like:

If col1 >= 126 and col2 > 1 then col3 = 0
if col1 >=126 and col2 < 1 then col3 = col1+col4

Now what I am trying to do is store all these rules in database and make it data driven. THe reason for that is to give the end user more flexibility. If tomorrow the business rules changes, end user have the flexibility to change it through the GUI. For eg. if tomorrow the business wants to change the comparision value from 126 to 200 they should be able to change that through the interface. As far as possible I am trying to give flexibility like ability to change columns too like business should able to change the rule so instead of col1 they can change new rules to col2. and if possible they can also have the ability to change the operators too instead of >= they can change it to <=.

I want to change it more data driven so when the value is changes in the table we don't need to change the code.

Is it possible to do this thing in database? Can someone suggest the data model that supports this business rules to be data driven?

解决方案

Do not store code in the database. The database is for data. Code is for code.

See the Inner-Platform Effect antipattern.

Maaaybe you could store values like your 126 and 200 in the database, but I'd put them in a config file. But once the users want so much flexibility that you have to design a data-driven business rules engine for them, you're totally reinventing the wheel.

It'll be a nightmare for you in the following ways:

  • Security risks, because user-specified expressions creates an opening for code injection attacks.
  • Testability, because you can't predict the ranges of operations if your rules engine includes a constructive grammar.
  • Performance, because users will add tons of arbitrary expressions and sorting criteria that won't go through performance testing and optimization before running on your server.
  • Maintenance, because users will become accustomed to the idea that they can do anything, but they can imagine reports far more complex than you can code your business rules to handle.

Update: there are business rules platforms such as Drools, but these should have their own language for executing business rules. SQL is not the best language to do that.

这篇关于数据驱动的业务规则。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆