Search in sources :

Example 26 with UpdateBuilder

use of com.cloud.utils.db.UpdateBuilder in project cloudstack by apache.

the class TemplatePrimaryDataStoreDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, TemplatePrimaryDataStoreVO vo, Object data) {
    Long oldUpdated = vo.getUpdatedCount();
    Date oldUpdatedTime = vo.getLastUpdated();
    SearchCriteria<TemplatePrimaryDataStoreVO> sc = updateSearchBuilder.create();
    sc.setParameters("id", vo.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", vo.getUpdatedCount());
    vo.incrUpdatedCount();
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "lastUpdated", new Date());
    int rows = update(vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        TemplatePrimaryDataStoreVO template = findByIdIncludingRemoved(vo.getId());
        if (template != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(template.getId()).append("; state=").append(template.getState()).append("; updatecount=").append(template.getUpdatedCount()).append(";updatedTime=").append(template.getLastUpdated());
            str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount()).append("; updatedTime=").append(vo.getLastUpdated());
            str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update template: id=" + vo.getId() + ", as there is no such template exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 27 with UpdateBuilder

use of com.cloud.utils.db.UpdateBuilder in project cloudstack by apache.

the class VolumeHostDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
    VolumeHostVO volHost = (VolumeHostVO) vo;
    Long oldUpdated = volHost.getUpdatedCount();
    Date oldUpdatedTime = volHost.getUpdated();
    SearchCriteria<VolumeHostVO> sc = updateStateSearch.create();
    sc.setParameters("id", volHost.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", volHost.getUpdatedCount());
    volHost.incrUpdatedCount();
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "updated", new Date());
    int rows = update((VolumeHostVO) vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        VolumeHostVO dbVol = findByIdIncludingRemoved(volHost.getId());
        if (dbVol != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated());
            str.append(": New Data={id=").append(volHost.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(volHost.getUpdatedCount()).append("; updatedTime=").append(volHost.getUpdated());
            str.append(": stale Data={id=").append(volHost.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update objectIndatastore: id=" + volHost.getId() + ", as there is no such object exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : VolumeHostVO(com.cloud.storage.VolumeHostVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Aggregations

UpdateBuilder (com.cloud.utils.db.UpdateBuilder)27 Date (java.util.Date)17 HostVO (com.cloud.host.HostVO)3 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)3 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)1 VMTemplateHostVO (com.cloud.storage.VMTemplateHostVO)1 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 VolumeHostVO (com.cloud.storage.VolumeHostVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 Pair (com.cloud.utils.Pair)1 ConsoleProxyVO (com.cloud.vm.ConsoleProxyVO)1 DomainRouterVO (com.cloud.vm.DomainRouterVO)1 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)1 EngineClusterVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineClusterVO)1 EngineDataCenterVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineDataCenterVO)1 EngineHostPodVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostPodVO)1