Exemplo n.º 1
0
 public boolean equals(Object other) {
   if (!(other instanceof CUDestination)) return false;
   CUDestination castOther = (CUDestination) other;
   return new EqualsBuilder()
       .append(this.getCudestinationid(), castOther.getCudestinationid())
       .isEquals();
 }
  public void insertComponentUpdateEntry(
      String in_componentId,
      String in_updateName,
      List<ComponentDescription> in_componentDescriptions)
      throws LoggingException {

    Session session = null;
    session = HibernateUtils.getNewSession();

    if (session == null) return;

    ArrayList<CUDestination> cuDestinationList = new ArrayList<CUDestination>();
    ArrayList<CUAttribute> cuAttributeList = new ArrayList<CUAttribute>();

    ComponentUpdate componentUpdateEntry = new ComponentUpdate();
    componentUpdateEntry.setComponentid(in_componentId);
    componentUpdateEntry.setUpdatename(in_updateName);
    componentUpdateEntry.setUpdatetime(new Date());

    for (ComponentDescription compDescr : in_componentDescriptions) {
      // Set up the cuDestination entry
      CUDestination cuDestinationEntry = new CUDestination();
      cuDestinationEntry.setComponentUpdate(componentUpdateEntry);
      cuDestinationEntry.setDestinationcomponentid(compDescr.id);
      cuDestinationEntry.setSuccess(new Boolean(true));
      cuDestinationList.add(cuDestinationEntry);

      AttributeNameValue<?> attributeNameValue;

      // Set up the constant attribute entries
      for (Attribute<?> attribute : compDescr.getConstantAttributes()) {
        CUAttribute cuAttributeEntry = new CUAttribute();
        cuAttributeEntry.setAttributename(attribute.getName());
        cuAttributeEntry.setAttributetype(attribute.getType());
        cuAttributeEntry.setConstant(true);
        cuAttributeEntry.setCUDestination(cuDestinationEntry);

        // AttributeNameValue is a subclass of Attribute
        if (attribute instanceof AttributeNameValue<?>) {
          // check the value associated with this AttributeNameValue
          attributeNameValue = (AttributeNameValue<?>) attribute;
          if (attributeNameValue.getType().equals(String.class)) {
            cuAttributeEntry.setAttributevaluestring((String) attributeNameValue.getValue());
          } else if (attributeNameValue.getType().isInstance(Number.class)) {
            cuAttributeEntry.setAttributevaluenumeric(
                Float.valueOf(attributeNameValue.getValue().toString()));
          }
        }
        cuAttributeList.add(cuAttributeEntry);
      }

      // Set up the non constant attribute entries
      for (Attribute<?> attribute : compDescr.getNonConstantAttributes().values()) {
        CUAttribute cuAttributeEntry = new CUAttribute();
        cuAttributeEntry.setAttributename(attribute.getName());
        cuAttributeEntry.setAttributetype(attribute.getType());
        cuAttributeEntry.setConstant(false);
        cuAttributeEntry.setCUDestination(cuDestinationEntry);

        if (attribute instanceof AttributeNameValue<?>) {
          attributeNameValue = (AttributeNameValue<?>) attribute;
          if (attributeNameValue.getType().equals(String.class)) {
            cuAttributeEntry.setAttributevaluestring((String) attributeNameValue.getValue());
          } else if (attributeNameValue.getType().isInstance(Number.class)) {
            cuAttributeEntry.setAttributevaluenumeric(
                Float.valueOf(attributeNameValue.getValue().toString()));
          }
        }
        cuAttributeList.add(cuAttributeEntry);
      }
    }

    Transaction tx = null;
    try {
      tx = session.beginTransaction();
      session.save(componentUpdateEntry);

      for (int i = 0; i < cuDestinationList.size(); i++) {
        session.save(cuDestinationList.get(i));
      }

      for (int i = 0; i < cuAttributeList.size(); i++) {
        session.save(cuAttributeList.get(i));
      }

      tx.commit(); // flush the Session and commit the transaction
    } catch (Exception e) {
      try {
        if (tx != null) tx.rollback(); // rollback the transaction
      } catch (Exception x) {
        throw new LoggingException(x);
      }
    } finally {
      try {
        session.close();
      } catch (Exception e) {
        throw new LoggingException(e);
      }
    }
  }