// TODO H2 single-quotes literal values, which is useful.
// MySQL does not single-quote literal values so its hard to
// differentiate a FUNCTION/VARIABLE from a literal value.
// function / variable
Pattern functionDefault = Pattern.compile("[^'].*[^']");
if (functionDefault.matcher(defaultValue).matches()) {
// hard to validate this since its in the database
// assume it is good
return true;
}
// STRING
if (modelClass == String.class) {
Pattern stringDefault = Pattern.compile("'(.|\\n)*'");
return stringDefault.matcher(defaultValue).matches();
}
String dateRegex = "[0-9]{1,4}[-/\\.][0-9]{1,2}[-/\\.][0-9]{1,2}";
String timeRegex = "[0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}";
// TIMESTAMP
if (modelClass == java.util.Date.class
|| modelClass == java.sql.Timestamp.class) {
// this may be a little loose....
// 00-00-00 00:00:00
// 00/00/00T00:00:00
// 00.00.00T00:00:00
Pattern pattern = Pattern.compile("'" + dateRegex + "." + timeRegex + "'");
return pattern.matcher(defaultValue).matches();
}
// DATE
if (modelClass == java.sql.Date.class) {
// this may be a little loose....
// 00-00-00
// 00/00/00
// 00.00.00
Pattern pattern = Pattern.compile("'" + dateRegex + "'");
return pattern.matcher(defaultValue).matches();
}
// TIME
if (modelClass == java.sql.Time.class) {
// 00:00:00
Pattern pattern = Pattern.compile("'" + timeRegex + "'");
return pattern.matcher(defaultValue).matches();
}
// NUMBER
if (Number.class.isAssignableFrom(modelClass)) {
// strip single quotes