protected String doDeriveNonQuotedLiteralTypeFromTestValue(String testValue) {
   final String plainTypeName;
   if (Srl.contains(testValue, ".")) {
     BigDecimal decimalValue = null;
     try {
       decimalValue = DfTypeUtil.toBigDecimal(testValue);
     } catch (NumberFormatException ignored) {
     }
     if (decimalValue != null) {
       plainTypeName = "BigDecimal";
     } else { // means unknown type
       plainTypeName = "String";
     }
   } else {
     Long longValue = null;
     try {
       longValue = DfTypeUtil.toLong(testValue);
     } catch (NumberFormatException ignored) {
     }
     if (longValue != null) {
       if (longValue > Long.valueOf(Integer.MAX_VALUE)) {
         plainTypeName = "Long";
       } else {
         plainTypeName = "Integer";
       }
     } else {
       if (testValue.equalsIgnoreCase("true") || testValue.equalsIgnoreCase("false")) {
         plainTypeName = "Boolean";
       } else { // means unknown type
         plainTypeName = "String";
       }
     }
   }
   return plainTypeName;
 }
 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;
 }
Пример #3
0
 @SuppressWarnings("unchecked")
 public <PROPERTY> PROPERTY analyzeDate(Class<PROPERTY> javaType) {
   final Object obj = getColumnValue();
   if (Time.class.isAssignableFrom(javaType)) {
     return (PROPERTY) DfTypeUtil.toTime(obj);
   } else if (Timestamp.class.isAssignableFrom(javaType)) {
     return (PROPERTY) DfTypeUtil.toTimestamp(obj);
   } else {
     return (PROPERTY) DfTypeUtil.toDate(obj);
   }
 }
  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'"));
  }
 /** @return The display string of all parameters. (NotNull) */
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append(DfTypeUtil.toClassTitle(this)).append(":");
   sb.append(xbuildColumnString());
   return sb.toString();
 }
Пример #6
0
 public void bindValue(Connection conn, CallableStatement cs, String parameterName, Object value)
     throws SQLException {
   if (value == null) {
     setNull(cs, parameterName);
   } else {
     cs.setInt(parameterName, DfTypeUtil.toPrimitiveInt(value));
   }
 }
Пример #7
0
 public void bindValue(Connection conn, PreparedStatement ps, int index, Object value)
     throws SQLException {
   if (value == null) {
     setNull(ps, index);
   } else {
     ps.setInt(index, DfTypeUtil.toPrimitiveInt(value));
   }
 }
Пример #8
0
 protected void checkDowncast(Entity entity) {
   assertObjectNotNull("entity", entity);
   final Class<?> entityType = getEntityType();
   final Class<?> targetType = entity.getClass();
   if (!entityType.isAssignableFrom(targetType)) {
     final String titleName = DfTypeUtil.toClassTitle(entityType);
     String msg = "The entity should be " + titleName + " but it was: " + targetType;
     throw new IllegalStateException(msg);
   }
 }
  // ===================================================================================
  //                                                                        BindVariable
  //                                                                        ============
  public void test_getBindVariableText_dateFormat_basic() {
    // ## Arrange ##
    Date date = DfTypeUtil.toDate("2009-10-27");

    // ## Act ##
    String actual = createTarget().getBindVariableText(date);

    // ## Assert ##
    assertEquals("'2009-10-27'", actual);
  }
Пример #10
0
 @SuppressWarnings("unchecked")
 public <PROPERTY> PROPERTY analyzeBinary(Class<PROPERTY> javaType) {
   final Object obj = getColumnValue();
   if (obj == null) {
     return null;
   }
   if (obj instanceof Serializable) {
     return (PROPERTY) DfTypeUtil.toBinary((Serializable) obj);
   }
   throw new UnsupportedOperationException("unsupported binary type: " + obj.getClass());
 }
  public void test_getBindVariableText_dateFormat_custom() {
    // ## Arrange ##
    String format = "date $df:{yyyy-MM-dd}";
    Date date = DfTypeUtil.toDate("2009-10-27");

    // ## Act ##
    String actual = createTargetWithDateFormat(format).getBindVariableText(date);

    // ## Assert ##
    assertEquals("date '2009-10-27'", actual);
  }
  public void test_getBindVariableText_timestampFormat_custom() {
    // ## Arrange ##
    String format = "timestamp $df:{yyyy-MM-dd HH:mm:ss.SSS}";
    Timestamp timestamp = DfTypeUtil.toTimestamp("2009-10-27 16:22:23.123");

    // ## Act ##
    String actual = createTargetWithTimestampFormat(format).getBindVariableText(timestamp);

    // ## Assert ##
    assertEquals("timestamp '2009-10-27 16:22:23.123'", actual);
  }
  public void test_buildDisplaySql_date_format() {
    // ## Arrange ##
    String sql = "select * from where FOO_DATE = ?";
    Date fooDate = DfTypeUtil.toDate("2010/12/12 12:34:56");

    // ## Act ##
    String actual =
        createTargetWithDateFormat("yyyy@MM@dd").buildDisplaySql(sql, new Object[] {fooDate});

    // ## Assert ##
    log(actual);
    assertTrue(actual.contains("FOO_DATE = '2010@12@12'"));
  }
Пример #14
0
 @SuppressWarnings("unchecked")
 public <PROPERTY> PROPERTY analyzeUUID(Class<PROPERTY> javaType) {
   final Object obj = getColumnValue();
   return (PROPERTY) DfTypeUtil.toUUID(obj);
 }
 protected String formatUtilDate(Date date) {
   String pattern = "yyyy-MM-dd HH:mm:ss"; // for Oracle
   return DfTypeUtil.toString(date, pattern);
 }
Пример #16
0
 public Object getValue(ResultSet rs, int index) throws SQLException {
   return DfTypeUtil.toInteger(rs.getObject(index));
 }
 protected Boolean toBoolean(Object obj) {
   return DfTypeUtil.toBoolean(obj);
 }
Пример #18
0
 protected static BigDecimal ctb(Object value) { // convertToBigDecimal
   return DfTypeUtil.toBigDecimal(value);
 }
Пример #19
0
 public Object getValue(CallableStatement cs, String parameterName) throws SQLException {
   return DfTypeUtil.toInteger(cs.getObject(parameterName));
 }
Пример #20
0
 public Object getValue(CallableStatement cs, int index) throws SQLException {
   return DfTypeUtil.toInteger(cs.getObject(index));
 }
Пример #21
0
 public Object getValue(ResultSet rs, String columnName) throws SQLException {
   return DfTypeUtil.toInteger(rs.getObject(columnName));
 }
Пример #22
0
 protected static Integer cti(Object value) { // convertToInteger
   return DfTypeUtil.toInteger(value);
 }
Пример #23
0
 protected static Long ctl(Object value) { // convertToLong
   return DfTypeUtil.toLong(value);
 }
 protected Date toUtilDate(Date date) {
   return DfTypeUtil.toDate(date); // if sub class, re-create as pure date
 }
Пример #25
0
 @SuppressWarnings("unchecked")
 protected static <NUMBER extends Number> NUMBER ctn(
     Object value, Class<NUMBER> type) { // convertToNumber
   return (NUMBER) DfTypeUtil.toNumber(value, type);
 }
 @SuppressWarnings("unchecked")
 protected <NUMBER extends Number> NUMBER toNumber(Object obj, Class<NUMBER> type) {
   return (NUMBER) DfTypeUtil.toNumber(obj, type);
 }