core: fix deadlock on update vm version

When a new template version created,
all vms using 'latest' of the template are updated to the new version.
seems that the update of template child count inside the insertVmStatic
stored procedure caused deadlock in db, because it would do select
count(*) on the table, without taking any lock.

in this patch the insert/delete vm static stored procedures are changed
to take a lock on the template, and the update line changed to +1 / -1
instead of count(*), because of the lock, now it is safe to do.

Change-Id: I2dfdb556e66658c3ef630cf71fba5f902ea26862
Signed-off-by: Omer Frenkel <ofrenkel@redhat.com>