示例#1
0
 private static String getClassDeclaration(String jrfColumnClassName, boolean usePrimitives) {
   String result = CodeGenUtil.getClassDeclarationValue(jrfColumnClassName);
   if (usePrimitives) { // Translate things like java.util.Long to long, if required.
     return JRFGeneratorUtil.translateWrapper(result);
   }
   return result;
 }
示例#2
0
 public String getGetterSetterImpl(String dbObjClassName) throws CodeGenException {
   return JRFGeneratorUtil.getGetterSetterImplCode(
       getterSetter,
       dbObjClassName,
       (String) super.transientKeys.get("objectName"),
       jrfColumnClassName,
       usePrimitives);
 }
示例#3
0
 public String getEncodedKeyCode() {
   if (type == T_DATE) {
     return "("
         + fieldName
         + " == null ? \"null\":new java.sql.Timestamp("
         + fieldName
         + ".getTime()).toString())";
   }
   if (usePrimitives) {
     return JRFGeneratorUtil.getPrimitiveWrapperCode(jrfColumnClassName, fieldName)
         + ".toString()";
   }
   return fieldName + ".toString()";
 }
示例#4
0
  public void resolveImpliedKeys() {
    String util = (String) super.transientKeys.get("jrfImpl");
    if (util == null) {
      util = (String) super.transientKeys.get("dbType");
      if (util == null)
        throw new IllegalArgumentException(this + ": neither jrfImpl or dbType is specified.");
      String t = (String) dbTypeToJrfImplMap.getProperty(util);
      if (t == null) {
        throw new IllegalArgumentException(
            this + ": no JRF column impl translation found for " + util);
      }
      util = t;
    }
    // fill out if required.
    if (util.indexOf(".") == -1) {
      util = "net.sf.jrf.column.columnspecs." + util;
    }
    super.transientKeys.put("jrfImpl", util);
    try {
      ColumnSpec spec = (ColumnSpec) Class.forName(util).newInstance();
      if (spec instanceof DayOfWeekColumnSpec) type = T_DOW;
      else if (spec instanceof TextColumnSpec) type = T_TEXT;
      else if (spec instanceof NumericColumnSpec) type = T_NUMERIC;
      else if (spec instanceof DateColumnSpec) type = T_DATE;
      else type = T_OTHER;
      jrfColumnClassName = spec.getColumnClass().getName();
    } catch (Exception ne) {
      throw new IllegalArgumentException(this + ": No such class: " + util);
    }
    if (nullable && type != T_DOW) {
      // If is nullable -- CANNOT be a primitive -- override default.
      usePrimitives = false;
    }
    util = (String) super.transientKeys.get("objectName");
    if (util == null) {
      if (initCapNameOnly) {
        util = (String) super.transientKeys.get("name");
        super.transientKeys.put(
            "objectName", java.lang.Character.toUpperCase(util.charAt(0)) + util.substring(1));
      } else
        super.transientKeys.put(
            "objectName",
            JRFGeneratorUtil.databaseNameToFieldName((String) super.transientKeys.get("name")));
      util = (String) super.transientKeys.get("objectName");
    }
    super.transientKeys.put("propertyName", generatePropertyName(util));
    getterSetter = super.transientKeys.get("objectName") + "GetterSetter";
    fieldName = "f_" + ((String) super.transientKeys.get("objectName"));
    util = (String) transientKeys.get("maxValue");
    if (util == null) {
      super.transientKeys.put("maxValue", "null");
    }
    util = (String) super.transientKeys.get("minValue");
    if (util == null) {
      super.transientKeys.put("minValue", "null");
    }
    util = (String) super.transientKeys.get("default");
    if (util == null || type == T_DOW) {
      super.transientKeys.put("default", "null");
    }
    if (type == T_DOW) {
      if (util == null) {
        defaultBeanValue = "net.sf.jrf.column.columnspecs.DayOfWeekColumnSpec.NULLDAYOFWEEK";
      } else {
        defaultBeanValue = util;
      }
    }
    if (util != null) {
      if (!util.startsWith("new")) {
        super.transientKeys.put(
            "default", JRFGeneratorUtil.getLiteralValueCode(jrfColumnClassName, util));
      }
    }

    util = (String) super.transientKeys.get("size");
    if (util == null) {
      super.transientKeys.put("size", "255");
    }
    super.transientKeys.put("listOfValues", "null");
    super.transientKeys.put("listOfValuesAdd", "");
    setDescriptionColor(primaryKey ? defaultPKColor : defaultColor);
    util = (String) super.transientKeys.get("writeOnce");
    if (util.equals("true") && !primaryKey) {
      super.transientKeys.put("writeOnceAdd", "    colVar.setWriteOnce(true);");
    } else {
      super.transientKeys.put("writeOnceAdd", "");
    }
  }