コード例 #1
0
  public void addOrderBy(Class<?> clazz, String field, boolean ascending) {
    if (field == null) {
      return;
    }
    Field f;
    Pair<Class<?>, Field> pair = ReflectUtil.getAnyField(clazz, field);
    assert (pair != null) : "Can't find field " + field + " in " + clazz.getName();
    clazz = pair.first();
    f = pair.second();

    Column column = f.getAnnotation(Column.class);
    String name = column != null ? column.name() : field;

    StringBuilder order = new StringBuilder();
    if (column.table() == null || column.table().length() == 0) {
      order.append(DbUtil.getTableName(clazz));
    } else {
      order.append(column.table());
    }
    order.append(".").append(name).append(ascending ? " ASC " : " DESC ");

    if (_orderBy == null) {
      _orderBy = order.insert(0, " ORDER BY ").toString();
    } else {
      _orderBy = order.insert(0, _orderBy).toString();
    }
  }
コード例 #2
0
  public void init() {
    BaseCmd.setComponents(new ApiResponseHelper());
    BaseListCmd.configure();

    _systemAccount = _accountMgr.getSystemAccount();
    _systemUser = _accountMgr.getSystemUser();
    _dispatcher = ApiDispatcher.getInstance();

    Integer apiPort = null; // api port, null by default
    ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
    ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
    SearchCriteria<ConfigurationVO> sc = configDao.createSearchCriteria();
    sc.addAnd("name", SearchCriteria.Op.EQ, "integration.api.port");
    List<ConfigurationVO> values = configDao.search(sc, null);
    if ((values != null) && (values.size() > 0)) {
      ConfigurationVO apiPortConfig = values.get(0);
      if (apiPortConfig.getValue() != null) {
        apiPort = Integer.parseInt(apiPortConfig.getValue());
      }
    }

    Set<Class<?>> cmdClasses =
        ReflectUtil.getClassesWithAnnotation(
            APICommand.class, new String[] {"org.apache.cloudstack.api", "com.cloud.api"});

    for (Class<?> cmdClass : cmdClasses) {
      String apiName = cmdClass.getAnnotation(APICommand.class).name();
      if (_apiNameCmdClassMap.containsKey(apiName)) {
        s_logger.error("API Cmd class " + cmdClass.getName() + " has non-unique apiname" + apiName);
        continue;
      }
      _apiNameCmdClassMap.put(apiName, cmdClass);
    }

    encodeApiResponse = Boolean.valueOf(configDao.getValue(Config.EncodeApiResponse.key()));
    String jsonType = configDao.getValue(Config.JavaScriptDefaultContentType.key());
    if (jsonType != null) {
      jsonContentType = jsonType;
    }

    if (apiPort != null) {
      ListenerThread listenerThread = new ListenerThread(this, apiPort);
      listenerThread.start();
    }
  }