| 34 | import org.slf4j.LoggerFactory; |
| 35 | |
| 36 | public abstract class SQLUtil { |
| 37 | private static final Logger LOG = LoggerFactory.getLogger(SQLUtil.class); |
| 38 | |
| 39 | private static final DateFormat[] timestamp_formats = |
| 40 | new DateFormat[] { |
| 41 | new SimpleDateFormat("yyyy-MM-dd"), |
| 42 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), |
| 43 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * Return a long from the given object Handles the different cases from the various DBMSs |
| 48 | * |
| 49 | * @param obj |
| 50 | * @return |
| 51 | */ |
| 52 | public static Long getLong(Object obj) { |
| 53 | if (obj == null) { |
| 54 | return (null); |
| 55 | } |
| 56 | |
| 57 | if (obj instanceof Long) { |
| 58 | return (Long) obj; |
| 59 | } else if (obj instanceof Integer) { |
| 60 | return ((Integer) obj).longValue(); |
| 61 | } else if (obj instanceof BigDecimal) { |
| 62 | return ((BigDecimal) obj).longValue(); |
| 63 | } |
| 64 | |
| 65 | LOG.warn("BAD BAD BAD: returning null because getLong does not support {}", obj.getClass()); |
| 66 | |
| 67 | return (null); |
| 68 | } |
| 69 | |
| 70 | public static Integer getInteger(Object obj) { |
| 71 | if (obj == null) { |
| 72 | return (null); |
| 73 | } |
| 74 | |
| 75 | if (obj instanceof Integer) { |
| 76 | return (Integer) obj; |
| 77 | } else if (obj instanceof Long) { |
| 78 | return ((Long) obj).intValue(); |
| 79 | } else if (obj instanceof BigDecimal) { |
| 80 | return ((BigDecimal) obj).intValue(); |
| 81 | } |
| 82 | |
| 83 | LOG.warn("BAD BAD BAD: returning null because getInteger does not support {}", obj.getClass()); |
| 84 | |
| 85 | return (null); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Return a double from the given object Handles the different cases from the various DBMSs |
| 90 | * |
| 91 | * @param obj |
| 92 | * @return |
| 93 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected