Fix CLOUDSTACK-2525: clean up db entries in vm_template and

template_store_ref in case of template creation failure.
This commit is contained in:
Min Chen 2013-05-20 16:21:45 -07:00
parent ef541a2a7b
commit 565bdfb27b
3 changed files with 13 additions and 0 deletions

View File

@ -37,6 +37,8 @@ public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Lo
public void deletePrimaryRecordsForStore(long id);
public void deletePrimaryRecordsForTemplate(long templateId);
List<TemplateDataStoreVO> listByTemplateStore(long templateId, long storeId);
List<TemplateDataStoreVO> listByTemplateStoreStatus(long templateId, long storeId, State... states);

View File

@ -182,6 +182,15 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
txn.commit();
}
@Override
public void deletePrimaryRecordsForTemplate(long templateId) {
SearchCriteria<TemplateDataStoreVO> sc = templateSearch.create();
sc.setParameters("template_id", templateId);
Transaction txn = Transaction.currentTxn();
txn.start();
expunge(sc);
txn.commit();
}
@Override
public List<TemplateDataStoreVO> listByTemplateStore(long templateId, long storeId) {

View File

@ -1456,6 +1456,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
if (privateTemplate == null) {
Transaction txn = Transaction.currentTxn();
txn.start();
// Remove the template_store_ref record first, otherwise, we cannot remove the template record due to FK constraints
this._tmplStoreDao.deletePrimaryRecordsForTemplate(templateId);
// Remove the template record
this._tmpltDao.expunge(templateId);