|
16 | 16 | // under the License. |
17 | 17 | package com.cloud.storage.dao; |
18 | 18 |
|
19 | | -import java.util.ArrayList; |
20 | | -import java.util.Date; |
21 | | -import java.util.List; |
22 | | -import java.util.Map; |
23 | | - |
24 | | -import javax.inject.Inject; |
25 | | -import javax.naming.ConfigurationException; |
26 | | - |
27 | | -import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
28 | | -import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
29 | | -import org.apache.log4j.Logger; |
30 | | -import org.springframework.stereotype.Component; |
31 | | - |
32 | 19 | import com.cloud.dc.dao.DataCenterDao; |
33 | 20 | import com.cloud.domain.dao.DomainDao; |
34 | 21 | import com.cloud.host.Host; |
|
57 | 44 | import com.cloud.utils.db.TransactionLegacy; |
58 | 45 | import com.cloud.utils.db.UpdateBuilder; |
59 | 46 | import com.cloud.utils.exception.CloudRuntimeException; |
| 47 | +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
| 48 | +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
| 49 | +import org.apache.log4j.Logger; |
| 50 | +import org.springframework.stereotype.Component; |
| 51 | + |
| 52 | +import javax.inject.Inject; |
| 53 | +import javax.naming.ConfigurationException; |
| 54 | +import java.sql.PreparedStatement; |
| 55 | +import java.sql.SQLException; |
| 56 | +import java.util.ArrayList; |
| 57 | +import java.util.Date; |
| 58 | +import java.util.List; |
| 59 | +import java.util.Map; |
60 | 60 |
|
61 | 61 | @Component |
62 | 62 | public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implements VMTemplateDao { |
@@ -105,6 +105,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem |
105 | 105 | private String routerTmpltName; |
106 | 106 | private String consoleProxyTmpltName; |
107 | 107 |
|
| 108 | + private static final String UPDATE_OLD_SYSTEMVM_TEMPLATE_TYPE = "UPDATE `cloud`.`vm_template` SET type = 'USER' WHERE name like '%systemvm%' AND type = 'SYSTEM' AND hypervisor_type = ? " + |
| 109 | + "AND id != (SELECT * FROM (SELECT MAX(id) FROM `cloud`.`vm_template` WHERE name like '%systemvm%' AND type = 'SYSTEM' AND hypervisor_type = ? ) as t)"; |
| 110 | + |
108 | 111 | public VMTemplateDaoImpl() { |
109 | 112 | super(); |
110 | 113 | LatestTemplateByHypervisorTypeSearch = createSearchBuilder(); |
@@ -717,4 +720,22 @@ public boolean updateState( |
717 | 720 | } |
718 | 721 | return rows > 0; |
719 | 722 | } |
| 723 | + |
| 724 | + @Override |
| 725 | + public void updateOldSystemVmTemplateType(HypervisorType hypervisorType) { |
| 726 | + TransactionLegacy txn = TransactionLegacy.currentTxn(); |
| 727 | + |
| 728 | + StringBuilder sql = new StringBuilder(UPDATE_OLD_SYSTEMVM_TEMPLATE_TYPE); |
| 729 | + try { |
| 730 | + PreparedStatement updateStatement = txn.prepareAutoCloseStatement(sql.toString()); |
| 731 | + updateStatement.setString(1, hypervisorType.name()); |
| 732 | + updateStatement.setString(2, hypervisorType.name()); |
| 733 | + updateStatement.executeUpdate(); |
| 734 | + } catch (SQLException e) { |
| 735 | + throw new CloudRuntimeException("DB Exception on: " + sql, e); |
| 736 | + } catch (Throwable e) { |
| 737 | + throw new CloudRuntimeException("Caught: " + sql, e); |
| 738 | + } |
| 739 | + |
| 740 | + } |
720 | 741 | } |
0 commit comments