Coverage Summary for Class: Util (net.sf.persism)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| Util | 100% (1/1) | 100% (10/10) | 79.6% (39/49) |
1 package net.sf.persism; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.math.BigDecimal; 6 import java.net.URL; 7 import java.nio.ByteBuffer; 8 import java.sql.*; 9 import java.sql.ResultSet; 10 import java.util.*; 11 import java.util.Date; 12 13 /** 14 * Comments for Util go here. 15 * 16 * @author Dan Howard 17 * @since 4/1/12 6:48 AM 18 */ 19 final class Util { 20 21 private static final Log log = Log.getLogger(Util.class); 22 23 private Util() { 24 } 25 26 27 static void rollback(Connection con) { 28 try { 29 if (con != null && !con.getAutoCommit()) { 30 con.rollback(); 31 } 32 } catch (SQLException e1) { 33 log.error(e1.getMessage(), e1); 34 } 35 36 } 37 38 static void cleanup(Statement st, ResultSet rs) { 39 try { 40 if (rs != null) { 41 rs.close(); 42 } 43 } catch (SQLException e) { 44 log.error(e.getMessage(), e); 45 } 46 try { 47 if (st != null) { 48 st.close(); 49 } 50 } catch (SQLException e) { 51 log.error(e.getMessage(), e); 52 } 53 } 54 55 static void cleanup(ResultSet rs) { 56 try { 57 if (rs != null) { 58 rs.close(); 59 } 60 } catch (SQLException e) { 61 log.error(e.getMessage(), e); 62 } 63 } 64 65 public static boolean containsColumn(ResultSet rs, String column) { 66 try { 67 rs.findColumn(column); 68 return true; 69 } catch (SQLException sqlex) { 70 } 71 return false; 72 } 73 74 public static String camelToTitleCase(String text) { 75 StringBuilder sb = new StringBuilder(); 76 77 for (int i = 0; i < text.length(); i++) { 78 char c = text.charAt(i); 79 if (i == 0) { 80 sb.append(c); 81 } else { 82 if (Character.isUpperCase(c)) { 83 sb.append(" "); 84 } 85 sb.append(c); 86 } 87 } 88 return sb.toString(); 89 } 90 91 public static String replaceAll(String text, char from, char to) { 92 StringBuilder sb = new StringBuilder(); 93 94 for (int i = 0; i < text.length(); i++) { 95 char c = text.charAt(i); 96 if (c == from) { 97 sb.append(to); 98 } else { 99 sb.append(c); 100 } 101 } 102 return sb.toString(); 103 } 104 105 static boolean isNotEmpty(String s) { 106 return !isEmpty(s); 107 } 108 109 static boolean isEmpty(String s) { 110 return s == null || s.trim().length() == 0; 111 } 112 113 114 public static <T> boolean isRecord(Class<T> objectClass) { 115 // Java 8 test for isRecord since class.isRecord doesn't exist in Java 8 116 Class<?> sup = objectClass.getSuperclass(); 117 while (!sup.equals(Object.class) ) { 118 if ("java.lang.Record".equals(sup.getName())) { 119 return true; 120 } 121 sup = sup.getSuperclass(); 122 } 123 return false; 124 } 125 126 127 128 }