示例#1
0
    @Override
    boolean objectsAreEqual(Object object, Object objectInTheList) {
      if (object == null && objectInTheList == null) {
        return true;
      }

      if (object != null && objectInTheList != null) {

        Map<?, ?> id = (Map<?, ?>) objectInTheList;
        Map<?, ?> map = (Map<?, ?>) object;

        if (id.size() != map.size()) {
          return false;
        }

        // id must be a subset of this map
        for (Map.Entry<?, ?> entry : id.entrySet()) {
          Object key = entry.getKey();
          Object value = entry.getValue();
          if (!Util.nullSafeEquals(value, map.get(key))) {
            return false;
          }
        }

        return true;
      }

      return false;
    }
  /** Initializes Query name from string. */
  void setQueryName(String newName) {
    if (newName != null && newName.trim().length() == 0) {
      newName = null;
    }

    AbstractQuery query = getQuery();

    if (query == null) {
      return;
    }

    if (Util.nullSafeEquals(newName, query.getName())) {
      return;
    }

    if (newName == null) {
      throw new ValidationException("SelectQuery name is required.");
    }

    DataMap map = mediator.getCurrentDataMap();
    Query matchingQuery = map.getQuery(newName);

    if (matchingQuery == null) {
      // completely new name, set new name for entity
      QueryEvent e = new QueryEvent(this, query, query.getName());
      ProjectUtil.setQueryName(map, query, newName);
      mediator.fireQueryEvent(e);
    } else if (matchingQuery != query) {
      // there is a query with the same name
      throw new ValidationException(
          "There is another query named '" + newName + "'. Use a different name.");
    }
  }
  /**
   * Method to create and check an expression
   *
   * @param text String to be converted as Expression
   * @return Expression if a new expression was created, null otherwise.
   * @throws ValidationException if <code>text</code> can't be converted
   */
  Expression createQualifier(String text) throws ValidationException {
    SelectQuery query = getQuery();
    if (query == null) {
      return null;
    }

    ExpressionConvertor convertor = new ExpressionConvertor();
    try {
      String oldQualifier = convertor.valueAsString(query.getQualifier());
      if (!Util.nullSafeEquals(oldQualifier, text)) {
        Expression exp = (Expression) convertor.stringAsValue(text);

        /** Advanced checking. See CAY-888 #1 */
        if (query.getRoot() instanceof Entity) {
          checkExpression((Entity) query.getRoot(), exp);
        }

        return exp;
      }

      return null;
    } catch (IllegalArgumentException ex) {
      // unparsable qualifier
      throw new ValidationException(ex.getMessage());
    }
  }
示例#4
0
    @Override
    boolean replacesObject(Object object, Object objectInTheList) {

      Map<?, ?> id = (Map<?, ?>) objectInTheList;
      if (id.size() > idWidth) {
        return false;
      }

      // id must be a subset of this map
      Map<?, ?> map = (Map<?, ?>) object;
      for (Map.Entry<?, ?> entry : id.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();
        if (!Util.nullSafeEquals(value, map.get(key))) {
          return false;
        }
      }

      return true;
    }
示例#5
0
  void setClassName(String newClassName) {
    if (newClassName != null && newClassName.trim().length() == 0) {
      newClassName = null;
    }

    Embeddable embeddable = mediator.getCurrentEmbeddable();

    if (embeddable == null) {
      return;
    }

    if (Util.nullSafeEquals(newClassName, embeddable.getClassName())) {
      return;
    }

    if (newClassName == null) {
      throw new ValidationException("Embeddable name is required.");
    } else if (embeddable.getDataMap().getEmbeddable(newClassName) == null) {

      // if newClassName dupliucates in other DataMaps
      DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
      if (domain != null) {
        for (DataMap nextMap : domain.getDataMaps()) {
          if (nextMap == embeddable.getDataMap()) {
            continue;
          }

          Embeddable conflictingEmbeddable = nextMap.getEmbeddable(newClassName);
          if (conflictingEmbeddable != null) {
            throw new ValidationException(
                "Duplicate Embeddable name in another DataMap: " + newClassName + ".");
          }
        }
      }

      // completely new name, set new name for embeddable
      EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
      String oldName = embeddable.getClassName();
      embeddable.setClassName(newClassName);

      mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());

      Iterator it =
          ((DataChannelDescriptor) mediator.getProject().getRootNode()).getDataMaps().iterator();
      while (it.hasNext()) {
        DataMap dataMap = (DataMap) it.next();
        Iterator<ObjEntity> ent = dataMap.getObjEntities().iterator();

        while (ent.hasNext()) {

          Collection<ObjAttribute> attr = ent.next().getAttributes();
          Iterator<ObjAttribute> attrIt = attr.iterator();

          while (attrIt.hasNext()) {
            ObjAttribute atribute = attrIt.next();
            if (atribute.getType() == null || atribute.getType().equals(oldName)) {
              atribute.setType(newClassName);
              AttributeEvent ev = new AttributeEvent(this, atribute, atribute.getEntity());
              mediator.fireObjAttributeEvent(ev);
            }
          }
        }
      }

    } else {
      // there is an embeddable with the same name
      throw new ValidationException(
          "There is another embeddable with name '" + newClassName + "'.");
    }
  }
示例#6
0
  @Override
  public boolean equals(Object obj) {

    if (obj == this) {
      return true;
    }

    if (obj == null) {
      return false;
    }

    if (obj.getClass() != this.getClass()) {
      return false;
    }

    DataSourceInfo dsi = (DataSourceInfo) obj;

    if (!Util.nullSafeEquals(this.userName, dsi.userName)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.password, dsi.password)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.jdbcDriver, dsi.jdbcDriver)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.dataSourceUrl, dsi.dataSourceUrl)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.adapterClassName, dsi.adapterClassName)) {
      return false;
    }

    if (this.minConnections != dsi.minConnections) {
      return false;
    }

    if (this.maxConnections != dsi.maxConnections) {
      return false;
    }

    if (!Util.nullSafeEquals(this.passwordEncoderClass, dsi.passwordEncoderClass)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.passwordEncoderKey, dsi.passwordEncoderKey)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.passwordSourceFilename, dsi.passwordSourceFilename)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.passwordSourceModel, dsi.passwordSourceModel)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.passwordSourceUrl, dsi.passwordSourceUrl)) {
      return false;
    }

    if (!Util.nullSafeEquals(this.passwordLocation, dsi.passwordLocation)) {
      return false;
    }

    return true;
  }