Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace function atualiza_biserver() returns trigger as
- $body$
- DECLARE
- username text;
- password text;
- conexao text;
- query text;
- BEGIN
- conexao:='dbname=hibernate port=5432 host=localhost user=hibuser password=password';
- IF(TG_OP = 'INSERT') THEN
- username:= NEW.login;
- password:=NEW.senha;
- query:='insert into users(username,password,enabled) values('''||username||''','''||password||''', true)';
- perform dblink_exec(conexao,query);
- query:='insert into granted_authorities(username,authority) values('''||username||''',''Authenticated'')';
- perform dblink_exec(conexao,query);
- --RAISE EXCEPTION '%' ,query;
- RETURN NEW;
- END IF;
- IF(TG_OP = 'UPDATE') THEN
- username:= NEW.login;
- password:=NEW.senha;
- query:='update users set username = '''||username||''',password='''||password||''' where username = '''||username||'''';
- perform dblink_exec(conexao,query);
- --RAISE EXCEPTION '%' ,query;
- RETURN NEW;
- END IF;
- IF(TG_OP = 'DELETE') THEN
- username:= OLD.login;
- query:='delete from granted_authorities where username = '''||username||'''';
- perform dblink_exec(conexao,query);
- query:='delete from users where username = '''||username||'''';
- perform dblink_exec(conexao,query);
- --RAISE EXCEPTION '%' ,query;
- RETURN OLD;
- END IF;
- END;
- $body$
- LANGUAGE plpgsql;
Add Comment
Please, Sign In to add comment