可以锁定触发器;(Can a trigger be locked; how would one determine that it is?)
在回答中如果我在应用程序运行时替换oracle触发器,我会错过任何更改吗? ,我去查看触发器是否被INSERT语句锁定。 它不是,我在互联网上找不到任何建议可以锁定触发器的东西。
如果我在一个会话中运行以下内容:
create table test_trigger (id number); create table test_trigger_h (id number); create or replace trigger test_trigger_t after insert on test_trigger for each row begin insert into test_trigger_h (id) values (:new.id); end; / insert into test_trigger select level from dual connect by level <= 1000000;
然后在第二个会话中尝试找出正在发生的锁定我得到以下内容:
select object_name, object_type , case l.block when 0 then 'Not Blocking' when 1 then 'Blocking' when 2 then 'Global' end as status , case v.locked_mode when 0 then 'None' when 1 then 'Null' when 2 then 'Row-S (SS)' when 3 then 'Row-X (SX)' when 4 then 'Share' when 5 then 'S/Row-X (SSX)' when 6 then 'Exclusive' else to_char(lmode) end as mode_held from v$locked_object v join dba_objects d on v.object_id = d.object_id join v$lock l on v.object_id = l.id1 join v$session s on v.session_id = s.sid ; OBJECT_NAME OBJECT_TYPE STATUS MODE_HELD -------------------- -------------------- --------------- --------------- TEST_TRIGGER TABLE Not Blocking Row-X (SX) TEST_TRIGGER_H TABLE Not Blocking Row-X (SX)
根据Oracle的说法,触发器没有被锁定。
但是,如果我在INSERT语句运行时尝试替换触发器,则在语句完成(不包括提交)之后将不会替换它,这意味着触发器已被锁定。
在这种情况下,触发器是否被锁定,如果是,那么如何判断它是什么?
In answering Will I miss any changes if I replace an oracle trigger while my application is running?, I went looking to see if the trigger was locked by an INSERT statement. It wasn't and I can't find anything on the internet to suggest that a trigger can be locked.
If I run the following in one session:
create table test_trigger (id number); create table test_trigger_h (id number); create or replace trigger test_trigger_t after insert on test_trigger for each row begin insert into test_trigger_h (id) values (:new.id); end; / insert into test_trigger select level from dual connect by level <= 1000000;
and then in a second session try to find out what locks are occurring I get the following:
select object_name, object_type , case l.block when 0 then 'Not Blocking' when 1 then 'Blocking' when 2 then 'Global' end as status , case v.locked_mode when 0 then 'None' when 1 then 'Null' when 2 then 'Row-S (SS)' when 3 then 'Row-X (SX)' when 4 then 'Share' when 5 then 'S/Row-X (SSX)' when 6 then 'Exclusive' else to_char(lmode) end as mode_held from v$locked_object v join dba_objects d on v.object_id = d.object_id join v$lock l on v.object_id = l.id1 join v$session s on v.session_id = s.sid ; OBJECT_NAME OBJECT_TYPE STATUS MODE_HELD -------------------- -------------------- --------------- --------------- TEST_TRIGGER TABLE Not Blocking Row-X (SX) TEST_TRIGGER_H TABLE Not Blocking Row-X (SX)
According to Oracle, the trigger is not being locked.
However, if I try to replace the trigger whilst the INSERT statement is running it will not be replaced until after the statement has completed (not including a commit), which implies that the trigger is locked.
In this situation, is the trigger locked and if so how would one determine that it is?
原文:https://stackoverflow.com/questions/18460260
最满意答案
您可能已经意识到,选项#1是不可能的。 为了让客户代表您进行API调用,您需要向他们发送您的密钥/令牌/您需要通过API进行身份验证的任何内容。 但是一旦他们拥有了这个,他们就可以使用脚本控制台来“按照你的意愿”进行他们想要的任何API调用。 这将是非常灾难性的。
选项#2可能过于复杂 - 我个人不确定你会怎么做。 使用像therubyracer这样的库可以从Ruby代码执行JavaScript代码,但是有一定程度的沙盒,这可能会破坏需要网络访问的代码。
这样您就可以使用选项#3,编写自己的Ruby库来与API进行交互。 这可能很容易或很困难,具体取决于API的毛茸茸程度,但是您已经掌握了JavaScript版本(希望REST服务本身也是文档),因此结合RestClient或HTTParty之类的路径应该是明确的。
至于API调用适合您的Rails代码的位置:如果您的模型基本上镜像了您通过REST服务与之交互的资源,那么将相关的API调用添加为这些模型上的方法或回调可能是有意义的。 否则,将它们放在相关的控制器操作中可能没问题,但是如果事情变得丑陋,请密切关注代码复杂性并提取到单独的类或模块。
(如果您在向用户发送内容之前不需要等待API的响应,则可能需要使用DelayedJob或类似方法在后台排队API调用。)
Option #1, as you've likely realized, is out of the question. For the client to make API calls on your behalf, you would need to send them your secret key/token/whatever you need to authenticate with the API. But once they have that, they could just use a script console to make whatever API calls they want "as you". This would be pretty disastrous.
Option #2 might be prohibitively complex -- I'm personally not sure how you'd go about it. It is possible, using a library like therubyracer, to execute JavaScript code from Ruby code, but there is some degree of sandboxing and this may break code that requires network access.
That leaves you with Option #3, writing your own Ruby library to interact with the API. This could be easy or difficult, depending on how hairy the API is, but you already have a JavaScript version on hand (and hopefully docs for the REST service itself), so combined with something like RestClient or HTTParty the path forward should be clear.
As for where the API calls would fit in your Rails code: If you have models that are basically mirroring the resources you're interacting with through the REST service, it might make sense to add the relevant API calls as methods or callbacks on those models. Otherwise it might be fine to put them in the relevant controller actions, but keep an eye on your code complexity and extract to a separate class or module if things are getting ugly.
(In cases where you don't need to wait for the response from the API before sending something back to the user, you may want to use DelayedJob or similar to queue your API calls in the background.)
相关问答
更多-
Rails是一个相对成熟的基于Ruby的Web框架,专为处理关系数据库后端中的对象映射数据持久性而设计。 Node.js 在场景上更新颖 ,与Rails不同,它是一个更简单的软件包,它允许服务器端的Javascript应用程序,这要归功于相当严格的HTTP(S)API。 节点应用程序本质上是事件驱动的 ,对于您的应用程序来说可能是也可能不是理想的。 由于看起来您需要数据持久性(您提到访问MySQL数据......),Rails可能更容易开始使用,因为它包含了您在这方面需要的所有内容,并且旨在为此提供便利应用 ...
-
我想你首先必须选择你想要学习的内容,因为这里有很多部分。 诸如facebooker之类的gem用于使用Web服务的API,而不是“创建”或公开API(用于Web服务)。 为了理解这样的库以及它的功能,您可以尝试更多地了解API,但也可以尝试使用Ruby来访问它们。 尽管Rails和Rails社区正在接受RESTful (或者实际上是REST)API,但还有其他一些形式,比如SOAP 。 Facebook例如已经放弃REST来支持他们的图形API。 查看这个处理不同类型的问题的答案,了解更多信息: 最佳SOA ...
-
这里是: validates :number, :length => { in: [13,15,16] } 但是,它有点像你可能应该使用正则表达式。 Here it is: validates :number, :length => { in: [13,15,16] } However, it smells like you probably should be using a regular expression.
-
我会看看Httparty gem,它应该做你需要消耗api的一切 这是使用omniauth和Httparty连接到第三方API的示例 I would take a look at Httparty gem, It should do everything you need to consume an api Here's an example of using omniauth and Httparty to connect to a 3rd party api
-
您可能已经意识到,选项#1是不可能的。 为了让客户代表您进行API调用,您需要向他们发送您的密钥/令牌/您需要通过API进行身份验证的任何内容。 但是一旦他们拥有了这个,他们就可以使用脚本控制台来“按照你的意愿”进行他们想要的任何API调用。 这将是非常灾难性的。 选项#2可能过于复杂 - 我个人不确定你会怎么做。 使用像therubyracer这样的库可以从Ruby代码执行JavaScript代码,但是有一定程度的沙盒,这可能会破坏需要网络访问的代码。 这样您就可以使用选项#3,编写自己的Ruby库来与A ...
-
请按照本文中的步骤操作,尤其是他们注意到,更好的位置为sqlite dll位于ruby bin目录中。 将它放在那里也可能有助于获取已加载的版本的排序顺序。 否则,我会做一个宝石卸载sqlite3-ruby,然后重新安装它。 Try following the steps in this article, in particular they note that a better location for the sqlite dll is in the ruby bin directory. Placin ...
-
Ruby API包装器和Rails(Ruby API wrapper and Rails)[2022-02-21]
Rails提供config / application.rb文件,用于指定各种Rails组件的设置。 我们想在任何其他设置之前设置我们的环境变量。 Rails提供了config.before_configuration方法。 您需要在config / application.rb中添加以下代码才能使用config / local_env.yml: config.before_configuration do env_file = File.join(Rails.root, 'config', 'l ... -
rails 3中的Restful API(Restful API in rails 3)[2022-05-09]
Rest 3在rails 3中的API? Rails是宁静的..只是使用路线[ 指南 ] 至于身份验证,我强烈建议设计 。 它也是我设法在rails 3上工作的唯一一个。 Restful API in rails 3? Rails is restful.. just use routes [guide] As for authentication, i strongly recommend devise. It's also the only one I have managed to get workin ... -
Rails生成的REST API可以被任何客户端使用,如果你想使用纯HTML和CSS而不使用.erb文件(对我来说在开发时带来很多好处)你可以通过AJAX访问Rails API数据 。 我给你以下教程: http://blog.project-sierra.de/archives/1788 希望能帮助到你 The REST API generated by Rails can be consume by any client, if you want to use pure HTML and CSS wit ...
-
Ruby on Rails终端问题(Ruby on Rails terminal issue)[2022-04-02]
使用以下命令创建rails项目: rails new my_app_name 。 将目录更改到文件夹: cd my_app_name 。 运行您喜欢的任何其他命令,例如rails server 。 Create a rails project with the command: rails new my_app_name. Change directory into the folder: cd my_app_name. Run whatever other commands you like, e.g. ...