source: cats/ISOcat/trunk/mod-ISOcat-access-data/access/lock_new.acc @ 2686

Last change on this file since 2686 was 2686, checked in by mwindhouwer, 11 years ago

Fixed the throtteling:

  • all SQL request go through the ISOcat.database throttle (settings in the ISOcat config), also the indirect DBX ones
  • big (more then 100 DCs) DCS to DCIF go through the big-dcif throttle (hardcoded settings)
File size: 6.6 KB
Line 
1<accessor debug="false">
2        <name>ISOcat.access.data.lock.new</name>
3        <descr>Create a new lock.</descr>
4        <param mandatory="true">
5                <name>session</name>
6                <descr>the session to which the new lock belongs</descr>
7        </param>
8        <param mandatory="true">
9                <name>ltype</name>
10                <descr>the lock type</descr>
11        </param>
12        <param mandatory="true">
13                <name>object</name>
14                <descr>the object to lock</descr>
15        </param>
16        <idoc>
17                <instr>
18                        <type>copy</type>
19                        <operand>var:session</operand>
20                        <target>var:sid</target>
21                </instr>
22                <instr>
23                        <type>ISOcat.access.data.session</type>
24                        <session>var:sid</session>
25                        <target>var:session</target>
26                </instr>
27                <accessor-debug>
28                        <instr>
29                                <type>copy</type>
30                                <operand>var:session</operand>
31                                <target>ffcpl:/trace/lock_new.session.xml</target>
32                        </instr>
33                </accessor-debug>
34                <!-- CHECK: can this user acquire a lock on this object? -->
35                <choose>
36                        <cond>
37                                <instr>
38                                        <type>xpath2eval</type>
39                                        <operand>var:ltype</operand>
40                                        <operator>
41                                                <xpath>.='data category'</xpath>
42                                        </operator>
43                                        <target>this:cond</target>
44                                </instr>
45                        </cond>
46                        <then>
47                                <instr>
48                                        <type>sloot.xpath2eval</type>
49                                        <operand>var:session</operand>
50                                        <operator>
51                                                <xpath>/session/owner/@user</xpath>
52                                        </operator>
53                                        <param>
54                                                <return>
55                                                        <canonical/>
56                                                        <string/>
57                                                </return>
58                                        </param>
59                                        <target>var:user</target>
60                                </instr>
61                                <instr>
62                                        <type>sloot.debug</type>
63                                        <debug>var:accessor-debug</debug>
64                                        <operand>var:user</operand>
65                                </instr>
66                                <instr>
67                                        <type>ISOcat.access.data.user.all</type>
68                                        <user>var:user</user>
69                                        <target>var:workspace</target>
70                                </instr>
71                                <accessor-debug>
72                                        <instr>
73                                                <type>copy</type>
74                                                <operand>var:workspace</operand>
75                                                <target>ffcpl:/trace/lock_new.ws.xml</target>
76                                        </instr>
77                                </accessor-debug>
78                                <instr>
79                                        <type>sloot.xquery</type>
80                                        <operator>
81                                                <xquery>
82                                                        declare variable $dc as node() external;
83                                                        declare variable $ws as node() external;
84                                                        &lt;b>{
85                                                                if              (contains($ws//dc[@ref=string($dc)]/@mode,'w'))
86                                                                then    ('t')
87                                                                else    ('f')
88                                                        }&lt;/b>
89                                                </xquery>
90                                        </operator>
91                                        <dc>var:object</dc>
92                                        <ws>var:workspace</ws>
93                                        <target>var:access</target>
94                                </instr>
95                                <accessor-debug>
96                                        <instr>
97                                                <type>log</type>
98                                                <operand>var:access</operand>
99                                        </instr>
100                                </accessor-debug>
101                        </then>
102                        <else>
103                                <instr>
104                                        <type>sloot.log</type>
105                                        <operand>
106                                                <msg>ERR: requesting a lock of an unknown type</msg>
107                                        </operand>
108                                </instr>
109                                <instr>
110                                        <type>copy</type>
111                                        <operand>
112                                                <b>f</b>
113                                        </operand>
114                                        <target>var:access</target>
115                                </instr>
116                        </else>
117                </choose>
118                <if>
119                        <cond>
120                                <instr>
121                                        <type>sloot.not</type>
122                                        <operand>var:access</operand>
123                                        <target>this:cond</target>
124                                </instr>
125                        </cond>
126                        <then>
127                                <instr>
128                                        <type>throw</type>
129                                        <operand>
130                                                <ex>
131                                                        <id>ISOcat[FORBIDDEN]</id>
132                                                        <message>This user isn't allowed to carry out this action.</message>
133                                                </ex>
134                                        </operand>
135                                </instr>
136                        </then>
137                </if>
138                <!-- create the new lock, which will fail if the object is already locked -->
139                <instr>
140                        <type>isocat.sqlQuery</type>
141                        <operand>
142                                <sql>
143                                        SELECT nextval('generic_lock_id_seq'::regclass) AS lid;
144                                </sql>
145                        </operand>
146                        <target>var:lid</target>
147                </instr>
148                <instr>
149                        <type>sloot.xpath2eval</type>
150                        <operand>var:lid</operand>
151                        <operator>
152                                <xpath>/results/row/lid</xpath>
153                        </operator>
154                        <param>
155                                <return>
156                                        <canonical/>
157                                        <string/>
158                                </return>
159                        </param>
160                        <target>var:lid</target>
161                </instr>
162                <instr>
163                        <type>sloot.xquery</type>
164                        <operator>
165                                <xquery>
166                                        declare variable $lid as node() external;
167                                        declare variable $sid as node() external;
168                                        declare variable $tpe as node() external;
169                                        declare variable $lck as node() external;
170                                        &lt;sql>
171                                                INSERT INTO
172                                                        generic_lock
173                                                (
174                                                        id,
175                                                        "session",
176                                                        "type",
177                                                        "lock"
178                                                )
179                                                VALUES
180                                                (
181                                                        {string($lid)},
182                                                        {string($sid)},
183                                                        '{replace(string($tpe),"'","''")}',
184                                                        {string($lck)}
185                                                )
186                                                ;
187                                        &lt;/sql>
188                                </xquery>
189                        </operator>
190                        <lid>var:lid</lid>
191                        <sid>var:sid</sid>
192                        <tpe>var:ltype</tpe>
193                        <lck>var:object</lck>
194                        <target>var:sql</target>
195                </instr>
196                <accessor-debug>
197                        <instr>
198                                <type>copy</type>
199                                <operand>var:sql</operand>
200                                <target>ffcpl:/trace/lock_new.sql.xml</target>
201                        </instr>
202                </accessor-debug>
203                <instr>
204                        <type>isocat.sqlUpdate</type>
205                        <operand>var:sql</operand>
206                        <target>var:result</target>
207                </instr>
208                <accessor-debug>
209                        <instr>
210                                <type>copy</type>
211                                <operand>var:result</operand>
212                                <target>ffcpl:/trace/lock_new.result.xml</target>
213                        </instr>
214                </accessor-debug>
215                <!-- get the lock -->
216                <instr>
217                        <type>ISOcat.access.data.lock</type>
218                        <lock>var:lid</lock>
219                        <register>
220                                <b>f</b>
221                        </register>
222                        <target>var:lock</target>
223                </instr>
224                <!-- log the lock -->
225                <instr>
226                        <type>xslt2</type>
227                        <operand>var:lock</operand>
228                        <operator>
229                                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
230                                        <xsl:template match="/lock">
231                                                <msg>INF: <xsl:value-of select="current-dateTime()"/>: new session[<xsl:value-of select="session"/>] lock[<xsl:value-of select="id"/>] <xsl:value-of select="type"/>[<xsl:value-of select="object"/>]</msg>
232                                        </xsl:template>
233                                </xsl:stylesheet>
234                        </operator>
235                        <target>var:msg</target>
236                </instr>
237                <instr>
238                        <type>sloot.log</type>
239                        <operand>var:msg</operand>
240                </instr>
241                <!-- return the lock -->
242                <instr>
243                        <type>copy</type>
244                        <operand>var:lock</operand>
245                        <target>this:response</target>
246                </instr>
247                <exception>
248                        <choose>
249                                <cond>
250                                        <instr>
251                                                <type>xpath2eval</type>
252                                                <operand>this:exception</operand>
253                                                <operator>
254                                                        <xpath>starts-with(/ex/message,'duplicate key value violates unique constraint')</xpath>
255                                                </operator>
256                                                <target>this:cond</target>
257                                        </instr>
258                                </cond>
259                                <then>
260                                        <!-- we failed to acquire the lock, we'll return some info on the current lock -->
261                                        <instr>
262                                                <type>isocat.sloot.dbx</type>
263                                                <ltype>var:ltype</ltype>
264                                                <object>var:object</object>
265                                                <operator>ffcpl:/dbx/session-nolock.xml</operator>
266                                                <debug>var:accessor-debug</debug>
267                                                <target>this:response</target>
268                                        </instr>
269                                </then>
270                                <else>
271                                        <instr>
272                                                <instr>throw</instr>
273                                                <operand>this:exception</operand>
274                                        </instr>
275                                </else>
276                        </choose>
277                </exception>
278        </idoc>
279        <exception>
280                <debug/>
281                <trace>ffcpl:/trace/lock_new.exception.xml</trace>
282                <throw/>
283        </exception>
284        <response>
285                <debug>ffcpl:/trace/lock_new.response.xml</debug>
286                <mime>application/xml</mime>
287                <expire>now</expire>
288        </response>
289</accessor>
Note: See TracBrowser for help on using the repository browser.