anchor.diff:  
   %% occi_backend callbacks
   -export([init/1,
  -	 terminate/1]).
  +		 terminate/1]).
   -export([update/2,
  -	 save/2,
  -	 delete/2,
  -	 find/2,
  -	 load/3,
  -	 action/3]).
  +		 save/2,
  +		 delete/2,
  +		 find/2,
  +		 load/3,
  +		 action/3]).
   
   -record(state, {}).
   
  
positive.code:     add_link_t(Id, occi_link:get_target(Link)),
      mnesia:write(Link),
      sets:fold(fun (#occi_cid{}=MixinId, _) ->
  		      add_to_collection_t(MixinId, [Id])
  	      end, ok, occi_link:get_mixins(Link)),
      ok.
  
  add_link_t(LinkId, Id) ->
      case get_resource_t(Id) of
  	false ->
  	    mnesia:abort({unknown_resource, Id});
  	{ok, Res} ->
  	    mnesia:write(occi_resource:add_link(Res, LinkId))
      end.
  
  save_node_t(#occi_node{id=Id}=Node) ->
      case mnesia:wread({occi_node, Id}) of
  	[_] -> 	
  	    mnesia:write(Node#occi_node{data=undefined});
  	[] -> 
  	    mnesia:write(Node#occi_node{data=undefined}),
  	    add_to_collection_t(occi_uri:get_parent(Id), {entity, Id})
      end.
  
  update_t(#occi_node{type=capabilities}=Node) ->
  
negative.code: init_schema(Opts) ->
      application:load(mnesia),
      case application:get_env(mnesia, dir, "") of
  		"" ->
  			init_db(Opts);
  		Path ->
  			case filelib:is_file(filename:join([Path, "schema.DAT"])) of
  				true ->
  					?debug("mnesia schema already exists on this node", []),
  					init_db(Opts);
  				false ->
  					?debug("Creating mnesia schema on ~s", [Path]),
  					case mnesia:create_schema([node()]) of
  						ok ->
  							init_db(Opts);
  						{error, {_, {already_exists,_}}} ->
  							init_db(Opts);
  						{error, Err} ->
  							?error("Error creating mnesia schema on node ~p: ~p", [node(), Err]),
  							{error, Err}
  					end
  			end
      end.
  
  init_db(Opts) ->
      application:start(mnesia, permanent),
      Tables = [{occi_collection, [{disc_copies, [node()]},
  								 {attributes, record_info(fields, occi_collection)}]},
  			  {occi_resource, [{disc_copies, [node()]},
  							   {attributes, record_info(fields, occi_resource)},
  							   {index, [#occi_resource.cid]}]},
  			  {occi_link, [{disc_copies, [node()]},
  						   {attributes, record_info(fields, occi_link)},
  						   {index, [#occi_link.cid]}]},
  			  {occi_mixin, [{disc_copies, [node()]},
  							{attributes, record_info(fields, occi_mixin)}]},
  			  {occi_node, [{disc_copies, [node()]}, 
  						   {attributes, record_info(fields, occi_node)},
  						   {index, [#occi_node.objid]},
  						   {type, 'ordered_set'}]},
  			  {occi_user, [{disc_copies, [node()]},
  						   {attributes, record_info(fields, occi_user)}]}],
      case init_tables(Tables) of
  		ok ->
  			mnesia:wait_for_tables([occi_collection, occi_resource, occi_link,
  									occi_mixin, occi_node, occi_user], 5000),
  			init_backend(Opts);
  		{error, Err} ->
  			?error("Error creating mnesia tables: ~p", [Err]),
  			{error, Err}
      end.
  
  init_tables([]) ->
      ok;
  init_tables([{Name, TabDef} | Tables]) ->
      case mnesia:create_table(Name, TabDef) of
  		{atomic, ok} ->
  			?debug("mnesia: created table: ~p~n", [Name]),
  			init_tables(Tables);
  		{aborted, {already_exists, Name}} ->
  			?debug("mnesia: table ~p already exists~n", [Name]),
  			init_tables(Tables);
  		{aborted, Reason} ->
  			{error, Reason}
      end.
  
  init_backend(Opts) ->
      Schemas = lists:map(fun ({path, _Path}=S) -> 
  								S;
  							({priv_dir, Path}) -> 
  								Fullpath = filename:join([code:priv_dir(occi_backend_mnesia), Path]),
  								{path, Fullpath}
  						end, 
  						proplists:get_value(schemas, Opts, []) 
  						++ application:get_env(occi_backend_mnesia, schemas, [])),
      F = fun() -> mnesia:match_object(#occi_node{type=capabilities, _='_'}) end,
      case mnesia:transaction(F) of
  		{atomic, []} -> 
  			{ok, [{schemas, Schemas}], #state{}};
  		{atomic, MixinsNodes} ->
  			Mixins = [ Mixin || #occi_node{data=Mixin} <- MixinsNodes],
  			{ok, [{schemas, lists:flatten([Schemas, Mixins])}], #state{}};
  		{aborted, Reason} ->
  			{error, Reason}
      end.
  