Skip to content
Snippets Groups Projects
Commit 786be2e7 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

raise an exception when p_id of orientdb user class will be duplicated

parent 89bb5f07
No related branches found
No related tags found
No related merge requests found
class DuplicatedUserIndexError < Orientdb4r::ServerError
end
\ No newline at end of file
...@@ -2,9 +2,15 @@ module OrientDb ...@@ -2,9 +2,15 @@ module OrientDb
class UserRepository < Base class UserRepository < Base
def create_graph_node(user) def create_graph_node(user)
if user.persisted? begin
connection.command sprintf("create vertex User set p_id = %d", user.id) if user.persisted?
return true connection.command sprintf("create vertex User set p_id = %d", user.id)
return true
end
rescue Orientdb4r::ServerError => e
if e.message =~ /ORecordDuplicatedException/
raise DuplicatedUserIndexError, 'The OrientDB index p_id of User class cannot be duplicated.'
end
end end
raise NotPersistedRecordError, 'The user wasn`t persisted yet.' raise NotPersistedRecordError, 'The user wasn`t persisted yet.'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment