| 1 51 package org.bsf.listOfValues.util; 52 53 import java.sql.ResultSet ; 54 import java.sql.SQLException ; 55 56 63 public class LovTypeManager { 64 public static final String BOOLEAN_TYPE = "java.lang.Boolean"; 66 public static final String DOUBLE_TYPE = "java.lang.Double"; 67 public static final String FLOAT_TYPE = "java.lang.Float"; 68 public static final String INTEGER_TYPE = "java.lang.Integer"; 69 public static final String LONG_TYPE = "java.lang.Long"; 70 public static final String STRING_TYPE = "java.lang.String"; 71 public static final String DATE_TYPE = "java.util.Date"; 72 public static final String SQL_DATE_TYPE = "java.sql.Date"; 73 74 83 public static Integer getInteger( ResultSet p_rs, int p_columnIndex ) throws SQLException { 84 if ( p_rs.getBigDecimal( p_columnIndex ) != null ) { 85 return new Integer ( p_rs.getInt( p_columnIndex ) ); 86 } else { 87 return null; 88 } 89 } 90 91 100 public static Long getLong( ResultSet p_rs, int p_columnIndex ) throws SQLException { 101 if ( p_rs.getBigDecimal( p_columnIndex ) != null ) { 102 return new Long ( p_rs.getLong( p_columnIndex ) ); 103 } else { 104 return null; 105 } 106 } 107 108 116 public static String getString( ResultSet p_rs, int p_columnIndex ) throws SQLException { 117 return p_rs.getString( p_columnIndex ); 118 } 119 120 130 public static Boolean getBoolean( ResultSet p_rs, int p_columnIndex ) throws SQLException { 131 if ( p_rs.getString( p_columnIndex ) != null ) { 132 return p_rs.getString( p_columnIndex ).equals( "0" ) ? Boolean.FALSE : Boolean.TRUE; 133 } else { 134 return null; 135 } 136 } 137 138 147 public static Double getDouble( ResultSet p_rs, int p_columnIndex ) throws SQLException { 148 if ( p_rs.getBigDecimal( p_columnIndex ) != null ) { 149 return new Double ( p_rs.getDouble( p_columnIndex ) ); 150 } else { 151 return null; 152 } 153 } 154 155 164 public static Float getFloat( ResultSet p_rs, int p_columnIndex ) throws SQLException { 165 if ( p_rs.getBigDecimal( p_columnIndex ) != null ) { 166 return new Float ( p_rs.getFloat( p_columnIndex ) ); 167 } else { 168 return null; 169 } 170 } 171 172 181 public static java.util.Date getDate( ResultSet p_rs, int p_columnIndex ) throws SQLException { 182 if ( p_rs.getDate( p_columnIndex ) != null ) { 183 return new java.util.Date ( p_rs.getDate( p_columnIndex ).getTime() ); 184 } else { 185 return null; 186 } 187 } 188 189 198 public static java.sql.Date getSqlDate( ResultSet p_rs, int p_columnIndex ) throws SQLException { 199 if ( p_rs.getDate( p_columnIndex ) != null ) { 200 return new java.sql.Date ( p_rs.getDate( p_columnIndex ).getTime() ); 201 } else { 202 return null; 203 } 204 } 205 206 219 public static Object getObjectOfType( String p_type, ResultSet p_rs, int p_columnIndex ) throws SQLException { 220 if ( p_type == null || p_rs == null ) { 221 String msg = "Need a non null typeOID and resultset to return an Object..."; 222 throw new IllegalArgumentException ( msg ); 223 } 224 225 if ( INTEGER_TYPE.equalsIgnoreCase( p_type ) ) { 226 return getInteger( p_rs, p_columnIndex ); 227 } else if ( LONG_TYPE.equalsIgnoreCase( p_type ) ) { 228 return getLong( p_rs, p_columnIndex ); 229 } else if ( STRING_TYPE.equalsIgnoreCase( p_type ) ) { 230 return getString( p_rs, p_columnIndex ); 231 } else if ( BOOLEAN_TYPE.equalsIgnoreCase( p_type ) ) { 232 return getBoolean( p_rs, p_columnIndex ); 233 } else if ( DOUBLE_TYPE.equalsIgnoreCase( p_type ) ) { 234 return getDouble( p_rs, p_columnIndex ); 235 } else if ( FLOAT_TYPE.equalsIgnoreCase( p_type ) ) { 236 return getFloat( p_rs, p_columnIndex ); 237 } else if ( DATE_TYPE.equalsIgnoreCase( p_type ) ) { 238 return getDate( p_rs, p_columnIndex ); 239 } else if ( SQL_DATE_TYPE.equalsIgnoreCase( p_type ) ) { 240 return getSqlDate( p_rs, p_columnIndex ); 241 } 242 243 throw new IllegalArgumentException ( "Unknown type " + p_type ); 244 } 245 } | Popular Tags |