All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tentackle.wurblet.UniqueDomainKey Maven / Gradle / Ivy

There is a newer version: 21.16.1.0
Show newest version
// wurblet generated by Wurbelizer 2.0.6, see http://www.wurbelizer.org

package org.tentackle.wurblet;

import org.tentackle.buildsupport.*;
import java.util.*;
import java.io.*;
import org.tentackle.common.*;
import org.wurbelizer.wurbel.*;
import org.tentackle.model.*;
import org.wurbelizer.wurblet.*;


public class UniqueDomainKey extends ModelWurblet {

  @Override
  public void run() throws WurbelException {
    super.run();
    try {
      // ----------------- begin wurblet code -----------------

    /**
     * Tentackle - http://www.tentackle.org
     *
     * This library is free software; you can redistribute it and/or
     * modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation; either
     * version 2.1 of the License, or (at your option) any later version.
     *
     * This library is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public
     * License along with this library; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     */



    /**
     * generate unique domain key class for a pdo.
     *
     * usage:  @wurblet  UniqueDomainKey --model=
     *
     *          is the mapping description
     *
     * Example: @wurblet uniqueDomainKey UniqueDomainKey --model=$mapping
     */

    List udk = getEntity().getUniqueDomainKey();
    List superUdk = null;
    if (getEntity().getSuperEntity() != null) {
      superUdk = getEntity().getSuperEntity().getUniqueDomainKey();
    }
    if (superUdk != null && !udk.isEmpty() && udk.equals(superUdk)) {
      out.print(source[0]); // 39:2 = "  // "
      out.print(getEntity());
      out.print(source[1]); // 41:20 = " inherits from "
      out.print(getEntity().getSuperEntity());
      out.print(source[2]); // 41:67 = ""
    }
    else if (!getEntity().isRootEntityAccordingToModel()) {
      out.print(source[3]); // 45:2 = "  // "
      out.print(getEntity());
      out.print(source[4]); // 47:20 = " is not a root entity"
    }
    else if (udk.isEmpty()) {
      out.print(source[5]); // 51:2 = "  // no unique domain key defined for "
      out.print(getEntity());
      out.print(source[6]); // 53:53 = ""
    }
    else if (udk.size() == 1) {
      out.print(source[7]); // 57:2 = "  // unique domain key for "
      out.print(getEntity());
      out.print(source[8]); // 59:42 = " is "
      out.print(udk.get(0));
      out.print(source[9]); // 59:60 = ""
    }
    else  {
      out.print(source[10]); // 63:2 = "  /**   * The unique domain key for "
      out.print(getEntity());
      out.print(source[11]); // 66:46 = ".   */  public static class "
      out.print(getEntity());
      out.print(source[12]); // 68:37 = "UDK implements Comparable<"
      out.print(getEntity());
      out.print(source[13]); // 68:78 = "UDK> {"
      StringBuilder con1Args = new StringBuilder();   // 1st constructor arguments
      StringBuilder con2Args = new StringBuilder();   // 2nd constructor arguments
      boolean first = true;
      for (Attribute attr: udk) {
        if (first) {
          first = false;
        }
        else {
          con1Args.append(", ");
          con2Args.append(", ");
        }
        con1Args.append(attr.getJavaType()).append(" ").append(attr.getJavaName());
        con2Args.append("pdo.").append(attr.getGetterName()).append("()");
        out.print(source[14]); // 83:2 = "    /** "
        out.print(attr.getOptions().getComment());
        out.print(source[15]); // 85:42 = ". */    public final "
        out.print(attr.getJavaType());
        out.print(source[16]); // 86:39 = " "
        out.print(attr.getJavaName());
        out.print(source[17]); // 86:62 = ";"

      }
      out.print(source[18]); // 90:2 = "    /**     * Creates a unique domain ..."
        for (Attribute attr: udk) {
          out.print(source[19]); // 97:2 = "     * @param "
          out.print(attr.getJavaName());
          out.print(source[20]); // 98:37 = " "
          out.print(attr.getOptions().getComment());
          out.print(source[21]); // 98:72 = ""
        }
        out.print(source[22]); // 101:2 = "     */    public "
        out.print(getEntity());
        out.print(source[23]); // 103:26 = "UDK("
        out.print(con1Args.toString());
        out.print(source[24]); // 103:53 = ") {"
        for (Attribute attr: udk) {
          out.print(source[25]); // 106:2 = "      this."
          out.print(attr.getJavaName());
          out.print(source[26]); // 107:33 = " = "
          out.print(attr.getJavaName());
          out.print(source[27]); // 107:58 = ";"
        }
        out.print(source[28]); // 110:2 = "    }    /**     * Creates a unique d..."
        out.print(getEntity());
        out.print(source[29]); // 118:26 = "UDK("
        out.print(getEntity());
        out.print(source[30]); // 118:45 = " pdo) {      this("
        out.print(con2Args.toString());
        out.print(source[31]); // 119:34 = ");    }    @Override    public int h..."
        for (Attribute attr: udk) {
          if (attr.getDataType().isPrimitive()) {
            out.print(source[32]); // 128:2 = "      hash = 79 * hash + "
            out.print(attr.getJavaName());
            out.print(source[33]); // 129:47 = ";"
          }
          else  {
            out.print(source[34]); // 133:2 = "      hash = 79 * hash + Objects.hashCod..."
            out.print(attr.getJavaName());
            out.print(source[35]); // 134:64 = ");"
          }
        }
        out.print(source[36]); // 138:2 = "      return hash;    }    @Override..."
        out.print(getEntity());
        out.print(source[37]); // 150:21 = "UDK other = ("
        out.print(getEntity());
        out.print(source[38]); // 150:49 = "UDK) obj;"
        for (Attribute attr: udk) {
          if (attr.getDataType().isPrimitive()) {
            out.print(source[39]); // 154:2 = "      if ("
            out.print(attr.getJavaName());
            out.print(source[40]); // 155:32 = " != other."
            out.print(attr.getJavaName());
            out.print(source[41]); // 155:64 = ") {        return false;      }"
          }
          else  {
            out.print(source[42]); // 161:2 = "      if (!Objects.equals("
            out.print(attr.getJavaName());
            out.print(source[43]); // 162:48 = ", other."
            out.print(attr.getJavaName());
            out.print(source[44]); // 162:78 = ")) {        return false;      }"
          }
        }
        out.print(source[45]); // 168:2 = "      return true;    }    @Override..."
        out.print(getEntity());
        out.print(source[46]); // 173:40 = "UDK other) {      int rv = other == nul..."
        String inset = "";
        for (Attribute attr: udk) {
          out.print(source[47]); // 178:2 = "      "
          out.print(inset);
          out.print(source[48]); // 179:15 = "if (rv == 0) {"
          if (attr.getDataType().isPrimitive()) {
            out.print(source[49]); // 182:2 = "      "
            out.print(inset);
            out.print(source[50]); // 183:15 = "  rv = "
            out.print(attr.getDataType().toNonPrimitive());
            out.print(source[51]); // 183:61 = ".compare("
            out.print(attr.getJavaName());
            out.print(source[52]); // 183:92 = ", other."
            out.print(attr.getJavaName());
            out.print(source[53]); // 183:122 = ");"
          }
          else  {
            out.print(source[54]); // 187:2 = "      "
            out.print(inset);
            out.print(source[55]); // 188:15 = "  rv = Compare.compare("
            out.print(attr.getJavaName());
            out.print(source[56]); // 188:60 = ", other."
            out.print(attr.getJavaName());
            out.print(source[57]); // 188:90 = ");"
          }
          inset += "  ";
        }

        do {
          inset = inset.substring(2);
          out.print(source[58]); // 196:2 = "      "
          out.print(inset);
          out.print(source[59]); // 197:15 = "}"

        } while (!inset.isEmpty());
         out.print(source[60]); // 201:2 = "      return rv;    }  }"
  }

      // ----------------- end wurblet code -----------------
    }
    catch (Exception ex) {
      throw new WurbelException("wurblet " + this + " failed", ex);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy