org.zstack.core.db.Q类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.zstack.core.db.Q类的一些代码示例,展示了Q类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Q类的具体详情如下:
包路径:org.zstack.core.db.Q
类名称:Q

Q介绍

[英]Created by xing5 on 2016/12/31.
[中]由兴5于2016/12/31创建。

代码示例

代码示例来源:origin: zstackio/zstack

public static boolean isLocalStorage(String psUuid){
    String psType = Q.New(PrimaryStorageVO.class)
        .select(PrimaryStorageVO_.type)
        .eq(PrimaryStorageVO_.uuid, psUuid)
        .findValue();

    return LocalStorageConstants.LOCAL_STORAGE_TYPE.equals(psType);
  }
}

代码示例来源:origin: zstackio/zstack

public static Integer getIsoDeviceId(String vmUuid, String isoUuid) {
  VmCdRomVO vmCdRomVO = Q.New(VmCdRomVO.class)
      .eq(VmCdRomVO_.vmInstanceUuid, vmUuid)
      .eq(VmCdRomVO_.isoUuid, isoUuid)
      .find();
  if (vmCdRomVO == null) {
    return null;
  }
  return vmCdRomVO.getDeviceId();
}

代码示例来源:origin: zstackio/zstack

private String getOverlapVniRangePool(String l2NetworkUuid, String clusterUuid) {
  List<VniRangeVO> checkRanges = Q.New(VniRangeVO.class).eq(VniRangeVO_.l2NetworkUuid, l2NetworkUuid).list();
  List<String> l2Uuids = Q.New(L2NetworkClusterRefVO.class).select(L2NetworkClusterRefVO_.l2NetworkUuid).eq(L2NetworkClusterRefVO_.clusterUuid, clusterUuid).listValues();
  for (String l2Uuid : l2Uuids) {
    List<VniRangeVO> ranges = Q.New(VniRangeVO.class).eq(VniRangeVO_.l2NetworkUuid, l2Uuid).list();
    for (VniRangeVO range : ranges) {
      Boolean result = checkRanges.stream()
          .map(r -> isVniRangeOverlap(r.getStartVni(), r.getEndVni(), range.getStartVni(), range.getEndVni()))
          .reduce(true, (l, r) -> l && r);
      if (result.equals(true)) {
        return l2Uuid;
      }
    }
  }
  return null;
}

代码示例来源:origin: zstackio/zstack

static VmCdRomVO getEmptyCdRom(String vmUuid) {
  VmCdRomVO cdRomVO = Q.New(VmCdRomVO.class)
      .eq(VmCdRomVO_.vmInstanceUuid, vmUuid)
      .isNull(VmCdRomVO_.isoUuid)
      .orderBy(VmCdRomVO_.deviceId, SimpleQuery.Od.ASC)
      .limit(1)
      .find();
  return cdRomVO;
}

代码示例来源:origin: zstackio/zstack

public static List<String> getIsoUuidByVmUuid(String vmUuid) {
  List<String> isoUuids = Q.New(VmCdRomVO.class)
      .select(VmCdRomVO_.isoUuid)
      .eq(VmCdRomVO_.vmInstanceUuid, vmUuid)
      .notNull(VmCdRomVO_.isoUuid)
      .listValues();
  return isoUuids;
}

代码示例来源:origin: zstackio/zstack

@Override
public boolean verifyCaptcha(String uuid, String verifyCode, String targetResourceIdentify) {
  if (Q.New(CaptchaVO.class)
      .eq(CaptchaVO_.uuid, uuid)
      .eq(CaptchaVO_.verifyCode, verifyCode)
      .eq(CaptchaVO_.targetResourceIdentity, targetResourceIdentify)
      .isExists()) {
    return true;
  }
  return false;
}

代码示例来源:origin: zstackio/zstack

@Override
protected List<VmNicInventory> scripts() {
  String vmNicUuid = Q.New(PortForwardingRuleVO.class)
      .select(PortForwardingRuleVO_.vmNicUuid)
      .eq(PortForwardingRuleVO_.uuid, ruleUuid)
      .findValue();
  if (vmNicUuid != null) {
    return new ArrayList<>();
  String zoneUuid = t.get(0, String.class);
  String vipUuid = t.get(1, String.class);
  List<VipPeerL3NetworkRefVO> vipPeerL3Refs = Q.New(VipPeerL3NetworkRefVO.class)
      .eq(VipPeerL3NetworkRefVO_.vipUuid, vipUuid)
      .list();
  List<String> vipPeerL3Uuids = new ArrayList<>();
  if (vipPeerL3Refs != null && !vipPeerL3Refs.isEmpty()) {
  VipVO vipVO = Q.New(VipVO.class).eq(VipVO_.uuid, vipUuid).find();
    VmNicVO rnic = Q.New(VmNicVO.class).in(VmNicVO_.l3NetworkUuid, vipPeerL3Uuids)
        .notNull(VmNicVO_.metaData).limit(1).find();
    if (rnic == null) {
      l3Uuids.addAll(vipPeerL3Uuids);
    } else {
      List<String> vrAttachedL3Uuids = Q.New(VmNicVO.class)
          .select(VmNicVO_.l3NetworkUuid)
          .eq(VmNicVO_.vmInstanceUuid, rnic.getVmInstanceUuid())
          .listValues();
      Set l3UuidSet = new HashSet<>(vipPeerL3Uuids);
      l3UuidSet.addAll(vrAttachedL3Uuids);

代码示例来源:origin: zstackio/zstack

private void deleteListenersForLoadBalancer(String lbUuid) {
  List<LoadBalancerListenerVO> listenerVOS = Q.New(LoadBalancerListenerVO.class)
      .eq(LoadBalancerListenerVO_.loadBalancerUuid, lbUuid)
      .list();
  if (listenerVOS != null && !listenerVOS.isEmpty()) {
    logger.debug(String.format("delete loadBalancerListeners[%s] for loadBalancer[uuid:%s]",
        listenerVOS.stream().map(vo -> vo.getUuid()).collect(Collectors.toList()), lbUuid));
    listenerVOS.forEach(vo -> dbf.remove(vo));
  }
}

代码示例来源:origin: zstackio/zstack

@Override
protected void scripts() {
  List<String> hostIps = q(HostVO.class)
      .select(HostVO_.managementIp)
      .eq(HostVO_.clusterUuid, cls.getUuid())
      .listValues();
        .select(PrimaryStorageVO_.uuid)
        .eq(PrimaryStorageVO_.type, NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE)
        .like(PrimaryStorageVO_.url, String.format("%s:/%%", hostIp))
        .limit(1)
        .findValue();
    if (psUuid == null || psUuid.equals("")) {
      continue;
        .select(VolumeVO_.uuid)
        .eq(VolumeVO_.type, VolumeType.Root)
        .eq(VolumeVO_.primaryStorageUuid, psUuid)
        .listValues();
    if (volumes == null || volumes.isEmpty()) {
      continue;
        .notEq(VmInstanceVO_.state, VmInstanceState.Stopped)
        .in(VmInstanceVO_.rootVolumeUuid, volumes)
        .isExists();
    if (vmRunning) {
      matched.add(hostIp);

代码示例来源:origin: zstackio/zstack

private List<String> getL3NetworkDns(String l3NetworkUuid){
  List<String> dns = Q.New(L3NetworkDnsVO.class).eq(L3NetworkDnsVO_.l3NetworkUuid, l3NetworkUuid)
      .select(L3NetworkDnsVO_.dns).orderBy(L3NetworkDnsVO_.id, SimpleQuery.Od.ASC).listValues();
  if (dns == null) {
    dns = new ArrayList<String>();
  }
  L3NetworkVO l3VO = Q.New(L3NetworkVO.class).eq(L3NetworkVO_.uuid, l3NetworkUuid).find();
  if (FlatNetwordProviderGlobalConfig.ALLOW_DEFAULT_DNS.value(Boolean.class) && l3VO.getIpVersion() == IPv6Constants.IPv4) {
    String dhcpIp = getDHCPServerIP(l3NetworkUuid);
    if (dhcpIp != null) {
      dns.add(dhcpIp);
    }
  }
  return dns;
}

代码示例来源:origin: zstackio/zstack

public static Collection<String> queryVmInGC(final String hostUuid, final Collection<String> vmUuids) {
    Collection<String> vmUuidsInGC = new HashSet<>();
    List<String> gcNames = Q.New(GarbageCollectorVO.class).select(GarbageCollectorVO_.name)
                    .eq(GarbageCollectorVO_.runnerClass, DeleteVmGC.class.getName())
                    .like(GarbageCollectorVO_.name, String.format("%%on-host-%s%%", hostUuid))
                    .notEq(GarbageCollectorVO_.status, GCStatus.Done).listValues();
    if (gcNames != null && !gcNames.isEmpty()) {
      vmUuidsInGC = vmUuids.stream().filter(uuid ->
          gcNames.contains(String.format("gc-vm-%s-on-host-%s", uuid, hostUuid))).collect(Collectors.toSet());
    }
    return vmUuidsInGC;
  }
}

代码示例来源:origin: zstackio/zstack

private void takeOverLongJob() {
  logger.debug("Starting to take over long jobs");
  final int group = 1000;
  long amount = dbf.count(LongJobVO.class);
  int times = (int) ((amount + group - 1)/group);
  int start = 0;
  for (int i = 0; i < times; i++) {
    List<String> uuids = Q.New(LongJobVO.class)
        .select(LongJobVO_.uuid)
        .isNull(LongJobVO_.managementNodeUuid)
        .limit(group).start(start).listValues();
    for (String uuid : uuids) {
      if (destinationMaker.isManagedByUs(uuid)) {
        retryTakeOverLongJob(uuid);
      }
    }
    start += group;
  }
}

代码示例来源:origin: zstackio/zstack

private void validate(APIUpdateRoleMsg msg) {
  if (Q.New(RoleVO.class).in(RoleVO_.type, list(RoleType.Predefined, RoleType.System)).eq(RoleVO_.uuid, msg.getUuid()).isExists()) {
    throw new ApiMessageInterceptionException(argerr("cannot update a system or predefined role"));
  }
}

代码示例来源:origin: zstackio/zstack

public static String getMemberKey(){
  String ldapServerUuid = Q.New(LdapServerVO.class).select(LdapServerVO_.uuid).findValue();
  String type = LdapSystemTags.LDAP_SERVER_TYPE.getTokenByResourceUuid(ldapServerUuid, LdapSystemTags.LDAP_SERVER_TYPE_TOKEN);
  if(LdapConstant.WindowsAD.TYPE.equals(type)){
    return LdapConstant.WindowsAD.MEMBER_KEY;
  }
  if(LdapConstant.OpenLdap.TYPE.equals(type)){
    return LdapConstant.OpenLdap.MEMBER_KEY;
  }
  // default WindowsAD
  return LdapConstant.WindowsAD.MEMBER_KEY;
}

代码示例来源:origin: zstackio/zstack

@Override
  protected void scripts() {
    if (!q(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.volumeUuid, volumeUuid).isExists()) {
      return;
    }
    List<String> treeUuids = q(VolumeSnapshotVO.class).select(VolumeSnapshotVO_.treeUuid).eq(VolumeSnapshotVO_.volumeUuid, volumeUuid).listValues();
    sql(VolumeSnapshotTreeVO.class).in(VolumeSnapshotTreeVO_.uuid, treeUuids).delete();
    sql(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.volumeUuid, volumeUuid).delete();
  }
}.execute();

代码示例来源:origin: zstackio/zstack

private void validateIpRangeOverlapWithVm(String l3NetworkUuid, String vmInstanceUuid) {
  List<VmNicVO> vmNicVOS = Q.New(VmNicVO.class).eq(VmNicVO_.vmInstanceUuid, vmInstanceUuid).list();
  List<IpRangeVO> newIpRangeVOS = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, l3NetworkUuid).list();
  if (newIpRangeVOS == null || newIpRangeVOS.isEmpty()) {
    throw new ApiMessageInterceptionException(operr("no ip ranges attached with l3 network[uuid:%s]", l3NetworkUuid));
  }
  for (VmNicVO vmNicVO: vmNicVOS) {
    List<IpRangeVO> ipRangeVOS = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, vmNicVO.getL3NetworkUuid()).limit(1).list();
    if (ipRangeVOS != null && !ipRangeVOS.isEmpty()) {
      if (NetworkUtils.isCidrOverlap(ipRangeVOS.get(0).getNetworkCidr(), newIpRangeVOS.get(0).getNetworkCidr())) {
        throw new ApiMessageInterceptionException(operr("unable to attach a L3 network. The cidr of l3[%s] to attach overlapped with l3[%s] already attached to vm", l3NetworkUuid, vmNicVO.getL3NetworkUuid()));
      }
    }
  }
}

代码示例来源:origin: zstackio/zstack

public List<SystemTagInventory> getTagInventories(String resourceUuid) {
  return SystemTagInventory.valueOf(Q.New(SystemTagVO.class).eq(SystemTagVO_.resourceType, getResourceClass().getSimpleName()).
      eq(SystemTagVO_.resourceUuid, resourceUuid).like(SystemTagVO_.tag, useTagFormat()).list());
}

代码示例来源:origin: zstackio/zstack

@Override
  public List<HostVO> filter(List<HostVO> candidates) {
    List<String> toRemoveHuuids = Q.New(HostVO.class).notEq(KVMHostVO_.username, "root").select(KVMHostVO_.uuid).listValues();
    if (!toRemoveHuuids.isEmpty()){
      candidates = CollectionUtils.transformToList(candidates, new Function<HostVO, HostVO>() {
        @Override
        public HostVO call(HostVO arg) {
          return toRemoveHuuids.contains(arg.getUuid()) ? null : arg;
        }
      });
    }
    return candidates;
  }
}

代码示例来源:origin: zstackio/zstack

@Transactional(readOnly = true)
private boolean noStorageAccessible(String hostUuid){
  // detach ps will delete PrimaryStorageClusterRefVO first.
  List<String> attachedPsUuids = SQL.New("select distinct ref.primaryStorageUuid" +
      " from PrimaryStorageClusterRefVO ref, HostVO h" +
      " where h.uuid =:hostUuid" +
      " and ref.clusterUuid = h.clusterUuid", String.class)
      .param("hostUuid", hostUuid)
      .list();
  long attachedPsCount = attachedPsUuids.size();
  long inaccessiblePsCount = attachedPsCount == 0 ? 0 : Q.New(PrimaryStorageHostRefVO.class)
      .eq(PrimaryStorageHostRefVO_.hostUuid, hostUuid)
      .eq(PrimaryStorageHostRefVO_.status, PrimaryStorageHostStatus.Disconnected)
      .in(PrimaryStorageHostRefVO_.primaryStorageUuid, attachedPsUuids)
      .count();
  return inaccessiblePsCount == attachedPsCount && attachedPsCount > 0;
}

代码示例来源:origin: zstackio/zstack

private Map<String, String> getUuidTypeMapByResourceUuids(List<String> resourceUuids) {
  List<Tuple> ts = Q.New(AccountResourceRefVO.class)
      .select(AccountResourceRefVO_.resourceUuid, AccountResourceRefVO_.resourceType)
      .in(AccountResourceRefVO_.resourceUuid, resourceUuids)
      .listTuple();
  Map<String, String> uuidType = new HashMap<String, String>();
  for (Tuple t : ts) {
    String resUuid = t.get(0, String.class);
    String resType = t.get(1, String.class);
    uuidType.put(resUuid, resType);
  }
  return uuidType;
}

相关文章