mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	Merge branch 'master' of ssh://git.cloud.com/var/lib/git/cloudstack-oss
This commit is contained in:
		
						commit
						6ca4851a3d
					
				@ -22,12 +22,10 @@ import org.apache.log4j.Logger;
 | 
			
		||||
 | 
			
		||||
import com.cloud.api.ApiDBUtils;
 | 
			
		||||
import com.cloud.api.BaseAsyncCmd;
 | 
			
		||||
import com.cloud.api.BaseCmd;
 | 
			
		||||
import com.cloud.api.BaseCmd.Manager;
 | 
			
		||||
import com.cloud.api.Implementation;
 | 
			
		||||
import com.cloud.api.Parameter;
 | 
			
		||||
import com.cloud.api.ServerApiException;
 | 
			
		||||
import com.cloud.api.response.SuccessResponse;
 | 
			
		||||
import com.cloud.api.response.DomainRouterResponse;
 | 
			
		||||
import com.cloud.event.EventTypes;
 | 
			
		||||
import com.cloud.user.Account;
 | 
			
		||||
import com.cloud.vm.DomainRouterVO;
 | 
			
		||||
@ -82,16 +80,45 @@ public class RebootRouterCmd extends BaseAsyncCmd {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override @SuppressWarnings("unchecked")
 | 
			
		||||
    public SuccessResponse getResponse() {
 | 
			
		||||
        SuccessResponse response = new SuccessResponse();
 | 
			
		||||
        Boolean responseObject = (Boolean)getResponseObject();
 | 
			
		||||
    public DomainRouterResponse getResponse() {
 | 
			
		||||
        DomainRouterResponse response = new DomainRouterResponse();
 | 
			
		||||
        DomainRouterVO router = (DomainRouterVO)getResponseObject();
 | 
			
		||||
      
 | 
			
		||||
        if (responseObject != null) {
 | 
			
		||||
        	response.setSuccess(responseObject);
 | 
			
		||||
        } else {
 | 
			
		||||
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reboot router");
 | 
			
		||||
        }
 | 
			
		||||
        response.setId(router.getId());
 | 
			
		||||
        response.setZoneId(router.getDataCenterId());
 | 
			
		||||
        response.setZoneName(ApiDBUtils.findZoneById(router.getDataCenterId()).getName());
 | 
			
		||||
        response.setDns1(router.getDns1());
 | 
			
		||||
        response.setDns2(router.getDns2());
 | 
			
		||||
        response.setNetworkDomain(router.getDomain());
 | 
			
		||||
        response.setGateway(router.getGateway());
 | 
			
		||||
        response.setName(router.getName());
 | 
			
		||||
        response.setPodId(router.getPodId());
 | 
			
		||||
 | 
			
		||||
        if (router.getHostId() != null) {
 | 
			
		||||
            response.setHostId(router.getHostId());
 | 
			
		||||
            response.setHostName(ApiDBUtils.findHostById(router.getHostId()).getName());
 | 
			
		||||
        } 
 | 
			
		||||
 | 
			
		||||
        response.setPrivateIp(router.getPrivateIpAddress());
 | 
			
		||||
        response.setPrivateMacAddress(router.getPrivateMacAddress());
 | 
			
		||||
        response.setPrivateNetmask(router.getPrivateNetmask());
 | 
			
		||||
        response.setPublicIp(router.getPublicIpAddress());
 | 
			
		||||
        response.setPublicMacAddress(router.getPublicMacAddress());
 | 
			
		||||
        response.setPublicNetmask(router.getPublicNetmask());
 | 
			
		||||
        response.setGuestIpAddress(router.getGuestIpAddress());
 | 
			
		||||
        response.setGuestMacAddress(router.getGuestMacAddress());
 | 
			
		||||
        response.setGuestNetmask(router.getGuestNetmask());
 | 
			
		||||
        response.setTemplateId(router.getTemplateId());
 | 
			
		||||
        response.setCreated(router.getCreated());
 | 
			
		||||
        response.setState(router.getState());
 | 
			
		||||
 | 
			
		||||
        Account accountTemp = ApiDBUtils.findAccountById(router.getAccountId());
 | 
			
		||||
        if (accountTemp != null) {
 | 
			
		||||
            response.setAccountName(accountTemp.getAccountName());
 | 
			
		||||
            response.setDomainId(accountTemp.getDomainId());
 | 
			
		||||
            response.setDomainName(ApiDBUtils.findDomainById(accountTemp.getDomainId()).getName());
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        response.setResponseName(getName());
 | 
			
		||||
        return response;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -43,7 +43,7 @@ public abstract class UpdateTemplateOrIsoCmd extends BaseCmd {
 | 
			
		||||
    private Long id;
 | 
			
		||||
 | 
			
		||||
    @Parameter(name="name", type=CommandType.STRING, description="the name of the image file")
 | 
			
		||||
    private String isoName;
 | 
			
		||||
    private String templateName;
 | 
			
		||||
 | 
			
		||||
    @Parameter(name="ostypeid", type=CommandType.LONG, description="the ID of the OS type that best represents the OS of this image.")
 | 
			
		||||
    private Long osTypeId;
 | 
			
		||||
@ -70,8 +70,8 @@ public abstract class UpdateTemplateOrIsoCmd extends BaseCmd {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String isoName() {
 | 
			
		||||
        return isoName;
 | 
			
		||||
    public String getTemplateName() {
 | 
			
		||||
        return templateName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Long getOsTypeId() {
 | 
			
		||||
@ -85,5 +85,4 @@ public abstract class UpdateTemplateOrIsoCmd extends BaseCmd {
 | 
			
		||||
    public String getFormat() {
 | 
			
		||||
        return format;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -17,6 +17,8 @@
 | 
			
		||||
 */
 | 
			
		||||
package com.cloud.api.commands;
 | 
			
		||||
 | 
			
		||||
import java.text.DecimalFormat;
 | 
			
		||||
 | 
			
		||||
import org.apache.log4j.Logger;
 | 
			
		||||
 | 
			
		||||
import com.cloud.api.ApiDBUtils;
 | 
			
		||||
@ -25,7 +27,7 @@ import com.cloud.api.BaseCmd.Manager;
 | 
			
		||||
import com.cloud.api.Implementation;
 | 
			
		||||
import com.cloud.api.Parameter;
 | 
			
		||||
import com.cloud.api.ServerApiException;
 | 
			
		||||
import com.cloud.api.response.UpgradeVmResponse;
 | 
			
		||||
import com.cloud.api.response.UserVmResponse;
 | 
			
		||||
import com.cloud.offering.ServiceOffering;
 | 
			
		||||
import com.cloud.service.ServiceOfferingVO;
 | 
			
		||||
import com.cloud.storage.VMTemplateVO;
 | 
			
		||||
@ -76,13 +78,14 @@ public class UpgradeVMCmd extends BaseCmd {
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Override @SuppressWarnings("unchecked")
 | 
			
		||||
    public UpgradeVmResponse getResponse() {
 | 
			
		||||
    public UserVmResponse getResponse() {
 | 
			
		||||
        UserVmVO userVm = (UserVmVO)getResponseObject();
 | 
			
		||||
 | 
			
		||||
        UpgradeVmResponse response = new UpgradeVmResponse();
 | 
			
		||||
        UserVmResponse response = new UserVmResponse();
 | 
			
		||||
        if (userVm != null) {
 | 
			
		||||
    		Account acct = ApiDBUtils.findAccountById(userVm.getAccountId());
 | 
			
		||||
    		response.setAccount(acct.getAccountName());
 | 
			
		||||
    		response.setId(userVm.getId());
 | 
			
		||||
    		response.setAccountName(acct.getAccountName());
 | 
			
		||||
 | 
			
		||||
    		ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
 | 
			
		||||
    		response.setCpuSpeed(offering.getSpeed());
 | 
			
		||||
@ -94,17 +97,26 @@ public class UpgradeVMCmd extends BaseCmd {
 | 
			
		||||
    		}
 | 
			
		||||
 | 
			
		||||
    		response.setServiceOfferingId(userVm.getServiceOfferingId());
 | 
			
		||||
    		
 | 
			
		||||
 | 
			
		||||
            //stats calculation
 | 
			
		||||
            DecimalFormat decimalFormat = new DecimalFormat("#.##");
 | 
			
		||||
            String cpuUsed = null;
 | 
			
		||||
    		VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
 | 
			
		||||
    		if (vmStats != null) {
 | 
			
		||||
    		    response.setCpuUsed((long) vmStats.getCPUUtilization());
 | 
			
		||||
    		    response.setNetworkKbsRead((long) vmStats.getNetworkReadKBs());
 | 
			
		||||
    		    response.setNetworkKbsWrite((long) vmStats.getNetworkWriteKBs());
 | 
			
		||||
                float cpuUtil = (float) vmStats.getCPUUtilization();
 | 
			
		||||
                cpuUsed = decimalFormat.format(cpuUtil) + "%";
 | 
			
		||||
                response.setCpuUsed(cpuUsed);
 | 
			
		||||
 | 
			
		||||
                long networkKbRead = (long)vmStats.getNetworkReadKBs();
 | 
			
		||||
                response.setNetworkKbsRead(networkKbRead);
 | 
			
		||||
                
 | 
			
		||||
                long networkKbWrite = (long)vmStats.getNetworkWriteKBs();
 | 
			
		||||
                response.setNetworkKbsWrite(networkKbWrite);
 | 
			
		||||
    		}
 | 
			
		||||
    		
 | 
			
		||||
    		response.setCreated(userVm.getCreated());
 | 
			
		||||
    		response.setDisplayName(userVm.getDisplayName());
 | 
			
		||||
    		response.setDomain(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
 | 
			
		||||
    		response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
 | 
			
		||||
    		response.setDomainId(acct.getDomainId());
 | 
			
		||||
    		response.setHaEnable(userVm.isHaEnabled());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -144,10 +144,10 @@ public interface NetworkManager extends Manager {
 | 
			
		||||
    /**
 | 
			
		||||
     * Reboots domain router
 | 
			
		||||
     * @param cmd the command specifying router's id
 | 
			
		||||
     * @return success or failure
 | 
			
		||||
     * @return the rebooted router
 | 
			
		||||
     * @throws InvalidParameterValueException, PermissionDeniedException
 | 
			
		||||
     */
 | 
			
		||||
    boolean rebootRouter(RebootRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
 | 
			
		||||
    DomainRouterVO rebootRouter(RebootRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
 | 
			
		||||
    /**
 | 
			
		||||
     * @param hostId get all of the virtual machine routers on a host.
 | 
			
		||||
     * @return collection of VirtualMachineRouter
 | 
			
		||||
 | 
			
		||||
@ -422,16 +422,16 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
 | 
			
		||||
    public boolean rebootRouter(final long routerId, long startEventId) {
 | 
			
		||||
        return _routerMgr.rebootRouter(routerId, startEventId);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean rebootRouter(RebootRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
 | 
			
		||||
        return _routerMgr.rebootRouter(cmd);
 | 
			
		||||
    public DomainRouterVO rebootRouter(RebootRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
 | 
			
		||||
        _routerMgr.rebootRouter(cmd);
 | 
			
		||||
        return _routerMgr.getRouter(cmd.getId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean associateIP(final DomainRouterVO router, final List<String> ipAddrList, final boolean add, long vmId) {
 | 
			
		||||
        Commands cmds = new Commands(OnError.Continue);
 | 
			
		||||
        int i=0;
 | 
			
		||||
        boolean sourceNat = false;
 | 
			
		||||
        for (final String ipAddress: ipAddrList) {
 | 
			
		||||
        	if (ipAddress.equalsIgnoreCase(router.getPublicIpAddress()))
 | 
			
		||||
 | 
			
		||||
@ -89,8 +89,10 @@ import com.cloud.api.commands.StopSystemVmCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateAccountCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateDomainCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateIPForwardingRuleCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateIsoCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateIsoPermissionsCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplateCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplatePermissionsCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateUserCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateVMGroupCmd;
 | 
			
		||||
import com.cloud.api.commands.UploadCustomCertificateCmd;
 | 
			
		||||
@ -595,10 +597,11 @@ public interface ManagementServer {
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a new template
 | 
			
		||||
     * @param cmd
 | 
			
		||||
     * @return success/failure
 | 
			
		||||
     * @return updated template
 | 
			
		||||
     * @throws InvalidParameterValueException, PermissionDeniedException
 | 
			
		||||
     */
 | 
			
		||||
    boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
 | 
			
		||||
    VMTemplateVO updateTemplate(UpdateIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
 | 
			
		||||
    VMTemplateVO updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * Copies a template from one secondary storage server to another
 | 
			
		||||
@ -1173,7 +1176,8 @@ public interface ManagementServer {
 | 
			
		||||
	boolean checkLocalStorageConfigVal(); 
 | 
			
		||||
 | 
			
		||||
	boolean updateUser(UpdateUserCmd cmd) throws InvalidParameterValueException;
 | 
			
		||||
	boolean updateTemplatePermissions(UpdateTemplateOrIsoPermissionsCmd cmd)throws InvalidParameterValueException, PermissionDeniedException,InternalErrorException;
 | 
			
		||||
	boolean updateTemplatePermissions(UpdateTemplatePermissionsCmd cmd)throws InvalidParameterValueException, PermissionDeniedException,InternalErrorException;
 | 
			
		||||
    boolean updateTemplatePermissions(UpdateIsoPermissionsCmd cmd)throws InvalidParameterValueException, PermissionDeniedException,InternalErrorException;
 | 
			
		||||
	String[] createApiKeyAndSecretKey(RegisterCmd cmd);
 | 
			
		||||
 | 
			
		||||
	VolumeVO findVolumeByInstanceAndDeviceId(long instanceId, long deviceId);
 | 
			
		||||
 | 
			
		||||
@ -128,7 +128,9 @@ import com.cloud.api.commands.StopSystemVmCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateAccountCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateDomainCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateIPForwardingRuleCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateIsoCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateIsoPermissionsCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplateCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
 | 
			
		||||
import com.cloud.api.commands.UpdateTemplatePermissionsCmd;
 | 
			
		||||
@ -222,8 +224,6 @@ import com.cloud.storage.GuestOSCategoryVO;
 | 
			
		||||
import com.cloud.storage.GuestOSVO;
 | 
			
		||||
import com.cloud.storage.LaunchPermissionVO;
 | 
			
		||||
import com.cloud.storage.Snapshot;
 | 
			
		||||
import com.cloud.storage.Upload;
 | 
			
		||||
import com.cloud.storage.Volume;
 | 
			
		||||
import com.cloud.storage.Snapshot.SnapshotType;
 | 
			
		||||
import com.cloud.storage.SnapshotPolicyVO;
 | 
			
		||||
import com.cloud.storage.SnapshotVO;
 | 
			
		||||
@ -236,7 +236,7 @@ import com.cloud.storage.StorageStats;
 | 
			
		||||
import com.cloud.storage.Upload.Type;
 | 
			
		||||
import com.cloud.storage.UploadVO;
 | 
			
		||||
import com.cloud.storage.VMTemplateVO;
 | 
			
		||||
import com.cloud.storage.Volume.VolumeType;
 | 
			
		||||
import com.cloud.storage.Volume;
 | 
			
		||||
import com.cloud.storage.VolumeStats;
 | 
			
		||||
import com.cloud.storage.VolumeVO;
 | 
			
		||||
import com.cloud.storage.dao.DiskOfferingDao;
 | 
			
		||||
@ -252,7 +252,6 @@ import com.cloud.storage.dao.UploadDao;
 | 
			
		||||
import com.cloud.storage.dao.VMTemplateDao;
 | 
			
		||||
import com.cloud.storage.dao.VMTemplateDao.TemplateFilter;
 | 
			
		||||
import com.cloud.storage.dao.VolumeDao;
 | 
			
		||||
import com.cloud.storage.download.DownloadMonitor;
 | 
			
		||||
import com.cloud.storage.preallocatedlun.PreallocatedLunVO;
 | 
			
		||||
import com.cloud.storage.preallocatedlun.dao.PreallocatedLunDao;
 | 
			
		||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
 | 
			
		||||
@ -3423,9 +3422,18 @@ public class ManagementServerImpl implements ManagementServer {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean updateTemplate(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
 | 
			
		||||
    public VMTemplateVO updateTemplate(UpdateIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
 | 
			
		||||
        return updateTemplateOrIso(cmd);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public VMTemplateVO updateTemplate(UpdateTemplateCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
 | 
			
		||||
        return updateTemplateOrIso(cmd);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private VMTemplateVO updateTemplateOrIso(UpdateTemplateOrIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
 | 
			
		||||
    	Long id = cmd.getId();
 | 
			
		||||
    	String name = cmd.getName();
 | 
			
		||||
    	String name = cmd.getTemplateName();
 | 
			
		||||
    	String displayText = cmd.getDisplayText();
 | 
			
		||||
    	String format = cmd.getFormat();
 | 
			
		||||
    	Long guestOSId = cmd.getOsTypeId();
 | 
			
		||||
@ -3462,7 +3470,7 @@ public class ManagementServerImpl implements ManagementServer {
 | 
			
		||||
 | 
			
		||||
    	boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null && bootable == null);
 | 
			
		||||
    	if (!updateNeeded) {
 | 
			
		||||
    		return true;
 | 
			
		||||
    		return template;
 | 
			
		||||
    	}
 | 
			
		||||
    	
 | 
			
		||||
    	template = _templateDao.createForUpdate(id);
 | 
			
		||||
@ -3504,7 +3512,9 @@ public class ManagementServerImpl implements ManagementServer {
 | 
			
		||||
    		template.setBootable(bootable);
 | 
			
		||||
    	}
 | 
			
		||||
    	
 | 
			
		||||
        return _templateDao.update(id, template);
 | 
			
		||||
        _templateDao.update(id, template);
 | 
			
		||||
 | 
			
		||||
        return _templateDao.findById(id);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
@ -5178,7 +5188,7 @@ public class ManagementServerImpl implements ManagementServer {
 | 
			
		||||
            sc.setParameters("accountId", accountId);
 | 
			
		||||
        } else if (domainId != null) {
 | 
			
		||||
            DomainVO domain = _domainDao.findById((Long)domainId);
 | 
			
		||||
            SearchCriteria joinSearch = sc.getJoin("accountSearch");
 | 
			
		||||
            SearchCriteria<?> joinSearch = sc.getJoin("accountSearch");
 | 
			
		||||
            joinSearch.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -5216,9 +5226,20 @@ public class ManagementServerImpl implements ManagementServer {
 | 
			
		||||
	            (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Override @DB
 | 
			
		||||
    public boolean updateTemplatePermissions(UpdateTemplatePermissionsCmd cmd) throws InvalidParameterValueException,
 | 
			
		||||
            PermissionDeniedException, InternalErrorException {
 | 
			
		||||
        return updateTemplateOrIsoPermissions(cmd);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override @DB
 | 
			
		||||
    public boolean updateTemplatePermissions(UpdateIsoPermissionsCmd cmd) throws InvalidParameterValueException,
 | 
			
		||||
            PermissionDeniedException, InternalErrorException {
 | 
			
		||||
        return updateTemplateOrIsoPermissions(cmd);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @DB
 | 
			
		||||
    public boolean updateTemplatePermissions(UpdateTemplateOrIsoPermissionsCmd cmd) throws InvalidParameterValueException,
 | 
			
		||||
    protected boolean updateTemplateOrIsoPermissions(UpdateTemplateOrIsoPermissionsCmd cmd) throws InvalidParameterValueException,
 | 
			
		||||
            PermissionDeniedException, InternalErrorException {
 | 
			
		||||
        Transaction txn = Transaction.currentTxn();
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
@ -343,15 +343,9 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (joins != null) {
 | 
			
		||||
                for (JoinBuilder<SearchCriteria<?>> join : joins) {
 | 
			
		||||
                    for (final Pair<Attribute, Object> value : join.getT().getValues()) {
 | 
			
		||||
                        prepareAttribute(++i, pstmt, value.first(), value.second());
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (s_logger.isTraceEnabled()) {
 | 
			
		||||
                    s_logger.trace("join search statement is " + pstmt.toString());
 | 
			
		||||
                }
 | 
			
		||||
                i = addJoinAttributes(i, pstmt, joins);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (s_logger.isDebugEnabled() && lock != null) {
 | 
			
		||||
            	txn.registerLock(pstmt.toString());
 | 
			
		||||
            }
 | 
			
		||||
@ -404,14 +398,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (joins != null) {
 | 
			
		||||
                for (JoinBuilder<SearchCriteria<?>> join : joins) {
 | 
			
		||||
                    for (final Pair<Attribute, Object> value : join.getT().getValues()) {
 | 
			
		||||
                        prepareAttribute(++i, pstmt, value.first(), value.second());
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (s_logger.isTraceEnabled()) {
 | 
			
		||||
                    s_logger.trace("join search statement is " + pstmt.toString());
 | 
			
		||||
                }
 | 
			
		||||
                i = addJoinAttributes(i, pstmt, joins);
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            ResultSet rs = pstmt.executeQuery();
 | 
			
		||||
@ -636,19 +623,21 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
 | 
			
		||||
            return (M)rs.getObject(index);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    @DB(txn=false)
 | 
			
		||||
    protected int addJoinAttributes(int count, PreparedStatement pstmt, List<Ternary<SearchCriteria<?>, Attribute, Attribute>> joins) throws SQLException {
 | 
			
		||||
        for (Ternary<SearchCriteria<?>, Attribute, Attribute> join : joins) {
 | 
			
		||||
            for (final Pair<Attribute, Object> value : join.first().getValues()) {
 | 
			
		||||
    protected int addJoinAttributes(int count, PreparedStatement pstmt, Collection<JoinBuilder<SearchCriteria<?>>> joins) throws SQLException {
 | 
			
		||||
        for (JoinBuilder<SearchCriteria<?>> join : joins) {
 | 
			
		||||
            for (final Pair<Attribute, Object> value : join.getT().getValues()) {
 | 
			
		||||
                prepareAttribute(++count, pstmt, value.first(), value.second());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        for (Ternary<SearchCriteria<?>, Attribute, Attribute> join : joins) {
 | 
			
		||||
            if (join.first().getJoins() != null) {
 | 
			
		||||
                count = addJoinAttributes(count, pstmt, joins);
 | 
			
		||||
 | 
			
		||||
        for (JoinBuilder<SearchCriteria<?>> join : joins) {
 | 
			
		||||
            if (join.getT().getJoins() != null) {
 | 
			
		||||
                count = addJoinAttributes(count, pstmt, join.getT().getJoins());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (s_logger.isTraceEnabled()) {
 | 
			
		||||
            s_logger.trace("join search statement is " + pstmt.toString());
 | 
			
		||||
        }
 | 
			
		||||
@ -1015,31 +1004,38 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
 | 
			
		||||
        return sql;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @DB(txn=false)
 | 
			
		||||
 | 
			
		||||
    @DB(txn = false)
 | 
			
		||||
    protected void addJoins(StringBuilder str, Collection<JoinBuilder<SearchCriteria<?>>> joins) {
 | 
			
		||||
        int fromIndex = str.lastIndexOf("WHERE");
 | 
			
		||||
        if (fromIndex == -1) {
 | 
			
		||||
        	fromIndex = str.length();
 | 
			
		||||
            fromIndex = str.length();
 | 
			
		||||
            str.append(" WHERE ");
 | 
			
		||||
        } else {
 | 
			
		||||
            str.append(" AND ");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
      for (JoinBuilder<SearchCriteria<?>> join : joins) {
 | 
			
		||||
    	StringBuilder onClause =  new StringBuilder();
 | 
			
		||||
    	onClause.append(" ").append(join.getType().getName()).append(" ").append(join.getSecondAttribute().table).append(" ON ").append(join.getFirstAttribute().table).append(".").append(join.getFirstAttribute().columnName).append("=").append(join.getSecondAttribute().table).append(".").append(join.getSecondAttribute().columnName).append(" ");
 | 
			
		||||
        str.insert(fromIndex, onClause);
 | 
			
		||||
        str.append(" (").append(join.getT().getWhereClause()).append(") AND ");
 | 
			
		||||
        fromIndex+=onClause.length();
 | 
			
		||||
      }
 | 
			
		||||
    
 | 
			
		||||
      str.delete(str.length() - 4, str.length());
 | 
			
		||||
        for (JoinBuilder<SearchCriteria<?>> join : joins) {
 | 
			
		||||
            StringBuilder onClause = new StringBuilder();
 | 
			
		||||
            onClause.append(" ").append(join.getType().getName()).append(" ").append(join.getSecondAttribute().table)
 | 
			
		||||
                    .append(" ON ").append(join.getFirstAttribute().table).append(".").append(join.getFirstAttribute().columnName)
 | 
			
		||||
                    .append("=").append(join.getSecondAttribute().table).append(".").append(join.getSecondAttribute().columnName)
 | 
			
		||||
                    .append(" ");
 | 
			
		||||
            str.insert(fromIndex, onClause);
 | 
			
		||||
            String whereClause = join.getT().getWhereClause();
 | 
			
		||||
            if ((whereClause != null) && !"".equals(whereClause)) {
 | 
			
		||||
                str.append(" (").append(whereClause).append(") AND");
 | 
			
		||||
            }
 | 
			
		||||
            fromIndex += onClause.length();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        str.delete(str.length() - 4, str.length());
 | 
			
		||||
 | 
			
		||||
        for (JoinBuilder<SearchCriteria<?>> join : joins) {
 | 
			
		||||
            if (join.getT().getJoins() != null) {
 | 
			
		||||
                addJoins(str, join.getT().getJoins());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override @DB(txn=false)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user