1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
<?xml version="1.0" encoding="UTF-8"?>
<sect1 id="Long_Transactions_Support">
<title>Long Transactions Support</title>
<para>This module and associated pl/pgsql functions have been
implemented to provide long locking support required by <ulink
url="http://www.opengeospatial.org/standards/wfs">Web Feature Service</ulink> specification.</para>
<note>
<para>Users must use <ulink
url="http://www.postgresql.org/docs/current/static/transaction-iso.html">serializable
transaction level</ulink> otherwise locking mechanism would
break.</para>
</note>
<refentry id="AddAuth">
<refnamediv>
<refname>AddAuth</refname>
<refpurpose>Add an authorization token to be used in current transaction.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>AddAuth</function></funcdef>
<paramdef><type>text </type> <parameter>auth_token</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Add an authorization token to be used in current transaction.</para>
<para>Creates/adds to a temp table called temp_lock_have_table the current transaction identifier
and authorization token key.</para>
<para>Availability: 1.1.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT LockRow('towns', '353', 'priscilla');
BEGIN TRANSACTION;
SELECT AddAuth('joey');
UPDATE towns SET the_geom = ST_Translate(the_geom,2,2) WHERE gid = 353;
COMMIT;
---Error--
ERROR: UPDATE where "gid" = '353' requires authorization 'priscilla'
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="LockRow" /></para>
</refsection>
</refentry>
<refentry id="CheckAuth">
<refnamediv>
<refname>CheckAuth</refname>
<refpurpose>Creates trigger on a table to prevent/allow updates and deletes of rows based on authorization token.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>CheckAuth</function></funcdef>
<paramdef><type>text </type> <parameter>a_schema_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>a_table_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>a_key_column_name</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>CheckAuth</function></funcdef>
<paramdef><type>text </type> <parameter>a_table_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>a_key_column_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Creates trigger on a table to prevent/allow updates and deletes of rows based on authorization token. Identify rows using <rowid_col> column.</para>
<para>If a_schema_name is not passed in, then searches for table in current schema.</para>
<note><para>If an authorization trigger already exists on this table function errors.</para>
<para>If Transaction support is not enabled, function throws an exception.</para>
</note>
<para>Availability: 1.1.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT CheckAuth('public', 'towns', 'gid');
result
------
0
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="EnableLongTransactions" /></para>
</refsection>
</refentry>
<refentry id="DisableLongTransactions">
<refnamediv>
<refname>DisableLongTransactions</refname>
<refpurpose>Disable long transaction support. This function removes the
long transaction support metadata tables, and drops all triggers
attached to lock-checked tables.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>DisableLongTransactions</function></funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Disable long transaction support. This function removes the
long transaction support metadata tables, and drops all triggers
attached to lock-checked tables.</para>
<para>Drops meta table called <varname>authorization_table</varname> and a view called <varname>authorized_tables</varname>
and all triggers called <varname>checkauthtrigger</varname></para>
<para>Availability: 1.1.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT DisableLongTransactions();
--result--
Long transactions support disabled
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="EnableLongTransactions" /></para>
</refsection>
</refentry>
<refentry id="EnableLongTransactions">
<refnamediv>
<refname>EnableLongTransactions</refname>
<refpurpose>Enable long transaction support. This function creates the
required metadata tables, needs to be called once before using the
other functions in this section. Calling it twice is
harmless.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>EnableLongTransactions</function></funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Enable long transaction support. This function creates the
required metadata tables, needs to be called once before using the
other functions in this section. Calling it twice is
harmless.</para>
<para>Creates a meta table called <varname>authorization_table</varname> and a view called <varname>authorized_tables</varname></para>
<para>Availability: 1.1.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT EnableLongTransactions();
--result--
Long transactions support enabled
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="DisableLongTransactions" /></para>
</refsection>
</refentry>
<refentry id="LockRow">
<refnamediv>
<refname>LockRow</refname>
<refpurpose>Set lock/authorization for specific row in table</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>LockRow</function></funcdef>
<paramdef><type>text </type> <parameter>a_schema_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>a_table_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>a_row_key</parameter></paramdef>
<paramdef><type>text</type> <parameter>an_auth_token</parameter></paramdef>
<paramdef><type>timestamp</type> <parameter>expire_dt</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>LockRow</function></funcdef>
<paramdef><type>text </type> <parameter>a_table_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>a_row_key</parameter></paramdef>
<paramdef><type>text</type> <parameter>an_auth_token</parameter></paramdef>
<paramdef><type>timestamp</type> <parameter>expire_dt</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>LockRow</function></funcdef>
<paramdef><type>text </type> <parameter>a_table_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>a_row_key</parameter></paramdef>
<paramdef><type>text</type> <parameter>an_auth_token</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Set lock/authorization for specific row in table
<authid> is a text value, <expires> is a timestamp
defaulting to now()+1hour. Returns 1 if lock has been assigned, 0
otherwise (already locked by other auth)</para>
<para>Availability: 1.1.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT LockRow('public', 'towns', '2', 'joey');
LockRow
-------
1
--Joey has already locked the record and Priscilla is out of luck
SELECT LockRow('public', 'towns', '2', 'priscilla');
LockRow
-------
0
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="UnlockRows" /></para>
</refsection>
</refentry>
<refentry id="UnlockRows">
<refnamediv>
<refname>UnlockRows</refname>
<refpurpose>Remove all locks held by specified authorization id. Returns
the number of locks released.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>UnlockRows</function></funcdef>
<paramdef><type>text </type> <parameter>auth_token</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Remove all locks held by specified authorization id. Returns
the number of locks released.</para>
<para>Availability: 1.1.3</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT LockRow('towns', '353', 'priscilla');
SELECT LockRow('towns', '2', 'priscilla');
SELECT UnLockRows('priscilla');
UnLockRows
------------
2
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="LockRow" /></para>
</refsection>
</refentry>
</sect1>
|