protected String doDerivePropertyTypeFromTestValue(String testValue) { // test point
   if (testValue == null) {
     String msg = "The argument 'testValue' should be not null.";
     throw new IllegalArgumentException(msg);
   }
   final DfLanguageGrammar grammar = getLanguageGrammar();
   final String plainTypeName;
   if (Srl.startsWithIgnoreCase(testValue, "date '", "date'")) {
     plainTypeName = "Date";
   } else if (Srl.startsWithIgnoreCase(testValue, "timestamp '", "timestamp'")) {
     plainTypeName = "Timestamp";
   } else if (Srl.startsWithIgnoreCase(testValue, "time '", "time'")) {
     plainTypeName = "Time";
   } else {
     if (Srl.isQuotedSingle(testValue)) {
       final String unquoted = Srl.unquoteSingle(testValue);
       Timestamp timestamp = null;
       Time time = null;
       try {
         timestamp = DfTypeUtil.toTimestamp(unquoted);
       } catch (ParseTimestampException ignored) {
         try {
           time = DfTypeUtil.toTime(unquoted);
         } catch (ParseTimeException andIgnored) {
         }
       }
       if (timestamp != null) {
         final String timeParts = DfTypeUtil.toString(timestamp, "HH:mm:ss.SSS");
         if (timeParts.equals("00:00:00.000")) {
           plainTypeName = "Date";
         } else {
           plainTypeName = "Timestamp";
         }
       } else if (time != null) {
         plainTypeName = "Time";
       } else {
         plainTypeName = "String";
       }
     } else if (Srl.isQuotedAnything(testValue, "(", ")")) {
       final String unquoted = Srl.unquoteAnything(testValue, "(", ")");
       final List<String> elementList = Srl.splitListTrimmed(unquoted, ",");
       if (elementList.size() > 0) {
         final String firstElement = elementList.get(0);
         // InScope for Date is unsupported at this analyzing
         if (Srl.isQuotedSingle(firstElement)) {
           plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
         } else {
           final String elementType = doDeriveNonQuotedLiteralTypeFromTestValue(firstElement);
           plainTypeName = "List" + grammar.buildGenericOneClassHint(elementType);
         }
       } else {
         plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
       }
     } else {
       plainTypeName = doDeriveNonQuotedLiteralTypeFromTestValue(testValue);
     }
   }
   return plainTypeName;
 }
  public void test_buildDisplaySql_date_default_bc_limit() {
    // ## Arrange ##
    String sql = "select * from where FOO_DATE = ?";
    Date fooDate = DfTypeUtil.toDate("BC0001/12/12 12:34:56");
    log(DfTypeUtil.toString(fooDate, "Gyyyy/MM/dd"));

    // ## Act ##
    String actual = createTarget().buildDisplaySql(sql, new Object[] {fooDate});

    // ## Assert ##
    log(actual);
    assertTrue(actual.contains("FOO_DATE = 'BC0001-12-12'"));
  }
Esempio n. 3
0
 @SuppressWarnings("unchecked")
 public <PROPERTY> PROPERTY analyzeString(Class<PROPERTY> javaType) {
   final Object obj = getColumnValue();
   return (PROPERTY) DfTypeUtil.toString(obj);
 }
 protected String formatUtilDate(Date date) {
   String pattern = "yyyy-MM-dd HH:mm:ss"; // for Oracle
   return DfTypeUtil.toString(date, pattern);
 }