protected List<ServiceInstanceData> getServiceInstanceInstancesData( long accountId, boolean client, long vnetId) { MultiRecordMapper<ServiceInstanceData> mapper = new MultiRecordMapper<ServiceInstanceData>() { @Override protected ServiceInstanceData map(List<Object> input) { Service service = (Service) input.get(0); IpAddress ip = (IpAddress) input.get(1); Instance instance = (Instance) input.get(2); ServiceExposeMap exposeMap = (ServiceExposeMap) input.get(3); Nic nic = (Nic) input.get(4); ServiceInstanceData data = new ServiceInstanceData(service, ip, instance, exposeMap, nic); return data; } }; ServiceTable service = mapper.add(SERVICE); IpAddressTable ipAddress = mapper.add(IP_ADDRESS); InstanceTable instance = mapper.add(INSTANCE); ServiceExposeMapTable exposeMap = mapper.add(SERVICE_EXPOSE_MAP); NicTable nic = mapper.add(NIC); Condition condition = null; if (client) { condition = ipAddress.ROLE.eq(IpAddressConstants.ROLE_PRIMARY).and(nic.VNET_ID.eq(vnetId)); } else { condition = (ipAddress.ROLE.isNull().and(ipAddress.ADDRESS.isNull())) .or(ipAddress.ROLE.eq(IpAddressConstants.ROLE_PRIMARY)) .and( instance .HEALTH_STATE .isNull() .or(instance.HEALTH_STATE.eq(HealthcheckConstants.HEALTH_STATE_HEALTHY))); } return create() .select(mapper.fields()) .from(service) .join(exposeMap) .on(service.ID.eq(exposeMap.SERVICE_ID)) .leftOuterJoin(instance) .on(instance.ID.eq(exposeMap.INSTANCE_ID)) .leftOuterJoin(nic) .on(nic.INSTANCE_ID.eq(exposeMap.INSTANCE_ID)) .leftOuterJoin(IP_ADDRESS_NIC_MAP) .on(IP_ADDRESS_NIC_MAP.NIC_ID.eq(nic.ID)) .leftOuterJoin(ipAddress) .on(IP_ADDRESS_NIC_MAP.IP_ADDRESS_ID.eq(ipAddress.ID)) .where(service.ACCOUNT_ID.eq(accountId)) .and(service.REMOVED.isNull()) .and(exposeMap.REMOVED.isNull()) .and(nic.REMOVED.isNull()) .and(ipAddress.REMOVED.isNull()) .and(instance.REMOVED.isNull()) .and( instance .STATE .isNull() .or( instance.STATE.in( InstanceConstants.STATE_RUNNING, InstanceConstants.STATE_STARTING))) .and(condition) .fetch() .map(mapper); }