首页 \ 问答 \ 可以锁定触发器;(Can a trigger be locked; how would one determine that it is?)

可以锁定触发器;(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
更新时间:2023-06-12 11:06

最满意答案

您可能已经意识到,选项#1是不可能的。 为了让客户代表您进行API调用,您需要向他们发送您的密钥/令牌/您需要通过API进行身份验证的任何内容。 但是一旦他们拥有了这个,他们就可以使用脚本控制台来“按照你的意愿”进行他们想要的任何API调用。 这将是非常灾难性的。

选项#2可能过于复杂 - 我个人不确定你会怎么做。 使用像therubyracer这样的库可以从Ruby代码执行JavaScript代码,但是有一定程度的沙盒,这可能会破坏需要网络访问的代码。

这样您就可以使用选项#3,编写自己的Ruby库来与API进行交互。 这可能很容易或很困难,具体取决于API的毛茸茸程度,但是您已经掌握了JavaScript版本(希望REST服务本身也是文档),因此结合RestClientHTTParty之类的路径应该是明确的。

至于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 ...
  • 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 ...
  • 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 ...
  • 使用以下命令创建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. ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。