[Geoserver-devel] using the trigger for locking rows

Here is dave's origional email .... I think it documented the work we lost in the Postgis 1.0 timeframe.

Actually looking at this - I think I made him change the id's to be strings (we need to "share" these strings between data sources - darn complicated wfs specification).

Jody

SQL:

CREATE FUNCTION lockcheck(TEXT,TEXT) RETURNS TRIGGER AS
'/data1/Refractions/Projects/PostGIS/work_dave/postgis/libpostgis.so.0.8'
LANGUAGE C;

CREATE TABLE geo_table (id int primary key,the_geom geometry, name text);

CREATE TRIGGER locktrig_geo_table BEFORE UPDATE OR DELETE
    ON geo_table FOR EACH ROW
    EXECUTE PROCEDURE lockcheck('id','geo_table_loc');

insert into geo_table values (1, 'POINT(0 0)', 'dave');
insert into geo_table values (2, 'POINT(1 0)', 'jody');
insert into geo_table values (3, 'POINT(2 0)', 'brent');
insert into geo_table values (4, 'POINT(3 0)', 'justin');

create table geo_table_loc (id int, lock_key int, expires date);

insert into geo_table_loc values (2, 666, '2100-1-1'); --loc row 2 with
lock id 666

BEGIN;
  select have_lock_for(666);
  select have_lock_for(667);
  select have_lock_for(668);

  update geo_table set name = 'nexus' where id =1; -- no lock here, so
its good
  update geo_table set name = 'tenderflake' where id =2; -- error or ignore

COMMIT;