Guest User

Untitled

a guest
Jan 6th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. create or replace function atualiza_biserver() returns trigger as
  2. $body$
  3. DECLARE
  4. username text;
  5. password text;
  6. conexao text;
  7. query text;
  8. BEGIN
  9. conexao:='dbname=hibernate port=5432 host=localhost user=hibuser password=password';
  10. IF(TG_OP = 'INSERT') THEN
  11. username:= NEW.login;
  12. password:=NEW.senha;
  13. query:='insert into users(username,password,enabled) values('''||username||''','''||password||''', true)';
  14. perform dblink_exec(conexao,query);
  15. query:='insert into granted_authorities(username,authority) values('''||username||''',''Authenticated'')';
  16. perform dblink_exec(conexao,query);
  17. --RAISE EXCEPTION '%' ,query;
  18. RETURN NEW;
  19. END IF;
  20. IF(TG_OP = 'UPDATE') THEN
  21. username:= NEW.login;
  22. password:=NEW.senha;
  23. query:='update users set username = '''||username||''',password='''||password||''' where username = '''||username||'''';
  24. perform dblink_exec(conexao,query);
  25. --RAISE EXCEPTION '%' ,query;
  26. RETURN NEW;
  27. END IF;
  28. IF(TG_OP = 'DELETE') THEN
  29. username:= OLD.login;
  30. query:='delete from granted_authorities where username = '''||username||'''';
  31. perform dblink_exec(conexao,query);
  32. query:='delete from users where username = '''||username||'''';
  33. perform dblink_exec(conexao,query);
  34.  
  35. --RAISE EXCEPTION '%' ,query;
  36. RETURN OLD;
  37. END IF;
  38. END;
  39. $body$
  40. LANGUAGE plpgsql;
Add Comment
Please, Sign In to add comment