コード例 #1
0
  @BigDBQuery
  public static Object getDeviceOracle(@BigDBParam("query") Query query) throws BigDBException {
    String entityClassName = null;

    assert query.getSteps() != null;
    assert query.getSteps().size() == 1;
    assert query.getStep(0).getName().equals(CURRENT_STEP_NAME);

    Step currentStep = query.getStep(0);

    final String id = currentStep.getExactMatchPredicateString(ID_FIELD_NAME);
    String macStr = currentStep.getExactMatchPredicateString(MAC_FIELD_NAME);
    Long vlanObj = (Long) currentStep.getExactMatchPredicateValue(VLAN_FIELD_NAME);
    entityClassName = currentStep.getExactMatchPredicateString(ENTITY_CLASS_FIELD_NAME);
    String dpidStr = currentStep.getExactMatchPredicateString(SWITCH_DPID_FIELD_NAME);
    Short portShort = (Short) currentStep.getExactMatchPredicateValue(SWITCH_PORT_FIELD_NAME);
    String ipStr = currentStep.getExactMatchPredicateString(IP_ADDRESS_FIELD_NAME);

    if (id != null && (macStr != null || vlanObj != null || entityClassName != null)) {
      throw new BigDBException(
          "This query only accepts a device id or "
              + "a combination of mac, vlan and entity-class-name, "
              + "but not both.");
    }
    if (id != null) {
      // convert from device-id to individual components
      try {
        IndexedEntity.EntityWithClassName e = IndexedEntity.getNamedEntityFromKeyString(id);
        DeviceOracle d =
            new DeviceOracle(
                id,
                e.getEntity().getMacAddress(),
                e.getEntity().getVlan(),
                e.getEntityClassName(),
                e.getEntity().getIpv4Address(),
                e.getEntity().getSwitchDPID(),
                e.getEntity().getSwitchPort());
        ArrayList<DeviceOracle> dd = new ArrayList<DeviceOracle>();
        dd.add(d);
        return dd;
      } catch (Exception e) {
        throw new BigDBException("Invalid device id " + id);
      }
    } else if (macStr != null && entityClassName != null) {
      DeviceOracle d =
          createDeviceOracle(macStr, vlanObj, entityClassName, ipStr, dpidStr, portShort);

      ArrayList<DeviceOracle> dd = new ArrayList<DeviceOracle>();
      dd.add(d);
      return dd;
    } else {
      throw new BigDBException(
          "This query requires a device id or a "
              + "combination of mac, vlan and entity-class-name");
    }
  }